Part 1 described Pattern A: ADO builds, uploads a zip, starts CodePipeline. The security story is AWS OIDC Azure DevOps federation—no access keys in variable groups, no “temporary” keys that never rotate.
This post is the wiring diagram: what the trust policy actually checks, how narrow the upload role should be, why bootstrap is a different principal, and why your green ADO job can still fail with AccessDenied on cloudformation:DescribeStacks even when someone has AdministratorAccess.

Previous: Azure DevOps AWS integration (Pattern A)
In Brief
- Issuer is
https://vstoken.dev.azure.com/{orgGuid}—the org GUID is not your tenant display name. - Subject must match the service connection exactly (
sc://org/project/connection-name); one typo =AccessDeniedonsts:AssumeRoleWithWebIdentity. - Audience is
api://AzureADTokenExchangefor workload identity federation. - Upload role gets
s3:PutObjectonsource/*pluscodepipeline:StartPipelineExecution—nothing else for daily CI. - Bootstrap deploys
RisPipeline-{env}once; org SCPs often block ADO from ever doing that—plan an out-of-band deploy.
The Token Path (ASCII)
Azure DevOps pipeline
│
│ 1. Request OIDC token (service connection)
▼
vstoken.dev.azure.com/{orgGuid}
│
│ 2. JWT claims: sub, aud, iss
▼
sts:AssumeRoleWithWebIdentity
│
│ 3. Session credentials (1h max)
▼
IAM role "ADO upload"
│
├── s3:PutObject → {prefix}-pipeline-source/source/ris-source.zip
└── codepipeline:StartPipelineExecution → ris-{env}-main
No AWS_ACCESS_KEY_ID. No AWS_SECRET_ACCESS_KEY in Library. If you see those for the upload path, you are on the wrong pattern.
Microsoft and AWS both document this path:
- Federate into AWS from Azure DevOps using OpenID Connect
- Creating OpenID Connect (OIDC) identity providers
CDK: What We Actually Deploy
When adoOidcOrgId and adoOidcSubject are set in environment config, the pipeline stack provisions:
- OIDC provider for
https://vstoken.dev.azure.com/{adoOidcOrgId}with client idapi://AzureADTokenExchange(or imports an existing provider ARN). - Upload IAM role with
WebIdentityPrincipalandStringEqualson:{issuer}:sub→ youradoOidcSubject{issuer}:aud→api://AzureADTokenExchange
- Inline policies:
grantPutonsource/*, tagging/list helpers,StartPipelineExecutionon the named pipeline.
Conceptually (not copy-paste production config):
const issuer = `https://vstoken.dev.azure.com/${adoOidcOrgId}`;
new iam.Role(this, "AdoUploadRole", {
assumedBy: new iam.WebIdentityPrincipal(providerArn, {
StringEquals: {
[`${issuer}:sub`]: adoOidcSubject,
[`${issuer}:aud`]: "api://AzureADTokenExchange",
},
}),
maxSessionDuration: Duration.hours(1),
});
Stack outputs should expose AdoUploadRoleArn for the ADO service connection—not the CodeBuild role, not the CDK deploy role.
Provider already exists?
Landing zones sometimes pre-create the OIDC provider. Pass adoOidcProviderArn and import it instead of creating a duplicate—duplicate provider errors are annoying during env promotion.
Configuring Azure DevOps
| Step | Where | What to copy |
|---|---|---|
| Org GUID | Azure DevOps → Organization settings | Path segment after vstoken.dev.azure.com/ |
| Subject | Service connection details | sc://{org}/{project}/{connectionName} |
| Role ARN | CloudFormation output AdoUploadRoleArn |
Into AWS → Workload identity federation connection |
| Pipeline task | AWSShellScript@1 or AWSCLI@1 |
awsCredentials: ris-aws-oidc (your connection name) |
Common mistake: Creating the service connection against a bootstrap role with AdministratorAccess, then never narrowing it. Daily uploads do not need CloudFormation.
Second mistake: Copying the subject from a different service connection in another project. The sub claim is per connection.
Debugging AccessDenied on assume role
- In a failing pipeline, print nothing secret—but confirm which service connection the task uses.
- In IAM → Role → Trust relationships, compare
subto the connection’s documented subject. - Confirm org GUID in CDK matches Organization settings (not Entra tenant id unless they happen to align—verify the DevOps doc).
- Check aud is exactly
api://AzureADTokenExchange. - If the role was deployed in account A but the connection points at account B, you will chase ghosts for an hour.
CloudTrail AssumeRoleWithWebIdentity events show the rejected sub when you have permission to read them—worth it once.
Two Roles, Two Lifetimes
| Role | Who assumes | When | Permissions (intent) |
|---|---|---|---|
| Bootstrap | Human break-glass, Bitbucket custom pipeline, or one-off ADO stage | Once per env / after pipeline stack changes | cdk bootstrap, deploy RisPipeline-{env}, create OIDC provider |
| Upload | ADO on every main push |
Daily | S3 put on source prefix + start pipeline |
┌─────────────────────┐ ┌─────────────────────┐
│ Bootstrap principal │ │ ADO upload role │
│ (broad, rare) │ │ (narrow, daily) │
└──────────┬──────────┘ └──────────┬──────────┘
│ │
▼ ▼
cdk deploy RisPipeline-* s3 cp + start-pipeline
creates buckets, OIDC, never touches VPC,
CodePipeline, upload role ECS, or Aurora
After bootstrap, delete or disable bootstrap credentials from routine pipelines. If ADO still has a path to cdk deploy Application on every commit, you have not finished the hybrid split—see part 1.
SCP Landmines (Why Bootstrap Fails in ADO)
Organization Service Control Policies apply to every principal in the account unless exempted. They win over identity-based AdministratorAccess.
Typical explicit denies that block cdk deploy RisPipeline-production from an ADO bootstrap role:
| API pattern | Why CDK cares |
|---|---|
cloudformation:DescribeStacks on CDKToolkit/* |
Synth/deploy reads bootstrap stack |
ssm:GetParameter on /cdk-bootstrap/hnb659fds/version |
Version check before deploy |
sts:AssumeRole on cdk-hnb659fds-*-role-* |
CDK asset publishing and deploy roles |
Symptom: ADO bootstrap stage fails with SCP name in the error (with an explicit deny in a service control policy). Same human with admin console access might still deploy from a different principal (e.g. SSO break-glass not in the denied OU).
Operational playbook:
- Deploy
RisPipeline-{env}once from a principal the SCP allows (security-approved workstation, deployment account, or org exception). - Record outputs: source bucket, upload role ARN, pipeline name.
- Wire ADO upload-only connection to the upload role.
- Stop trying to bootstrap from ADO until IAM/Cloud Center exempts a dedicated bootstrap role.
This is not a failure of OIDC—it is governance doing its job. The hybrid pattern exists partly so daily CI does not need those permissions at all.
S3 Upload Without Pipeline Start
Assume role succeeds; aws s3 cp succeeds; nothing runs in CodePipeline.
Check the upload role policy, not OIDC:
{
"Effect": "Allow",
"Action": "codepipeline:StartPipelineExecution",
"Resource": "arn:aws:codepipeline:eu-west-1:ACCOUNT:ris-production-main"
}
Pipeline name must match ris-{env}-main for the selected risEnv parameter. Region on the CLI must match the pipeline’s region.
When adoOidc* is configured, disable S3→EventBridge auto-start for the same bucket—ADO calls start-pipeline-execution explicitly. Two triggers = duplicate executions and self-mutation races.
EventBridge vs Explicit Start (IAM Angle)
| Trigger | IAM on upload role | Double-run risk |
|---|---|---|
EventBridge on Object Created |
Put only | Low if ADO does not also start |
ADO start-pipeline-execution |
Put + Start | Low if EventBridge disabled |
| Both | Put + Start + EventBridge | High — two executions per zip |
CDK can gate EventBridge creation on !config.adoOidcOrgId. Treat that as infrastructure-as-contract: the same zip should not enter the pipeline twice.
Security Review Checklist
- Upload role trust uses
StringEqualsonsubandaud(not wildcards onsub). - Session duration ≤ 1 hour; no unused
sts:AssumeRoleon upload role for humans. - S3 scope is prefix
source/*, not entire account. - No
kms:Decrypton production CMKs unless upload encrypts with CMK (usually SSE-S3 is enough). - CloudTrail alerts on
AssumeRoleWithWebIdentityto upload role from unexpectedsub(optional, nice in regulated industries). - Bootstrap role not referenced in daily
azure-pipelines.yml.
What’s Next
Part 3 covers parallel CI, merged Cobertura, and path filters—the ADO side of hybrid delivery so PR signal stays fast without lying about coverage.
Series: Part 1 — Pattern A · Part 2 (this) · Part 3 — Parallel CI
Related: CloudFormation stack layers · AWS CDK deployment post-mortem
Fighting OIDC sub mismatches or SCP denies on CDK bootstrap? Connect with me.