Files
floci/docs/services/sts.md
T
Alex Banna d54a307ca9 feat(iam): enforce AssumeRole trust policies when enforcement is enabled (#1552)
* feat(iam): enforce AssumeRole trust policies when enforcement is enabled

When floci.iam.enforcement-enabled is true, STS AssumeRole now evaluates the
target role's trust policy (AssumeRolePolicyDocument) against the caller and
returns AccessDenied if it is not permitted. Enforcement is off by default,
so existing behavior is unchanged.

Trust policies are principal-centric and carry no Resource element, so the
identity/resource-oriented IamPolicyEvaluator cannot evaluate them. A focused
AssumeRolePolicyEvaluator matches each statement's Action (sts:AssumeRole) and
AWS Principal (account id, account-root ARN, exact principal ARN, or "*")
against the caller, with explicit Deny taking precedence. The role is resolved
in its own account (from the role ARN) via a new IamService.findRole overload,
since roles are account-namespaced. Roles unknown to Floci stay permissive to
preserve backward compatibility.

Tests: unit coverage for the evaluator across principal/action/deny/malformed
cases, plus an enforcement-enabled integration test asserting a permitted
caller succeeds, an unauthorized caller is denied, and an unknown role stays
permissive.

* docs(sts): restore Configuration section and note NotAction limitation

Greptile review on #1552:
- Restore the FLOCI_SERVICES_STS_ENABLED Configuration section that was dropped
  when the Trust Policy Enforcement section was added.
- Document that NotAction is not evaluated (a Deny with NotAction won't block).

* fix(iam): honor NotAction in AssumeRole trust statements

evaluateStatement only inspected the Action key, so a trust statement using
NotAction returned NO_MATCH and was skipped entirely. A Deny that should block
sts:AssumeRole (NotAction excluding some other action) was therefore ignored,
over-permitting AssumeRole when IAM enforcement is enabled. Add actionApplies()
mirroring IamPolicyEvaluator's Action/NotAction semantics: Action applies when
any pattern matches, NotAction applies when none match. Covered by three new
AssumeRolePolicyEvaluatorTest cases.

* fix(iam): match an assumed-role caller against a role-ARN trust principal

When a caller uses assumed-role temporary credentials, resolveCallerArn (rightly,
for GetCallerIdentity) yields the STS assumed-role ARN
(arn:aws:sts::ACCT:assumed-role/Role/session). enforceTrustPolicy passes that to
the trust-policy evaluator, but role trust policies name the role's IAM principal
ARN (arn:aws:iam::ACCT:role/Role) — the canonical form AWS resolves the session
back to. So a legitimate role-to-role AssumeRole was denied.

matchesAwsPrincipal now also normalizes an assumed-role caller ARN to its
underlying IAM role ARN and matches the principal against that, while still
matching an exact session-ARN principal. resolveCallerArn is unchanged, so
GetCallerIdentity keeps returning the assumed-role ARN.

Adds AssumeRolePolicyEvaluatorTest cases for role-ARN match, differing-role
denial, and exact session-ARN match.
2026-06-30 21:44:04 -05:00

2.7 KiB

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

Configuration

Variable Default Description
FLOCI_SERVICES_STS_ENABLED true Enable or disable the service

Trust Policy Enforcement

By default AssumeRole succeeds for any caller. When FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED=true, AssumeRole 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. Roles that Floci has no record of stay permissive, so this only affects roles created through IAM with a real trust policy.

Known limitations

  • Condition blocks are not evaluated. A trust policy that requires sts:ExternalId (the confused-deputy guard) is matched on its principal alone, so the role is assumable without passing ExternalId, and the ExternalId request parameter is ignored. This matches moto/LocalStack.
  • Only the trust policy is checked. Cross-account AssumeRole in AWS also requires the caller's own identity policy to allow sts:AssumeRole; that side is not enforced.

Examples

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.

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.