Skip to content

Let a job token revoke itself; serve a finished job's uploaded step logs - #77

Open
waynesun09 wants to merge 3 commits into
mainfrom
emu-08b-job-token-revoke-step-logs
Open

waynesun09 wants to merge 3 commits into
mainfrom
emu-08b-job-token-revoke-step-logs

Conversation

@waynesun09

Copy link
Copy Markdown
Member

Summary

Two GitHub-compatibility gaps left over from the Actions context work (#35):

  • A job token can revoke itself. DELETE /installation/token with a job's GITHUB_TOKEN now 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.
  • A finished job's log is whole. GET /repos/{owner}/{repo}/actions/jobs/{id}/logs now 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

Call Before After
DELETE /installation/token, job token 403 204
Any API call with that token afterwards as before the call 401 "Bad credentials"
Runner protocol calls with that token accepted still accepted (the job keeps reporting)
DELETE /installation/token, personal access token 403 403
Job logs, finished job with uploaded step logs live feed, lines cut at 1024 uploaded step logs, in log-id order
Job logs, running job live feed live feed
  • A job token may revoke itself whatever permissions its job declared.
  • The revocation is kept in memory until the token expires: the job's timeout plus 5 minutes (6 h 5 min by default, 24 h at most). After that, token validation refuses the token anyway. A server restart forgets revocations; the bug ledger lists this.

Commits

  1. Let a job token revoke itself through DELETE /installation/token
  2. Serve a finished job's uploaded step logs
  3. Record the job token revoke and finished job log fixes in the bug ledger

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.
  • Without the source changes, the revoke tests fail with 403 and the finished-log test gets the cut line.
  • Targeted run, 18 test files that touch these routes: 202 passed. pre-commit run --from-ref main --to-ref HEAD is clean.

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>
@fullsend-ai-review

fullsend-ai-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 1:02 AM UTC · Completed 1:14 AM UTC

Commit: ba16d80 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $2.47

@qodo-code-review

qodo-code-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Allow job-token self-revocation and serve complete finished-job logs

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Let job tokens revoke their API access without interrupting runner reporting.
• Serve finished jobs’ uploaded step logs instead of the truncated live feed.
• Add regression tests and record the fixes and restart limitation.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: Actions job observability, Workflow job-token credential lifecycle.
  • The changed endpoint and the distributed-task upload path jointly implement one user-visible behavior: retrieving a job's console or uploaded step logs.
  • The uploaded files are the producer/storage hop and get_job_logs is the consumer; they are not separate capabilities.
  • The revoke endpoint, permission exception, in-memory revocation registry, and shared authentication gate form one bounded credential-lifecycle behavior.
  • The API routes are downstream consumers of the shared gate rather than separate capabilities; runner protocol validation is intentionally preserved and is not an affected API outcome.
Behavioral complexity 🔴 High 🧩 State transitions, Interacting branches

  • Before: a job token remained valid according to signed-token validation.
  • After: the same token has a second lifecycle state—API-revoked but still valid for runner validation—and requests must distinguish initial revoke, subsequent API calls, natural expiry, cleanup, and process restart.
  • The new correctness condition is that API rejection must persist for the intended token lifetime while runner/reporting behavior remains usable.
  • The change introduces an interacting credential-state protocol rather than merely calling an existing helper; the process-local storage also creates a restart transition that must be handled or explicitly bounded.
Sources

src/app/services/job_token_service.py[41-49]

# Job tokens revoked through DELETE /installation/token, each with the time
# it expires. The runner authenticates with the same token, so a revocation
# applies only where the job token stands in for GITHUB_TOKEN (the REST,
# GraphQL and git routes that authenticate through app.api.deps), never to
# the runner protocol. An entry is kept until its token expires, which is up
# to the job's timeout plus 5 minutes (6 h 5 min by default, 24 h at most):
# after that validate_job_token refuses the token anyway. Kept in memory,
# because the emulator is one process.
_revoked_api_tokens: dict[str, int] = {}
Potential damage 🔴 High 🩹 Confidentiality

  • A token holder who explicitly revoked the credential can regain API authentication after the local revocation state disappears, including access to API surfaces covered by the shared dependency and potentially repository data or mutations allowed by that token.
  • Reverting the code does not repair the lost revocation state; supported recovery is to revoke again after the process is available, or wait for the token's natural expiry.
  • The runner protocol's continued operation is preserved and is not itself a damage path.
  • Recoverable by reissuing the revocation after restart/routing stabilization or by natural JWT expiry, but there is a window in which API access is restored.
  • Any writes or external effects made during that window require ordinary application-specific investigation and are not automatically compensated.
Sources

src/app/services/job_token_service.py[41-49]

# Job tokens revoked through DELETE /installation/token, each with the time
# it expires. The runner authenticates with the same token, so a revocation
# applies only where the job token stands in for GITHUB_TOKEN (the REST,
# GraphQL and git routes that authenticate through app.api.deps), never to
# the runner protocol. An entry is kept until its token expires, which is up
# to the job's timeout plus 5 minutes (6 h 5 min by default, 24 h at most):
# after that validate_job_token refuses the token anyway. Kept in memory,
# because the emulator is one process.
_revoked_api_tokens: dict[str, int] = {}
Assessed commit ba16d80
Diagram

graph TD
  T["Job token"] --> A["API auth"] --> R["Revocation map"]
  T --> P["Runner protocol"]
  L["Job logs"] --> S{"Completed?"}
  S -->|yes| U["Uploaded logs"]
  S -->|no or empty| F["Live feed"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Persist job-token revocations
  • ➕ Preserves revocation across server restarts.
  • ➖ Adds durable storage and cleanup for tokens that already have short, bounded lifetimes.

Recommendation: The in-memory revocation map is proportionate to the emulator’s single-process design and keeps runner authentication separate from API authorization. Persistent revocation is worth considering if restart-proof invalidation becomes a requirement; the current limitation is documented.

Files changed (9) +265 / -5

Bug fix (5) +85 / -2
actions.pyServe uploaded logs for completed jobs +29/-1

Serve uploaded logs for completed jobs

• Reads nonempty uploaded step-log files in numeric log-id order for completed jobs. Running jobs and completed jobs without uploaded content retain the live-feed fallback.

src/app/api/actions.py

apps.pyAccept job-token self-revocation +14/-0

Accept job-token self-revocation

• Allows an authenticated job token to revoke its API access through DELETE /installation/token while retaining the personal-access-token refusal. Missing or invalid credentials receive a 401 response.

src/app/api/apps.py

deps.pyReject revoked job tokens at API authentication +6/-1

Reject revoked job tokens at API authentication

• Returns 401 Bad credentials for revoked job tokens before route authorization or anonymous public-repository access. Exposes the validated token to the revocation endpoint.

src/app/api/deps.py

job_permissions.pyPermit self-revocation regardless of job permissions +5/-0

Permit self-revocation regardless of job permissions

• Exempts DELETE /installation/token from job permission checks so restricted jobs can revoke their own tokens.

src/app/services/job_permissions.py

job_token_service.pyTrack API-only job-token revocations until expiry +31/-0

Track API-only job-token revocations until expiry

• Adds an in-memory revocation map keyed by token, with expiry read from the token and expired entries removed on subsequent revocations. Runner token validation remains unchanged.

src/app/services/job_token_service.py

Tests (2) +133 / -3
test_finished_job_logs.pyTest finished and running job log sources +71/-0

Test finished and running job log sources

• Verifies that completed jobs serve whole uploaded lines in numeric log-id order, skip empty logs, and that running jobs still serve the live feed.

tests/actions/test_finished_job_logs.py

test_job_token_installation_routes.pyTest API-only job-token self-revocation +62/-3

Test API-only job-token self-revocation

• Covers successful revocation, rejection on a public repository, continued runner-token validation, personal-access-token refusal, and retention through token expiry. Isolates the in-memory revocation map between tests.

tests/actions/test_job_token_installation_routes.py

Documentation (2) +47 / -0
PLAN.mdIndex the fixed bug entry +1/-0

Index the fixed bug entry

• Adds the job-token and finished-log fix to the Actions bug ledger index.

PLAN.md

job-token-revoke-and-finished-job-logs.mdDocument both compatibility fixes and the remaining gap +46/-0

Document both compatibility fixes and the remaining gap

• Records the prior behavior, expected GitHub-compatible responses, log-source selection, test coverage, and the fact that a restart forgets revocations.

docs/bugs/fixed/job-token-revoke-and-finished-job-logs.md

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Revoked job tokens still read public GraphQL data 🐞 Bug ⛨ Security
Description
_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.”
Code

src/app/api/deps.py[R163-166]

+        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")
Relevance

●●● Strong

Concrete bug that contradicts the PR's stated behavior (GraphQL must answer 401 for revoked tokens).
Team historically accepts job-token security fixes; no dismissals or rejections match this GraphQL
context issue.

PR-#31
PR-#35

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed dependency raises for a revoked token, but GraphQL catches the exception before a
resolver runs. Public repository reads then remain permitted for the resulting anonymous context.

src/app/api/deps.py[160-166]
src/app/main.py[287-310]
src/app/graphql/authz.py[85-101]
src/app/services/repository_access.py[51-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #35
✅ Compliance rules (platform): 6 rules
✅ Cross-repo context — repo relationships
  Explored: repo: fullsend-ai/fullsend (sha: 3381ce46) — View relationship
Review mode: Auto: ⚖️ Balanced: Downgraded extended -> standard: change is below the extended eligibility bar (hunks 14/18, lines 270/200; both must reach the floor). Router rationale: Auth revocation and log serving span independent, subtle behavioral paths.

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/app/api/deps.py
Comment on lines +163 to +166
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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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

Dismiss ↗ | View ↗

@fullsend-ai-review

Copy link
Copy Markdown

Risk Assessment: moderate (2/5)

Details

Moderate change size across 9 files with no protected paths or dependency modifications, balanced by recent churn and regression history in touched API modules.

@fullsend-ai-review

Copy link
Copy Markdown

Review

Findings

Medium

  • [api-contract] src/app/api/deps.py:166 — The new revocation 401 never reaches GraphQL. get_graphql_context in src/app/main.py wraps get_current_user in try/except Exception: pass and continues anonymously, so a revoked bearer job token gets a normal GraphQL response instead of 401 "Bad credentials". This contradicts the PR body and bug ledger entry, which say GraphQL answers 401. The added tests cover only REST.
    Remediation: Let authentication HTTPExceptions (at least 401) propagate from get_graphql_context (or narrow the documented claim), and add a test that revokes a job token then POSTs to /api/graphql expecting 401 "Bad credentials".
    See also: [auth-bypass] finding at this location.
  • [auth-bypass] src/app/api/deps.py:166 — Same root cause, security view: a revoked Bearer job token can still query public repositories through GraphQL instead of being refused. Exposure is limited to anonymous-readable data, but the PR promises a 401.
    Remediation: Same fix as above; assert HTTP 401 for a revoked token on a public repository query.
    See also: [api-contract] finding at this location.

Low

  • [api-contract] src/app/api/deps.py:163 — The revocation check is not reached when the token arrives as a Basic-auth password (the usual git credential format): validate_basic_auth returns early and does not recognise job JWTs, so the request is anonymous. Public REST reads and git fetches stay open instead of the documented 401. This predates the PR (an unrevoked job token over Basic was already anonymous), so it is mainly an overstated claim.
    Remediation: Route job-token-shaped Basic passwords through the job-token validation/revocation path before the Basic early return, or limit the documented claim to Bearer/token schemes; add a regression test for Basic x-access-token:<revoked token> on a public info/refs route.
    See also: [auth-bypass] finding at this location.
  • [auth-bypass] src/app/api/deps.py:163 — Same Basic-auth gap, security view: no private-repository access is gained, but public-route rejection of a revoked job token is incomplete.
    Remediation: Check the extracted Basic password against job-token revocations before the Basic early return and cover public REST and git routes.
    See also: [api-contract] finding at this location.
  • [backward-incompatible] src/app/api/apps.py:427 — DELETE /installation/token now returns 401 for unauthenticated, unknown or revoked callers where BASE fell through to 403. This matches GitHub, but consumers or tests that expect 403 would break. Finished-job logs also now come from uploaded step logs instead of the live feed.
    Remediation: No code change needed; optionally note the 403-to-401 change in the bug ledger entry.

Labels: The PR fixes GitHub-compatibility bugs in the job token and job logs routes.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

@fullsend-ai-review fullsend-ai-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the review comment for full details.

Comment thread src/app/api/deps.py
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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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".

Comment thread src/app/api/deps.py
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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread src/app/api/deps.py
validated = await validate_job_token(db, token_value)
if validated is not None:
job, run = validated
if job_token_revoked_for_api(token_value):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread src/app/api/deps.py
validated = await validate_job_token(db, token_value)
if validated is not None:
job, run = validated
if job_token_revoked_for_api(token_value):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread src/app/api/apps.py
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@fullsend-ai-review fullsend-ai-review Bot added the bug Something isn't working label Nov 20, 2026

@jctanner jctanner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants