Files
floci/docs/services/secrets-manager.md
T
Priamo Germosen e4ee7816ad fix(iam): check each secret a Secrets Manager batch read returns as GetSecretValue (#9774)
The API reference's required permissions for BatchGetSecretValue say "you must have secretsmanager:GetSecretValue for
each secret", and the Service Reference lists that action among the operation's. Floci checked the batch action only,
so a caller allowed secretsmanager:BatchGetSecretValue read every secret, whatever its policies said about
GetSecretValue on each one.

The authorized-actions generator now reads that clause, already vendored by
fetch_secretsmanager_required_permissions.py, into a perEntry section: the action an operation needs on each entry it
reads, with the type of the action the clause's words name as the generators' names go (stem: secret is Secret),
where the Service Reference lists the action among the operation's. IamAuthorizedActions reads it, and the Secrets
Manager handler checks each secret a batch read returns against it, both by SecretIdList and by Filters. A secret the
caller may not read goes to Errors as AccessDeniedException, under the id it was requested as (its ARN for a filtered
read), and the others are returned, as AWS's own fidelity check records it
(check_batch_get_secret_value_returns_partial_results_with_a_per_secret_error_for_a_denied_secret).

Each secret is checked with the condition keys of its own stored tags (aws:ResourceTag/<key>,
secretsmanager:ResourceTag/<key>), through IamEnforcementFilter.authorizeEntryResource, so a grant or a deny scoped to
a tag holds for each secret of a batch as it does for a GetSecretValue of that secret alone.

The gates this change runs need today's AWS too, so the tables they cover are synced: the Service Reference lists 37
more Glue actions with no resource type and S3 Tables' ListStorageLensConfigurations (iam-authorized-actions.json),
S3 Tables' StorageLens type on its tagging actions with its ARN format and tag keys, and the elasticfilesystem-endpoint
and s3files-endpoint namespaces it does not read (iam-request-resources.json), three S3 actions taking
s3:ResourceAccount, GetBucketDefaultStorageClass, PutBucketDefaultStorageClass and GetIncompleteUpload
(s3control-tag-condition-keys.json), and the S3 user guide's permissions table gives the two default storage class
operations (tools/aws/sources/s3-required-actions.json).
2026-11-29 19:06:49 -04:00

271 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Secrets Manager
**Protocol:** JSON 1.1 (`X-Amz-Target: secretsmanager.*`)
**Endpoint:** `POST http://localhost:4566/`
## Supported Actions
<!-- floci:actions:start -->
| 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` | Cancel a scheduled deletion and restore the secret |
| `RotateSecret` | Trigger secret rotation, via a Lambda or by the owning service |
| `CancelRotateSecret` | Turn off automatic rotation and report any half-staged `AWSPENDING` version |
| `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 |
| `ValidateResourcePolicy` | Check a resource policy for overly broad principals |
| `ReplicateSecretToRegions` | Replicate a secret into other regions |
| `RemoveRegionsFromReplication` | Delete replicas from the given regions |
| `StopReplicationToReplica` | Promote a replica to a standalone primary |
<!-- floci:actions:end -->
## IAM resource tags
With IAM enforcement enabled, secret-scoped operations read current stored tags
for `aws:ResourceTag/<key>` and `secretsmanager:ResourceTag/<key>` conditions.
Names and full ARNs resolve to the same stored secret before authorization.
Retagging or removing a tag affects the next request; request tags cannot replace
the stored tags during a write. Missing secrets contribute no stored tags.
Case-variant tag keys retain all their values in the case-insensitive IAM context,
so set operators such as `ForAnyValue:StringEquals` inspect every stored value.
Bare operators retain the shared evaluator's single-value semantics; use consistent
tag key casing or a set operator for case-variant keys.
The keys are the ones the Service Reference gives the `Secret` resource type, from
the generated `resourceTagKeys` table in `iam-request-resources.json`, regenerated by
`tools/aws/regen_iam_request_resources.py`.
## IAM required permissions
With IAM enforcement enabled, a request is checked for the actions the
[API reference's](https://docs.aws.amazon.com/secretsmanager/latest/apireference/Welcome.html) required permissions
say it needs beside its own, as each operation's page gives them:
- `BatchGetSecretValue` using `Filters` needs `secretsmanager:ListSecrets`: "If you use filters, you must also have
secretsmanager:ListSecrets".
- `CreateSecret` with `AddReplicaRegions` needs `secretsmanager:ReplicateSecretToRegions`: "To add replica Regions,
you must also have secretsmanager:ReplicateSecretToRegions".
- `ValidateResourcePolicy` needs `secretsmanager:PutResourcePolicy` on the secret it names, or on every resource where
it names none, as its own action is: "Required permissions: secretsmanager:ValidateResourcePolicy and
secretsmanager:PutResourcePolicy".
- `BatchGetSecretValue` needs `secretsmanager:GetSecretValue` on each secret it reads: "you must have
secretsmanager:GetSecretValue for each secret". A secret the caller may not read is answered in the response's
`Errors`, as `AccessDeniedException` under the id it was requested as (its ARN for a read using `Filters`), and the
others are returned, as AWS does, rather than the whole call being refused.
A tagged `CreateSecret` needs `secretsmanager:TagResource`, which the tagging check gives already. Not checked yet:
`secretsmanager:PutResourcePolicy` for a cross-account replica
(`CrossAccountPrimaryARN`) and `secretsmanager:DeleteResourcePolicy` for one stopped replicating, whose sentences name
no member of the request; and the KMS permissions of a secret encrypted with a customer managed key.
## Secret write events
Successful `PutSecretValue` and `UpdateSecret` API calls emit an EventBridge event with
`source: aws.secretsmanager` and `detail-type: AWS API Call via CloudTrail`. A metadata-only
`UpdateSecret` also emits an event. Delivery requires:
- A CloudTrail trail in the caller's account with logging started. A single-region trail must
cover the request's region; a multi-region trail can cover other regions in its partition.
- Management writes selected by that trail. New trails select management events by default.
Basic selectors must include management events and allow `All` or `WriteOnly`. Advanced
selectors must match the management event; data-only and read-only selectors do not qualify.
- An enabled rule on the **default event bus**, in the secret's account and region, with an
appropriate target. A custom bus receives these events only through an explicit forwarding rule.
Match a particular secret with this pattern, replacing the example ARN with the ARN returned
by `CreateSecret`:
```json
{
"source": ["aws.secretsmanager"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventName": ["PutSecretValue", "UpdateSecret"],
"responseElements": {
"arn": ["arn:aws:secretsmanager:us-east-1:000000000000:secret:example-AbCdEf"]
}
}
}
```
The lowercase `responseElements.arn` follows the current AWS CloudTrail format. Records include
the operation, account, region, caller identity, secret name, and version ID when returned.
Request metadata is restricted to the secret ID, client request token, version stages, and KMS
key ID. Secret strings, binary values, descriptions, and unrecognized request fields are omitted
from both EventBridge events and CloudTrail logs.
One event is published per successful API call even when several trails select it. Matching
trails also buffer the same redacted record for their normal S3 log delivery. EventBridge target
delivery is asynchronous and does not wait for the CloudTrail S3 flush interval.
Coverage is limited to these two successful API operations. Reads, failed writes, and internal
service writes do not emit these API-call events. Native `Secret Label Updated` events and
`RotationSucceeded` service events are separate contracts and are not generated by this hook.
Event publication is best effort: a delivery failure does not fail the completed secret write.
Publication runs on two background workers with a bounded queue of 256 pending events. Slow
targets do not hold the secret-write response open. Each queued delivery restores the originating
account and region. Notifications are dropped and logged when the queue is full or publication
is paused or stopped. Pending notifications are in memory and are not retained across shutdown.
An emulator reset discards queued notifications and pauses new notifications. Active deliveries
finish before storage is cleared, then publication resumes, including after a failed reset. If
active deliveries cannot drain within 30 seconds, or draining is interrupted, reset fails before
the storage wipe.
See AWS's [Secrets Manager event types](https://docs.aws.amazon.com/secretsmanager/latest/userguide/monitoring-eventbridge.html)
and [CloudTrail event prerequisites](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event-cloudtrail.html).
## 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 |
| `FLOCI_SERVICES_SECRETSMANAGER_SCHEDULED_ROTATION_ENABLED` | `true` | Run the background sweep that fires rotations when a schedule comes due |
| `FLOCI_SERVICES_SECRETSMANAGER_ROTATION_TICK_SECONDS` | `60` | How often that sweep looks for due rotations |
## Examples
```bash
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
# Turn on scheduled rotation, then turn it back off
aws secretsmanager rotate-secret \
--secret-id /app/database-url \
--rotation-lambda-arn arn:aws:lambda:us-east-1:000000000000:function:my-rotator \
--rotation-rules '{"ScheduleExpression":"rate(10 days)"}' \
--endpoint-url $AWS_ENDPOINT_URL
aws secretsmanager cancel-rotate-secret \
--secret-id /app/database-url \
--endpoint-url $AWS_ENDPOINT_URL
# Replicate to another region, then promote the replica to its own primary
aws secretsmanager replicate-secret-to-regions \
--secret-id /app/database-url \
--add-replica-regions Region=eu-west-1 \
--endpoint-url $AWS_ENDPOINT_URL
aws secretsmanager stop-replication-to-replica \
--secret-id /app/database-url \
--region eu-west-1 \
--endpoint-url $AWS_ENDPOINT_URL
# Check a resource policy before attaching it
aws secretsmanager validate-resource-policy \
--secret-id /app/database-url \
--resource-policy file://policy.json \
--endpoint-url $AWS_ENDPOINT_URL
```
## Behaviour notes
- **Rotation schedules fire.** A background sweep (see the config table) rotates any secret whose
`NextRotationDate` has passed. `AutomaticallyAfterDays`, `rate()` and `cron()` are all honoured.
- **Redshift-owned master secrets rotate with their cluster.** `RotateSecret` and scheduled
rotation change the provisioned Redshift cluster password, then publish the matching secret
version. The cluster must be available, and a rotation Lambda is not used.
- **`RotateSecret` also needs `lambda:InvokeFunction` under IAM enforcement.** As on AWS, the caller
must be allowed to invoke the rotation function as well as to call `RotateSecret`. A caller that
is not gets `AccessDeniedException` with HTTP 400, as Secrets Manager reports it, and the secret is
left as it was. A function in another account is checked as any cross-account call is: its
function policy must allow the caller too. Rotations started by the background sweep have no
caller and are not checked.
- **A rotation function that does not exist** is reported as AWS reports it: `AccessDeniedException`
(HTTP 400), "Secrets Manager cannot invoke the specified Lambda function". The function is looked
up where the rotation runs it, in the account its ARN names and as the version or alias the ARN
names, so a missing alias is reported the same way. The secret's rotation settings are left as
they were, including any rotation function configured before.
- **A rotation function reference Lambda refuses**, one it cannot parse or a full ARN in another
Region, gets `InvalidParameterException` (HTTP 400), the error `RotateSecret` declares for an
invalid parameter, with Lambda's reason in the message. The secret is left as it was. AWS does not
document which error a function in another Region gets.
- **Replication is synchronous.** Real AWS reports `InProgress` first; floci copies the secret
immediately, so a replica is `InSync` by the time the call returns. Replicas are read-only and
track later writes to the primary.
- **Secret values are stored in the clear.** `KmsKeyId` is validated — a missing key is rejected,
and a disabled or pending-deletion key raises `EncryptionFailure` — but values are not actually
encrypted, since encrypting with the emulator's own KMS would protect nothing.
- **`ValidateResourcePolicy` and `BlockPublicPolicy` check for wildcard principals only.** AWS runs
the policy through Zelkova; a pass here is weaker than a pass on AWS. `PutResourcePolicy` with
`BlockPublicPolicy` raises `PublicPolicyException` for a wildcard principal, and — as on AWS —
leaves such a policy alone when the flag is absent.
- **`PrimaryRegion` and `ReplicationStatus` appear only on multi-region secrets**, matching AWS's
"only returns fields that have a value" rule — a standalone secret carries neither.
- **Rotation schedule limits are enforced**: `AutomaticallyAfterDays` 1–1000, `Duration` as `Nh`,
and `rate()` in hours or days no faster than every four hours.
- **Known deviation:** `RotateSecret` with `RotateImmediately: false` invokes the rotation
function's `testSecret` step but does not first create the throwaway `AWSPENDING` version that
AWS creates and removes, so a rotation function whose `testSecret` reads that version by id
will not find it.