Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CredentialsProvider class added to support password rotation #2261

Merged
merged 24 commits into from Nov 10, 2022

Conversation

barshaul
Copy link
Contributor

@barshaul barshaul commented Jul 5, 2022

Pull Request check-list

Please make sure to review and check all of these items:

  • Does $ tox pass with this change (including linting)?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

Instead of providing a simple pair of username+password, the users can create a CredentialsProvider object with their own credentials supplier function, and have redis-py call it whenever a new connection is created.
By doing so, users will be able to fetch the current password and rotate credentials without having to create a new client.

See related feature request in Lettuce: redis/lettuce#1774

@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2022

Codecov Report

Base: 92.04% // Head: 92.12% // Increases project coverage by +0.07% 🎉

Coverage data is based on head (4c82551) compared to base (fb64743).
Patch coverage: 97.28% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2261      +/-   ##
==========================================
+ Coverage   92.04%   92.12%   +0.07%     
==========================================
  Files         110      113       +3     
  Lines       28746    29063     +317     
==========================================
+ Hits        26460    26773     +313     
- Misses       2286     2290       +4     
Impacted Files Coverage Δ
redis/cluster.py 89.85% <ø> (ø)
redis/asyncio/connection.py 86.61% <84.61%> (+0.22%) ⬆️
redis/connection.py 86.42% <85.71%> (+0.11%) ⬆️
redis/credentials.py 91.66% <91.66%> (ø)
tests/test_credentials.py 98.44% <98.44%> (ø)
tests/test_asyncio/test_credentials.py 98.73% <98.73%> (ø)
redis/__init__.py 90.90% <100.00%> (+0.43%) ⬆️
redis/asyncio/client.py 92.28% <100.00%> (+0.01%) ⬆️
redis/asyncio/cluster.py 90.77% <100.00%> (+0.01%) ⬆️
redis/client.py 89.12% <100.00%> (+0.02%) ⬆️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@barshaul barshaul force-pushed the creds_provider branch 2 times, most recently from 3affd60 to 7b958e0 Compare July 5, 2022 15:59
@barshaul barshaul marked this pull request as ready for review July 5, 2022 16:22
Copy link
Collaborator

@dvora-h dvora-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except these tiny comments - it looks great!

redis/connection.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
@barshaul
Copy link
Contributor Author

Added type hints + moved CredentialsProvider to a separate file

redis/credentials.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
@barshaul
Copy link
Contributor Author

barshaul commented Aug 9, 2022

@chayim @dvora-h - Finished round, ready for review :). Tests failed here from some internal error, in my fork it seems that tests are passing:
barshaul#16 (comment)

redis/client.py Outdated Show resolved Hide resolved
redis/client.py Outdated Show resolved Hide resolved
redis/cluster.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
redis/credentials.py Outdated Show resolved Hide resolved
@chayim
Copy link
Contributor

chayim commented Aug 11, 2022

@barshaul Thanks as always. I left a tonne of comments - and will give it another once over. As part of this, I suggest a MockCredentialProvider or similar. It would be nice to provide an example of a standard provider, perhaps implemented by a single (useless) function. This is how @dvora-h initially looked at this PR in fact.

@barshaul
Copy link
Contributor Author

@chayim Finished round. I left some of the reviews open with questions

redis/connection.py Outdated Show resolved Hide resolved
redis/connection.py Outdated Show resolved Hide resolved
@barshaul
Copy link
Contributor Author

barshaul commented Nov 2, 2022

@chayim @dvora-h @akx - finished round

@dvora-h
Copy link
Collaborator

dvora-h commented Nov 8, 2022

@barshaul I think that after adding async support we are good to go.

@dvora-h
Copy link
Collaborator

dvora-h commented Nov 10, 2022

LGTM now!

@dvora-h dvora-h merged commit bb06ccd into redis:master Nov 10, 2022
sazzad16 added a commit to redis/jedis that referenced this pull request Feb 14, 2023
References:

1. #1602 and related PRs. Current PR is probably better than handling in JedisFactory 
2. redis/redis-py#2261 - main reason of this PR 
3. redis/lettuce#1774 
4. #632 

---

* Introduce credentials provider

* use volatile

* Test in Sentineled mode

* Support CharSequence in DefaultRedisCredentials

* Added doc for prepare() and cleanUp()

* Test the provider interface

* Added example

* Removed deprecations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants