-
Notifications
You must be signed in to change notification settings - Fork 28
The decorators do not refresh the cache #27
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
Comments
We are looking into the request and will share more details. |
Is there any update on this? I am also facing this issue. We have secret rotation setup on our database, and the cache manager does refresh the value of the secret on exception or even when the TTL has elapsed. |
We just ran into this with the same (AWS Rotate Secret) and had to directly/manually manage the password failure. For our use case, we're in Django, so we use I'm not sure if there's a good "general" solution for this because most likely it would involve an SQS notification and then SecretsCache would have to subscribe to that. |
@nitsujri Can you share some sample code for that? I am struggling with the same problem. |
@ibraheem-111 Yeah this discussion helped me open source our library: https://github.com/jenfi-eng/dj-db-rotated-secret The code that pulls the secret: # DJ_DB_ROTATED_SECRET_FUNC points wherever this function lives.
def get_db_creds_now():
return SecretsHelper.by_name_json(f"/{core_network_name}/RDS_CREDENTIALS", break_cache=True)
# secrets_helper.py
import json
from aws_secretsmanager_caching import SecretCache
class SecretsHelper:
cache = SecretCache()
@classmethod
def by_name(cls, name, break_cache=False):
if break_cache:
cls.cache.refresh_secret_now(name)
return cls.cache.get_secret_string(name)
@classmethod
def by_name_json(cls, name, break_cache=False):
secret_json_str = cls.by_name(name, break_cache)
return json.loads(secret_json_str) The above library combined with this code gives us rotation protection on both our Website & background Workers. |
While secrets being stale after rotation is expected behavior and therefore not considered a bug, the issue of the decorators not refreshing secrets on subsequent calls is fixed by #59 |
The decorators capture their secrets at import time, and do not re-get their secrets when the target function is called. So the cache logic doesn't have a chance to run again, and the values stay potentially stale. This code illustrates the problem:
The text was updated successfully, but these errors were encountered: