diff --git a/.github/workflows/ai-issue-implementation.yml b/.github/workflows/ai-issue-implementation.yml index 088a3b2..f4a9ad8 100644 --- a/.github/workflows/ai-issue-implementation.yml +++ b/.github/workflows/ai-issue-implementation.yml @@ -44,6 +44,11 @@ on: default: false workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest issue-number: description: Optional authorized issue number to implement required: false @@ -93,6 +98,7 @@ jobs: pull-requests: read uses: ./.github/workflows/ai-work-item-resolver.yml with: + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} work-scope: implementation requested-issue-number: ${{ inputs['issue-number'] || '' }} no-pr-label: >- @@ -113,6 +119,7 @@ jobs: pull-requests: write uses: ./.github/workflows/codex-issue-worker.yml with: + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} issue-number: ${{ matrix.issue_number }} pull-request-number: ${{ matrix.pull_request_number }} address-only: ${{ matrix.address_only }} diff --git a/.github/workflows/ai-pr-review-address.yml b/.github/workflows/ai-pr-review-address.yml index f6988c4..09c0f2a 100644 --- a/.github/workflows/ai-pr-review-address.yml +++ b/.github/workflows/ai-pr-review-address.yml @@ -13,6 +13,11 @@ on: type: string workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest pull-request-number: description: Optional pull request number with authorized feedback required: false @@ -67,7 +72,7 @@ jobs: validate-dispatch: name: Validate manual dispatch ref if: github.event_name == 'workflow_dispatch' - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 5 steps: @@ -99,6 +104,7 @@ jobs: pull-requests: read uses: ./.github/workflows/ai-work-item-resolver.yml with: + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} work-scope: review requested-pull-request-number: >- ${{ inputs['pull-request-number'] || '' }} @@ -114,7 +120,7 @@ jobs: github.event.workflow_run.event == 'pull_request_review_comment' && github.event.workflow_run.conclusion == 'success' - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 10 permissions: actions: read @@ -225,6 +231,7 @@ jobs: pull-requests: write uses: ./.github/workflows/codex-issue-worker.yml with: + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} issue-number: ${{ matrix.issue_number }} pull-request-number: ${{ matrix.pull_request_number }} address-only: ${{ matrix.address_only }} diff --git a/.github/workflows/ai-pr-review.yml b/.github/workflows/ai-pr-review.yml index 70ab9f6..c4fe8b2 100644 --- a/.github/workflows/ai-pr-review.yml +++ b/.github/workflows/ai-pr-review.yml @@ -11,6 +11,11 @@ on: types: [created] workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest prompt-path: description: Optional prompt file relative to the caller repository required: false @@ -69,7 +74,7 @@ jobs: github.event_name == 'issue_comment' && github.event.issue.pull_request ) - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} permissions: contents: write pull-requests: write @@ -100,7 +105,7 @@ jobs: contains(github.event.comment.body, '/ai') && contains(github.event.comment.body, 'review') ) - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} permissions: contents: read pull-requests: read @@ -144,6 +149,7 @@ jobs: pull-requests: write uses: ./.github/workflows/claude-review.yml with: + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} pull-request-number: >- ${{ needs.resolve_review.outputs.pull-request-number }} base-sha: ${{ needs.resolve_review.outputs.base-sha }} @@ -171,6 +177,7 @@ jobs: pull-requests: write uses: ./.github/workflows/codex-review.yml with: + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} pull-request-number: >- ${{ needs.resolve_review.outputs.pull-request-number }} base-sha: ${{ needs.resolve_review.outputs.base-sha }} diff --git a/.github/workflows/ai-work-item-resolver.yml b/.github/workflows/ai-work-item-resolver.yml index d8b7b92..147668c 100644 --- a/.github/workflows/ai-work-item-resolver.yml +++ b/.github/workflows/ai-work-item-resolver.yml @@ -3,6 +3,11 @@ name: AI Work Item Resolver on: workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest work-scope: description: Resolve issue implementation or PR review work required: true @@ -43,7 +48,7 @@ permissions: {} jobs: resolve: name: Resolve authorized work - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 10 permissions: contents: read diff --git a/.github/workflows/claude-review.yml b/.github/workflows/claude-review.yml index c738b3b..dea5638 100644 --- a/.github/workflows/claude-review.yml +++ b/.github/workflows/claude-review.yml @@ -3,6 +3,11 @@ name: Claude PR Review on: workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest pull-request-number: description: Pull request number to review required: true @@ -62,7 +67,7 @@ concurrency: jobs: generate: name: Generate Claude review - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} environment: >- ${{ inputs['environment-name'] || 'ai-pr-review-runtime' }} timeout-minutes: 30 @@ -161,19 +166,7 @@ jobs: } >> "$GITHUB_OUTPUT" - name: Prepare unprivileged Claude user - run: | - bash .ai-review-toolkit/scripts/prepare_ai_review_user.sh claude-review - - # The Claude CLI runs through sudo. Preserve only its Bedrock - # credentials and the action's subprocess-isolation controls. - sudo sh -c \ - 'printf "%s\n" \ - "Defaults:runner env_keep += \"AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION AWS_DEFAULT_REGION AWS_BEARER_TOKEN_BEDROCK\"" \ - "Defaults:runner env_keep += \"ANTHROPIC_BEDROCK_BASE_URL CLAUDE_CODE_USE_BEDROCK CLAUDE_CODE_ENTRYPOINT CLAUDE_CODE_ACTION CLAUDE_CODE_ATTRIBUTION_HEADER\"" \ - "Defaults:runner env_keep += \"CLAUDE_CODE_SUBPROCESS_ENV_SCRUB CLAUDE_CODE_SCRIPT_CAPS DETAILED_PERMISSION_MESSAGES\"" \ - > /etc/sudoers.d/claude-review-env' - sudo chmod 440 /etc/sudoers.d/claude-review-env - sudo visudo -cf /etc/sudoers.d/claude-review-env + run: bash .ai-review-toolkit/scripts/prepare_ai_review_user.sh claude-review - name: Configure AWS credentials for Claude uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0 @@ -260,7 +253,7 @@ jobs: post: name: Post Claude review needs: generate - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 10 permissions: contents: write diff --git a/.github/workflows/codex-issue-worker.yml b/.github/workflows/codex-issue-worker.yml index 6df0e4f..5b4d7fb 100644 --- a/.github/workflows/codex-issue-worker.yml +++ b/.github/workflows/codex-issue-worker.yml @@ -3,6 +3,11 @@ name: Codex Issue Worker on: workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest issue-number: description: Issue number, or zero for PR-scoped review work required: true @@ -78,7 +83,7 @@ env: jobs: reconcile: name: Reconcile ${{ inputs['work-key'] }} - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} environment: >- ${{ inputs['environment-name'] || 'ai-pr-review-runtime' }} timeout-minutes: 140 @@ -499,12 +504,12 @@ jobs: sudo install \ -m 600 \ - -o runner \ - -g runner \ + -o "$(id -un)" \ + -g "$(id -gn)" \ "$output_file" \ "${RUNNER_TEMP}/codex-implementation-result.json" - sudo chown -R runner:runner "$GITHUB_WORKSPACE" + sudo chown -R "$(id -un):$(id -gn)" "$GITHUB_WORKSPACE" sudo chmod -R u+rwX,go-rwx "$GITHUB_WORKSPACE" export AWS_CONTAINER_AUTHORIZATION_TOKEN="$credential_proxy_token" @@ -546,7 +551,7 @@ jobs: if: >- always() && needs.reconcile.result != 'cancelled' - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 20 permissions: contents: write diff --git a/.github/workflows/codex-review.yml b/.github/workflows/codex-review.yml index d8075a2..fc15a3f 100644 --- a/.github/workflows/codex-review.yml +++ b/.github/workflows/codex-review.yml @@ -3,6 +3,11 @@ name: Codex PR Review on: workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest pull-request-number: description: Pull request number to review required: true @@ -62,7 +67,7 @@ concurrency: jobs: generate: name: Generate Codex review - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} environment: >- ${{ inputs['environment-name'] || 'ai-pr-review-runtime' }} timeout-minutes: 45 @@ -153,14 +158,6 @@ jobs: run: | bash .ai-review-toolkit/scripts/prepare_ai_review_user.sh codex-review - # Codex runs through sudo, so preserve its AWS SDK credential chain. - sudo sh -c \ - 'printf "%s\n" \ - "Defaults:runner env_keep += \"AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION AWS_DEFAULT_REGION\"" \ - > /etc/sudoers.d/codex-review-env' - sudo chmod 440 /etc/sudoers.d/codex-review-env - sudo visudo -cf /etc/sudoers.d/codex-review-env - current_userns="$( sysctl -n kernel.unprivileged_userns_clone 2>/dev/null || true )" @@ -233,24 +230,35 @@ jobs: output_schema="${GITHUB_WORKSPACE}/.ai-review-toolkit/.github/prompts/ai-pr-review-schema.json" trap 'sudo rm -rf "$output_dir"' EXIT - sudo -u codex-review -- sh -c ' - : "${AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID was not preserved by sudo}" - : "${AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY was not preserved by sudo}" - : "${AWS_SESSION_TOKEN:?AWS_SESSION_TOKEN was not preserved by sudo}" - : "${AWS_REGION:?AWS_REGION was not preserved by sudo}" - ' + for required in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION; do + : "${!required:?${required} is not set in the job environment}" + done review_ready=false for attempt in 1 2; do sudo -u codex-review -- rm -f "$output_file" + # The model receives only this allowlist. `env -i` makes that true + # regardless of the runner image's sudo env_reset/env_keep policy. # Keep enough of the job budget for a complete second attempt. - if sudo -u codex-review -- timeout \ + if sudo -u codex-review -- env -i \ + AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \ + AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \ + AWS_SESSION_TOKEN="$AWS_SESSION_TOKEN" \ + AWS_REGION="$AWS_REGION" \ + AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION" \ + AWS_EC2_METADATA_DISABLED=true \ + CODEX_HOME=/home/codex-review/.codex \ + HOME=/home/codex-review \ + LANG=C.UTF-8 \ + LOGNAME=codex-review \ + PATH="$PATH" \ + SHELL=/bin/bash \ + USER=codex-review \ + /usr/bin/timeout \ --signal=TERM \ --kill-after=30s \ 20m \ - env \ - CODEX_HOME=/home/codex-review/.codex \ "$codex_bin" exec \ --skip-git-repo-check \ --cd "$GITHUB_WORKSPACE" \ @@ -295,8 +303,8 @@ jobs: sudo install \ -m 600 \ - -o runner \ - -g runner \ + -o "$(id -un)" \ + -g "$(id -gn)" \ "$output_file" \ "${RUNNER_TEMP}/codex-review.json" @@ -312,7 +320,7 @@ jobs: post: name: Post Codex review needs: generate - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 10 permissions: contents: write diff --git a/.github/workflows/issue-triage.yml b/.github/workflows/issue-triage.yml index 83c0ed3..495baed 100644 --- a/.github/workflows/issue-triage.yml +++ b/.github/workflows/issue-triage.yml @@ -5,6 +5,11 @@ on: types: [opened] workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest environment-name: description: GitHub environment used for the model job required: false @@ -76,7 +81,7 @@ concurrency: jobs: classify: name: Classify issue with Codex - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} environment: >- ${{ inputs['environment-name'] || 'ai-pr-review-runtime' }} timeout-minutes: 30 @@ -150,14 +155,6 @@ jobs: run: | bash scripts/prepare_ai_triage_user.sh - # Codex runs through sudo, so preserve its AWS SDK credential chain. - sudo sh -c \ - 'printf "%s\n" \ - "Defaults:runner env_keep += \"AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION AWS_DEFAULT_REGION\"" \ - > /etc/sudoers.d/codex-triage-env' - sudo chmod 440 /etc/sudoers.d/codex-triage-env - sudo visudo -cf /etc/sudoers.d/codex-triage-env - current_userns="$( sysctl -n kernel.unprivileged_userns_clone 2>/dev/null || true )" @@ -244,24 +241,35 @@ jobs: # The unprivileged user cannot traverse the workspace. Run from /tmp; # stdin is opened by the runner before sudo drops privileges. cd /tmp - sudo -u codex-triage -- sh -c ' - : "${AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID was not preserved by sudo}" - : "${AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY was not preserved by sudo}" - : "${AWS_SESSION_TOKEN:?AWS_SESSION_TOKEN was not preserved by sudo}" - : "${AWS_REGION:?AWS_REGION was not preserved by sudo}" - ' + for required in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION; do + : "${!required:?${required} is not set in the job environment}" + done triage_ready=false for attempt in 1 2; do sudo -u codex-triage -- rm -f "$output_file" rm -f "$raw_result" "$validated_file" - if sudo -u codex-triage -- timeout \ + # The model receives only this allowlist. `env -i` makes that true + # regardless of the runner image's sudo env_reset/env_keep policy. + if sudo -u codex-triage -- env -i \ + AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \ + AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \ + AWS_SESSION_TOKEN="$AWS_SESSION_TOKEN" \ + AWS_REGION="$AWS_REGION" \ + AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION" \ + AWS_EC2_METADATA_DISABLED=true \ + CODEX_HOME=/home/codex-triage/.codex \ + HOME=/home/codex-triage \ + LANG=C.UTF-8 \ + LOGNAME=codex-triage \ + PATH="$PATH" \ + SHELL=/bin/bash \ + USER=codex-triage \ + /usr/bin/timeout \ --signal=TERM \ --kill-after=30s \ 12m \ - env \ - CODEX_HOME=/home/codex-triage/.codex \ "$codex_bin" \ --ask-for-approval never \ --sandbox read-only \ @@ -297,8 +305,8 @@ jobs: then sudo install \ -m 600 \ - -o runner \ - -g runner \ + -o "$(id -un)" \ + -g "$(id -gn)" \ "$output_file" \ "$raw_result" @@ -335,7 +343,7 @@ jobs: name: Apply issue labels needs: classify if: always() && !cancelled() - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 10 permissions: contents: read diff --git a/.github/workflows/notify.yml b/.github/workflows/notify.yml index 17fac20..294941e 100644 --- a/.github/workflows/notify.yml +++ b/.github/workflows/notify.yml @@ -11,6 +11,11 @@ on: types: [published] workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest environment-name: description: GitHub environment used for the model job required: false @@ -46,7 +51,7 @@ jobs: if: >- github.event_name != 'pull_request_target' || github.event.pull_request.draft == false - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} environment: >- ${{ inputs['environment-name'] || 'ai-pr-review-runtime' }} timeout-minutes: 10 @@ -167,19 +172,30 @@ jobs: trusted_prompt="$(cat "$prompt_file")" cd /tmp - sudo -u codex-summary -- sh -c ' - : "${AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID was not preserved by sudo}" - : "${AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY was not preserved by sudo}" - : "${AWS_SESSION_TOKEN:?AWS_SESSION_TOKEN was not preserved by sudo}" - : "${AWS_REGION:?AWS_REGION was not preserved by sudo}" - ' + for required in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION; do + : "${!required:?${required} is not set in the job environment}" + done - sudo -u codex-summary -- timeout \ + # The model receives only this allowlist. `env -i` makes that true + # regardless of the runner image's sudo env_reset/env_keep policy. + sudo -u codex-summary -- env -i \ + AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID" \ + AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY" \ + AWS_SESSION_TOKEN="$AWS_SESSION_TOKEN" \ + AWS_REGION="$AWS_REGION" \ + AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION" \ + AWS_EC2_METADATA_DISABLED=true \ + CODEX_HOME=/home/codex-summary/.codex \ + HOME=/home/codex-summary \ + LANG=C.UTF-8 \ + LOGNAME=codex-summary \ + PATH="$PATH" \ + SHELL=/bin/bash \ + USER=codex-summary \ + /usr/bin/timeout \ --signal=TERM \ --kill-after=15s \ 2m \ - env \ - CODEX_HOME=/home/codex-summary/.codex \ "$codex_bin" \ --ask-for-approval never \ --sandbox read-only \ @@ -214,8 +230,8 @@ jobs: sudo install \ -m 600 \ - -o runner \ - -g runner \ + -o "$(id -un)" \ + -g "$(id -gn)" \ "$model_output" \ "${summary_dir}/raw-summary.txt" @@ -236,7 +252,7 @@ jobs: !cancelled() && github.event_name == 'pull_request_target' && github.event.pull_request.draft == false - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 5 permissions: {} steps: @@ -260,7 +276,7 @@ jobs: always() && !cancelled() && github.event_name == 'issues' - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 5 permissions: {} steps: @@ -284,7 +300,7 @@ jobs: always() && !cancelled() && github.event_name == 'discussion' - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 5 permissions: {} steps: @@ -308,7 +324,7 @@ jobs: always() && !cancelled() && github.event_name == 'release' - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 5 permissions: {} steps: diff --git a/.github/workflows/stale-issue-closer.yml b/.github/workflows/stale-issue-closer.yml index 84b2870..e60a7ab 100644 --- a/.github/workflows/stale-issue-closer.yml +++ b/.github/workflows/stale-issue-closer.yml @@ -10,6 +10,11 @@ on: workflow_dispatch: workflow_call: inputs: + runs-on: + description: Runner label for every job in this workflow + required: false + type: string + default: ubuntu-latest days-until-close: description: Days without a response before an issue is closed required: false @@ -29,7 +34,7 @@ concurrency: jobs: close-stale: name: Close stale issues - runs-on: ubuntu-latest + runs-on: ${{ inputs['runs-on'] || 'ubuntu-latest' }} timeout-minutes: 15 permissions: contents: read diff --git a/README.md b/README.md index 3f4a50d..4f7fa4c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,48 @@ Shared GitHub Actions workflows for AWS Durable Execution repositories. - [Issue triage](docs/issue-triage.md): Uses AI to classify new issues with existing repository labels. - [Stale issue closer](docs/stale-issue-closer.md): Closes issues with a `needs-info` label after 14 days without a response. Clears the label if a response was posted within the 14 day window. +### Runner selection + +Every shareable workflow accepts an optional `runs-on` input that sets the +runner label for all of its jobs. It defaults to `ubuntu-latest`. A caller that +hosts its own runners, for example through CodeBuild-hosted GitHub Actions +runners, passes the label in the `with` block: + +```yaml + uses: aws/aws-durable-execution-ci/.github/workflows/ai-pr-review.yml@ + with: + runs-on: codebuild-github-actions-runner-${{ github.run_id }}-${{ github.run_attempt }} + secrets: inherit +``` + +Workflows that run model jobs (`ai-pr-review`, `ai-pr-review-address`, +`ai-issue-implementation`, `notify`, `issue-triage`) create an unprivileged +user and drop into it with `sudo`. The selected runner must therefore: + +- be ephemeral, with a fresh environment for every job: GitHub-hosted runners + and CodeBuild-hosted runners both discard the container after one job. The + workflows create the unprivileged user and its home directory + unconditionally and never remove them, so a persistent self-hosted runner + fails on its second job and would carry the model's writable state from one + job to the next; +- run jobs as an account with passwordless `sudo` (the account's name does not + matter: `runner` on GitHub-hosted runners and `root` on CodeBuild-hosted + runners are both resolved at runtime with `id -un`); +- provide `adduser` and `setfacl`; +- allow the job to run for at least as long as the workflow's + `timeout-minutes`. + +A consuming repository that calls the same reusable workflow from more than one +caller must pass `runs-on` in each of them. `ai-pr-review-address.yml` is +called from both the intake/address caller and the `workflow_run` +continuation; see `docs/ai-pr-review-address.md`. + +The model process is started with `sudo -u -- env -i` and an explicit +allowlist of variables (its Bedrock credentials and the CLI's own settings), so +it never sees the job's environment, whatever the runner image's `sudo` +environment policy is. On CodeBuild that is what keeps the project's service +role credentials out of the model's reach. + ## Dependency updates Dependabot checks the npm runtime dependencies and SHA-pinned GitHub Actions diff --git a/docs/ai-pr-review-address.md b/docs/ai-pr-review-address.md index a4e98d9..348168c 100644 --- a/docs/ai-pr-review-address.md +++ b/docs/ai-pr-review-address.md @@ -61,6 +61,8 @@ jobs: issues: read pull-requests: read uses: aws/aws-durable-execution-ci/.github/workflows/ai-pr-review-address.yml@ + with: + runs-on: ubuntu-latest address: if: >- @@ -75,6 +77,7 @@ jobs: uses: aws/aws-durable-execution-ci/.github/workflows/ai-pr-review-address.yml@ with: pull-request-number: ${{ inputs['pull-request-number'] || '' }} + runs-on: ubuntu-latest secrets: inherit ``` @@ -118,9 +121,17 @@ jobs: ${{ format('{0}', github.event.workflow_run.id || '') }} source-run-attempt: >- ${{ format('{0}', github.event.workflow_run.run_attempt || '') }} + runs-on: ubuntu-latest secrets: inherit ``` +Pass the same `runs-on` value to every call of `ai-pr-review-address.yml` in +the consuming repository: the intake and address jobs above and the +continuation's address job. The continuation is a separate workflow file, so a +runner label set only in `ai-pr-review-address.yml` leaves inline-comment +reconciliation on `ubuntu-latest`. The input and its runner requirements are +described in the README under "Runner selection". + The continuation has a different workflow name, so its completion cannot trigger itself. It does not filter completed runs by branch name; a fork pull request whose head branch is named like the target repository's default branch diff --git a/scripts/prepare_ai_review_user.sh b/scripts/prepare_ai_review_user.sh index d5fbafd..dc7c53a 100755 --- a/scripts/prepare_ai_review_user.sh +++ b/scripts/prepare_ai_review_user.sh @@ -41,13 +41,23 @@ sudo install \ -g "$review_user" \ "${private_dirs[@]}" -# Standard hosted runners make /home/runner traversable. Keep this exact ACL -# fallback for images that use a private runner home instead. -if ! sudo -u "$review_user" test -x /home/runner; then - sudo setfacl -m "u:${review_user}:--x" /home/runner -fi +# The review user must traverse every directory above the workspace. Hosted +# runners keep it under a private /home/runner; CodeBuild runners keep it +# under a world-traversable /codebuild tree. Grant execute-only ACLs on exactly +# the ancestors that block traversal, checking top-down so each test only +# depends on ancestors already handled. +ancestor="/" +IFS=/ read -r -a ancestor_parts <<< "$(dirname "${GITHUB_WORKSPACE#/}")" +for part in "${ancestor_parts[@]}"; do + ancestor="${ancestor%/}/${part}" + if ! sudo -u "$review_user" test -x "$ancestor"; then + sudo setfacl -m "u:${review_user}:--x" "$ancestor" + fi +done -sudo chown -R "runner:${review_user}" "$GITHUB_WORKSPACE" +# The workspace stays owned by the account running the job (`runner` on +# hosted runners, `root` on CodeBuild); only group access is opened. +sudo chown -R "$(id -un):${review_user}" "$GITHUB_WORKSPACE" sudo chmod -R g-w,o-rwx "$GITHUB_WORKSPACE" sudo chmod -R g+rX "$GITHUB_WORKSPACE" diff --git a/scripts/prepare_ai_summary_user.sh b/scripts/prepare_ai_summary_user.sh index b59b157..18d4f03 100644 --- a/scripts/prepare_ai_summary_user.sh +++ b/scripts/prepare_ai_summary_user.sh @@ -23,13 +23,6 @@ sudo install \ -g "$summary_user" \ "${home_dir}/.codex" -sudo sh -c \ - 'printf "%s\n" \ - "Defaults:runner env_keep += \"AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION AWS_DEFAULT_REGION\"" \ - > /etc/sudoers.d/codex-summary-env' -sudo chmod 440 /etc/sudoers.d/codex-summary-env -sudo visudo -cf /etc/sudoers.d/codex-summary-env - current_userns="$( sysctl -n kernel.unprivileged_userns_clone 2>/dev/null || true )" diff --git a/scripts/prepare_codex_implementation_user.sh b/scripts/prepare_codex_implementation_user.sh index 5b3b189..cb20e4c 100644 --- a/scripts/prepare_codex_implementation_user.sh +++ b/scripts/prepare_codex_implementation_user.sh @@ -23,16 +23,27 @@ sudo install \ -g "$implementation_user" \ "${home_dir}/.codex" -# Standard hosted runners make /home/runner traversable. Keep this exact ACL -# fallback for images that use a private runner home instead. -if ! sudo -u "$implementation_user" test -x /home/runner; then - sudo setfacl -m "u:${implementation_user}:--x" /home/runner -fi +# The implementation user must traverse every directory above the workspace. +# Hosted runners keep it under a private /home/runner; CodeBuild runners keep +# it under a world-traversable /codebuild tree. Grant execute-only ACLs on +# exactly the ancestors that block traversal, checking top-down so each test +# only depends on ancestors already handled. +ancestor="/" +IFS=/ read -r -a ancestor_parts <<< "$(dirname "${GITHUB_WORKSPACE#/}")" +for part in "${ancestor_parts[@]}"; do + ancestor="${ancestor%/}/${part}" + if ! sudo -u "$implementation_user" test -x "$ancestor"; then + sudo setfacl -m "u:${implementation_user}:--x" "$ancestor" + fi +done -# Keep Git metadata read-only while allowing Codex to edit the worktree. +# Keep Git metadata read-only while allowing Codex to edit the worktree. The +# workspace root and .git stay owned by the account running the job (`runner` +# on hosted runners, `root` on CodeBuild). +job_user="$(id -un)" sudo chown -R "${implementation_user}:${implementation_user}" "$GITHUB_WORKSPACE" -sudo chown "runner:${implementation_user}" "$GITHUB_WORKSPACE" -sudo chown -R "runner:${implementation_user}" "$GITHUB_WORKSPACE/.git" +sudo chown "${job_user}:${implementation_user}" "$GITHUB_WORKSPACE" +sudo chown -R "${job_user}:${implementation_user}" "$GITHUB_WORKSPACE/.git" sudo chmod -R u+rwX,go-rwx "$GITHUB_WORKSPACE" sudo chmod -R g-w,o-rwx "$GITHUB_WORKSPACE/.git" sudo chmod -R g+rX "$GITHUB_WORKSPACE/.git" diff --git a/scripts/run_claude_isolated.sh b/scripts/run_claude_isolated.sh index 004e1c9..8503972 100755 --- a/scripts/run_claude_isolated.sh +++ b/scripts/run_claude_isolated.sh @@ -22,7 +22,41 @@ if ! sudo -H -u claude-review -- test -x "${bun_dir}/bun"; then exit 1 fi -exec sudo -H -u claude-review -- env \ +# Claude receives only this allowlist: its Bedrock credentials and the +# action's subprocess-isolation controls. `env -i` makes that true regardless +# of the runner image's sudo env_reset/env_keep policy. Unset variables are +# skipped rather than passed as empty strings. +allowlist=( + AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY + AWS_SESSION_TOKEN + AWS_REGION + AWS_DEFAULT_REGION + AWS_BEARER_TOKEN_BEDROCK + ANTHROPIC_BEDROCK_BASE_URL + CLAUDE_CODE_USE_BEDROCK + CLAUDE_CODE_ENTRYPOINT + CLAUDE_CODE_ACTION + CLAUDE_CODE_ATTRIBUTION_HEADER + CLAUDE_CODE_SUBPROCESS_ENV_SCRUB + CLAUDE_CODE_SCRIPT_CAPS + DETAILED_PERMISSION_MESSAGES +) +model_env=() +for name in "${allowlist[@]}"; do + if [[ -n "${!name+x}" ]]; then + model_env+=("${name}=${!name}") + fi +done + +exec sudo -u claude-review -- env -i \ + "${model_env[@]}" \ + AWS_EC2_METADATA_DISABLED=true \ + HOME=/home/claude-review \ + LANG=C.UTF-8 \ + LOGNAME=claude-review \ PATH="${bun_dir}:/usr/local/bin:/usr/bin:/bin" \ + SHELL=/bin/bash \ TMPDIR=/home/claude-review/tmp \ + USER=claude-review \ "$claude_bin" "$@" diff --git a/tests/test_codex_issue_implementation.py b/tests/test_codex_issue_implementation.py index b4ad93a..9854d12 100644 --- a/tests/test_codex_issue_implementation.py +++ b/tests/test_codex_issue_implementation.py @@ -6289,7 +6289,7 @@ def test_prompt_marks_repository_requests_as_untrusted(self): def test_unprivileged_user_can_write_only_the_worktree(self): self.assertIn("codex-implement", USER_SCRIPT) self.assertIn( - 'sudo chown -R "runner:${implementation_user}" ' + 'sudo chown -R "${job_user}:${implementation_user}" ' '"$GITHUB_WORKSPACE/.git"', USER_SCRIPT, ) diff --git a/tests/test_prepare_codex_implementation_user.py b/tests/test_prepare_codex_implementation_user.py index ce2dce7..7b0d30d 100644 --- a/tests/test_prepare_codex_implementation_user.py +++ b/tests/test_prepare_codex_implementation_user.py @@ -11,19 +11,41 @@ class PrepareCodexImplementationUserTest(unittest.TestCase): - def test_private_runner_home_gets_execute_only_traversal(self): + def test_blocking_workspace_ancestors_get_execute_only_traversal(self): fallback = """\ -if ! sudo -u "$implementation_user" test -x /home/runner; then - sudo setfacl -m "u:${implementation_user}:--x" /home/runner -fi +for part in "${ancestor_parts[@]}"; do + ancestor="${ancestor%/}/${part}" + if ! sudo -u "$implementation_user" test -x "$ancestor"; then + sudo setfacl -m "u:${implementation_user}:--x" "$ancestor" + fi +done """ self.assertIn(fallback, SCRIPT) + self.assertIn( + 'IFS=/ read -r -a ancestor_parts <<< ' + '"$(dirname "${GITHUB_WORKSPACE#/}")"', + SCRIPT, + ) + code_lines = [ + line for line in SCRIPT.splitlines() + if not line.lstrip().startswith("#") + ] + self.assertFalse(any("/home/runner" in line for line in code_lines)) self.assertLess( SCRIPT.index(fallback), SCRIPT.index("git config --global --add safe.directory"), ) + def test_workspace_ownership_uses_the_invoking_account(self): + self.assertIn('job_user="$(id -un)"', SCRIPT) + self.assertIn( + 'sudo chown "${job_user}:${implementation_user}" ' + '"$GITHUB_WORKSPACE"', + SCRIPT, + ) + self.assertNotIn('"runner:', SCRIPT) + if __name__ == "__main__": unittest.main()