Skip to content

fix(auth): make github/sts compose with default GitHub token injection - #2557

Merged
Andriy Knysh (aknysh) merged 7 commits into
mainfrom
osterman/default-pro-github-token
Jun 2, 2026
Merged

Andriy Knysh (aknysh) merged 7 commits into
mainfrom
osterman/default-pro-github-token

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

what

  • Stop Atmos's go-getter token injection from silently shadowing github/sts-minted GitHub tokens: CustomGitDetector now skips URL token injection when a live GIT_CONFIG_* insteadOf rewrite already matches the URL's host/owner, so git's rewrite (carrying the correct least-privilege token) wins.
  • Make the ATMOS_PRO_GITHUB_TOKEN bridge consistent: resolveToken falls back to the live env var (which the broker sets after startup), mirroring pkg/http/client.go.
  • Default token_env to ATMOS_PRO_GITHUB_TOKEN (was empty) so a single-owner mint reaches gh/REST and Atmos's in-process git path automatically.
  • Replace the ad-hoc {owner} placeholder with Atmos's standard Go-template syntax ({{ .owner }}, plus .host); update docs, PRD, and add a docs/fixes/ write-up.

why

  • A real CI job resolving a remote import: from a second private repo failed with remote: Repository not found — the minted token was correct, but the ambient GITHUB_TOKEN was being injected into the URL ahead of it, defeating git's insteadOf rewrite. The only fix was the settings.inject_github_token: false workaround.
  • These changes make github/sts (introduced in feat(auth): Atmos Pro STS — JIT GitHub token broker for CI #2546) compose with the default settings.inject_github_token: true, so it "just works" with no workaround. Reproduced first with a simulated-broker e2e test, then fixed.

references

Summary by CodeRabbit

  • Bug Fixes

    • Prevented minted GitHub tokens from being silently overridden by detecting broker-provided git URL rewrites and skipping ambient token injection.
  • New Features

    • token_env accepts Go-template names (e.g., GH_TOKEN_{{ .owner }}) and defaults to ATMOS_PRO_GITHUB_TOKEN when appropriate.
    • Token resolution prefers a live exported broker token before falling back to configured values; minted tokens are not logged.
  • Documentation

    • Clarified github/sts token_env semantics, templating, multi-owner behavior, and URL-rewrite interactions.
  • Tests

    • Added/expanded tests for token-env defaults, templating, precedence, and insteadOf handling.
  • Chores

    • Made license NOTICE generation produce deterministic URLs.

The just-shipped github/sts feature (#2546) mints least-privilege tokens
and routes git over them via GIT_CONFIG_* insteadOf rewrites, but for
Atmos-native go-getter reads (vendor pull, source:, remote import:)
CustomGitDetector injected the ambient GITHUB_TOKEN into the URL first.
Once the URL carried userinfo, git's insteadOf no longer prefix-matched,
silently shadowing the minted token — a second private repo failed to
clone with "Repository not found". The only fix was the
settings.inject_github_token: false workaround.

- Skip URL token injection when a live GIT_CONFIG_* insteadOf already
  matches the URL's host/owner, so git's rewrite (correct minted token)
  wins; host/owner-scoped, so non-minted owners still get injected.
- resolveToken falls back to live os.Getenv("ATMOS_PRO_GITHUB_TOKEN")
  (the broker sets it after startup), mirroring pkg/http/client.go.
- token_env now defaults to ATMOS_PRO_GITHUB_TOKEN so a single-owner
  mint bridges to gh/REST and the in-process git path automatically.
- Replace the ad-hoc {owner} placeholder with Atmos-standard Go
  template syntax ({{ .owner }}, plus .host) for token_env.

Reproduced first with a simulated-broker e2e test, then fixed. Docs and
PRD updated.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@atmos-pro

atmos-pro Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@osterman Erik Osterman (Cloud Posse) (osterman) added the patch A minor, backward compatible change label Jun 2, 2026
@github-actions github-actions Bot added the size/m Medium size PR label Jun 2, 2026
@github-actions

github-actions Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6353319a-3b5f-49c2-9ce9-4cfd09e45278

📥 Commits

Reviewing files that changed from the base of the PR and between 1980c79 and 7821a3e.

📒 Files selected for processing (5)
  • docs/prd/atmos-pro-sts.md
  • pkg/auth/integrations/github/sts.go
  • website/blog/2026-05-29-atmos-pro-github-sts.mdx
  • website/docs/cli/commands/auth/auth-env.mdx
  • website/docs/cli/configuration/auth/index.mdx
✅ Files skipped from review due to trivial changes (1)
  • website/blog/2026-05-29-atmos-pro-github-sts.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/auth/integrations/github/sts.go

📝 Walkthrough

Walkthrough

Fixes a regression where minted GitHub tokens were overridden by in-process git URL rewriting by (1) detecting broker-exported GIT_CONFIG_* insteadOf rewrites to skip token injection, (2) preferring live ATMOS_PRO_GITHUB_TOKEN, (3) defaulting token_env to ATMOS_PRO_GITHUB_TOKEN, and (4) adding Go-template token_env rendering plus tests/docs.

Changes

GitHub STS Token Injection Shadowing Fix

Layer / File(s) Summary
Regression analysis and fix documentation
docs/fixes/2026-06-01-github-sts-token-injection-shadowing.md, docs/prd/atmos-pro-sts.md
Regression write-up documents CI symptom and root cause (URL userinfo token injection shadowing broker insteadOf and env/struct mismatch) and lists implemented fixes and verification steps; PRD clarifies token_env semantics and insteadOf handling.
STS token_env contract and defaulting
pkg/auth/integrations/github/sts.go
Introduced ATMOS_PRO_GITHUB_TOKEN default and updated parseSTSSpec to initialize tokenEnv with the default, preserving it when spec.TokenEnv is empty.
STS token_env template rendering implementation
pkg/auth/integrations/github/sts.go
Replaced {owner} placeholder with Go-template rendering (text/template) in addTokenEnv, added renderTokenEnvName helper with missing-key error handling and sanitization, and changed logging behavior for default vs user-provided literals.
STS token_env behavior and template tests
pkg/auth/integrations/github/sts_test.go, pkg/auth/integrations/github/sts_errors_test.go
Env-mode tests now assert single-owner default export to ATMOS_PRO_GITHUB_TOKEN vs multi-owner skip; added templating tests for {{ .owner }}/{{ .host }} plus invalid-template skipping; file-mode default bridge test added.
CustomGitDetector broker insteadOf suppression
pkg/downloader/custom_git_detector.go
injectToken now checks GIT_CONFIG_COUNT + GIT_CONFIG_KEY_*/GIT_CONFIG_VALUE_* and uses brokerInsteadOfMatchesURL/gitConfigInsteadOfMatches/firstPathSegment helpers to skip token injection when a broker-provided insteadOf covers the repo.
CustomGitDetector token resolution live environment fallback
pkg/downloader/custom_git_detector.go
resolveToken now reads live os.Getenv("ATMOS_PRO_GITHUB_TOKEN") and returns it (with source label) before consulting configured AtmosProGithubToken and other fallbacks.
CustomGitDetector unit and integration tests
pkg/downloader/broker_insteadof_helper_test.go, pkg/downloader/broker_insteadof_test.go
Added unit tests for brokerInsteadOfMatchesURL and token-resolution precedence; end-to-end test verifies injection suppression for broker-covered owners and continued injection for uncovered owners; tests use t.Setenv for isolation.
Test environment isolation and determinism
pkg/downloader/atmos_pro_token_test.go, pkg/downloader/token_injection_test.go
Existing token-resolution tests now clear ATMOS_PRO_GITHUB_TOKEN via t.Setenv to ensure deterministic precedence evaluation.
Schema and website docs updates
pkg/schema/schema_auth.go, website/docs/cli/commands/auth/auth-env.mdx, website/docs/cli/configuration/auth/index.mdx, website/blog/*
TokenEnv docs updated to document template-capable naming and default ATMOS_PRO_GITHUB_TOKEN behavior; website docs updated with examples and guidance on templating and insteadOf interaction.
NOTICE and license URL generation script
NOTICE, scripts/generate-notice.sh
NOTICE entry updated for inet.af/netaddr; scripts/generate-notice.sh now post-processes go-licenses CSV to produce deterministic license URLs for vanity imports using REPO_OVERRIDES and helper functions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • cloudposse/atmos#1647: Modifies pkg/downloader/custom_git_detector.go token resolution and injection behavior with related credential precedence logic.

Suggested reviewers

  • aknysh
  • RoseSecurity
  • kevcube
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing github/sts to work properly with default GitHub token injection by preventing token shadowing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/default-pro-github-token

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/auth/integrations/github/sts.go (1)

7-28: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Organize imports into three groups per coding guidelines.

The imports should be organized into three groups separated by blank lines: (1) Go stdlib, (2) 3rd-party libraries (excluding cloudposse/atmos), (3) Atmos packages. Currently, all cloudposse/atmos imports are mixed with the stdlib group.

♻️ Proposed fix
 import (
 	"bytes"
 	"context"
 	"encoding/json"
 	"fmt"
 	"net/http"
 	"os"
 	"path/filepath"
 	"strconv"
 	"strings"
 	"text/template"
 	"time"
 
 	errUtils "github.com/cloudposse/atmos/errors"
 	"github.com/cloudposse/atmos/pkg/auth/integrations"
 	"github.com/cloudposse/atmos/pkg/auth/types"
 	log "github.com/cloudposse/atmos/pkg/logger"
 	"github.com/cloudposse/atmos/pkg/perf"
 	"github.com/cloudposse/atmos/pkg/schema"
 	"github.com/cloudposse/atmos/pkg/ui"
 	"github.com/cloudposse/atmos/pkg/xdg"
 )

As per coding guidelines: Organize imports in three groups separated by blank lines, sorted alphabetically: (1) Go stdlib, (2) 3rd-party (NOT cloudposse/atmos), (3) Atmos packages. Maintain aliases: cfg, log, u, errUtils.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/auth/integrations/github/sts.go` around lines 7 - 28, Rearrange the
import block into three groups separated by a blank line: first all Go standard
library imports (bytes, context, encoding/json, fmt, net/http, os,
path/filepath, strconv, strings, text/template, time) sorted alphabetically;
second any third‑party imports (none of the github.com/cloudposse/atmos
packages) sorted alphabetically; and third all Atmos package imports (errUtils
alias, integrations, types, log alias, perf, schema, ui, xdg) sorted
alphabetically, preserving existing aliases (`errUtils`, `log`, and any
`cfg`/`u` aliases mentioned elsewhere) and keeping a single blank line between
each group.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@website/docs/cli/configuration/auth/index.mdx`:
- Line 169: The sentence about exporting the minted token as
ATMOS_PRO_GITHUB_TOKEN is too absolute; change the wording to state that
ATMOS_PRO_GITHUB_TOKEN is exported by default only for single-owner mints (see
token_env), and clarify that multi-owner mints may skip raw export or use
literal names; also keep the note that Atmos prefers ATMOS_PRO_GITHUB_TOKEN over
ATMOS_GITHUB_TOKEN and GITHUB_TOKEN and that when a github/sts GIT_CONFIG_*
rewrite already covers a repo owner Atmos skips URL token injection so git's
rewrite wins and settings.inject_github_token can remain true.

---

Outside diff comments:
In `@pkg/auth/integrations/github/sts.go`:
- Around line 7-28: Rearrange the import block into three groups separated by a
blank line: first all Go standard library imports (bytes, context,
encoding/json, fmt, net/http, os, path/filepath, strconv, strings,
text/template, time) sorted alphabetically; second any third‑party imports (none
of the github.com/cloudposse/atmos packages) sorted alphabetically; and third
all Atmos package imports (errUtils alias, integrations, types, log alias, perf,
schema, ui, xdg) sorted alphabetically, preserving existing aliases (`errUtils`,
`log`, and any `cfg`/`u` aliases mentioned elsewhere) and keeping a single blank
line between each group.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 68b6a7d4-f428-4317-a562-b079ace9caf2

📥 Commits

Reviewing files that changed from the base of the PR and between edca67f and 70f8337.

📒 Files selected for processing (13)
  • docs/fixes/2026-06-01-github-sts-token-injection-shadowing.md
  • docs/prd/atmos-pro-sts.md
  • pkg/auth/integrations/github/sts.go
  • pkg/auth/integrations/github/sts_errors_test.go
  • pkg/auth/integrations/github/sts_test.go
  • pkg/downloader/atmos_pro_token_test.go
  • pkg/downloader/broker_insteadof_helper_test.go
  • pkg/downloader/broker_insteadof_test.go
  • pkg/downloader/custom_git_detector.go
  • pkg/downloader/token_injection_test.go
  • pkg/schema/schema_auth.go
  • website/docs/cli/commands/auth/auth-env.mdx
  • website/docs/cli/configuration/auth/index.mdx

Address CodeRabbit review on PR #2557: the default-export sentence read as
unconditional, but the raw token export only happens for a single-owner mint
when token_env is left at its default. Multi-owner mints under the literal
default skip the bare var and rely on the GIT_CONFIG_* rewrites.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@NOTICE`:
- Line 635: Replace the "URL: Unknown" entry for the dependency identifier
"dario.cat/mergo" in the NOTICE file with the upstream license link or the
vendored license path; specifically update the URL for dario.cat/mergo to point
to the project's license (for example the upstream LICENSE at
https://github.com/imdario/mergo/blob/master/LICENSE or the local vendored
license file path) so the NOTICE entry for dario.cat/mergo contains a concrete,
traceable license URL.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 77701f73-5747-4503-b228-f76a247539f9

📥 Commits

Reviewing files that changed from the base of the PR and between aab7528 and 09c7eea.

📒 Files selected for processing (1)
  • NOTICE

Comment thread NOTICE Resolved
@codecov

codecov Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.83%. Comparing base (fb93f72) to head (dbbbca4).

Files with missing lines Patch % Lines
pkg/downloader/custom_git_detector.go 90.00% 2 Missing and 1 partial ⚠️
pkg/auth/integrations/github/sts.go 92.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2557      +/-   ##
==========================================
+ Coverage   78.81%   78.83%   +0.01%     
==========================================
  Files        1195     1195              
  Lines      114221   114267      +46     
==========================================
+ Hits        90025    90079      +54     
+ Misses      19247    19234      -13     
- Partials     4949     4954       +5     
Flag Coverage Δ
unittests 78.83% <90.90%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/schema/schema_auth.go 100.00% <ø> (ø)
pkg/auth/integrations/github/sts.go 84.69% <92.00%> (-0.54%) ⬇️
pkg/downloader/custom_git_detector.go 88.88% <90.00%> (+0.25%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The NOTICE generator (scripts/generate-notice.sh) resolves each dependency's
license URL via `go-licenses report`, which does a network fetch to map a
module's import path to its source repo. For vanity import paths whose source
lives on a different host (dario.cat/mergo -> github.com/imdario/mergo,
inet.af/netaddr -> github.com/inetaf/netaddr) that fetch is flaky, so a regen
run that can't reach the vanity domain emits "URL: Unknown" and produces a
spurious NOTICE diff (which dependency-review.yml then fails on).

Add a deterministic override step: for the affected vanity modules, rebuild the
LICENSE URL from the version already pinned in go.mod (`go list -m`, no network).
Tags are used verbatim; pseudo-versions resolve to their trailing commit hash so
the GitHub blob URL is valid. The override is a plain newline-delimited list (not
a bash 4 associative array) so it works on macOS's stock bash 3.2.

NOTICE: inet.af/netaddr URL is now a concrete link instead of "Unknown";
dario.cat/mergo is unchanged (the override reproduces its existing URL).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 2, 2026
Octo-STS is an external project; referencing it as a comparison point in
shipped code comments, the blog post, and user-facing docs is undesirable.
Reword those mentions to describe the github/sts raw-token export capability
generically (mint a token, hand it to any GitHub-token consumer).

The only surviving Octo-STS reference now lives in a new References section
of the PRD, credited as inspiration rather than framed as parity.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@aknysh
Andriy Knysh (aknysh) merged commit 4427fbb into main Jun 2, 2026
95 of 96 checks passed
@aknysh
Andriy Knysh (aknysh) deleted the osterman/default-pro-github-token branch June 2, 2026 21:29
@atmos-pro

atmos-pro Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

These changes were released in v1.221.0-rc.3.

This branch was successfully deployed

1 active deployment
preview — dbbbca48 Deployed Jun 2, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants