# hkb-pipeline-site-sync

Site content role (step 4.4, DQ-59). Reads the hkb-site stack outputs, syncs the built site to the site bucket and clears the CloudFront cache. No CloudFormation changes, no IAM.

- **Lives in:** [Sandbox](/architecture/sandbox/), [Dev](/architecture/dev/), [Prod](/architecture/prod/). **Trusted by:** `hkb-pipeline-sync`.
- **Boundary:** `hkb-pipeline-boundary`.
- **Reach:** 9 named actions across 4 services (cloudformation, cloudfront, kms, s3); 0 statements on all resources.
- **Source:** `baseline/hkb-baseline-iam.yaml`, resource `SiteSyncRole`.

## Trust policy

```yaml
AssumeRolePolicyDocument:
  Version: "2012-10-17"
  Statement:
    - Effect: Allow
      Principal:
        AWS: !Sub arn:${AWS::Partition}:iam::${SharedServicesAccountId}:role/hkb-pipeline-sync
      Action: sts:AssumeRole
```

## Permissions

```yaml
Policies:
  - PolicyName: hkb-pipeline-site-sync
    PolicyDocument:
      Version: "2012-10-17"
      Statement:
        - Sid: ReadSiteStackOutputs
          Effect: Allow
          Action: cloudformation:DescribeStacks
          Resource: !Sub arn:${AWS::Partition}:cloudformation:*:${AWS::AccountId}:stack/hkb-site/*
        - Sid: SyncSiteContent
          Effect: Allow
          Action:
            - s3:ListBucket
            - s3:GetBucketLocation
            - s3:PutObject
            - s3:DeleteObject
          # The bucket is named hkb-site-<account> (ruled at 4.1, DQ-57).
          Resource:
            - !Sub arn:${AWS::Partition}:s3:::hkb-site-${AWS::AccountId}
            - !Sub arn:${AWS::Partition}:s3:::hkb-site-${AWS::AccountId}/*
        - Sid: SiteContentKey
          Effect: Allow
          Action:
            - kms:GenerateDataKey
            - kms:Decrypt
          Resource: !Sub arn:${AWS::Partition}:kms:*:${AWS::AccountId}:key/*
          Condition:
            StringEquals:
              aws:ResourceTag/Component: site
        - Sid: InvalidateSiteCache
          Effect: Allow
          Action:
            - cloudfront:CreateInvalidation
            - cloudfront:GetInvalidation
          Resource: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/*
          Condition:
            StringEquals:
              aws:ResourceTag/Component: site
```
