Repository navigation
Check job tokens, caller roles and runner scope on Actions routes as GitHub does - #31
Conversation
PR Summary by QodoEnforce job-token, repository-role, and runner-scope checks
AI Description
Merge Risk
|
|
🤖 Finished Review · ✅ Success · Started 10:40 PM UTC · Completed 10:53 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $4.14 |
Code Review by Qodo
1.
|
|
Risk Assessment: moderate (2/5) DetailsModerate change size with solid test coverage and no protected or dependency files, closely aligned with linked issue scope despite modifying existing authorization behavior without flags. Previous runRisk Assessment: moderate (2/5) DetailsModerate change size with solid test coverage and no protected or dependency files, closely aligned with linked issue scope despite modifying existing authorization behavior without flags. Previous run (2)Risk Assessment: moderate (2/5) DetailsModerate change size across 9 files implementing Actions token, role, and runner scope checks with solid test coverage and no protected paths, dependency changes, or author contention. |
ReviewFindingsMedium
Low
Next steps:
Previous run<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJyZXF1ZXN0LWNoYW5nZXMiLCJmaW5kaW5ncyI6W3sic2V2ZXJpdHkiOiJtZWRpdW0iLCJjYXRlZ29yeSI6ImJhY2t3YXJkLWluY29tcGF0aWJsZSIsImZpbGUiOiJzcmMvYXBwL3NlcnZpY2VzL2pvYl90b2tlbl9zZXJ2aWNlLnB5IiwiaWQiOiJmX2UwZGQzMTk2MDU3NjcyYTQiLCJsaW5lIjo2NywiYWN0aW9uYWJsZSI6dHJ1ZSwiZGltZW5zaW9uIjoiY3Jvc3MtcmVwby1jb250cmFjdHMifSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJhdXRoLWJ5cGFzcyIsImZpbGUiOiJzcmMvYXBwL2FwaS9hY3Rpb25zX2Rpc3RyaWJ1dGVkX3Rhc2sucHkiLCJpZCI6ImZfZmY2MmMxNzZhMzc5OWU0NCIsImxpbmUiOjI3NCwiYWN0aW9uYWJsZSI6ZmFsc2UsImRpbWVuc2lvbiI6InNlY3VyaXR5In1dfQ== --> ReviewFindingsMedium
Low
Next steps:
Previous run (2)ReviewReason: tool-failure This PR was NOT reviewed. Do not count this as an approval. Previous run (3)<!-- fullsend:review-findings-v2:eyJ2ZXJzaW9uIjoyLCJhY3Rpb24iOiJyZXF1ZXN0LWNoYW5nZXMiLCJmaW5kaW5ncyI6W3sic2V2ZXJpdHkiOiJtZWRpdW0iLCJjYXRlZ29yeSI6InJiYWMtdmlvbGF0aW9uIiwiZmlsZSI6InNyYy9hcHAvYXBpL2FjdGlvbnMucHkiLCJpZCI6ImZfYjE1NmQ3NTJhYjExYWFmYiIsImxpbmUiOjM3MywiYWN0aW9uYWJsZSI6ZmFsc2UsImRpbWVuc2lvbiI6InNlY3VyaXR5In0seyJzZXZlcml0eSI6Im1lZGl1bSIsImNhdGVnb3J5IjoicmJhYy12aW9sYXRpb24iLCJmaWxlIjoic3JjL2FwcC9hcGkvYWN0aW9uc19kaXN0cmlidXRlZF90YXNrLnB5IiwiaWQiOiJmXzIxMWNmMDdjNjRkZGQ1ZjAiLCJsaW5lIjoxMjY4LCJhY3Rpb25hYmxlIjpmYWxzZSwiZGltZW5zaW9uIjoic2VjdXJpdHkifSx7InNldmVyaXR5IjoibWVkaXVtIiwiY2F0ZWdvcnkiOiJhcGktY29udHJhY3QiLCJmaWxlIjoic3JjL2FwcC9hcGkvYWN0aW9ucy5weSIsImlkIjoiZl8wYzYxMDBkMzkwODkyMzYyIiwibGluZSI6OTg0LCJhY3Rpb25hYmxlIjpmYWxzZSwiZGltZW5zaW9uIjoiY29ycmVjdG5lc3MifSx7InNldmVyaXR5IjoibG93IiwiY2F0ZWdvcnkiOiJlZGdlLWNhc2UiLCJmaWxlIjoic3JjL2FwcC9hcGkvYWN0aW9uc19kaXN0cmlidXRlZF90YXNrLnB5IiwiaWQiOiJmXzczYjI4NjA2MDJmYzBjNjEiLCJsaW5lIjozNzcsImFjdGlvbmFibGUiOnRydWUsImRpbWVuc2lvbiI6ImNvcnJlY3RuZXNzIn0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5IjoiYXBpLWNvbnRyYWN0IiwiZmlsZSI6InNyYy9hcHAvYXBpL2FjdGlvbnMucHkiLCJpZCI6ImZfMWRhZTFmMDc0NzVkZDEzNSIsImxpbmUiOjg0OCwiYWN0aW9uYWJsZSI6ZmFsc2UsImRpbWVuc2lvbiI6ImNvcnJlY3RuZXNzIn0seyJzZXZlcml0eSI6ImxvdyIsImNhdGVnb3J5IjoiYmFja3dhcmQtaW5jb21wYXRpYmxlIiwiZmlsZSI6InNyYy9hcHAvYXBpL2FjdGlvbnMucHkiLCJpZCI6ImZfYjIzYzEwYmRiODRhNjRhMyIsImFjdGlvbmFibGUiOmZhbHNlLCJkaW1lbnNpb24iOiJjcm9zcy1yZXBvLWNvbnRyYWN0cyJ9LHsic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6ImJhY2t3YXJkLWluY29tcGF0aWJsZSIsImZpbGUiOiJzcmMvYXBwL2FwaS9hY3Rpb25zX2Rpc3RyaWJ1dGVkX3Rhc2sucHkiLCJpZCI6ImZfMmYyZjk0ODkzODZiNWI2NyIsImFjdGlvbmFibGUiOmZhbHNlLCJkaW1lbnNpb24iOiJjcm9zcy1yZXBvLWNvbnRyYWN0cyJ9LHsic2V2ZXJpdHkiOiJsb3ciLCJjYXRlZ29yeSI6ImJhY2t3YXJkLWluY29tcGF0aWJsZSIsImZpbGUiOiJzcmMvYXBwL2FwaS9hY3Rpb25zX2Rpc3RyaWJ1dGVkX3Rhc2sucHkiLCJpZCI6ImZfMjI2NDc0ZjM1YjQxYThlNCIsImFjdGlvbmFibGUiOmZhbHNlLCJkaW1lbnNpb24iOiJjcm9zcy1yZXBvLWNvbnRyYWN0cyJ9XX0= --> ReviewFindingsMedium
Low
Next steps:
|
|
🤖 Finished Review · ❌ Failure (post-script /home/runner/work/github-emulator/github-emulator/.fullsend/.fullsend-cache/resources/sha256/e7a9998a1b648e11a40a2f74e5b270e63707430a0953227f2f651b4c86d70654/scripts/post-review.sh failed:…) · Started 11:16 PM UTC · Completed 11:37 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $0.37 |
|
🤖 Finished Review · ✅ Success · Started 3:09 AM UTC · Completed 3:20 AM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.79 |
jctanner
left a comment
There was a problem hiding this comment.
Approving with nits. This is the security keystone for the batch: signature/issuer/lifetime verification on every job-server route, plan/timeline binding to the token's own job, runner-scope filtering on the pool agent routes, and role checks on the Actions write routes — all verified with negative tests. One medium known issue, already fixed by #34: the job token's 1 h expiry with no refresh would 401 long-running jobs on the job-server routes — keep the #31 → #34 merge order. Nits: note the dt_oauth_token limitation in the scoping bug note (fixed by #44), and the low findings the bot reclassified as intentional are fine.
The job-server routes the upstream runner calls (timeline records and feed, logs, action download info and the action archive) now authenticate the job token through the existing validate_job_token, which checks its signature, issuer and lifetime, and answer 401 when it fails. GitHub accepts only a job token it issued; the runner's own token works as before. Tests: tests/actions/test_job_token_routes.py (a bad signature, an unsigned token, another issuer and an expired token on every route). Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
Dispatch, cancel, re-run and artifact upload or delete now require write access to the repository. Actions secrets, variables and permissions require admin access (the owner, for a personal repository). A site admin passes. A job's GITHUB_TOKEN and an App installation token keep the per-route permission checks they already get at authentication. Cancel acts only on a run of the repository in its path; another run id is 404, as for re-run. Tests: tests/test_actions_write_permissions.py (cancel by a user with no role, a reader and a writer; a run of another repository; re-run by a reader; secrets, variables and permissions by each role). Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
Listing, updating and removing pool agents covered every runner on the instance. On GitHub a runner belongs to the repository, organization or enterprise it registered with, and its credential sees only the agents there. The three routes now match on that scope; a runner outside it is not listed, and updating or removing it is 404. Tests: tests/actions/test_runner_agent_scope.py. Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
The runner addresses each job-server call with the plan (the run) and timeline (the job) ids from its job message. The feed, timeline records, log and action download info routes now check that the plan and timeline in the path are the job token's own, answer 404 otherwise, and write only to the token's job. They no longer look a job up by plan or timeline id, so two jobs of one run also keep their logs apart. validate_job_token now refuses a token whose header or payload is not a JSON object (401), instead of failing with a server error. Tests: tests/actions/test_job_token_route_targets.py (another run's plan, another job's timeline in the same run); two more token shapes in tests/actions/test_job_token_routes.py. Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
…s or settings GitHub's REST reference for repository variables asks for write access, so variable create, update and delete now take the write role instead of admin. Secrets and Actions permissions keep admin. A job's GITHUB_TOKEN has no permission for secrets, variables or repository administration, so GitHub answers it with 403 "Resource not accessible by integration" on those routes. The emulator now does the same; a job token's actions permission still covers dispatch, cancel, re-run and artifacts. Tests: tests/test_actions_write_permissions.py (a writer manages variables, a reader and a user with no role cannot; a job token with actions: write gets 403 on secrets, variables and permissions and can still cancel a run). Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
724efda to
f3b349f
Compare
|
🤖 Finished Review · ✅ Success · Started 5:22 PM UTC · Completed 5:31 PM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.77 |
There was a problem hiding this comment.
Note: The following review comments could not be posted on the diff (GitHub returned 422) and are included here instead:
src/app/services/job_token_service.py(file-level): Line 67 ·
[low] backward-incompatible
issue_job_token sets exp = now + 3600 and validate_job_token enforces it. The job-server routes now go through it, so a job running over one hour gets 401 Invalid job token on them. The same expiry already applied to the REST API and OIDC paths.
Suggested fix: Make the token lifetime match the job timeout (configurable exp of 6 hours or more, or derived from timeout-minutes), document it, and add a test for a job running longer than an hour.
src/app/api/actions_distributed_task.py(file-level): Line 274 ·
[low] auth-bypass
Pre-existing: dt_oauth_token issues and stores a runner bearer token based only on the caller-supplied runner_id, which undermines the new _same_scope_as pool-agent scoping. Not changed by this PR.
Suggested fix: Authenticate the OAuth client against the selected runner credential or public key before rotating its token, and add a regression test; may be handled in the follow-up issue.
Rebased onto #31, every other job-server route answers 404 for a plan that is not the job's own run; the plan events route now does too. validate_job_token comes from the module-level import #31 added. #31's route-target test counts the per-step log files this change writes, since uploads no longer append to the console log. Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
…scope with runner scoping - migrations 0018_runner_public_key/0019_runner_registration_broker renumbered to 0020/0021 (0018 and 0019 are taken by merged #41 and #24) - dt_update_pool_agent: ordinary runners keep #31's scope-filtered lookup (out-of-scope is 404); registration brokers look up unscoped and get #44's 403 broker-scope refusal, as both PRs' tests pin - full suite: 1494 passed, 1 known sandbox failure (test_security_headers needs a built frontend/dist)
…egister Merges current main into the branch, renumbers the migrations to 0020_runner_public_key and 0021_runner_registration_broker (0018 and 0019 are taken by merged #41 and #24), and reconciles the pool-agent update authorization: ordinary runners keep #31's scope-filtered lookup (out-of-scope is 404) while registration brokers look up unscoped and get the 403 broker-scope refusal, as both PRs' tests pin. Full suite: 1494 passed, 1 known sandbox failure (test_security_headers needs a built frontend/dist). Signed-off-by: James Tanner <jtanner+github@redhat.com>
Part of #39
Access checks on job-server, Actions write and pool agent routes
This PR makes three groups of routes check what GitHub checks:
validate_job_token), and that the plan and timeline are the token's ownEach group has its own
docs/bugs/fixed/entry andPLAN.mdline.Changes
1. Job-server routes validate the job token
_job_from_token_valueinsrc/app/api/actions_distributed_task.pynow calls the existingvalidate_job_token(src/app/services/job_token_service.py). It checks the HS256 signature, the issuer andexp/nbf.Invalid job token, including one whose header or payload is not a JSON object. The job's own token works as before._job_for_planchecks that the plan (the run) and timeline (the job) in the path are the token's own, from its job message, and answers 404 otherwise. The routes write only to the token's job, so two jobs of one run also keep their logs apart.2. Actions write routes require the role GitHub documents
_require_repository_roleinsrc/app/api/actions.pyanswers 403 unless the person holds the role:GITHUB_TOKEN)Must have write access to this repository.actionspermissionactionspermissionPOST,PATCH,DELETE)PUT,DELETE)Must have admin rights to Repository.PUT .../actions/permissionsand.../permissions/workflowGITHUB_TOKENhas no permission for secrets, variables or repository administration, so on those routes it gets 403Resource not accessible by integration, as on GitHub.3. Pool agent routes are scoped to the runner
_same_scope_asmatches the caller'srepo_id,org_idandenterprise_slug.dt_list_pool_agents,dt_update_pool_agentanddt_delete_pool_agentuse it.config.sh --replacefinds only the runner with that name in its own scope.Tests
Every new test fails on
mainand passes with this PR.tests/actions/test_job_token_routes.py(2 tests)tests/actions/test_job_token_route_targets.py(2 tests)tests/test_actions_write_permissions.py(6 tests)actions: writeon secrets, variables and permissions, and on canceltests/actions/test_runner_agent_scope.py(1 test)Full suite: runs in this pull request's CI (
ci.yml).Effect on existing behaviour
GITHUB_TOKENcan no longer change Actions secrets, variables or settings.