# hkb-pipeline-cfn-stacksets

CloudFormation service role for hkb-stacksets-* stacks. Manages hkb-* service-managed StackSets as StackSets delegated administrator; no IAM or Organizations write access.

- **Lives in:** [Shared Services](/architecture/shared-services/). **Trusted by:** `cloudformation.amazonaws.com`.
- **Boundary:** `hkb-pipeline-boundary`.
- **Reach:** 23 named actions across 5 services (cloudformation, kms, organizations, s3, ssm); 2 statements on all resources.
- **Source:** `pipeline/hkb-pipeline-foundation.yaml`, resource `CfnStackSetsRole`.

## Trust policy

```yaml
AssumeRolePolicyDocument:
  Version: "2012-10-17"
  Statement:
    - Effect: Allow
      Principal:
        Service: cloudformation.amazonaws.com
      Action: sts:AssumeRole
      Condition:
        StringEquals:
          aws:SourceAccount: !Ref AWS::AccountId
```

## Permissions

```yaml
Policies:
  - PolicyName: hkb-pipeline-cfn-stacksets
    PolicyDocument:
      Version: "2012-10-17"
      Statement:
        # A service-managed StackSet made by the delegated administrator belongs to the management
        # account, so its ARN carries the master account ID, not this one.
        - Sid: ManageHkbStackSets
          Effect: Allow
          Action:
            - cloudformation:CreateStackSet
            - cloudformation:UpdateStackSet
            - cloudformation:DeleteStackSet
            - cloudformation:DescribeStackSet
            - cloudformation:DescribeStackSetOperation
            - cloudformation:ListStackSetOperations
            - cloudformation:ListStackSetOperationResults
            - cloudformation:CreateStackInstances
            - cloudformation:UpdateStackInstances
            - cloudformation:DeleteStackInstances
            - cloudformation:ListStackInstances
            - cloudformation:DescribeStackInstance
            - cloudformation:TagResource
            - cloudformation:UntagResource
          Resource:
            - !Sub arn:${AWS::Partition}:cloudformation:*:${MasterAccountId}:stackset/hkb-*:*
            - !Sub arn:${AWS::Partition}:cloudformation:*:*:stackset-target/*
            - !Sub arn:${AWS::Partition}:cloudformation:*:*:type/resource/*
        - Sid: ReadStackSetTemplateSummary
          Effect: Allow
          Action: cloudformation:GetTemplateSummary
          Resource: "*"
        - Sid: ConfirmDelegatedAdministrator
          Effect: Allow
          Action:
            - organizations:DescribeOrganization
            - organizations:ListDelegatedAdministrators
            - organizations:ListAWSServiceAccessForOrganization
          Resource: "*"
        - Sid: ReadStackSetTemplates
          Effect: Allow
          Action:
            - s3:GetObject
            - s3:GetObjectVersion
          Resource: !Sub ${ArtifactBucket.Arn}/*
        - Sid: ArtifactKey
          Effect: Allow
          Action:
            - kms:Decrypt
            - kms:DescribeKey
          Resource: !GetAtt PipelineKey.Arn
        - Sid: ResolveIdParameters
          Effect: Allow
          Action: ssm:GetParameters
          Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/hkb/aws/*
```
