Files
floci/docs/services/sts.md
T
Priamo Germosen 494a6725a1 feat(iam): release and exchange the delegation token (#5914)
M4a dispatched the delegation request lifecycle as far as ACCEPTED and
stopped there, so no request reached FINALIZED and the credentials the whole
feature exists to hand over could not be obtained at all. This is the token
half: IAM SendDelegationToken and STS GetDelegatedAccessToken, the last two
of the ten operations the family spans.

SendDelegationToken takes a request id, answers no output shape, and moves an
ACCEPTED request to FINALIZED. The reference says that "cannot be rolled
back", which makes it the one transition that refuses to repeat itself:
releasing twice answers ConcurrentModification, the wrong-state shape the
other four writers already use. Releasing mints the token and records the
instant it happened, both on the request, because the shape publishes neither
and nothing else is going to hold them.

Releasing is also where OnlySendByOwner is finally read. M4a stored the flag
with nothing looking at it, which was right while nothing could release;
SendDelegationToken is the one operation it speaks to. It "prevents any party
other than the owner from calling SendDelegationToken API for this delegation
request", for the case the reference spells out: the owner lacked the
permission to approve, forwarded the request to a more privileged user, and
still has to be the one who hands the token over. So the release is the one
call on this family decided per identity rather than per account, the handler
passing the caller ARN as associate and accept already do, and an approver who
is not the owner answers AccessDenied 403, which the API reference publishes
as a common error for every IAM operation.

GetDelegatedAccessToken exchanges that token for credentials in the
customer's account. The delegation period "starts when customer releases the
exchange token, not when the product provider redeems it", and "all
credentials obtained from the same exchange token expire at the same time",
so the expiry is release plus SessionDuration whenever it is redeemed and a
token can be exchanged repeatedly, each exchange buying less time than the
one before. AssumedPrincipal is the identity that approved the request rather
than the one that claimed it: accepting a request "records the details and the
state of the identity that called this API", and "this is the identity that
gets mapped to the delegated credential", which the user guide says the same
way, the provider obtaining the "approver's temporary credentials". The two
are the same identity until a request is forwarded for approval, which is the
case OnlySendByOwner serves. PackedPolicySize is left out: the model
deprecates it and states it is not populated for this operation.

Two answers had to be chosen rather than read off, both forced by the error
set. GetDelegatedAccessToken models exactly three errors, and none of them
says "no such token", so a token nothing matches is answered as an expired
one: from the caller's side the two are the same situation, and the
reference's own remedy, "Request a new token and retry the operation", fits
both. A token offered by an account that did not file the request answers
AccessDenied 403 instead, the shape this handler already uses for a caller
who may not perform the operation, because "the exchange token can only be
redeemed by the product provider account that created the delegation
request" is a refusal rather than an expiry. The account is checked before
the window so that neither guard can hide the other, and both are tested
with the other one passing.

The code is ExpiredTradeInTokenException, not ExpiredTradeInToken. The model
writes the Exception suffix into error.code for that shape and for
RegionDisabledException while PackedPolicyTooLarge drops it, so each code is
read off its own shape rather than derived from the shape's name.

What the credentials carry is the request's PermissionPolicy, the policy AWS
renders from the partner's registered template. No API registers a template,
so nothing sets it and the session carries none, which is where M4a left
PolicyTemplateArn for the same reason.

The session is filed in the customer's account with no issuing key, and as a
delegated session rather than an issued one. The delegation is the customer's
grant, so a partner key that happened to name an IAM user must not become the
session's issuer: issuingUser bounds a session by the issuer's own
permissions, which would be the partner's rather than what the customer gave
away. The approver is carried in a field of its own for the same reason the
issuer is left empty. An issued session holds its identity in the role ARN
slot, which is resolved by name, so an approver named like a role would act
with that role's permissions, one named like no role would act with none, and
GetCallerIdentity would answer for a role that does not exist. A delegated
session instead resolves its approver from what the ARN says it is: a user's
own policies and boundary, the account's access where the root approved the
request, the role behind a session assumed from one, and nothing where that
identity is gone. The account is the owner's either way, a request being
visible only from the account that claimed it. The request's PermissionPolicy
still bounds it on top wherever one exists, which is where the registered
template would land.

One gap this step cannot close on its own. AWS publishes the exchange token
only in the ExchangeToken notification on the partner's SNS topic, and no
operation on the family answers it. Floci sends no notification yet, so the
token is minted onto the record and nothing hands it back over the wire. The
integration test reads it from the service for that one step and drives
everything either side of it over the wire.

Twenty-one tests: eight on the service covering the release, the owner-only
flag either way, the repeated exchange, both refusals and the window, with a
clock the test owns, eight over the wire across the two accounts, one on the
handler holding the session to the customer's account and to its approver, and
four under IAM enforcement on what the credentials may then do: an approver
allowed to read and not write, whose delegated credentials do exactly that, a
request forwarded to an administrator who approved it, whose credentials write
where its owner can only read, a role carrying the approver's name that lends
them nothing, and a request approved by the account root. Four probes, each
reverting one thing: mapping the credentials to the owner fails the forwarded
case and the handler test and nothing else, anchoring the expiry at the
redemption instant fails the two tests that describe it, filing the session
against the partner fails the one that holds it, and dropping the owner-only
guard fails the one that asks for it.
SendDelegationToken joins the delegation family in ResourceArnBuilder, AWS
giving it the delegation-request type, so it is authorized against the
request rather than the wildcard. Routing needs nothing added since #5879
reads each service's actions from its botocore model, which names both of
these, so the matrix rows in docs/services/index.md are the only counts this
moves: IAM 174 to 175 and STS 7 to 8.
2026-10-18 20:43:05 -05:00

152 lines
9.5 KiB
Markdown

# STS
**Protocol:** Query (XML), `POST http://localhost:4566/` with `Action=` parameter
## Supported Actions
| Action | Description |
|---|---|
| `GetCallerIdentity` | Returns the account ID, user ID, and ARN |
| `AssumeRole` | Assume an IAM role, returns temporary credentials |
| `AssumeRoleWithWebIdentity` | Assume a role using a web identity token (OIDC) |
| `AssumeRoleWithSAML` | Assume a role using a SAML assertion |
| `GetSessionToken` | Get temporary credentials for an IAM user |
| `GetFederationToken` | Get temporary credentials for a federated user |
| `DecodeAuthorizationMessage` | Decode an encoded authorization failure message |
| `GetDelegatedAccessToken` | Exchange a delegation request's trade-in token for temporary credentials |
## Delegated Access Token
`GetDelegatedAccessToken` takes the exchange token an IAM delegation request released and answers
credentials in the customer's account, acting as the identity that approved the request, which is
the `AssumedPrincipal` it returns. Accepting a request records the identity that called it, and
that is the identity mapped to the delegated credential, so a request its owner forwarded to an
administrator for approval hands over the administrator's access rather than the owner's. The
credentials expire at the moment the customer released the token plus the request's
`SessionDuration`, not at the exchange, so the same token can be exchanged repeatedly and every
session it mints ends at the same time.
The credentials carry the permissions of that identity. AWS bounds them by the permission policy it
renders from the partner's registered policy template, which no API registers, so Floci bounds them
by the approving identity's own permissions: a user's policies and boundary, the account's access
where the account root approved the request, and nothing at all where that identity no longer
exists.
Only the account that filed the delegation request may exchange its token; any other account gets
`AccessDenied`. A token past its window, and a token nothing matches, both answer
`ExpiredTradeInTokenException`. `PackedPolicySize` is not returned, the model deprecating it and
stating it is not populated for this operation. See the delegation request section of the
[IAM service doc](iam.md) for the lifecycle that issues the token.
## Configuration
| Variable | Default | Description |
|---|---|---|
| `FLOCI_SERVICES_STS_ENABLED` | `true` | Enable or disable the service |
## Session Token and Federation Token Permissions
`GetSessionToken` and `GetFederationToken` reject temporary callers with `AccessDenied` before issuing credentials,
including when IAM policy enforcement is disabled. Use a long-term IAM user or account key.
For an authenticated temporary caller, `GetFederationToken` returns
`Cannot call GetFederationToken with session credentials` with either enforcement setting.
When `FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED=true`, credentials from `GetSessionToken` and `GetFederationToken`
are evaluated as the identity whose long-term key signed the call, as on AWS:
- `GetSessionToken` credentials have the permissions of that IAM user, or of the account root when its key minted them,
still bounded by the account's service control policies.
- `GetFederationToken` credentials have no permissions without a session policy (`Policy`). With one, they have the
intersection of that policy and the permissions of the IAM user that minted them, never those of a role that shares
the federated user's name. A resource policy naming the federated user's ARN can grant access on its own, but not
past an explicit `Deny` in the user's policies or permissions boundary. Whatever their policies allow, they cannot
call any IAM operation, nor any STS operation except `GetCallerIdentity`.
Managed session policies (`PolicyArns`) are not supported yet.
A session minted with another session's temporary credentials, which AWS does not accept here, with an inactive access
key or one that belongs to another account, or by an IAM user since deleted and recreated under the same name, is not
a valid credential: it is refused like an unknown access key. A key IAM does not know anywhere mints sessions that act
as the account root, as the key itself does.
## Trust Policy Enforcement
`AssumeRole` and `AssumeRoleWithWebIdentity` require the target role to exist in IAM, returning `AccessDenied` (403)
if it does not.
When `FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED=true`, `AssumeRole` also evaluates the target role's trust policy
(`AssumeRolePolicyDocument`) against the caller and returns `AccessDenied` if it is not permitted. AWS principal
forms are matched: `"*"`, an account id, an account-root ARN (`arn:aws:iam::<acct>:root`), and exact principal ARNs;
and an explicit `Deny` always wins. Both `Action` and `NotAction` elements are honored when matching `sts:AssumeRole`.
The caller is the account that owns the request's credentials, whether they sign the
`Authorization` header or a presigned query string: an IAM user's or a role session's access key
belongs to its own account, not to the default one. A role session matches a `Principal` that
names its session ARN or its role's ARN, path included.
`Condition` blocks are evaluated with the same operators as identity and resource policies. The
request context holds `sts:RoleSessionName`, `sts:ExternalId` when the caller passes `ExternalId`,
`aws:PrincipalArn` (for a caller using assumed-role credentials, the role's ARN with its path, as on AWS),
`aws:PrincipalAccount`, `aws:ResourceAccount`, `aws:RequestedRegion` and
`aws:PrincipalIsAWSService`. A trust policy that requires `sts:ExternalId`, the confused-deputy
guard, refuses a call that omits it or passes another value, and a conditional `Deny` applies only
when its condition matches.
### Known limitations
- **Session tags and source identity are not modelled.** `aws:RequestTag/*`, `aws:TagKeys`,
`sts:TransitiveTagKeys` and `sts:SourceIdentity` are not in the request context, so a condition
on them does not match, and `sts:TagSession` and `sts:SetSourceIdentity` are not checked.
- **The caller's own permission is checked against `*`.** The caller's identity policy must allow
`sts:AssumeRole`, but it is evaluated for resource `*` rather than the role's ARN, so a policy
that names the role in `Resource` does not grant it.
## Web Identity Validation (IRSA)
`AssumeRoleWithWebIdentity` validates tokens minted by an OIDC issuer Floci hosts - currently an EKS cluster's IRSA provider.
When the token's `iss` names a known Floci issuer, all of the following are enforced:
- the RS256 signature, against the issuer's public key
- `iss` matches that issuer exactly
- `aud` contains `sts.amazonaws.com`
- `exp` / `nbf`, with 60s of clock-skew tolerance
- the role's trust policy: `Principal.Federated` plus the `Condition` block, comparing `<oidcProvider>:sub` and `<oidcProvider>:aud` with exact, **case-sensitive** equality (`StringEquals`, `StringNotEquals`, `StringLike`, and `StringNotLike` are supported)
The response carries the token's real claims in `SubjectFromWebIdentityToken`, `Provider`, and `Audience`. A bad token returns `InvalidIdentityToken` (400), an expired one returns `ExpiredTokenException` (400), and a role that does not exist or a trust policy that does not permit the subject returns `AccessDenied` (403).
By default, tokens from an issuer Floci does not host, or tokens that are not parseable JWTs, are treated as opaque and accepted for compatibility with existing workflows, provided the target role exists in IAM. When `FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED=true`, those tokens return `InvalidIdentityToken` because Floci cannot verify a third-party provider's signature. See [EKS](eks.md) for the full IRSA walkthrough and the token-minting endpoint.
## Examples
```bash
export AWS_ENDPOINT_URL=http://localhost:4566
# Get caller identity (always works, useful for smoke testing)
aws sts get-caller-identity --endpoint-url $AWS_ENDPOINT_URL
# Assume a role
aws sts assume-role \
--role-arn arn:aws:iam::000000000000:role/my-role \
--role-session-name dev-session \
--endpoint-url $AWS_ENDPOINT_URL
# Get a session token
aws sts get-session-token --endpoint-url $AWS_ENDPOINT_URL
```
`GetCallerIdentity` is commonly used in CI pipelines and integration tests as a quick connectivity check before running more complex tests.
For temporary credentials returned by an assumed-role action, its `Arn` and `UserId` match
the `AssumedRoleUser.Arn` and `AssumedRoleUser.AssumedRoleId` returned when the session was created.
For `GetSessionToken` credentials they are those of the IAM user that minted them, and for `GetFederationToken`
credentials the `FederatedUser.Arn` and `FederatedUser.FederatedUserId` (`<account>:<name>`).
The response resolves both header and query-string credentials, including the query session token,
so a presigned request reports the same caller identity. A nonblank Authorization header retains
precedence over query credentials.
When `FLOCI_SERVICES_IAM_SEED_DEPLOYER_PRINCIPAL=true`, requests signed with the seeded `floci` access key return `arn:aws:iam::000000000000:user/floci-deployer`. Other unknown local credentials continue to return the account root ARN for backward compatibility.
When `FLOCI_AUTH_VALIDATE_SIGNATURES=true`, the shared signature verifier checks presigned query
credentials for STS operations, including `GetCallerIdentity`, `GetSessionToken`, `GetFederationToken`
and `AssumeRole`. It checks the request signature, credential scope, expiry and session token before
execution. Nonblank Authorization headers retain priority. See [signature checks](../configuration/multi-account.md#signature-validation).