mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
* fix(secretsmanager): rotate secrets that an AWS service manages RotateSecret required a rotation Lambda for every secret, so a secret RDS manages through ManageMasterUserPassword could never enable rotation: InvalidRequestException: You tried to enable rotation on a secret that doesn't already have a Lambda function ARN configured and you didn't include such an ARN as a parameter in this call. AWS rotates those secrets itself, so they carry no Lambda at all. It accepts RotateSecret with rotation rules alone, and refuses a Lambda ARN outright: "Rotation Lambda ARN is not supported for a service-managed secret." Key the behaviour off ownership rather than the rds! name prefix, since anyone may create an ordinary secret called rds!something and that must not grant it managed-rotation semantics: - Secret carries an owningService, set by floci services only and never settable over the wire - RDS marks the master user secret it creates as owned by rds, with the two tags AWS attaches to it - RotateSecret needs no Lambda for an owned secret, rejects one, and skips the Lambda rotation lifecycle that has nothing to invoke - DescribeSecret and ListSecrets report OwningService, and the owning-service ListSecrets filter matches on it instead of always returning nothing Covered by unit tests and by a CLI compatibility test that walks the whole path: create the instance with --manage-master-user-password, describe the secret it produced, then rotate it with rules and no Lambda ARN. Behaviour confirmed against a live AWS account: a db.t3.micro postgres instance created with --manage-master-user-password, then describe-secret and rotate-secret against the secret it produced. * fix(secretsmanager): keep managed rotation across restarts, report a real version Two problems in the previous commit: A secret persisted before ownership tracking deserializes without an owning service, so after an upgrade RotateSecret went on rejecting the Lambda-free call these secrets are rotated with. RDS backfills ownership at startup from the instances that name those secrets: RDS state is what makes a secret managed, so that is what the backfill reads, never the secret's name. RotateSecret answered a service-managed rotation with the request token as VersionId, while nothing stages a version for that token, so reading the advertised version failed with "can't find the specified secret version". Report the current version instead, which exists and holds the value a caller reads back. * fix(secretsmanager): back-fill ownership per account, stop claiming a rotation The startup backfill ran outside any request, so the secrets store resolved the default account while the instances it read span every account. Secrets owned by another account were left unmarked, and a same-named default-account secret could be written instead. The secret's ARN names its own account and region, so markOwnedByService takes the ARN and addresses that account's store directly. RotateSecret also recorded LastRotatedDate for a service-managed secret while neither the master password nor the stored value changed, so the secret claimed a rotation that GetSecretValue and the database would contradict. floci does not re-issue the credential, so it no longer reports one: rotation is enabled and scheduled, and NextRotationDate still follows from the rules. * fix(rds): never fail startup on the master user secret backfill The backfill reads persisted state at StartupEvent, so a storage error while scanning instances would have stopped the emulator from starting over work that is not needed to serve requests. It now logs and moves on, per instance and for the scan as a whole. * fix(rds): run the secret ownership backfill after storage is loaded The backfill observed StartupEvent, as does EmulatorLifecycle.onStart, which calls storageFactory.loadAll(). Two observers of one event have no ordering between them, so under hybrid or WAL storage the backfill could write ownership into memory that the reload then replaced with the older on-disk secret, leaving rotation rejected exactly where the backfill exists to help. It now hangs off restorePersistedRuntime(), which the lifecycle already calls after loadAll() for the same reason, alongside the other persisted-state fixups.
3.2 KiB
3.2 KiB
Secrets Manager
Protocol: JSON 1.1 (X-Amz-Target: secretsmanager.*)
Endpoint: POST http://localhost:4566/
Supported Actions
| Action | Description |
|---|---|
CreateSecret |
Create a new secret |
GetSecretValue |
Retrieve the current secret value |
PutSecretValue |
Update the secret value (new version) |
UpdateSecret |
Update secret metadata or value |
DescribeSecret |
Get secret metadata and version info |
ListSecrets |
List all secrets |
DeleteSecret |
Delete a secret (with recovery window) |
RestoreSecret |
- |
RotateSecret |
Trigger secret rotation, via a Lambda or by the owning service |
TagResource |
Tag a secret |
UntagResource |
Remove tags |
ListSecretVersionIds |
List all versions of a secret |
GetResourcePolicy |
Get the resource policy |
GetRandomPassword |
Generate a random password |
BatchGetSecretValue |
Retrieve multiple secret values in one call |
DeleteResourcePolicy |
Remove the resource policy |
PutResourcePolicy |
Attach a resource policy |
UpdateSecretVersionStage |
Move a staging label between versions |
Configuration
| Variable | Default | Description |
|---|---|---|
FLOCI_SERVICES_SECRETSMANAGER_ENABLED |
true |
Enable or disable the service |
FLOCI_SERVICES_SECRETSMANAGER_DEFAULT_RECOVERY_WINDOW_DAYS |
30 |
Days before a deleted secret is permanently purged |
Examples
export AWS_ENDPOINT_URL=http://localhost:4566
# Create a string secret
aws secretsmanager create-secret \
--name /app/database-url \
--secret-string "postgresql://admin:secret@localhost/mydb" \
--endpoint-url $AWS_ENDPOINT_URL
# Create a JSON secret
aws secretsmanager create-secret \
--name /app/api-keys \
--secret-string '{"stripe":"sk_test_xxx","sendgrid":"SG.xxx"}' \
--endpoint-url $AWS_ENDPOINT_URL
# Retrieve a secret
aws secretsmanager get-secret-value \
--secret-id /app/database-url \
--endpoint-url $AWS_ENDPOINT_URL
# Update a secret
aws secretsmanager put-secret-value \
--secret-id /app/database-url \
--secret-string "postgresql://admin:new-password@localhost/mydb" \
--endpoint-url $AWS_ENDPOINT_URL
# List secrets
aws secretsmanager list-secrets --endpoint-url $AWS_ENDPOINT_URL
# Delete (with recovery window)
aws secretsmanager delete-secret \
--secret-id /app/database-url \
--recovery-window-in-days 7 \
--endpoint-url $AWS_ENDPOINT_URL
# Delete immediately (no recovery)
aws secretsmanager delete-secret \
--secret-id /app/database-url \
--force-delete-without-recovery \
--endpoint-url $AWS_ENDPOINT_URL
# Generate a random password
aws secretsmanager get-random-password \
--password-length 24 \
--exclude-punctuation \
--endpoint-url $AWS_ENDPOINT_URL
# Batch-fetch multiple secrets in one call
aws secretsmanager batch-get-secret-value \
--secret-id-list /app/database-url /app/api-keys \
--endpoint-url $AWS_ENDPOINT_URL
# Move the AWSCURRENT label to a different version (e.g. during a rotation)
aws secretsmanager update-secret-version-stage \
--secret-id /app/database-url \
--version-stage AWSCURRENT \
--move-to-version-id <new-version-id> \
--remove-from-version-id <old-version-id> \
--endpoint-url $AWS_ENDPOINT_URL