Skip to content

CloudFormation: model a stack's service role (RoleARN) and attribute resource calls to it #562

Closed

Description

@scttfrdmn

Summary

A CloudFormation stack can carry a service role (RoleARN on CreateStack /
UpdateStack / DeleteStack, surfaced as RoleARN on DescribeStacks). When one
is set, CloudFormation makes every resource call using that role rather than the
calling principal's permissions; when it is absent, it uses the caller's. Substrate
models neither — StackDeployer.dispatch (emulator/cfn_deployer.go:3925) builds a
RequestContext with no Principal at all, and cfnIdentity (:807) carries only
account and region.

Split out of #411, where the immediate decision was which principal a deploy and
its rollback run as. That question is answered there for the no-service-role case (the
stack's creating principal). This issue is the faithful general answer, and it is
strictly larger.

Observables this makes accurate

All of these are reachable through an API call today and all of them are currently
wrong or absent:

  • RoleARN accepted on CreateStack / UpdateStack / DeleteStack and reported on
    DescribeStacks. Currently not modelled, so a template that sets one round-trips
    as though it had not.
  • DeleteStack's RoleARN overriding the stack's stored role for that operation
    only, which is the documented behaviour and a common source of a stuck delete on
    real AWS.
  • A stack whose service role lacks a permission for one resource: the resource fails,
    the stack goes CREATE_FAILED → ROLLBACK_*, and the StackEvent's
    ResourceStatusReason names the authorization failure. That is a real, seedable
    observable and exactly the failure a consumer wants to catch before spending on a
    real deploy.
  • InsufficientCapabilitiesException is a distinct existing error and is not this
    — worth stating so the two are not conflated during implementation.

Depends on

Notes for whoever takes it

  • Verify the request/response shapes and the exact error codes against the
    CloudFormation API reference rather than inferring them; in particular what
    DescribeStacks reports for a stack with no role, and whether an unassumable role
    fails at stack-operation time or at resource-call time.
  • Keep it inside the scope boundary: substrate models the observation that a call
    was denied and the stack status that follows, not any role-assumption machinery
    beyond what an API caller can see.

Acceptance criteria

  • RoleARN is accepted, persisted, and reported by DescribeStacks, with shapes
    checked against the API reference.
  • Resource calls a stack makes are attributed to the stack's service role when one
    is set, and to the creating principal when it is not (per Principal-aware test mode: enforce IAM authorization in composition tests #411's answer).
  • DeleteStack --role-arn overrides the stored role for that operation only.
  • A test shows a stack whose role is missing one permission reaching
    ROLLBACK_COMPLETE with a StackEvent reason naming the denial.
  • docs/services.md CloudFormation section covers RoleARN.

Activity

  1. added
    type: feature
    priority: low
    on Aug 4, 2026
  2. added this to the v0.92.0 milestone on Aug 4, 2026
  3. scttfrdmn commented on Aug 5, 2026

    @scttfrdmn
    OwnerAuthor

    Scoped for v0.92.0 alongside #411. Four of the five acceptance criteria are in scope; the fifth is blocked and stays open.

    In scope for v0.92.0:

    • RoleARN accepted on CreateStack/UpdateStack/DeleteStack and reported by DescribeStacks. Confirmed against the botocore model: RoleARN is a member of all three inputs and of the Stack output shape.
    • Resource calls attributed to the stack's service role when one is set, and to the creating principal when it is not — which requires storing the creating principal on the stack record. Principal-aware test mode: enforce IAM authorization in composition tests #411's answer stands: a rollback's deletes run as the principal that created the stack.
    • DeleteStack --role-arn overriding the stored role for that operation only, without persisting it. UpdateStack without a RoleARN keeps the stored one, per the model's "always uses this role for all future operations on the stack".
    • docs/services.md covering RoleARN.

    Blocked and left open: the StackEvent criterion. DescribeStackEvents is deliberately refused with UnsupportedOperation (emulator/cloudformation_plugin.go:158-174) because "substrate models stack status, not per-resource stack events" — that is #501, which wants events derived from the event store, with reverse-chronological ordering, NextToken pagination, and a decision about whether a deploy advances the shared clock. Satisfying one checkbox here would pre-empt that design.

    The denial is observable in the meantime, without inventing an event model. DescribeStackResources already derives CREATE_FAILED plus a ResourceStatusReason from DeployedResource.Error (emulator/cloudformation_plugin.go:555-568), and cfnDispatchError (emulator/cfn_deployer.go:3958) lifts the error code out of a 4xx body. So a stack whose role lacks one permission will reach ROLLBACK_COMPLETE with AccessDeniedException named in the resource's status reason. v0.92.0 will ship a test asserting exactly that, and the StackEvent form of the same observation follows #501.

    One further finding relevant here: the dependency on #411 is deeper than "principal-aware enforcement". StackDeployer.dispatch (emulator/cfn_deployer.go:3920) calls registry.RouteRequest directly, and RouteRequest never calls CheckAccess — the only non-test call site is emulator/server.go:564, in the HTTP path. So authorization has to be added to the deployer, not merely handed a principal. The good news is that create, update, rollback and delete all funnel through that one dispatch, via deleteStackResources → deleteOneResource → dispatchResourceDelete for the sweeps, so there is a single place to get it right.

    This issue will therefore not be closed by v0.92.0; it will move to the next milestone with the StackEvent criterion outstanding.

  4. scttfrdmn commented on Aug 5, 2026

    @scttfrdmn
    OwnerAuthor

    v0.92.0 ships four of the five criteria here. Leaving this open for the fifth, and moving it to the next milestone.

    Shipped (#574, released in v0.92.0)

    • RoleARN accepted and reported — on CreateStack, UpdateStack and DeleteStack, stored on the stack, and reported by DescribeStacks (omitempty, so a stack without one reports nothing rather than an empty string). Length-validated per the model.

    • The documented lifetime semantics, not the convenient ones. An UpdateStack that omits RoleARN keeps the stored role ("CloudFormation uses the role that was previously associated with the stack"); one that supplies it replaces the role for that update and every operation after. A DeleteStack's applies to that operation only and is not persisted — a delete refused by its override leaves the stack's own role intact, so a retry runs as the identity the stack was created with rather than silently as a different one.

    • Resource calls attributed to the role. Resolution is service role → creating principal → nil, in one place, so create, update, rollback and delete cannot disagree: a resource created by a role is deleted by that role, not by whoever asks for the delete, and a rollback's sweep runs as the identity that created what it is tearing down. Absent a role, calls are attributed to the creating principal — otherwise CreateStack would be a way to launder a permission the caller does not have.

    • A denial is observable. AccessDeniedException, naming the action and the resource ARN, as that resource's ResourceStatusReason in DescribeStackResources, with the stack reaching ROLLBACK_COMPLETE. Verified live:

      aws cloudformation describe-stacks --query 'Stacks[0].[StackStatus,RoleARN]'
      # ROLLBACK_COMPLETE   arn:aws:iam::123456789012:role/narrow
      aws cloudformation describe-stack-resources --query 'StackResources[0].ResourceStatusReason'
      # AccessDeniedException: User: arn:aws:iam::123456789012:role/narrow is not
      # authorized to perform: s3:CreateBucket on resource: arn:aws:s3:::e2e-role-bucket
      

    Also documented (#575): the RoleARN semantics in docs/services.md and a "Testing IAM Permissions" section in docs/testing-guide.md.

    Still open: the StackEvent criterion

    Blocked by #501. DescribeStackEvents is deliberately refused with UnsupportedOperation because substrate models stack status, not per-resource stack events, and deriving events from the event store carries its own design questions — ordering, pagination, and a clock decision — that belong to #501 rather than being pre-empted here. Building an event model to satisfy one checkbox would have made this the largest release in the series.

    Nothing in v0.92.0 changed that analysis, but it does add weight to #501: this is now a second consumer for it, which I've noted there. In the meantime the denial is observable per-resource through DescribeStackResources, which is what a consumer needs to act on a refused deploy.

    Moving to the next milestone.

  5. modified the milestones: v0.92.0, v0.93.0 on Aug 5, 2026
  6. scttfrdmn commented on Aug 6, 2026

    @scttfrdmn
    OwnerAuthor

    Moved to milestone v0.94.0 — v0.93.0 shipped without it.

    Why it moved: unchanged from when it was deferred out of v0.92.0. The acceptance criterion that a role-attributed call surfaces in DescribeStackEvents cannot be written against a DescribeStackEvents that has no backing event model, which is #501. Nothing in v0.93.0 touched CloudFormation.

    Did the shipped release change the analysis? No, but it is worth recording one thing that is now precedent rather than speculation. v0.93.0's #540 work established that a control-plane seed — not a fault rule — is the right shape when a test needs an outcome the emulator cannot derive from state, because a seed reaches the plugin and can therefore write the consequence of the outcome, whereas a fault short-circuits at Step 4.5 and writes no state. If this issue ends up needing a way to make a role-attributed call fail as the role (rather than as the caller), that is the pattern to follow, and emulator/s3_conditional_control.go is now the closest in-repo example.

    Still blocked on #501.

  7. modified the milestones: v0.93.0, v0.94.0, v0.95.0 on Aug 6, 2026
  8. scttfrdmn commented on Aug 6, 2026

    @scttfrdmn
    OwnerAuthor

    Moved to milestone v0.95.0. Still blocked on #501 (no IAM authorization decision to
    attribute a call to), so it was deferred out of v0.94.0 rather than attempted.

    Nothing in v0.94.0 changes the analysis here. The release touched the deployer's
    physical-name resolution (#560) and its delete sweep (#581), both of which run inside
    one dispatch per resource — the layer this issue needs is around that dispatch, deciding
    which principal it is made as. The one point of contact is that resource calls are now
    dispatched from more places in the delete path than before: an instance profile's delete
    emits a RemoveRoleFromInstanceProfile pre-step through dispatchResourceDelete
    alongside its own delete. Whatever attributes a call to the stack's service role will
    need to cover the pre-step too, or a stack with a service role would attribute part of
    its own teardown to the caller.

  9. scttfrdmn commented on Aug 9, 2026

    @scttfrdmn
    OwnerAuthor

    The fifth criterion is met

    The remaining acceptance criterion was "a test shows a stack whose role is missing one
    permission reaching ROLLBACK_COMPLETE with a StackEvent reason naming the denial".
    It could not be written because DescribeStackEvents returned UnsupportedOperation
    (400), which is why this issue deferred across v0.92.0 → v0.93.0 → v0.94.0 → v0.95.0.

    #501 shipped the events model, so the criterion is now asserted in three places:

    • emulator/cfn_service_role_test.go — TestCFN_DeniedResourceNamesTheDenialInStackEvents:
      a stack under a role granting only s3:ListBucket reaches ROLLBACK_COMPLETE, its
      newest event is the stack's ROLLBACK_COMPLETE, and a CREATE_FAILED event for the
      refused resource names both AccessDeniedException and s3:CreateBucket.
    • test/e2e/journey_cfn_events_test.go — TestJourney_StackEventsNameARoleDenial: the
      same chain through the real AWS SDK, with the role built via the IAM SDK rather than
      seeded into state, so the whole sequence a consumer writes is exercised.
    • Verified live through the AWS CLI:
    $ aws cloudformation describe-stacks --stack-name denied --query 'Stacks[0].StackStatus'
    ROLLBACK_COMPLETE
    $ aws cloudformation describe-stack-events --stack-name denied \
        --query 'StackEvents[?ResourceStatus==`CREATE_FAILED`].ResourceStatusReason' --output text
    AccessDeniedException: User: arn:aws:iam::123456789012:role/narrow is not authorized to
    perform: s3:CreateBucket on resource: arn:aws:s3:::denied-demo-bucket
    $ aws cloudformation describe-stack-events --stack-name denied \
        --query 'StackEvents[].[ResourceStatus,LogicalResourceId]' --output text
    ROLLBACK_COMPLETE   denied
    CREATE_FAILED       B
    CREATE_IN_PROGRESS  denied
    

    The DescribeStackResources assertion this issue already had is kept: both views now
    share one derivation (cfnResourceStatus), so they cannot disagree about whether a
    resource failed. docs/services.md no longer says the denial is "not reported as a
    StackEvent".

    All five criteria are met, so this closes with #501.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fidelitypriority: lowtype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions