Skip to content

fix: prepare non-writable files for custom secret masking - #66160

Merged
pelikhan merged 3 commits into
mainfrom
pelikhan-secret-masking-reliability
Oct 6, 2026
Merged

pelikhan merged 3 commits into
mainfrom
pelikhan-secret-masking-reliability

Conversation

@pelikhan

@pelikhan pelikhan commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Prepare readable but non-writable logs for downstream secret-masking.steps, even when built-in redaction finds no matching secrets. Atomically replace them with runner-owned, owner-only read/write copies without sudo or recursive permission changes.
  • Tolerate disappearing files/directories during scanning, runtime-mask collection, and processing. Report other failures and remove unsanitized artifact sources rather than silently leaving them uploadable.
  • Add regression tests, custom-hook guidance, and a patch changeset.

Failure investigated

githubnext/gh-aw-rai failing job, step 43 failed with EACCES from fs.writeFileSync('/tmp/gh-aw/mcp-logs/safeoutputs/server.log') in its custom RAI redactor. Built-in redaction had scanned 314 files and reported no matching secrets, so it never attempted a write to that file. The logs establish a write-permission failure, not an OS-level lock; readable, non-writable logs reproduce the failure.

Validation

Passed:

  • make build, executed by the final validation target.
  • Direct Node assertions using real read-only files: custom rewriting with zero secret matches, exact-value redaction, private atomic replacement, missing logs/HTML/directories, blocked replacement cleanup, unrelated ENOENT, fatal removal errors, and malformed HTML fail-closed behavior.
  • Direct integration assertion: disappearing agent-stdio.log does not abort redaction of other artifacts.
  • node --check actions/setup/js/redact_secrets.cjs, Prettier formatting, and git diff --check.

Blocked:

  • PATH="/opt/homebrew/bin:$PATH" make agent-report-progress built successfully but could not complete JavaScript lint/typecheck/tests because tsc is unavailable.
  • Focused Vitest execution could not load the missing local package. Restoring pinned dependencies failed: the configured feed returned 404 for vitest-5.0.3.tgz, and the approved 1ES feed reported no [email protected]. A public-registry retry did not complete and was stopped. Dependency manifests and lockfiles are unchanged.

Boundaries

Replacement requires a writable parent directory. It does not bypass OS locks, reclaim inaccessible directories, or prepare files outside the built-in scan. Custom hooks must handle those cases explicitly, tolerate absent optional sources, and stop log writers before sanitization.

Replace readable non-writable logs atomically before custom redaction, including files without built-in secret matches. Handle disappearing sources and remove unsanitized artifacts on processing failures.

Co-authored-by: Copilot App <[email protected]>
Comment thread actions/setup/js/redact_secrets.cjs Resolved
@pelikhan
pelikhan marked this pull request as ready for review October 6, 2026 13:42
Copilot AI balanced review requested due to automatic review settings October 6, 2026 13:42
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🔎 PR Code Quality Reviewer is reviewing code quality for this pull request...

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Lean already. Ship.

Generated by Ponytail Reviewer for #66160

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

No ADR enforcement needed: PR #66160 does not have the 'implementation' label (has_implementation_label=false) and has 0 new lines in business logic directories (default_business_additions=0, threshold=100, 4 files changed, no custom .design-gate.yml).

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Failed cleanup can leave unsanitized files uploadable, and one scanning race remains unhandled.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Improves secret-redaction reliability for non-writable and disappearing artifact files.

Changes:

  • Atomically replaces non-writable files with private writable copies.
  • Handles disappearing files and adds regression coverage.
  • Documents custom masking requirements and records a patch changeset.
File Description
actions/​setup/​js/​redact_secrets.cjs Adds replacement and cleanup handling.
actions/​setup/​js/​redact_secrets.test.cjs Adds reliability regression tests.
docs/​src/​content/​docs/​reference/​imports.md Documents custom masking hooks.
.changeset/​patch-secret-redaction-file-reliability.md Records the patch release.

Comment thread actions/setup/js/redact_secrets.cjs Outdated
Comment on lines +36 to +39
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
core.warning(`Skipping directory that disappeared during secret redaction: ${currentDir}`);
continue;
}

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.

Fixed the symlink-removal race by treating ENOENT as a vanished entry; the existing artifact cleanup path already tolerated missing files. Added regression coverage. Commit fa741ce.

@pelikhan

pelikhan commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot run pr-finisher skill

@github-actions github-actions 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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /codebase-design — this is a solid, well-tested reliability fix; only minor non-blocking suggestions.

📋 Key Themes & Highlights

