Files
floci/docs/services
Michal Schreiber 23015a7475 fix(secretsmanager,rds): rotate secrets that an AWS service manages (#2378)
* 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.
2026-08-18 17:38:11 -04:00
..
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00