mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
* 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.