# hkb-pipeline-cfn-site

CloudFormation service role for the hkb-site and hkb-dns stacks. Site bucket, its KMS key, CloudFront, the hosted zone and the certificate; no IAM.

- **Lives in:** [Sandbox](/architecture/sandbox/), [Dev](/architecture/dev/), [Prod](/architecture/prod/). **Trusted by:** `cloudformation.amazonaws.com`.
- **Boundary:** `hkb-pipeline-boundary`.
- **Reach:** 92 named actions across 7 services (acm, cloudfront, kms, logs, route53, s3, ssm); 3 statements on all resources.
- **Source:** `baseline/hkb-baseline-iam.yaml`, resource `SiteCfnRole`.

## 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-site
    PolicyDocument:
      Version: "2012-10-17"
      Statement:
        - Sid: SiteBuckets
          Effect: Allow
          Action:
            - s3:CreateBucket
            - s3:DeleteBucket
            - s3:ListBucket
            - s3:GetBucket*
            - s3:PutBucket*
            - s3:DeleteBucketPolicy
            - s3:GetEncryptionConfiguration
            - s3:PutEncryptionConfiguration
            - s3:GetLifecycleConfiguration
            - s3:PutLifecycleConfiguration
          Resource: !Sub arn:${AWS::Partition}:s3:::hkb-site-${AWS::AccountId}
        - Sid: CreateSiteKeys
          Effect: Allow
          Action:
            - kms:CreateKey
            - kms:TagResource
          Resource: "*"
          Condition:
            StringEquals:
              aws:RequestTag/Project: hkb
              aws:RequestTag/Component: site
        - Sid: ManageSiteKeys
          Effect: Allow
          Action:
            - kms:DescribeKey
            - kms:GetKeyPolicy
            - kms:PutKeyPolicy
            - kms:GetKeyRotationStatus
            - kms:EnableKeyRotation
            - kms:ListResourceTags
            - kms:TagResource
            - kms:UntagResource
            - kms:UpdateKeyDescription
            - kms:ScheduleKeyDeletion
            - kms:CreateAlias
            - kms:DeleteAlias
            - kms:UpdateAlias
          Resource:
            - !Sub arn:${AWS::Partition}:kms:*:${AWS::AccountId}:key/*
            - !Sub arn:${AWS::Partition}:kms:*:${AWS::AccountId}:alias/hkb-site
          Condition:
            StringEqualsIfExists:
              aws:ResourceTag/Component: site
        - Sid: ListForCloudFormation
          Effect: Allow
          Action:
            - kms:ListAliases
            - cloudfront:List*
            - acm:ListCertificates
            - route53:ListHostedZones
            - route53:ListHostedZonesByName
            - logs:DescribeDeliveries   # the v2 log delivery (DQ-132)
            - logs:DescribeDeliverySources
            - logs:DescribeDeliveryDestinations
          Resource: "*"
        # CloudFormation resolves SSM-typed parameters as the role it is passed, so this role
        # reads the catalog's Log Archive account ID for Prod's access logs (DQ-81, DQ-132).
        - Sid: ResolveCatalogParameters
          Effect: Allow
          Action: ssm:GetParameters
          Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/hkb/aws/*
        - Sid: SiteDistribution
          Effect: Allow
          Action:
            - cloudfront:CreateDistribution
            - cloudfront:UpdateDistribution
            - cloudfront:DeleteDistribution
            - cloudfront:GetDistribution
            - cloudfront:GetDistributionConfig
            - cloudfront:TagResource
            - cloudfront:UntagResource
            - cloudfront:ListTagsForResource
            - cloudfront:CreateOriginAccessControl
            - cloudfront:UpdateOriginAccessControl
            - cloudfront:DeleteOriginAccessControl
            - cloudfront:GetOriginAccessControl
            - cloudfront:GetOriginAccessControlConfig
            - cloudfront:CreateResponseHeadersPolicy
            - cloudfront:UpdateResponseHeadersPolicy
            - cloudfront:DeleteResponseHeadersPolicy
            - cloudfront:GetResponseHeadersPolicy
            - cloudfront:GetResponseHeadersPolicyConfig
            - cloudfront:GetCachePolicy
            # The index and gate function and its key value store (DQ-49, DQ-168)
            - cloudfront:*Function
            - cloudfront:*KeyValueStore
          Resource: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:*
        # Prod's access logs, CloudFront standard logging v2 to Log Archive (DQ-132)
        - !If
          - IsProd
          - Sid: SiteAccessLogs
            Effect: Allow
            Action:
              - cloudfront:AllowVendedLogDeliveryForResource
              - logs:PutDeliverySource
              - logs:GetDeliverySource
              - logs:DeleteDeliverySource
              - logs:PutDeliveryDestination
              - logs:GetDeliveryDestination
              - logs:DeleteDeliveryDestination
              - logs:CreateDelivery
              - logs:GetDelivery
              - logs:UpdateDeliveryConfiguration
              - logs:DeleteDelivery
              - logs:TagResource
              - logs:UntagResource
              - logs:ListTagsForResource
            Resource:
              - !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/*
              - !Sub arn:${AWS::Partition}:logs:us-east-1:${AWS::AccountId}:*
              # The destination is in Log Archive (cross-account delivery)
              - !Sub arn:${AWS::Partition}:logs:us-east-1:*:delivery-destination:hkb-site-logs
          - !Ref AWS::NoValue
        # The hosted zone and the certificate exist only in Prod (DQ-28, DQ-29); zone and
        # certificate IDs are not known before they exist, so the resource is "*".
        - !If
          - IsProd
          - Sid: SiteZoneAndCertificate
            Effect: Allow
            Action:
              - route53:CreateHostedZone
              - route53:DeleteHostedZone
              - route53:GetHostedZone
              - route53:ChangeResourceRecordSets
              - route53:ListResourceRecordSets
              - route53:ChangeTagsForResource
              - route53:ListTagsForResource
              - route53:GetChange
              # The HostedZone handler reads the zone's query logging on read and
              # delete, and edits the zone comment on update (4.6P failure, 2026-10-20).
              - route53:ListQueryLoggingConfigs
              - route53:UpdateHostedZoneComment
              - route53:UpdateHostedZoneFeatures
              # Query logs (Route53.2): the config, its log group, the account resource policy
              - route53:*QueryLoggingConfig
              - logs:*LogGroup
              - logs:DescribeLogGroups
              - logs:*RetentionPolicy
              - logs:*ResourcePolic*
              - logs:*TagResource
              - logs:ListTagsForResource
              - acm:RequestCertificate
              - acm:DescribeCertificate
              - acm:DeleteCertificate
              - acm:AddTagsToCertificate
              - acm:ListTagsForCertificate
              # The Certificate handler's update and delete (6.3, from the resource schema).
              - acm:RemoveTagsFromCertificate
              - acm:UpdateCertificateOptions
            Resource: "*"
          - !Ref AWS::NoValue
```