Key Themes

  • Repeated error-guard boilerplate: the "code" in error && error.code === X pattern appears 5 times across the file; a small isErrnoCode() helper would reduce duplication risk (/codebase-design).
  • Scope of ENOENT tolerance: the mask-collection loop's ENOENT handling (flagged earlier by the security bot) is correctly scoped to agent-stdio.log only and does not weaken the fail-closed path for other files — a short inline comment would make that reasoning self-evident rather than relying on the PR description (/diagnosing-bugs).

Positive Highlights

  • ✅ Root cause properly addressed: the atomic-replace via mkdtempSync/writeFileSync(..., { flag: "wx" })/renameSync correctly handles container-owned readable-but-non-writable logs without sudo or recursive chmod.
  • ✅ Strong regression coverage: new tests exercise EACCES/EPERM replacement, blocked replacement cleanup, disappearing files mid-scan, mid-mask-collection, and mid-processing — closely mirroring the real failure investigated.
  • ✅ Fail-closed behavior preserved: any non-ENOENT/EACCES/EPERM error, or a blocked replacement, still removes the unsanitized artifact and calls core.setFailed.
  • ✅ Docs updated (imports.md) to set clear expectations for custom hook authors (writable parent dir requirement, no bypass of locks/inaccessible dirs, ENOENT tolerance).

Note: this is a 305-line diff, well within the truncation cap, so the full change was reviewed.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 72.3 AIC · ⌖ 14.7 AIC · ⊞ 10.2K
Comment /matt to run again

Comment thread actions/setup/js/redact_secrets.cjs Outdated
}
return;
} catch (error) {
if (!(error && typeof error === "object" && "code" in error && (error.code === "EACCES" || error.code === "EPERM"))) {

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.

[/codebase-design] Five call sites repeat error && typeof error === "object" && "code" in error && error.code === "X" (lines 36, 40, 290, 344, 419). Extracting a small isErrnoCode(error, ...codes) helper would make each guard a one-liner and remove the risk of a typo silently breaking one of the fail-closed checks.

💡 Suggested helper
function isErrnoCode(error, ...codes) {
  return !!(error && typeof error === "object" && "code" in error && codes.includes(error.code));
}

Then each guard becomes e.g. isErrnoCode(error, "ENOENT") or isErrnoCode(error, "EACCES", "EPERM"). This is a /codebase-design deepening: the repeated conditional is boilerplate that obscures the actual branching logic (ENOENT vs permission vs other), and a shared predicate makes the module's error-handling vocabulary explicit and easier to audit for correctness.

@copilot please address this.

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.

Added a shared isErrnoCode helper and applied it across the file’s errno checks. Commit fa741ce.

Comment thread actions/setup/js/redact_secrets.cjs Outdated
for (const value of collectAddMaskedValues(fs.readFileSync(file, "utf8"))) masks.add(value);
} catch (error) {
for (const source of files) fs.unlinkSync(source);
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {

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.

[/diagnosing-bugs] This ENOENT tolerance only covers agent-stdio.log disappearing between the glob scan and the read in this loop — it does not weaken the fail-closed guarantee for other files, since the existing catch branch (which removes every artifact and throws) still fires for any other error code. The flagged security-bot concern looks addressed by scope, but it'd help future readers if the comment made that narrowing explicit.

💡 Suggested comment
// Only agent-stdio.log is optional here: its disappearance means no runtime
// masks were ever emitted, not that redaction failed. Any other error still
// removes all artifact sources below.
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {

Root-cause framing per /diagnosing-bugs: the fix narrows a fail-open-looking branch to a single known-optional file, but the "why is this safe" reasoning currently only lives in your PR description, not in the code.

@copilot please address this.

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.

The agent-stdio.log ENOENT exception has been removed. A missing runtime-mask source now removes the artifact sources and fails redaction, so the optional-file comment no longer applies. Commit fa741ce.

@pelikhan

pelikhan commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot update instructions to deter agents to try to create issues directly / use secrets in post-steps / secret-scanning steps

Copilot AI commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@copilot update instructions to deter agents to try to create issues directly / use secrets in post-steps / secret-scanning steps

Updated .github/aw/workflow-constraints.md with explicit rules: issue creation must use safe-outputs.create-issue with duplicate checks, and credentials must not be passed to post-steps or custom secret-scanning steps. Commit $(git rev-parse --short HEAD).

@pelikhan
pelikhan merged commit 2502eb0 into main Oct 6, 2026
1 check passed
@pelikhan
pelikhan deleted the pelikhan-secret-masking-reliability branch October 6, 2026 14:33
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.91.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants