Skip to content

Never write or follow a link in the staging directory as root - #2102

Merged
fog-workflows[bot] merged 2 commits into
dev-branchfrom
fix/node-cert-staging-symlinks
Nov 17, 2026
Merged

fog-workflows[bot] merged 2 commits into
dev-branchfrom
fix/node-cert-staging-symlinks

Conversation

@mastacontrola

Copy link
Copy Markdown
Member

Problem

fog-sign-node-cert runs as root through sudo, but the web user owns the staging directory it works in. Root wrote, chmodded and read files there by name. A process running as the web user could place a symlink there and make root overwrite, or chmod 0644, a file the link names. A linked name list made root print another file's lines in its error. This needs the web user already compromised; it raises that to root-file damage.

Change

  • The helper works in a root-only directory (mktemp -d) beside staging, on the same filesystem.
  • Staged inputs (.csr, .san, .agent) are copied in with dd iflag=nofollow,nonblock, so a link is refused.
  • Outputs are built there and moved into staging with mv -T. rename replaces a link and never writes through one.
  • The parent of staging must be owned by root and writable only by root. Otherwise the helper refuses and names the chown/chmod that fixes it. A default install (/opt/fog, root 0755) passes.
  • A name-list refusal names the line number, not the line: nofollow does not stop a hard link where fs.protected_hardlinks=0.

The PHP callers (service/nodecert.php, Agent\Enrollment) are unchanged. The outputs are still root-owned 0644 in staging.

Verified

  • tests/node-cert-external-ca.test.sh case H:
    • A linked name list with a valid target issues nothing.
    • A refused entry is not printed.
  • Run against the old helper, against the helper with nofollow removed, and against a helper that prints the line, case H fails each time. On the fix, all 27 checks pass.
  • agent-ca-follows-root and trust-anchor pass.
  • Reviewed by spec-reviewer and standards-reviewer (both opus), two rounds. All findings were fixed, and the last two fixes were tested by putting each defect back.

🤖 Generated with Claude Code

fog-sign-node-cert runs as root through sudo, but the web user owns the
staging directory it works in. Root wrote, chmodded and read files there
by name. A symlink placed at the right moment made root overwrite a file
the link named and make it world-readable, and a linked name list made
root print another file's lines back in its error.

The helper now works in a root-only directory beside staging. It copies
the staged inputs in with dd iflag=nofollow, so a link is refused. It
builds the outputs there and renames them into staging; rename replaces
a link and never writes through one. The parent of staging must be owned
by root and writable only by root, or the helper refuses to run.

A name-list refusal now names the line number, not the line. nofollow
does not stop a hard link, so printing the line could still hand a
root-only file's content to the web user where fs.protected_hardlinks
is off.

tests/node-cert-external-ca.test.sh case H: a linked name list whose
target is valid must issue nothing, and a refused entry must not be
printed. Both fail on the old helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot enabled auto-merge November 17, 2026 14:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot added this pull request to the merge queue Nov 17, 2026
Merged via the queue into dev-branch with commit 5b9143f Nov 17, 2026
11 checks passed
@fog-workflows
fog-workflows Bot deleted the fix/node-cert-staging-symlinks branch November 17, 2026 14:34
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.

1 participant