Repository navigation
Let a job token revoke itself; serve a finished job's uploaded step logs - #77
waynesun09 wants to merge 3 commits into
Conversation
On GitHub a job's GITHUB_TOKEN is an installation token: DELETE /installation/token answers 204 and the token is refused from then on. Here it answered 403 "Resource not accessible by personal access token", and clients that revoke their token when a step ends took that as a failure. - A job token may make the call whatever permissions its job declared. - From then on the REST, GraphQL and git routes answer 401 "Bad credentials" for it, public repositories included. The runner authenticates with the same token, so the runner protocol keeps accepting it and the job still reports its steps and result. - The revocation is kept in memory until the token expires (the job's timeout plus 5 minutes, 24 h at most); validation refuses it after that. Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
GET /actions/jobs/{id}/logs served the live console feed even after the
job finished. The runner cuts each feed line at 1024 characters, so a long
line came back cut short. GitHub serves a finished job's log from the step
logs the runner uploads, which hold each line whole.
A finished job's log is now its uploaded step logs, joined in log-id
order. A running job, or a finished one with no uploaded step logs, still
gets the live feed.
Assisted-by: Claude
Signed-off-by: Wayne Sun <gsun@redhat.com>
Assisted-by: Claude Signed-off-by: Wayne Sun <gsun@redhat.com>
|
🤖 Finished Review · ✅ Success · Started 1:02 AM UTC · Completed 1:14 AM UTC Commit: Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.47 |
PR Summary by QodoAllow job-token self-revocation and serve complete finished-job logs
AI Description
Merge Risk
|
Code Review by Qodo
1. Revoked job tokens still read public GraphQL data
|
| if job_token_revoked_for_api(token_value): | ||
| # Refused outright, as GitHub does: falling through to anonymous | ||
| # would let a revoked token still read public repositories. | ||
| raise HTTPException(status_code=401, detail="Bad credentials") |
There was a problem hiding this comment.
1. Revoked job tokens still read public graphql data 🐞 Bug ⛨ Security
_resolve_user raises a 401 for a revoked job token, but the GraphQL context getter catches that exception and substitutes an anonymous user. A request to either GraphQL endpoint with the revoked token can therefore still resolve public repository data instead of returning “Bad credentials.”
Agent Prompt
## Issue description
GraphQL swallows the new revoked-job-token 401 and treats the request as anonymous, allowing public reads with a revoked credential.
## Fix Focus Areas
- src/app/main.py[287-299]
- src/app/api/deps.py[160-166]
## Recommended Fix
Make the GraphQL context getter propagate authentication failures for presented, revoked job tokens rather than converting them to anonymous requests. Preserve anonymous GraphQL access when no credential is presented, and add a regression test for a public GraphQL query using a revoked token.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Risk Assessment: moderate (2/5) DetailsModerate change size across 9 files with no protected paths or dependency modifications, balanced by recent churn and regression history in touched API modules. |
ReviewFindingsMedium
Low
Labels: The PR fixes GitHub-compatibility bugs in the job token and job logs routes. Next steps:
|
| if job_token_revoked_for_api(token_value): | ||
| # Refused outright, as GitHub does: falling through to anonymous | ||
| # would let a revoked token still read public repositories. | ||
| raise HTTPException(status_code=401, detail="Bad credentials") |
There was a problem hiding this comment.
[medium] api-contract
The new revocation 401 never reaches GraphQL. In src/app/main.py (~lines 290-294) get_graphql_context wraps get_current_user in try/except Exception: pass and continues with user=None, so a revoked bearer job token gets a normal anonymous GraphQL response instead of 401 "Bad credentials". This contradicts the PR body and the bug ledger entry, which say the REST, GraphQL and git routes answer 401. The added tests cover only REST.
Suggested fix: Let authentication HTTPExceptions (at least 401) propagate from get_graphql_context instead of turning them into anonymous requests (or narrow the documented claim). Add a test that revokes a job token, POSTs to /api/graphql with it, and asserts 401 "Bad credentials".
| if job_token_revoked_for_api(token_value): | ||
| # Refused outright, as GitHub does: falling through to anonymous | ||
| # would let a revoked token still read public repositories. | ||
| raise HTTPException(status_code=401, detail="Bad credentials") |
There was a problem hiding this comment.
[medium] auth-bypass
Rejection of revoked tokens is not enforced on GraphQL. The unchanged get_graphql_context in src/app/main.py catches every exception from get_current_user, including the new HTTPException, and carries on anonymously. A revoked Bearer job token can therefore still query public repositories instead of getting 401. Exposure is limited to anonymous-readable data, but the PR explicitly promises a 401.
Suggested fix: Let authentication HTTPExceptions propagate from get_graphql_context rather than converting them into anonymous requests. Add a test that revokes a job token and then queries a public repository through /api/graphql, expecting HTTP 401.
| validated = await validate_job_token(db, token_value) | ||
| if validated is not None: | ||
| job, run = validated | ||
| if job_token_revoked_for_api(token_value): |
There was a problem hiding this comment.
[low] api-contract
The revocation check is never reached when the token arrives as a Basic-auth password (the usual git HTTP credential format). In resolve_user (deps.py ~127-131) any Basic password without the ghs prefix returns early through validate_basic_auth, which does not recognise job JWTs, so the request is anonymous. Public REST reads and git fetches therefore stay open instead of returning the documented 401 for a revoked token. The gap predates the PR (an unrevoked job token over Basic was already anonymous), so this is an overstated claim rather than a new exposure.
Suggested fix: Before the Basic early return, send job-token-shaped Basic passwords through the job-token validation/revocation path, or limit the documented 401 claim to Bearer/token schemes. Add a regression test using Basic x-access-token: on a public info/refs route.
| validated = await validate_job_token(db, token_value) | ||
| if validated is not None: | ||
| job, run = validated | ||
| if job_token_revoked_for_api(token_value): |
There was a problem hiding this comment.
[low] auth-bypass
Revocation checks miss HTTP Basic credentials: Basic x-access-token: returns earlier through validate_basic_auth, so public REST reads and public git fetches proceed anonymously instead of returning 401. Private repositories stay protected and the same anonymous fallback existed for unrevoked Basic job tokens before this PR.
Suggested fix: Check the extracted Basic password against job-token revocations before the Basic-auth early return, or route job JWT passwords through the common job-token branch. Cover revoked Basic credentials on public REST and git routes.
| A personal access token is refused, as on the repositories route above. | ||
| """ | ||
| installation_token = getattr(request.state, "installation_token", None) | ||
| if current_user is None: |
There was a problem hiding this comment.
[low] backward-incompatible
DELETE /installation/token now returns 401 ("Bad credentials" or "Requires authentication") when the caller is unauthenticated or the token is unknown or revoked; on BASE this fell through to 403. This matches GitHub, but consumers or tests that expect 403 for unauthenticated callers would break. A finished job's /actions/jobs/{id}/logs body also now comes from uploaded step logs instead of the live feed.
Suggested fix: No code change needed. Optionally note the unauthenticated 403-to-401 change in the bug ledger entry.
jctanner
left a comment
There was a problem hiding this comment.
Requesting changes — the REST side is verified good (revocation refused outright with 401 Bad credentials, no fall-through to anonymous; runner protocol unaffected; PAT still 403; finished-job logs joined in log-id order with the 1024-cut edge pinned), but the GraphQL half of the PR's own claim is not implemented:
get_graphql_context (src/app/main.py ~291) still wraps get_current_user in try/except Exception: pass and continues anonymously, so a revoked bearer job token gets a normal GraphQL response on public data instead of the 401 Bad credentials the PR body and bug ledger promise.
Fix: let authentication HTTPExceptions (at least 401s) propagate from get_graphql_context, and add a test that revokes a job token then POSTs to /api/graphql expecting 401 Bad credentials on a public repository query. Alternatively, narrow the documented claim to REST and git routes.
The Basic-auth gap the bot notes (a job JWT as a Basic password bypasses the revocation check — pre-existing, unrevoked job tokens over Basic were already anonymous) is optional to fix here; scoping the claim covers it.
Summary
Two GitHub-compatibility gaps left over from the Actions context work (#35):
DELETE /installation/tokenwith a job'sGITHUB_TOKENnow answers 204, as on GitHub, where the job token is an installation token. It used to answer 403 "Resource not accessible by personal access token", and clients that revoke their token when a step ends took that as a failure. After the call, the REST, GraphQL and git routes answer 401 "Bad credentials" for the token, public repositories included.GET /repos/{owner}/{repo}/actions/jobs/{id}/logsnow serves a finished job's uploaded step logs. It used to serve the live console feed, whose lines the runner cuts at 1024 characters.Behaviour
DELETE /installation/token, job tokenDELETE /installation/token, personal access tokenCommits
Tests
tests/actions/test_job_token_installation_routes.py: revoke for the API only, 401 on a public repository after revoke, a personal access token still refused, and a revocation kept until its token expires.tests/actions/test_finished_job_logs.py: a finished job serves its uploaded step logs (log id 10 after 2, an empty reserved log skipped); a running job serves the live feed.pre-commit run --from-ref main --to-ref HEADis clean.