You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding cache refresh logic with new URL RefreshNow parameter (#65)
*Issue #, if available:* Closes 12
*Description of changes:*
Supports new refreshNow parameter in URL requests to the agent, setting
this parameter to true will call Secrets Manger to get latest value of
secret
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
---------
Co-authored-by: Caitlin Russell <caitarus@amazon.com>
Copy file name to clipboardexpand all lines: README.md
+88
Original file line number
Diff line number
Diff line change
@@ -345,7 +345,95 @@ def get_secret():
345
345
# Handle network errors
346
346
raiseException(f"Error: {e}")
347
347
```
348
+
------
349
+
350
+
**Force-refresh secrets with `RefreshNow`**
351
+
352
+
Learn how to use the refreshNow parameter to force the Secrets Manager Agent (SMA) to refresh secret values.
353
+
354
+
Secrets Manager Agent uses an in-memory cache to store secret values, which it refreshes periodically. By default, this refresh occurs when you request a secret after the Time to Live (TTL) has expired, typically every 300 seconds. However, this approach can sometimes result in stale secret values, especially if a secret rotates before the cache entry expires.
355
+
356
+
To address this limitation, Secrets Manager Agent supports a parameter called `refreshNow` in the URL. You can use this parameter to force an immediate refresh of a secret's value, bypassing the cache and ensuring you have the most up-to-date information.
357
+
358
+
Default behavior (without `refreshNow`):
359
+
- Uses cached values until TTL expires
360
+
- Refreshes secrets only after TTL (default 300 seconds)
361
+
- May return stale values if secrets rotate before the cache expires
362
+
363
+
Behavior with `refreshNow=true`:
364
+
- Bypasses the cache entirely
365
+
- Retrieves the latest secret value directly from Secrets Manager
366
+
- Updates the cache with the fresh value and resets the TTL
367
+
- Ensures you always get the most current secret value
368
+
369
+
By using the `refreshNow` parameter, you can ensure that you're always working with the most current secret values, even in scenarios where frequent secret rotation is necessary.
370
+
371
+
## `refreshNow` parameter behavior
372
+
373
+
`refreshNow` set to `true`:
374
+
- If Secrets Manager Agent can't retrieve the secret from Secrets Manager, it returns an error and does not update the cache.
375
+
376
+
`refreshNow` set to `false` or not specified:
377
+
- Secrets Manager Agent follows its default behavior:
378
+
- If the cached value is fresher than the TTL, Secrets Manager Agent returns the cached value.
379
+
- If the cached value is older than the TTL, Secrets Manager Agent makes a call to Secrets Manager.
380
+
381
+
## Using the refreshNow parameter
382
+
383
+
To use the `refreshNow` parameter, include it in the URL for the Secrets Manager Agent GET request.
384
+
385
+
### Example - Secrets Manager Agent GET request with refreshNow parameter
386
+
387
+
> **Important**: The default value of `refreshNow` is `false`. When set to `true`, it overrides the TTL specified in the Secrets Manager Agent configuration file and makes an API call to Secrets Manager.
388
+
389
+
#### [ curl ]
390
+
391
+
The following curl example shows how force Secrets Manager Agent to refresh the secret. The example relies on the SSRF being present in a file, which is where it is stored by the install script.
The following Python example shows how to get a secret from the Secrets Manager Agent. The example relies on the SSRF being present in a file, which is where it is stored by the install script.
403
+
404
+
```python
405
+
import requests
406
+
import json
348
407
408
+
# Function that fetches the secret from Secrets Manager Agent for the provided secret id.
0 commit comments