Skip to content

Security hardening Phase 3#212

Merged
jeremy merged 9 commits intomainfrom
harden
Mar 8, 2026
Merged

Security hardening Phase 3#212
jeremy merged 9 commits intomainfrom
harden

Conversation

@jeremy
Copy link
Copy Markdown
Member

@jeremy jeremy commented Mar 7, 2026

Summary

  • Remove stale private SDK access: basecamp-sdk is now public; remove GOPRIVATE, app token generation, and git config steps from test, release, gosec, and codeql jobs in both release.yml and security.yml
  • Release concurrency guard: prevent overlapping release runs with concurrency group
  • Build provenance attestation: attest GoReleaser checksums via actions/attest-build-provenance
  • GoReleaser version pinning: pin to exact v2.14.1 instead of floating ~> v2
  • OpenSSF Scorecard: new weekly scorecard workflow with SARIF upload
  • App token scope narrowing: add explicit permission-contents: write to Homebrew tap token; add permission-contents, permission-pull-requests, permission-issues to skills token

Test plan

  • Verify release.yml passes syntax validation (actionlint or GitHub's workflow editor)
  • Verify security.yml passes syntax validation
  • Verify scorecard.yml passes syntax validation
  • Confirm gosec and codeql jobs no longer need private SDK tokens (SDK is public)
  • Confirm release job still generates Homebrew tap token with correct scope
  • Confirm skills sync token has narrowed permissions

Summary by cubic

Hardened CI and release workflows and added a release environment management script to enforce protections, migrate secrets/vars, and block admin bypass with a single-PUT apply. Also removed stale private SDK access, tightened job permissions, added build provenance and weekly Scorecards, and made SARIF uploads resilient when Advanced Security is unavailable.

  • New Features

    • Attest GoReleaser checksums via actions/attest-build-provenance (adds attestations: write).
    • Weekly OpenSSF Scorecard workflow with SARIF upload via ossf/scorecard-action.
    • Add scripts/manage-release-env.sh to audit/apply env protections and migrate secrets/vars; uses exact reviewer slug matching with post-apply identity checks, reads back state, enforces can_admins_bypass correctly, fails on drift, and handles repos without existing rules.
  • Refactors

    • Remove private basecamp-sdk access everywhere, including all 7 jobs in test.yml (drop GOPRIVATE, app token, git config).
    • Add release concurrency group to prevent overlapping runs.
    • Pin goreleaser/goreleaser-action to v2.14.1.
    • Narrow tokens and job permissions: explicit minimal permissions for the release.yml security job; scoped Homebrew and skills tokens.
    • Pin reusable basecamp/.github AI labeler workflows to a fixed SHA with JSON parsing fix and PR read perms for private repos.
    • Scorecard SARIF upload uses continue-on-error to tolerate repos without Advanced Security.

Written for commit 7af61eb. Summary will update on new commits.

Copilot AI review requested due to automatic review settings March 7, 2026 23:36
@github-actions github-actions bot added the ci CI/CD workflows label Mar 7, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the repo’s security hardening work by reducing unnecessary credential usage in GitHub Actions, tightening release protections, adding provenance attestations, and introducing OpenSSF Scorecard reporting.

Changes:

  • Removed private basecamp-sdk access setup (GOPRIVATE/app-token/git config) from security.yml and release.yml.
  • Added release workflow concurrency guard, pinned GoReleaser to an exact version, and added build provenance attestation.
  • Added a new weekly OpenSSF Scorecard workflow that uploads SARIF results.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/security.yml Removes private module token/GOPRIVATE setup from gosec + CodeQL jobs.
.github/workflows/scorecard.yml Adds a Scorecard workflow with SARIF artifact + Security tab upload.
.github/workflows/release.yml Adds release concurrency, pins GoReleaser, adds provenance attestation, and narrows app token repos/permissions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 476750e0ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

jeremy added 2 commits March 7, 2026 15:57
Updates ai-labeler to use the fixed shared workflows that parse JSON
responses correctly and include pull-requests:read for private repos.
Idempotent script to audit and enforce release environment protection
across all CLI repos. Supports four modes:

  audit           — print environment existence, reviewers, deployment
                    policies, and secret scope per repo
  apply           — create environments, set required reviewers,
                    deployment tag policies, and admin bypass rules
  migrate-secrets — provision secrets from 1Password to env scope,
                    optionally delete repo-scoped copies
  migrate-vars    — move variables from repo to env scope

Driven by a repo manifest. Reads back state after every write and
fails on drift.
Copilot AI review requested due to automatic review settings March 7, 2026 23:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/manage-release-env.sh">

<violation number="1" location="scripts/manage-release-env.sh:148">
P2: Function `set_no_admin_bypass` sets `prevent_self_review`, not admin bypass. `prevent_self_review` prevents a deployment *creator* from approving their own run — it does not prevent admins from bypassing environment protection rules. The function name and manifest field (`admin_bypass`) are misleading. Consider renaming to `set_prevent_self_review` for accuracy, or documenting why this is the intended proxy.</violation>

<violation number="2" location="scripts/manage-release-env.sh:273">
P1: Sequential PUT calls to the same environment endpoint overwrite each other's fields. The GitHub Environments API uses PUT (full replacement), so `set_reviewers` sets reviewers, then `set_deployment_policy` resets reviewers while setting the branch policy, then `set_no_admin_bypass` resets both while setting `prevent_self_review`. The environment can never converge to the desired state.

Consolidate all three settings into a single PUT call that sends `reviewers`, `deployment_branch_policy`, and `prevent_self_review` together.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copilot AI review requested due to automatic review settings March 8, 2026 00:06
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/manage-release-env.sh">

<violation number="1" location="scripts/manage-release-env.sh:293">
P3: The refactored `apply_repo` now uses inline API calls, leaving `create_env`, `set_deployment_policy`, `set_reviewers`, and `set_no_admin_bypass` as dead code with no remaining callers. Consider removing them to keep the script easy to follow.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Remove private SDK access (GOPRIVATE, app-token, git config) from all
  7 jobs in test.yml — the SDK is now public
- Add explicit minimal permissions to security job in release.yml
- Remove dead functions from manage-release-env.sh (create_env,
  set_deployment_policy, set_reviewers, set_no_admin_bypass)
- Fix reviewer name formatting and add team identity verification
  to audit
@jeremy jeremy requested a review from a team as a code owner March 8, 2026 00:22
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/manage-release-env.sh">

<violation number="1" location="scripts/manage-release-env.sh:121">
P2: Substring `grep` can false-pass on partial slug matches. For example, expected slug `sip` would match `sip-extended`. Use a word-boundary or exact-element match for this security-audit check.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…review

These are two separate GitHub environment fields:
- can_admins_bypass: whether admins can skip protection rules
- prevent_self_review: whether reviewers can approve their own deploys

The script was only setting/checking prevent_self_review. Now sets
can_admins_bypass: false in the PUT payload, and checks it correctly
in both audit and apply verification.

Also fixes jq `// true` gotcha: jq's alternative operator treats
`false` as falsy, so `false // true` returns `true`. Use
`if has("can_admins_bypass") then .can_admins_bypass else true end`
instead.
Copilot AI review requested due to automatic review settings March 8, 2026 00:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Use exact jq element match instead of grep substring for reviewer
  slug verification (avoids false positive on partial matches like
  sip vs sip-extended)
- Add reviewer identity check to post-apply verification
- Add continue-on-error to upload-sarif step in scorecard workflow
  (graceful degradation when Advanced Security isn't available)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/manage-release-env.sh">

<violation number="1" location="scripts/manage-release-env.sh:121">
P2: Use `jq --arg` instead of shell string interpolation to pass `$expected_slug` into the jq filter. If the slug ever contains `"`, `\`, or other jq-special characters, the current concatenation will break the expression. This is a minor robustness issue—but particularly worth fixing in a security-hardening PR.</violation>

<violation number="2" location="scripts/manage-release-env.sh:300">
P2: Same shell-interpolation-in-jq issue as in `audit_repo`. Use `--arg slug "$expected_slug"` and reference `$slug` in the filter.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

# Verify correct team
local expected_slug
expected_slug=$(echo "$reviewer" | cut -d/ -f2)
if echo "$env_json" | jq -e '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == "'"$expected_slug"'")' >/dev/null 2>&1; then
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 8, 2026

Choose a reason for hiding this comment

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

P2: Same shell-interpolation-in-jq issue as in audit_repo. Use --arg slug "$expected_slug" and reference $slug in the filter.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/manage-release-env.sh, line 300:

<comment>Same shell-interpolation-in-jq issue as in `audit_repo`. Use `--arg slug "$expected_slug"` and reference `$slug` in the filter.</comment>

<file context>
@@ -294,7 +294,15 @@ apply_repo() {
+    # Verify correct team
+    local expected_slug
+    expected_slug=$(echo "$reviewer" | cut -d/ -f2)
+    if echo "$env_json" | jq -e '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == "'"$expected_slug"'")' >/dev/null 2>&1; then
+      ok "Reviewers verified ($expected_slug)"
+    else
</file context>
Suggested change
if echo "$env_json" | jq -e '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == "'"$expected_slug"'")' >/dev/null 2>&1; then
if echo "$env_json" | jq -e --arg slug "$expected_slug" '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == $slug)' >/dev/null 2>&1; then
Fix with Cubic

# Verify expected team is a reviewer (exact match, not substring)
local expected_slug
expected_slug=$(echo "$reviewer" | cut -d/ -f2)
if ! echo "$env_json" | jq -e '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == "'"$expected_slug"'")' >/dev/null 2>&1; then
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 8, 2026

Choose a reason for hiding this comment

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

P2: Use jq --arg instead of shell string interpolation to pass $expected_slug into the jq filter. If the slug ever contains ", \, or other jq-special characters, the current concatenation will break the expression. This is a minor robustness issue—but particularly worth fixing in a security-hardening PR.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/manage-release-env.sh, line 121:

<comment>Use `jq --arg` instead of shell string interpolation to pass `$expected_slug` into the jq filter. If the slug ever contains `"`, `\`, or other jq-special characters, the current concatenation will break the expression. This is a minor robustness issue—but particularly worth fixing in a security-hardening PR.</comment>

<file context>
@@ -115,10 +115,10 @@ audit_repo() {
     local expected_slug
     expected_slug=$(echo "$reviewer" | cut -d/ -f2)
-    if ! echo "$reviewer_names" | grep -q "$expected_slug"; then
+    if ! echo "$env_json" | jq -e '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == "'"$expected_slug"'")' >/dev/null 2>&1; then
       fail "Expected reviewer '$reviewer' not found (have: $reviewer_names)"
       drift=1
</file context>
Suggested change
if ! echo "$env_json" | jq -e '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == "'"$expected_slug"'")' >/dev/null 2>&1; then
if ! echo "$env_json" | jq -e --arg slug "$expected_slug" '[.protection_rules // [] | .[] | select(.type == "required_reviewers")] | .[0].reviewers // [] | [.[].reviewer | .slug // .login] | any(. == $slug)' >/dev/null 2>&1; then
Fix with Cubic

@jeremy jeremy merged commit 7dbe05d into main Mar 8, 2026
24 checks passed
@jeremy jeremy deleted the harden branch March 8, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci CI/CD workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants