Commit Graph
11 Commits
Author SHA1 Message Date
Vũ Thế Huy ce0933be9b feat(redshift): rotate managed master passwords (#6505)
* feat(redshift): rotate managed master passwords

* fix(redshift): serialize managed secret rotation

* fix(redshift): address managed secret rotation review

* fix(redshift): keep concurrent rotation retries idempotent

* fix: defer managed secret guard until rotation reservation succeeds

* fix: preserve secret versions saved during rotation reservation

* fix: guarantee required character types in serverless passwords

* revert: defer serverless password character types fix to dedicated PR

* test(secretsmanager): extract blocking reserve helper across rotators
2026-10-26 09:30:08 -04:00
Priamo Germosen 6d7d85f0f8 fix(lambda): enforce function policies on cross-account calls (#5476)
Under IAM enforcement, a caller whose own policy allowed lambda:InvokeFunction could invoke
another account's function by ARN even when that function's policy granted nothing, and
RotateSecret could be pointed at another account's function the same way. Three things combined:
there was no resource-policy provider for Lambda, so the call was judged as same-account; the
function name was cut at its first colon, so an ARN was evaluated as function:arn in the caller's
account, where no Allow or Deny written for the function could match; and the invoke followed the
account in the ARN.

- LambdaResourcePolicyProvider supplies a function's policy statements and the account its ARN
  names, also when the function has no policy, so a call to another account's function needs that
  function's policy to allow the caller as well as the caller's own policy. It is keyed on the
  ARN, so RotateSecret's check on its rotation function, made under the secretsmanager scope,
  sees it too.
- ResourceArnBuilder evaluates each call against the function it acts on. An invoke runs in the
  account and Region a full or partial ARN names, as the version or alias it names in the function
  name or in Qualifier, since Lambda authorizes a qualified call against the qualified ARN.
  GetFunction, GetFunctionConfiguration and ListDurableExecutionsByFunction read a qualified full
  ARN in the account it names, so they are evaluated there too, and a read of another account's
  function needs its policy as on AWS. Every other route acts on the caller's own function of that
  name, so it is evaluated against that function, unqualified because not all of their handlers
  act on the qualifier.
- An invoke by partial ARN runs in the account it names, as one by full ARN already did.
- RotateSecret looks its function up where the rotation runs it: in the ARN's account, and as the
  version or alias the ARN names.
2026-10-11 21:47:27 -05:00
Priamo Germosen a5379cd5d8 fix(secretsmanager): refuse a rotation function in another Region with InvalidParameterException (#4873)
Follow-up from the review of #4768.

A well-formed full function ARN in another Region passed the reference check,
then Lambda's lookup refused it with InvalidParameterValueException ("Region
'us-west-2' in ARN does not match request region 'us-east-1'") and RotateSecret
rethrew that unchanged. InvalidParameterValueException is not an error
RotateSecret declares, so an SDK client could not type the refusal.

The Region is now checked with the rest of the reference, before the caller's
lambda:InvokeFunction check, and refused with InvalidParameterException and
Lambda's reason in the message, like a reference Lambda cannot parse. Checked
only at the lookup, it came after the caller check, so under IAM enforcement a
caller not allowed to invoke that ARN got AccessDeniedException for a reference
that is invalid whoever sends it. Any other 400 Lambda gives at the lookup is
mapped the same way, through one helper; a missing function is still
AccessDeniedException and anything else still passes through. The secret is
left as it was.

Neither the Secrets Manager User Guide nor the API Reference says which error a
function in another Region gets, or that the function must share the secret's
Region. InvalidParameterException is the one RotateSecret declares for an
invalid parameter value.

An integration test runs RotateSecret against the real Lambda service with a
us-west-2 function ARN from us-east-1; it fails on main with
InvalidParameterValueException. Unit tests check the Region refusal comes
before the caller check and keeps a previously configured function, and that a
Lambda 400 at the lookup maps too. docs/services/secrets-manager.md describes it.
2026-10-02 07:45:59 -05:00
Priamo Germosen a075e25290 fix(secretsmanager): require lambda:InvokeFunction for RotateSecret under IAM enforcement (#4697)
AWS requires the caller of RotateSecret to hold lambda:InvokeFunction on the rotation function as
well as secretsmanager:RotateSecret (Secrets Manager API Reference, RotateSecret, "Required
permissions"). Floci checked only RotateSecret and then invoked the function in-process, so under
IAM enforcement a caller refused lambda:InvokeFunction could still run any function it could name by
configuring it as a rotation function.

RotateSecret now authorizes the invoke for the same caller the filter evaluated, against the exact
function the rotation will run (the requested ARN, or the one already configured, with a bare name
or partial ARN resolved in the secret's account and Region), and the rotation then invokes that same
full ARN. Invoking the reference as given would let a name or partial ARN resolve in whatever account
the rotation thread sees, so the function checked and the function run could differ. The check runs
before the function is
looked up or the secret changed, so a refused call leaves nothing configured for the scheduled sweep
to invoke later. A refusal is reported as Secrets Manager reports one: AccessDeniedException with
HTTP 400 (API Reference, "Common Errors").

A rotation function that does not exist is now reported the way AWS reports it too:
AccessDeniedException, HTTP 400, "Secrets Manager cannot invoke the specified Lambda function. Ensure
that the function policy grants access to the principal secretsmanager.amazonaws.com.", with the
secret's rotation settings left as they were. It used to be ResourceNotFoundException with HTTP 404.

The caller credential reaches the handler through IamEnforcementFilter.requestAuthorization, the
filter's own header-or-presigned logic, so a presigned request is checked the same way. Requests
with no caller credential, such as API Gateway service integrations, and rotations started by the
scheduled sweep are unchanged. With IAM enforcement off the caller check does not run; the
missing-function response above applies either way.
2026-09-29 18:54:38 -05:00
Abhigya 33d17c0146 feat(secretsmanager): add the five missing actions and correct response fidelity (#3711)
* feat(secretsmanager): add the five missing actions and correct response fidelity

Secrets Manager implemented 18 of the 23 actions in the API reference. This
adds the remaining five and corrects a number of response and validation
divergences found by working through each operation's reference page.

New actions:

- CancelRotateSecret turns rotation off and reports the half-built AWSPENDING
  version an interrupted rotation left behind. The staging labels are left
  alone, as AWS leaves them, because that version id is the only handle on a
  stale AWSPENDING - and a stale AWSPENDING that is not also AWSCURRENT makes
  every later RotateSecret fail with "a previous rotation isn't complete".
- ValidateResourcePolicy reports wildcard principals under the same
  REFLEXIVE_PRINCIPAL_CHECK name AWS uses. BlockPublicPolicy on
  PutResourcePolicy now enforces the same check.
- ReplicateSecretToRegions, RemoveRegionsFromReplication and
  StopReplicationToReplica, backed by a replication model on Secret. Replicas
  carry the primary's ARN with the Region swapped, track later writes to the
  primary, and are read-only; a primary that still has replicas cannot be
  deleted.

Scheduled rotation now fires. RotationRules were stored and echoed back but
never acted on, so AutomaticallyAfterDays and ScheduleExpression described a
schedule that could not happen. A background sweep rotates secrets whose
NextRotationDate has passed, reusing the EventBridge Scheduler expression
parser for rate() and cron(). The schedule advances when a rotation is
dispatched rather than when it succeeds, so a failing rotation cannot pin the
sweep on one secret forever.

Response fidelity:

- ListSecrets honours SortBy, SortOrder and IncludePlannedDeletion, and its
  entries carry SecretVersionsToStages, the rotation fields, DeletedDate and
  PrimaryRegion.
- PrimaryRegion and ReplicationStatus appear only on multi-Region secrets,
  matching AWS's "only returns fields that have a value" rule.
- Versions with no staging labels are deprecated: DescribeSecret and
  ListSecretVersionIds omit them unless IncludeDeprecated is set, and an empty
  VersionStages array is omitted rather than sent.
- ListSecretVersionIds gained IncludeDeprecated, LastAccessedDate and paging.

Validation, all previously accepted silently:

- DeleteSecret rejects a recovery window outside 7-30 and the
  ForceDeleteWithoutRecovery/RecoveryWindowInDays combination. A window of 0
  used to fall through to force-delete, turning a request for no recovery
  window into an unrecoverable delete.
- CreateSecret uses ClientRequestToken as the version id and is idempotent on
  retry; UpdateSecret, which AWS documents as not idempotent, rejects a token
  that already names a version.
- RotationRules bounds, secret name charset, SecretString/SecretBinary
  exclusivity, KMS key existence and state, and the documented caps on
  BatchGetSecretValue, Filters, ExcludeCharacters and ResourcePolicy.

Secret values remain stored in the clear; encrypting them with the emulator's
own KMS would protect nothing while making the store unreadable. KmsKeyId is
validated instead, which is the part a caller can observe.

Two deviations are deliberate and recorded in docs/services/secrets-manager.md:
LastRotatedDate is retained after CancelRotateSecret, and RotateSecret with
RotateImmediately=false does not create the throwaway AWSPENDING version.

* test(secretsmanager): create a real KMS key in the sdk-test-java compat test

kmsKeyIdPreservation asserted that floci round-trips whatever KmsKeyId it is
handed, using an ARN that was never created. That passed only because floci
did not check the key; real AWS rejects a key it cannot access, and so does
the new validation.

The test now creates a key through the emulated KMS and round-trips that ARN,
so it still covers KmsKeyId preservation without depending on the missing
check. A second case pins the rejection itself.

* refactor(secretsmanager): import types instead of qualifying them inline

AGENTS.md asks for imports unless a name collision forces qualification.
AwsException and UUID had neither.

* fix(secretsmanager): hold the rotation lock while promoting a replica

StopReplicationToReplica wrote the promoted replica outside the per-secret
lock every other mutation in this file takes. The promotion races the
primary's replica sync, and losing that race writes the replica back over the
copy the call just promoted.

Also imports KmsKey, ConcurrentHashMap and HashMap rather than qualifying
them inline, per the same AGENTS.md rule.

* test(secretsmanager): assert the KMS rejection by exception type, not message text

createSecretWithAnUnknownKmsKeyIsRejected matched "InvalidParameterException"
against the message, but that is the exception type; the message itself reads
"You can't access the KMS key ... in this Region". The assertion now checks
the typed InvalidParameterException and the text it actually carries.

* test(secretsmanager): give the new KMS compat test its own order

createSecretWithAnUnknownKmsKeyIsRejected inherited @Order(13) from the test
it was added next to, so two cases shared a position. JUnit breaks the tie
deterministically, but the duplicate made the sequence misleading; the tail is
renumbered so each case keeps a distinct order.

Also sorts the new KMS imports, which landed between the lambda ones.

* fix(secretsmanager): guard every write to a secret with its owning monitor

UpdateSecret read, mutated and persisted without taking the secret's lock,
unlike every other mutator in the class, so two concurrent calls could drop
one another's field.

StopReplicationToReplica locked the replica's own ARN, but persist() writes a
primary's replica slots while holding only the primary's lock: two monitors
guarding one store slot, so a sync landing after the promotion could overwrite
the promoted copy. The promotion now runs under the primary's monitor, and its
two halves run in one critical section so nothing lands between them.

SecretsManagerWriteLockTest parks a write mid-flight and asserts the second
caller waits; both cases fail without the fixes.
2026-09-16 15:13:57 -04:00
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
TiM 7d70f64162 feat(docs): generate Supported Actions tables from handler source (#1641)
* feat(docs): generate Supported Actions tables from handler source

The "Supported Actions" tables in docs/services/*.md were hand-maintained and
drifted from the handlers. For example secrets-manager.md omitted RestoreSecret,
which SecretsManagerJsonHandler dispatches, and acm.md listed RenewCertificate,
which is not implemented anywhere in src/.

Derive the action list from handler source so it cannot drift, while keeping the
hand-written Description column:

- tools/docs/regen_action_docs.py extracts actions from `case "X" ->` switch arms
  (including multi-label arms) and JAX-RS REST controllers, and rewrites only the
  rows between the <!-- floci:actions --> markers. Descriptions are preserved by
  action name; new actions get a "-" placeholder. PascalCase-only matching avoids
  picking up SCREAMING_CASE labels from non-action switches.
- tools/docs/services.yaml registers 18 single-table switch services and lists the
  remaining switch handlers under deferred_handlers, so the new-service sentinel
  fires only on a genuinely unregistered handler.
- make docs-sync / docs-check / docs-test, plus a Python-only CI workflow that
  gates on handler, doc, and tooling changes.
- Migrate 18 service docs into marker blocks, reconciling real drift (adds
  RestoreSecret, ImportCertificate, and others; drops the unimplemented
  RenewCertificate).

Revives the parser and CI gate from #738 by @ericbsantana and completes the
description-preservation its spec described. REST-mode, mixed-mode, multi-table,
non-tabular, S3, and ecr docs are deferred and tracked in deferred_handlers.

* docs: drop standalone design spec from action-docs tooling

Remove ideas/auto-generated-action-tables.spec.md and the four references
to it (CONTRIBUTING.md, Makefile, regen_action_docs.py docstring,
services.yaml). It was a planning artifact; the operational docs live in
CONTRIBUTING.md and the tooling is self-documenting. The #738 / @ericbsantana
credit is preserved in the PR description.

* chore: address review on action-docs tooling

- pin actions/checkout to v7.0.0 in docs-actions workflow to match the
  repo-wide bump (#1690), so dependabot does not immediately flag the new file
- document in the generator docstring that a switch case label counts as
  supported purely by existing, so a per-action UnsupportedOperation stub
  would be a false positive (handlers here reject from the default arm)

* docs: regenerate action tables against current handler source

Resync the generated Supported Actions tables to handler source after
rebasing onto the latest main:

- cloudformation: add DescribeStackInstance and DescribeStackSetOperation
  now emitted by the handler, and keep the implemented StackSet descriptions
- cloudtrail: add LookupEvents
- firehose: add UpdateDestination
- step-functions: add PublishStateMachineVersion, ListStateMachineVersions,
  DeleteStateMachineVersion
- register the cloudcontrol handler in deferred_handlers so the strict
  unregistered-handler gate passes (no standalone action table yet)

* fix(docs): prevent action-table generator from silently dropping actions

Address the latest review pass on the action-docs tooling:

- switch extraction now captures case arms whose labels wrap across lines
  (valid Java 14+ syntax). The capture group excludes only `{ } ;` boundaries,
  so it spans newlines between labels but stops at the arm's `->`. A wrapped
  arm was previously missed, and docs-check would stay green because the doc
  and the generated output agreed on the omission, defeating the whole
  drift-prevention guarantee.
- REST extraction skips Javadoc / inline comments between a verb annotation
  and the method signature; such a line otherwise reset the lookahead and
  dropped the action.
- parse_marker_block raises a descriptive error when a marker is not on its
  own line, instead of a bare "substring not found".
- doc, source, and registry reads/writes are pinned to UTF-8 so generation is
  locale-independent (the docs contain non-ASCII text).
- the docs-actions push trigger watches Makefile and the workflow file,
  matching its pull_request trigger.

Adds regression tests for the multi-line arm and comment-skip paths (20 total).
2026-07-06 21:02:04 -05:00
Hector Ventura 9e35046647 Docs/enviroment instead yml (#764)
* docs: moving all config to env instead of yml
* docs: sync with main and new features
* docs: reverting docker-compose.yml
2026-05-10 11:53:31 -05:00
Eric Bitencourt de Santana 99204e2caf docs: update secrets manager with new handlers (#698) 2026-05-04 17:21:14 -05:00
TiM a32b7f1f3b docs: comprehensive audit sweep + CHANGELOG backfill (1.1.0-1.5.2) (#326)
CHANGELOG.md was empty for the 1.1.0-1.5.2 release cycle and service docs
had drifted from code behaviour. This sweep reconciles docs against the
current codebase on upstream/main.

- Backfill CHANGELOG.md for 1.1.0 through 1.5.2 from git history
- Correct exact operation counts in docs/services/index.md: S3 (~30 -> 58),
  Lambda (~25 -> 30), API Gateway v1 (~24 -> 62). Counts now come from the
  actual dispatch handlers rather than @Path annotation counts.
- Rewrite README "Supported Services" table to drop per-service op counts
  (they drift too fast); point readers at docs/services/index.md
- Update 24 service docs for accuracy, add "Not Implemented" sections
  where relevant (s3.md, lambda.md, api-gateway.md)
- Refresh configuration and getting-started docs
- Add EventBridge Scheduler and AppConfig to mkdocs nav
- Add AppConfig / AppConfigData rows to README and services index
  following the 1.5.2 upstream release
2026-04-10 10:52:34 -05:00
Hector Ventura 61433f59ab firt commit 2026-03-15 17:43:56 -05:00