Skip to content

fix(auth-oidc): fail fast at synth when cognitoFederated() is configured (#447) - #516

Open
osama-rizk wants to merge 1 commit into
mainfrom
fix/auth-oidc-cognito-federated-ssm-secure
Open

fix(auth-oidc): fail fast at synth when cognitoFederated() is configured (#447)#516
osama-rizk wants to merge 1 commit into
mainfrom
fix/auth-oidc-cognito-federated-ssm-secure

Conversation

@osama-rizk

Copy link
Copy Markdown
Contributor

Problem

cognitoFederated() produced a CloudFormation template that always failed to deploy (#447). The CDK layer registered the federated IdP by writing the client client_id / client_secret into AWS::Cognito::UserPoolIdentityProvider.ProviderDetails as {{resolve:ssm-secure:...}} dynamic references, but CloudFormation only allows ssm-secure references on a small allowlist of properties that excludes ProviderDetails.

cdk synth succeeded, so the problem was invisible until cdk deploy, which failed at change-set creation — before any resource was created — leaving the stack in REVIEW_IN_PROGRESS:

SSM Secure reference is not supported in:
[AWS::Cognito::UserPoolIdentityProvider/Properties/ProviderDetails/client_secret,
 AWS::Cognito::UserPoolIdentityProvider/Properties/ProviderDetails/client_id]

This affected every cognitoFederated() user — the credentials are always sourced from secret AppSettings, so ssm-secure was the only code path.

Fix (scoped: surface at synth)

Per the maintainer-sanctioned direction in the issue ("surface the limitation at synth time and document"), AuthOIDC now registers a synth error (via cdk.Annotations.of(this).addError(...)) when a cognitoFederated() provider is configured. This aborts cdk deploy early with an actionable message naming the offending provider(s) and pointing at the self-hosted runtime providers — google(), github(), customOidc(), customOauth2() — which resolve IdP credentials at runtime via AppSetting.get() (not through CloudFormation) and deploy cleanly.

Strict DX improvement: the path was 100% undeployable before, so no working configuration is affected — a cryptic deploy-time change-set failure becomes a clear synth-time error with the workaround inline.

The provisioning scaffolding is left intact (it's built but never synthesized, since the error aborts synth) so the eventual proper fix has a starting point — see below.

Follow-up (the real fix, out of scope here)

Register the IdP through a deploy-time custom resource (AwsCustomResource calling CreateIdentityProvider / UpdateIdentityProvider) that reads the SecureString at deploy time instead of via a CFN dynamic reference. Documented in DESIGN.md; that work is L and needs a sandbox, so it's deliberately not attempted here.

Tests

packages/bb-auth-oidc/src/index.cdk.test.ts (new):

  • cognitoFederated() → asserts the synth error is present (verified as a true red: fails without the guard).
  • a self-hosted google() provider → asserts no such error (control).

Docs

  • cognitoFederated() JSDoc — @remarks limitation + workaround.
  • README "Cognito-mediated federation" — > [!WARNING] callout.
  • DESIGN.md — "Known limitation" section + the custom-resource fix path.

Checklist

  • npm run build, biome lint, check:api clean
  • bb-auth-oidc suite 124/124; new cdk test verified red→green
  • Changeset added (@aws-blocks/bb-auth-oidc patch + @aws-blocks/blocks patch)
  • No API/export changes; docs updated in this PR

Fixes #447

cognitoFederated() emitted a CloudFormation template that always failed to
deploy: the CDK layer wrote the IdP client_id/client_secret into
AWS::Cognito::UserPoolIdentityProvider.ProviderDetails as {{resolve:ssm-secure}}
dynamic references, which CloudFormation does not permit on that property. synth
succeeded; deploy failed at change-set creation (stack left REVIEW_IN_PROGRESS).

Surface the limitation at synth via Annotations.addError with an actionable
message pointing at the self-hosted runtime providers (google/github/customOidc/
customOauth2), which resolve credentials at runtime and deploy cleanly. Docs +
regression test added.

Fixes #447
@osama-rizk
osama-rizk requested a review from a team as a code owner September 8, 2026 15:41
@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 165ccb3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-blocks/bb-auth-oidc Patch
@aws-blocks/blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth-oidc: cognitoFederated() is undeployable — CloudFormation rejects {{resolve:ssm-secure}} in UserPoolIdentityProvider.ProviderDetails

1 participant