Skip to content

feat(github): add credential-isolated CDK preview workflow - #43

Merged
ncipollina merged 2 commits into
mainfrom
feat/cdk-deployed-templates
Oct 13, 2026
Merged

ncipollina merged 2 commits into
mainfrom
feat/cdk-deployed-templates

Conversation

@ncipollina

@ncipollina ncipollina commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds cdk-preview.yaml, a credential-isolated CDK preview for pull requests (sharedale/sharedale#69). Pairs with #42 for the v11.0.0 release.

Job Credentials What it does
deployed templates read-only role through GitHub OIDC GetTemplate --template-stage Original for each stack; uploads <stack>.json (1-day retention). Never checks out, downloads, or caches anything from the caller; only the runner's AWS CLI/jq and two commit-pinned actions run (configure-aws-credentials v6.3.0, upload-artifact v7.0.2).
diff none (contents: read only) checks out the PR, runs cdk diff <stack> --template <deployed>.json with per-stack context, and writes every stack's result to the job summary; fails if any diff fails
  • One stacks input describes each stack: stack, optional context (cdk -c values), and optional contextFromDeployed (a regex with a (?<value>...) group read from the deployed template, e.g. the currently deployed image tag so only infrastructure changes show).
  • Inputs are validated (role ARN, region, exact cdkVersion, 1–20 distinct well-formed stack names, single-line context values, capture-group regexes) and reach commands through environment variables or argument arrays.
  • IAM is the authoritative allowlist: roles are expected to trust this workflow by job_workflow_ref pinned to a commit SHA and allow only cloudformation:GetTemplate on the listed stacks.

Validation

  • actionlint 1.7.12: clean.
  • Fetch-job input validation: 12/12 cases behaved as expected (shell metacharacters, path traversal, duplicates, malformed account IDs, etc. rejected). The no-credentials error path fails with Could not read the deployed template of <stack>.
  • diff job, run locally from this workflow's own script against Sharedale with no AWS credentials and the deployed Nonproduction templates: inputs accepted; a regex without a capture group rejected. sharedale-development and sharedale-staging-dns diffed; contextFromDeployed extracted the deployed image tag (cd094e6a04b9). sharedale-staging fails until Sharedale consumes feat(cognito): accept an explicit hosted zone for custom domains cdk-constructs#99 (synth-time hosted-zone lookup), and the job reports it.
  • Pending: an end-to-end run after the Sharedale preview role is deployed (sharedale/sharedale#96/#97).

🤖 Generated with Claude Code

@ncipollina ncipollina changed the title feat(github): add credential-isolated CDK deployed-templates workflow feat(github): add credential-isolated CDK preview workflow Oct 13, 2026
ncipollina and others added 2 commits October 13, 2026 19:37
Add a reusable workflow that assumes a read-only role through GitHub OIDC,
fetches the deployed CloudFormation templates of named stacks, and uploads
them as an artifact. It never checks out or runs anything from the caller, so
callers can compare pull request synthesis against deployed state with
cdk diff --template in a separate job that has no credentials.

Inputs are validated before use and reach commands only through environment
variables; actions are pinned to commit SHAs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…K preview

Rename cdk-deployed-templates.yaml to cdk-preview.yaml and add the
credential-free diff job: it checks out the pull request, synthesizes it,
and runs cdk diff against each deployed template, reporting every stack in
the job summary. Per-stack context values can be fixed or read from the
deployed template (for example the currently deployed image tag), so callers
need a single reusable-workflow reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ncipollina
ncipollina marked this pull request as ready for review October 13, 2026 23:37
@ncipollina
ncipollina force-pushed the feat/cdk-deployed-templates branch from e7ba9a7 to d8a0aa3 Compare October 13, 2026 23:37
@github-actions github-actions Bot added the type: feat New feature label Oct 13, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T23:40:49.061937Z d8a0aa3 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ncipollina
ncipollina merged commit 694a8ee into main Oct 13, 2026
4 checks passed
@ncipollina
ncipollina deleted the feat/cdk-deployed-templates branch October 13, 2026 23:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8a0aa3e0f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

done < <(jq -r '(.context // {}) | to_entries[] | [.key, .value] | @tsv' <<<"$entry")
while IFS=$'\t' read -r key regex; do
[[ -n "$key" ]] || continue
value=$(jq -r --arg re "$regex" '[.. | strings | capture($re)?.value] | first // empty' "$deployed")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fix the invalid jq optional-capture expression

Whenever a stack supplies a nonempty contextFromDeployed object—including the documented README example—jq rejects capture($re)?.value with syntax error, unexpected FIELD. Because the step uses set -e, it aborts before running any CDK diff; the optional result must be parenthesized or piped to .value using valid jq syntax.

Useful? React with 👍 / 👎.

continue 2
fi
args+=(-c "$key=$value")
done < <(jq -r '(.contextFromDeployed // {}) | to_entries[] | [.key, .value] | @tsv' <<<"$entry")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve regex escapes when reading deployed contexts

When a contextFromDeployed regex contains a backslash, as common patterns such as (?<value>\d+) do, @tsv escapes that backslash and read -r intentionally leaves the escape doubled. The altered regex is then passed to jq and fails to match the intended template string; use a transport that round-trips arbitrary JSON strings instead of TSV. The same serialization pattern on line 206 also alters direct context values containing backslashes or tabs.

Useful? React with 👍 / 👎.

[[ "$name" =~ ^[A-Za-z][A-Za-z0-9-]{0,127}$ ]] || { echo "::error::Invalid CloudFormation stack name: $name"; exit 1; }
done < <(jq -r '.[].stack' <<<"$STACKS")
jq -r '.[].stack' <<<"$STACKS" > "$RUNNER_TEMP/stack-names.txt"
echo "artifactName=cdk-deployed-templates-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make artifact names unique per workflow invocation

When a caller invokes this reusable workflow more than once in a run—for example, once per role or region—every fetch job receives the same github.run_id and github.run_attempt, so they upload under the same name. upload-artifact@v7 requires artifact names to be unique within a workflow run and the later upload fails with a conflict (official action documentation); include a value unique to the individual reusable-workflow invocation.

Useful? React with 👍 / 👎.

STACKS: ${{ inputs.stacks }}
run: |
set -euo pipefail
[[ "$ROLE_ARN" =~ ^arn:aws:iam::[0-9]{12}:role/[A-Za-z0-9+=,.@_/-]{1,64}$ ]] || { echo "::error::roleArn is not an IAM role ARN."; exit 1; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept valid IAM role partitions and paths

For callers using China/GovCloud partitions or a role path whose combined path and name exceeds 64 characters, this validation rejects an otherwise valid role ARN before credential setup. IAM ARNs can use partitions such as aws-cn, and AWS permits a role path of up to 512 characters in addition to the 64-character role name (IAM identifier documentation, role limits); validate the partition, path, and role name separately rather than limiting the entire resource suffix.

Useful? React with 👍 / 👎.

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

Labels

type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant