Skip to content

fix(codex/build): fetch ephemeral token for codex-link-index reads#110

Merged
theletterf merged 4 commits intomainfrom
fix/codex-build-fetch-codex-link-index-token
Apr 24, 2026
Merged

fix(codex/build): fetch ephemeral token for codex-link-index reads#110
theletterf merged 4 commits intomainfrom
fix/codex-build-fetch-codex-link-index-token

Conversation

@theletterf
Copy link
Copy Markdown
Member

@theletterf theletterf commented Apr 24, 2026

Summary

  • The codex/build composite action runs docs-builder, which clones elastic/codex-link-index at build time to resolve codex/internal cross-links. That repo is private, but this action never fetched a token — docs-builder's GitLinkIndexReader fell back to anonymous HTTPS and failed with fatal: could not read Username for 'https://github.com': No such device or address.
  • Any consumer declaring a codex cross-link hit this as soon as the fetch path was exercised. Callers without cross-links kept working because CrossLinkFetcher never invoked the git reader.
  • Mirror the token-fetch pattern already used by codex/update-link-index — fetch an ephemeral token from Vault (keyed by a hash of the workflow ref, matching catalog-info registration) and expose it as GITHUB_TOKEN to the build step so docs-builder picks it up.

Context

Surfaced via elastic/platform-capacity-team#1328 — the first PR in that repo to introduce a platform-observability-team:// cross-link. The catalog-info side was already registered in elastic/catalog-info#3698 (both the shared pull policy and the per-repo push policy), but the build step was never wired up to consume the pull policy.

A companion docs-builder PR (elastic/docs-builder#3174) fixes a misleading fallback error URL that surfaced while debugging this, but that's cosmetic — this PR is the actual fix that unblocks the preview build.

Changes

  • codex/build/action.yml:
    • Add a Generate vault role step that derives token-policy-<12-char-hash> from GITHUB_WORKFLOW_REF, matching the pattern used by codex/update-link-index and the role name catalog-info registers against.
    • Add a Fetch ephemeral GitHub token for codex-link-index read step (Vault via elastic/ci-gh-actions/fetch-github-token@v1, using the hash-derived role).
    • Mark the fetch step continue-on-error: true so it doesn't break callers that don't need the token.
    • Pass the fetched token to the Build step as GITHUB_TOKEN, which docs-builder's GitLinkIndexReader.GetCodexLinkIndexGitUrl() already reads.
  • .github/workflows/codex-preview.yml:
    • Add id-token: write to the build job so the OIDC JWT needed by fetch-github-token is available.

Failure modes after this PR

  • No codex cross-links in docset → token fetch may fail (e.g. self-test without id-token: write), build runs without token, same as before this PR. No regression.
  • Cross-links declared but policy not registered in catalog-info → fetch fails, build falls back to anonymous HTTPS, errors the same way as before this PR. No regression — caller was already broken, now with an additional actionable annotation from the Vault step.
  • Properly configured caller → fetch succeeds, GITHUB_TOKEN is injected, private clone works. ✅

Test plan

  • test-codex-build self-test on this PR passes (mock docset has no cross-links; fetch is skipped via continue-on-error).
  • After merge, rerun platform-capacity-team#1328 and confirm the build no longer errors on could not read Username for 'https://github.com'.

🤖 Generated with Claude Code

docs-builder's cross-link fetcher clones elastic/codex-link-index to
resolve codex/internal cross-links at build time. The private repo
needs credentials, which this action did not fetch. As a result any
consumer declaring a codex cross-link would fail with:

  fatal: could not read Username for 'https://github.com':
  No such device or address

Mirror the token-fetch pattern used by codex/update-link-index, but
targeting the shared read policy `token-policy-pull-codex-repositories`
(registered via catalog-info for each consumer) and exporting the token
as GITHUB_TOKEN so docs-builder's GitLinkIndexReader picks it up.

Surfaced via elastic/platform-capacity-team#1328, the first PR in that
repo to introduce a cross-link.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@theletterf theletterf requested a review from a team as a code owner April 24, 2026 09:15
@theletterf theletterf added the fix label Apr 24, 2026
@theletterf theletterf self-assigned this Apr 24, 2026
The self-test workflow runs codex/build against a mock docset with no
cross-links and without id-token:write permission, so the Vault fetch
fails with "OIDC token endpoint not exposed". Real consumers that
don't declare codex cross-links would hit the same issue if their
workflow isn't configured for OIDC or registered in catalog-info.

Make the fetch step non-fatal so:
- no cross-links: build runs without a token, same as before this PR;
- missing policy: falls back to anonymous HTTPS, same as before;
- properly configured: token is obtained and the private clone works.
Comment thread codex/build/action.yml
Comment thread codex/build/action.yml Outdated
Copy link
Copy Markdown
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

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

Unblocking PR approval,

Not entirely sure why we need skip-token-revoke: true

Per reviewer feedback, align codex/build with codex/update-link-index:
- derive the vault role name from the workflow ref hash instead of
  using the shared policy filename directly, matching the
  catalog-info registration pattern.
- grant id-token:write to the build job in codex-preview.yml so
  `elastic/ci-gh-actions/fetch-github-token` can obtain an OIDC JWT.
@theletterf theletterf merged commit 5b4c82c into main Apr 24, 2026
4 checks passed
@theletterf theletterf deleted the fix/codex-build-fetch-codex-link-index-token branch April 24, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants