fix(ci): add least-privilege permissions to workflow files#2944
Open
waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
Open
fix(ci): add least-privilege permissions to workflow files#2944waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
waveywaves wants to merge 1 commit intochainloop-dev:mainfrom
Conversation
3da776c to
dcdd23f
Compare
There was a problem hiding this comment.
1 issue found across 4 files
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="pkg/attestation/crafter/collector_aiagentconfig.go">
<violation number="1" location="pkg/attestation/crafter/collector_aiagentconfig.go:105">
P1: Deterministic file name in `/tmp` replaces `CreateTemp`, introducing predictable temp-file path risk (pre-creation/symlink attack surface).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| tmpFile.Close() | ||
| // Use a deterministic filename based on the config hash so that retries | ||
| // produce the same file path and avoid duplicate CAS uploads. | ||
| tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("ai-agent-config-%s-%s.json", agentName, data.ConfigHash[:12])) |
There was a problem hiding this comment.
P1: Deterministic file name in /tmp replaces CreateTemp, introducing predictable temp-file path risk (pre-creation/symlink attack surface).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/attestation/crafter/collector_aiagentconfig.go, line 105:
<comment>Deterministic file name in `/tmp` replaces `CreateTemp`, introducing predictable temp-file path risk (pre-creation/symlink attack surface).</comment>
<file context>
@@ -99,20 +100,16 @@ func (c *AIAgentConfigCollector) uploadAgentConfig(
- tmpFile.Close()
+ // Use a deterministic filename based on the config hash so that retries
+ // produce the same file path and avoid duplicate CAS uploads.
+ tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("ai-agent-config-%s-%s.json", agentName, data.ConfigHash[:12]))
+ if err := os.WriteFile(tmpPath, jsonData, 0o600); err != nil {
return fmt.Errorf("writing temp file: %w", err)
</file context>
dcdd23f to
96bcd23
Compare
Add top-level permissions blocks following the two-tier permission
pattern recommended by OpenSSF Scorecard:
- stale.yml: add `permissions: {}` at workflow level (job already has
issues: write + pull-requests: write)
- build_external_container_images.yaml: move `packages: write` from
workflow level to job level; set workflow level to `permissions: read-all`
scm_configuration_check.yaml already had `permissions: read-all` at
workflow level so no change was needed.
Fixes chainloop-dev#2841
Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
96bcd23 to
a5f8adc
Compare
Contributor
Author
|
@jiparis @migmartri gentle ping — this is ready for review. All CI green. Adds least-privilege permissions to 3 workflow files (stale, build_external_container_images, codeql). Full 12-workflow audit in the PR description. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add top-level
permissionsblocks to workflow files following the two-tier permission pattern recommended by OpenSSF Scorecard. This tightens the default GITHUB_TOKEN scope so that each job only receives the permissions it explicitly declares.Changes
stale.yml: addedpermissions: {}at workflow level (job-levelissues: write+pull-requests: writealready correct)build_external_container_images.yaml: movedpackages: writefrom workflow level to job level; set workflow level topermissions: { contents: read }codeql.yml: removedid-token: writefrom workflow level (keptcontents: read); job level already hasid-token: writeFull 12-Workflow Audit
author_verification.ymlread-allbuild_external_container_images.yamlcontents: read(was alsopackages: write)packages: writeto job levelcodeql.ymlcontents: read(was alsoid-token: write)id-token: write; job already declares itlint.ymlcontents: read,pull-requests: readpackage_chart.yamlread-allpackages: write+id-token: write)release.yamlread-allscm_configuration_check.yamlread-allscorecards.ymlread-allsecrets-scan-daily.ymlread-allstale.yml{}(was missing entirely)issues: write+pull-requests: writesync_contracts.ymlread-alltest.ymlcontents: readResult: 3 workflows fixed, 9 were already compliant. All 12 workflow files now follow the least-privilege two-tier pattern.
Test Plan
stale.ymlworkflow runs correctly (cron or manual dispatch) with the new top-levelpermissions: {}build_external_container_images.yamlworkflow can still build and push container images withpackages: writenow at job levelcodeql.ymlworkflow still generates SLSA provenance withid-token: writeonly at job levelFixes #2841