# hkb-pipeline-orchestrator

CodePipeline service role for hkb-pipeline-main (platform). Moves artifacts, starts the Validate build, assumes the platform action roles. Deploys nothing itself.

- **Lives in:** [Shared Services](/architecture/shared-services/). **Trusted by:** `codepipeline.amazonaws.com`.
- **Boundary:** `hkb-pipeline-boundary`.
- **Reach:** 14 named actions across 5 services (codebuild, codeconnections, kms, s3, sts); 0 statements on all resources.
- **Source:** `pipeline/hkb-pipeline-foundation.yaml`, resource `OrchestratorRole`.

## Trust policy

```yaml
AssumeRolePolicyDocument:
  Version: "2012-10-17"
  Statement:
    - Effect: Allow
      Principal:
        Service: codepipeline.amazonaws.com
      Action: sts:AssumeRole
      Condition:
        StringEquals:
          aws:SourceAccount: !Ref AWS::AccountId
        ArnLike:
          aws:SourceArn: !Sub arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${PipelineName}
```

## Permissions

```yaml
Policies:
  - PolicyName: hkb-pipeline-orchestrator
    PolicyDocument:
      Version: "2012-10-17"
      Statement:
        - Sid: Artifacts
          Effect: Allow
          Action:
            - s3:GetObject
            - s3:GetObjectVersion
            - s3:PutObject
            - s3:GetBucketLocation
            - s3:ListBucket
          Resource:
            - !GetAtt ArtifactBucket.Arn
            - !Sub ${ArtifactBucket.Arn}/*
        - Sid: ArtifactKey
          Effect: Allow
          Action:
            - kms:Decrypt
            - kms:Encrypt
            - kms:GenerateDataKey*
            - kms:DescribeKey
            - kms:ReEncrypt*
          Resource: !GetAtt PipelineKey.Arn
        - Sid: UseGitHubConnection
          Effect: Allow
          Action: codeconnections:UseConnection
          Resource: !Sub arn:${AWS::Partition}:codeconnections:${AWS::Region}:${AWS::AccountId}:connection/*
        # The site deploy roles and the site-sync build belong to hkb-pipeline-site-orchestrator (3.14, DQ-103).
        - Sid: RunValidateBuilds
          Effect: Allow
          Action:
            - codebuild:StartBuild
            - codebuild:BatchGetBuilds
          Resource: !Sub arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:project/hkb-pipeline-validate
        - Sid: AssumeActionRoles
          Effect: Allow
          Action: sts:AssumeRole
          Resource:
            - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/hkb-pipeline-self
            - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/hkb-pipeline-stacksets
            - !Sub arn:${AWS::Partition}:iam::${SecurityAccountId}:role/hkb-pipeline-security
            # The VPC tier (step 5.5, DQ-110), promoted Sandbox, Dev, Prod.
            - !Sub arn:${AWS::Partition}:iam::${SandboxAccountId}:role/hkb-pipeline-network
            - !Sub arn:${AWS::Partition}:iam::${DevAccountId}:role/hkb-pipeline-network
            - !Sub arn:${AWS::Partition}:iam::${ProdAccountId}:role/hkb-pipeline-network
```
