Repository navigation
feat(ci): fork-PR safety gate for atmos git clone - #2661
Conversation
`atmos git clone` (Atmos's native actions/checkout replacement) now refuses by default to clone untrusted fork content under GitHub's elevated pull_request_target and workflow_run events — mirroring actions/checkout v7's "pwn request" hardening. The gate triggers only on a PR head/merge ref override or a cross-repository clone URI; safe no-arg base checkouts and low-privilege pull_request/push events are unaffected. A grep-able opt-in is provided: --allow-unsafe-fork flag, ATMOS_ALLOW_UNSAFE_FORK_EXECUTION env, or ci.allow_unsafe_fork_execution config. Includes the gate logic (pkg/ci.EvaluateForkCheckout), provider ElevatedEvent signal, cmd/git wiring, ErrUnsafeForkCheckout sentinel, unit tests, docs, and the native-ci PRD (fork-pr-trust-gate.md). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
Resource Changes Found for
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a fail-closed fork-PR safety gate to ChangesFork-PR Safety Gate for
Native CI GOPROXY Fallback
Estimated code review effort: 4 (Complex) | ~50 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
🧹 Nitpick comments (1)
cmd/git/forktrust_test.go (1)
39-107: 🔒 Security & Privacy | 🔵 Trivial | 🏗️ Heavy liftAdd a behavior-level test for the clone path wiring.
These tests validate the helper directly, but the feature risk is the
runCloneURI/runCICheckoutintegration. Add at least one test proving an unsafe elevated clone returnsErrUnsafeForkCheckoutbefore cloning. As per coding guidelines, “Test behavior, not implementation.”🤖 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 `@cmd/git/forktrust_test.go` around lines 39 - 107, The current tests exercise guardForkCheckout directly, but they miss the behavior-level clone path. Add an integration-style test around runCloneURI or runCICheckout that sets up an elevated fork PR environment and verifies an unsafe cross-repo or PR ref clone is rejected with ErrUnsafeForkCheckout before any clone is attempted. Use the existing helpers like setForkPRTargetEnv and the runCloneURI/runCICheckout entrypoints to keep the test focused on observable behavior rather than the guard implementation.Source: Coding guidelines
🤖 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 `@cmd/git/clone.go`:
- Around line 371-376: The Fork-checkout gate in detected.Context handling
currently fails open when CI metadata cannot be read, which disables the
security check. Update the clone flow around the ciCtx, err :=
detected.Context() branch to return a wrapped error instead of logging and
returning nil when the CI context is unavailable, so unknown trust context
blocks the clone. Keep the fix localized to the detected.Context() error path in
clone.go and preserve the existing gate behavior for valid contexts.
- Around line 198-201: The named clone path in runCloneNamed bypasses the fork
opt-in gate, so it can clone a configured fork repo without checking approval.
Add the same guardForkCheckout validation used in the ad hoc URI and CI paths
before the exec.Clone call, using the resolved URI/branch inputs already
available in runCloneNamed so all clone entrypoints are gated consistently.
In `@docs/prd/native-ci/framework/fork-pr-trust-gate.md`:
- Around line 158-159: Remove the stale “follow-up implementation PR” wording
from the PRD and update the referenced scope note to reflect that the
implementation is already included in this stack. Adjust the text around the
rollout/implementation summary in fork-pr-trust-gate.md so it matches the
existing work in cmd/git/clone.go, pkg/ci/forktrust.go, and the schema/errors
changes, without implying additional future follow-up.
- Around line 78-80: FR-30 currently treats any available event payload fork
signal as equivalent to a fork-targeting clone, which conflicts with the trusted
no-arg checkout behavior and the existing evaluator logic in forktrust.go.
Tighten the requirement in the PR trust gate spec so only explicit PR refs or
cross-repo clone indicators are treated as untrusted, and keep the safe default
checkout path trusted when no repo URI/ref override is present. Use the
trusted/default checkout language already aligned with the forktrust evaluator
to locate the affected requirement text.
In `@pkg/ci/forktrust.go`:
- Around line 72-79: The trust check in forktrust.go only compares the
normalized repository slug in the fork-verdict logic, so it can miss malicious
clones from a different host. Update the URI comparison in the ForkVerdict path
to validate the full remote identity by checking the clone host against
ciCtx.ServerURL and ciCtx.CloneURL, not just repoSlugFromURI and
normalizeRepoSlug. Keep the existing untrusted return in the same ForkVerdict
branch, but make the mismatch detection include host and repository together so
ErrUnsafeForkCheckout is triggered for cross-host clones.
In `@website/src/data/roadmap.js`:
- Line 435: The shipped roadmap milestone for “Fork-PR safety gate for `atmos
git clone`” is missing the required PR reference, so update the roadmap entry in
the `website/src/data/roadmap.js` data object to include a `pr` field alongside
the existing `changelog` value. Use the same milestone object and keep the other
shipped metadata intact while adding the PR number in the format used by other
entries so it conforms to the roadmap contract.
- Line 413: The `ci-cd` initiative progress value is now inconsistent with its
milestone counts in `roadmap.js`. Update the `progress` field for the `ci-cd`
entry so it matches 19 shipped and 1 in-progress milestones, and keep the value
aligned with the roadmap’s existing progress calculation used in the initiative
object.
---
Nitpick comments:
In `@cmd/git/forktrust_test.go`:
- Around line 39-107: The current tests exercise guardForkCheckout directly, but
they miss the behavior-level clone path. Add an integration-style test around
runCloneURI or runCICheckout that sets up an elevated fork PR environment and
verifies an unsafe cross-repo or PR ref clone is rejected with
ErrUnsafeForkCheckout before any clone is attempted. Use the existing helpers
like setForkPRTargetEnv and the runCloneURI/runCICheckout entrypoints to keep
the test focused on observable behavior rather than the guard implementation.
🪄 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: 773be39e-bead-42d0-9633-e4dba271b681
📒 Files selected for processing (18)
cmd/git/clone.gocmd/git/flags.gocmd/git/forktrust_test.godocs/prd/native-ci/README.mddocs/prd/native-ci/framework/README.mddocs/prd/native-ci/framework/fork-pr-trust-gate.mddocs/prd/native-ci/overview.mderrors/errors.gopkg/ci/forktrust.gopkg/ci/forktrust_test.gopkg/ci/internal/provider/types.gopkg/ci/providers/github/provider.gopkg/ci/providers/github/provider_test.gopkg/schema/schema.gowebsite/blog/2026-06-27-git-clone-fork-pr-safety-gate.mdxwebsite/docs/cli/commands/git/git-clone.mdxwebsite/docs/cli/configuration/ci/index.mdxwebsite/src/data/roadmap.js
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2661 +/- ##
==========================================
+ Coverage 80.64% 80.67% +0.02%
==========================================
Files 1530 1531 +1
Lines 144898 145006 +108
==========================================
+ Hits 116854 116981 +127
+ Misses 21492 21463 -29
- Partials 6552 6562 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…d, named clones) Addresses CodeRabbit findings on the fork-PR safety gate: - Compare clone host as well as owner/repo, so a same-slug different-host URI (e.g. https://evil.example.com/acme/infra.git) is treated as untrusted; extract evaluateCloneTarget to keep complexity in check. - Fail closed when a detected CI provider's context cannot be read, matching the gate's documented fail-closed design. - Gate the named-clone path on pull-request ref overrides (configured URIs stay trusted), closing the `atmos git clone <name> --branch refs/pull/N/merge` hole. - Align PRD FR-30 wording with the implemented detection inputs, drop the stale "follow-up implementation PR" note, and add pr:2661 + corrected progress to the roadmap milestone. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
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 `@website/src/data/roadmap.js`:
- Line 435: Update the roadmap entry for the `Fork-PR safety gate for \`atmos
git clone\`` item so it explicitly mentions host mismatches as a trigger, not
just PR ref overrides and cross-repository clone URIs. Adjust the `description`
text in `roadmap.js` to match the shipped behavior described by `atmos git
clone` and the PRD/docs, using the existing `label`/`description` entry to note
that host or `owner/repo` mismatches are treated as fork-targeting.
🪄 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: 278a764e-b49b-4023-8fdd-5cc0be4f7056
📒 Files selected for processing (6)
cmd/git/clone.gocmd/git/forktrust_test.godocs/prd/native-ci/framework/fork-pr-trust-gate.mdpkg/ci/forktrust.gopkg/ci/forktrust_test.gowebsite/src/data/roadmap.js
🚧 Files skipped from review as they are similar to previous changes (4)
- pkg/ci/forktrust_test.go
- pkg/ci/forktrust.go
- cmd/git/clone.go
- cmd/git/forktrust_test.go
…ranches - Roadmap milestone description now states the gate triggers on a clone URI whose host or owner/repo differs from base (not just "cross-repository"), matching the shipped behavior (CodeRabbit). - Add unit tests for baseHostFromContext (ServerURL/CloneURL fallback), CloneURL-only host comparison, and single-segment slug parsing to raise patch coverage on pkg/ci/forktrust.go. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
|
Important Cloud Posse Engineering Team Review RequiredThis pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes. To expedite this process, reach out to us on Slack in the |
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
|
Note SHA Pin Verification Passed ✅All 101 SHA-pinned action(s) verified against upstream tags. |
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
Warning Release Documentation RequiredThis PR is labeled
|
|
These changes were released in v1.223.0-rc.3. |
what
atmos git clone(Atmos's nativeactions/checkoutreplacement) now refuses by default to clone untrusted fork content under GitHub's elevatedpull_request_targetandworkflow_runevents.refs/pull/<N>/merge, or an ad hoc clone URI whoseowner/repodiffers from the baseGITHUB_REPOSITORY). Safe no-arg base checkouts and low-privilegepull_request/push/merge_groupevents are unaffected.--allow-unsafe-forkflag,ATMOS_ALLOW_UNSAFE_FORK_EXECUTIONenv var, andci.allow_unsafe_fork_executionconfig key.pkg/ci.EvaluateForkCheckout), aContext.ElevatedEventtrust signal set by the GitHub provider, theErrUnsafeForkCheckoutsentinel, and unit tests (incl. negative paths).docs/prd/native-ci/framework/fork-pr-trust-gate.md,atmos git cloneCLI docs, CI configuration reference, and a changelog blog post + roadmap milestone.why
atmos git clonefills the same role asactions/checkout, it inherited the same "pwn request" risk: cloning a fork's PR code in a job that holds the base repository's secrets/GITHUB_TOKEN/cloud credentials lets a malicious contributor exfiltrate them.actions/checkoutv7 hardening (fail-closed by default, explicit grep-able opt-out), bringing Atmos's checkout replacement to parity.references
docs/prd/native-ci/framework/fork-pr-trust-gate.md/cli/commands/git/clone#fork-pr-safety-gate