Repository navigation
Closed
Labels
Description
Motivation
Problem. build-deploy.yaml assumes one hard-coded AWS role for every consumer:
- name: Configure AWS Credentials via OIDC
if: inputs.runCdk == true
uses: aws-actions/configure-aws-credentials@v6
with:
audience: sts.amazonaws.com
aws-region: us-east-1
role-to-assume: arn:aws:iam::403542860824:role/github-deploy-role- One account for everyone. Every caller deploys into the same AWS account (the Organization management account) with the same role and region. A repository whose resources live in another account, such as a dedicated member account, cannot use the template without forking it.
- One role for every environment. The same role is used for the development deployment (push to
main,<stackName>-dev) and the production deployment (tag push,<stackName>-prod). It is also used for the post-deploy integration tests (integrationTestSolution). Consumers cannot give development and production different, narrower roles. - Workflow inherits the account's trust policy. Because the template, not the caller, chooses the role, the template only works for a consumer if that one role's trust policy admits the consumer's repository. That pushes the role toward broad trust (currently any
ncipollinarepository). Any narrowing of that role has to be coordinated across every consumer at once.
Desired behavior. A consumer configures which role (and region) the deployment assumes in its own workflow, without modifying the shared template, and can use different roles for development and production deployments.
Consistency with v11.0. v11.0 (#42/#43/#44) established these conventions:
pr-build.yamlnever requests credentials.cdk-preview.yamltakes the role as an input (roleArn,awsRegion), validates it before use, and passes it toconfigure-aws-credentialswith an explicit audience and a short session.- Roles are referenced by callers and secured by the role's own trust policy (repository identity,
subcontext such asref:refs/heads/mainor a protected environment, least-privilege permissions). Trust does not pin a reusable-workflow version (job_workflow_ref), so template updates, including Dependabot's, never require IAM changes.
build-deploy.yaml should follow the same input conventions.
Proposed solution
Inputs (names aligned with cdk-preview.yaml):
roleArn(string): role assumed for deployments. WhenproductionRoleArnis set, this is used only for non-tag (development) deployments.productionRoleArn(string, optional): role assumed for tag (production) deployments. Lets consumers keep production credentials separate from development and restrict production trust to tags or a protected environment.awsRegion(string, defaultus-east-1).
Behavior:
- Validate role ARNs and the region before any credentials are requested (same checks as
cdk-preview.yaml). Fail with a clear error whenrunCdk: trueand no usable role is configured. - Select the role by ref: tag runs use
productionRoleArnwhen set, otherwiseroleArn; other runs useroleArn. Log which input was selected (the account ID stays masked). - Keep
audience: sts.amazonaws.com,mask-aws-account-id, and a boundedrole-duration-seconds. - No change to IAM, trust policies, or the permissions any role has. The template only stops choosing the role for the caller.
Backward compatibility (to decide in implementation):
- Every current consumer is pinned to a tag (
v7.2,v10.7,v10.8):ncipollina/infrastructure,ncipollina/trivia-platform(4 workflows),ncipollina/trivia-manager,ncipollina/lightsaber-skill,ncipollina/cosmere-tracker. None is affected until it changes its reference. - Option A, minor release:
roleArndefaults to the current ARN. Existing callers that upgrade keep working without changes, but the template keeps a hard-coded account and role as a default. - Option B, major release (recommended):
roleArnis required whenrunCdk: true, with a migration note giving the exact value existing callers pass to keep today's behavior. This removes the coupling entirely; each consumer then sets its role explicitly when it upgrades. - Either way, the template must not silently fall back from
productionRoleArnto a broader role in a way the consumer didn't configure. The fallback toroleArnapplies only whenproductionRoleArnis not set, and is documented.
Out of scope:
- The
outputPathdefect ([Bug]: build-deploy exports outputPath, redirecting every project's MSBuild OutputPath #45). - The application-specific
TMD_*/TMP_*/OPENAI_*secrets passed to the CDK deploy step. - Changing the existing management-account role or its trust policy, which is tracked separately where that role is defined.
Security considerations:
- Trust stays the boundary. Making the role configurable must not broaden any IAM trust relationship or deployment permission. IAM trust remains the security boundary: a caller can only assume a role whose trust policy admits that caller's repository and run context.
- No pull-request credentials. Deployment roles should never be assumable from
pull_requestcontexts. Document recommendingsubrestricted toref:refs/heads/main, tags, or a protectedenvironment, plusrepository_id. - No new permissions. The template should not request permissions beyond the existing
id-token: writefor the deploy job.
Acceptance criteria
- The deployment role is configurable through workflow inputs; no AWS account ID or role ARN is hard-coded in
build-deploy.yaml(or only as a documented, deprecated default under Option A). - Tag deployments use
productionRoleArnwhen provided; non-tag deployments never useproductionRoleArn. - Invalid role ARNs or regions fail before
configure-aws-credentialsruns, with a clear error.runCdk: truewithout a usable role fails clearly (Option B). - Callers pinned to the current major version keep their current behavior; the release is classified correctly (minor for A, breaking
!for B) and its notes include the migration value for existing callers. - A self-test or consumer validation demonstrates that a configured role is the one assumed (for example by logging the assumed role name). It also demonstrates that a role whose trust does not admit the caller is denied (
Not authorized to perform sts:AssumeRoleWithWebIdentity). - README documents the inputs, the role-selection rules, and the recommended trust conditions (
aud,repository_id,subformain/tags/environment; nojob_workflow_refpinning).
Activity
feat(github): configurable build-deploy roles and separate MSBuild ou…
feat(github): configurable build-deploy roles and separate MSBuild ou…