Skip to content

[Feature]: Make the build-deploy AWS deployment role configurable #46

Closed

Description

@ncipollina

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 ncipollina repository). 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.yaml never requests credentials.
  • cdk-preview.yaml takes the role as an input (roleArn, awsRegion), validates it before use, and passes it to configure-aws-credentials with an explicit audience and a short session.
  • Roles are referenced by callers and secured by the role's own trust policy (repository identity, sub context such as ref:refs/heads/main or 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. When productionRoleArn is 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, default us-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 when runCdk: true and no usable role is configured.
  • Select the role by ref: tag runs use productionRoleArn when set, otherwise roleArn; other runs use roleArn. Log which input was selected (the account ID stays masked).
  • Keep audience: sts.amazonaws.com, mask-aws-account-id, and a bounded role-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: roleArn defaults 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): roleArn is required when runCdk: 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 productionRoleArn to a broader role in a way the consumer didn't configure. The fallback to roleArn applies only when productionRoleArn is not set, and is documented.

Out of scope:

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_request contexts. Document recommending sub restricted to ref:refs/heads/main, tags, or a protected environment, plus repository_id.
  • No new permissions. The template should not request permissions beyond the existing id-token: write for 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 productionRoleArn when provided; non-tag deployments never use productionRoleArn.
  • Invalid role ARNs or regions fail before configure-aws-credentials runs, with a clear error. runCdk: true without 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, sub for main/tags/environment; no job_workflow_ref pinning).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ enhancement💡 idea

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions