# hkb-pipeline-cfn-security

CloudFormation service role for hkb-security-events (DQ-74, DQ-78) and hkb-security-tools-findings (TL.1). The event bus, rules, alert topic, the tools' findings bucket and the keys; no IAM.

- **Lives in:** [Security](/architecture/security/). **Trusted by:** `cloudformation.amazonaws.com`.
- **Boundary:** `hkb-pipeline-boundary`.
- **Reach:** 55 named actions across 5 services (events, kms, s3, sns, ssm); 2 statements on all resources.
- **Source:** `baseline/hkb-baseline-iam.yaml`, resource `SecurityCfnRole`.

## 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-security
    PolicyDocument:
      Version: "2012-10-17"
      Statement:
        # CloudFormation resolves the SSM-typed parameters with its service role, not the
        # action role (3.4e first run, 2026-10-21).
        - Sid: ResolveCatalogParameters
          Effect: Allow
          Action: ssm:GetParameters
          Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/hkb/aws/*
        # Handler permissions from the resource schemas in the cfn-lint bundle (2026-10-21).
        - Sid: SecurityEventBus
          Effect: Allow
          Action:
            - events:CreateEventBus
            - events:DeleteEventBus
            - events:DescribeEventBus
            - events:UpdateEventBus
            - events:PutPermission
            - events:RemovePermission
            - events:TagResource
            - events:UntagResource
            - events:ListTagsForResource
          Resource: !Sub arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:event-bus/hkb-security-events
        - Sid: SecurityEventRules
          Effect: Allow
          Action:
            - events:PutRule
            - events:DeleteRule
            - events:DescribeRule
            - events:PutTargets
            - events:RemoveTargets
            - events:ListTargetsByRule
            - events:TagResource
            - events:UntagResource
            - events:ListTagsForResource   # drift detection reads the rule with this (DQ-145)
          Resource: !Sub arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/hkb-security-events/hkb-*
        - Sid: AlertTopic
          Effect: Allow
          Action:
            - sns:CreateTopic
            - sns:DeleteTopic
            - sns:GetTopicAttributes
            - sns:SetTopicAttributes
            - sns:Subscribe
            - sns:Unsubscribe
            - sns:ListSubscriptionsByTopic
            - sns:TagResource
            - sns:UntagResource
            - sns:ListTagsForResource
            - sns:GetDataProtectionPolicy
            - sns:PutDataProtectionPolicy
          Resource: !Sub arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:hkb-security-events
        - Sid: CreateAlertKey
          Effect: Allow
          Action:
            - kms:CreateKey
            - kms:TagResource
          Resource: "*"
          Condition:
            StringEquals:
              aws:RequestTag/Project: hkb
              aws:RequestTag/Component: [security-events, tools]
        - Sid: ManageAlertKey
          Effect: Allow
          Action:
            - kms:DescribeKey
            - kms:GetKeyPolicy
            - kms:PutKeyPolicy
            - kms:GetKeyRotationStatus
            - kms:EnableKeyRotation
            - kms:DisableKeyRotation
            - kms:EnableKey
            - kms:DisableKey
            - kms:ListResourceTags
            - kms:TagResource
            - kms:UntagResource
            - kms:UpdateKeyDescription
            - kms:ScheduleKeyDeletion
            - kms:CreateAlias
            - kms:DeleteAlias
            - kms:UpdateAlias
          Resource:
            - !Sub arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/*
            - !Sub arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:alias/hkb-security-events
            - !Sub arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:alias/hkb-tools-findings
          Condition:
            StringEqualsIfExists:
              aws:ResourceTag/Component: [security-events, tools]
        - Sid: ListForCloudFormation
          Effect: Allow
          Action: kms:ListAliases
          Resource: "*"
        # The tools' findings bucket (TL.1, DQ-130 item 4); the stack retains it.
        - Sid: ToolsFindingsBucket
          Effect: Allow
          Action:
            - s3:CreateBucket
            - s3:ListBucket
            - s3:GetBucket*
            - s3:PutBucket*
            - s3:DeleteBucketPolicy
            - s3:GetEncryptionConfiguration
            - s3:PutEncryptionConfiguration
            - s3:GetLifecycleConfiguration
            - s3:PutLifecycleConfiguration
          Resource: !Sub arn:${AWS::Partition}:s3:::hkb-tools-findings-${AWS::AccountId}
```
