pillar: fix decimal literals used as file modes - #6264
Conversation
6cd2852 to
50b15f9
Compare
8c36d0b to
7978d0e
Compare
| log.Warnf("[ATTEST] Received empty integrity token") | ||
| } | ||
| err := os.WriteFile(types.ITokenFile, token, 644) | ||
| err := os.WriteFile(types.ITokenFile, token, 0o644) |
There was a problem hiding this comment.
Good catch, but just adding a leading 0 make it work (it's the octal notation for Go). TBH I really don't see 0o being used very often and I don't see any advantages other than make strange to the eyes.... 😆
So 0644, 0755 it works as well...
There was a problem hiding this comment.
Sure, fixed :-)
|
/rerun red |
7978d0e to
ffad981
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6264 +/- ##
==========================================
+ Coverage 24.13% 24.48% +0.34%
==========================================
Files 512 522 +10
Lines 93537 95253 +1716
==========================================
+ Hits 22575 23322 +747
- Misses 69177 69961 +784
- Partials 1785 1970 +185 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if len(token) == 0 { | ||
| log.Warnf("[ATTEST] Received empty integrity token") | ||
| } | ||
| err := os.WriteFile(types.ITokenFile, token, 644) |
There was a problem hiding this comment.
This seems error prone to begin with and the leading zero doesn't make it less so. Should we make all of them use syscall.S_IRUSR etc to not have any numeric values?
There was a problem hiding this comment.
I would prefer the numeric values (to write and to read).
I added a commit to add a semgrep rule and to actually run semgrep on the rules we already have: bbea20f
386447c to
ee87f6e
Compare
os.MkdirAll(dir, 755) and os.WriteFile(file, data, 644) pass decimal, not octal, values. Go reads 755 as 0o1363, leaving permission bits 0o363 (-wxrw--wx), and 644 as 0o1204, leaving 0o204 (-w----r--). The vault directories were therefore created world-writable, and the attestation integrity token was written world-readable while not being readable by its owner. Use octal literals, keeping the permissions each site already intended. In vault/key.go that is not sufficient on its own: stageKey() mounts a tmpfs onto the key staging directory right after creating it, and a tmpfs root defaults to 01777, which masks the mode underneath for as long as the unsealed vault key is staged there. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Ostarek <christoph@zededa.com>
tests/semgrep-rules/ has held rules since May 2025, but nothing ever invoked them: no make target, no workflow, no yetus plugin. They ran only if someone installed semgrep and pointed it at the directory by hand. Add make semgrep, plus a workflow that runs it on pull requests. Only ERROR rules gate. The two big.Int rules are WARNING and match any Bytes() call, so they stay available through make semgrep-all but never fail a build. CI passes --baseline-commit so a pull request is judged on the findings it introduces rather than on pre-existing ones. Add non-octal-file-mode, which flags file modes written as decimal literals: 755 is 0o1363, whose permission bits are 0o363 (-wxrw--wx). Narrow os-openfile-non-perm-mode, which rejected any mode that was not an octal literal and so flagged legitimate expressions such as the os.FileMode(header.Mode) in evetest/utils/tar.go. It now reports only decimal literals and non-permission os.Mode* bits, and still catches the os.ModeAppend it was written for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Christoph Ostarek <christoph@zededa.com>
ee87f6e to
bbea20f
Compare
|
/rerun red |
Description
Several file-mode arguments in pillar are written as decimal literals, so the
permission bits they produce are not the ones they read as:
7550o13630o363—-wxrw--wx6440o12040o204—-w----r--Measured, not inferred:
So the vault directories were created world-writable, and the attestation
integrity token file (
/run/eve.integrity_token) was written world-readablewhile not being readable by its owner. Affected call sites:
pkg/pillar/vault/key.go— key staging directorypkg/pillar/vault/handler_ext4.go(x2) — default vault and vault pathpkg/pillar/vault/handler_unsupported.go— default vaultpkg/pillar/cmd/zedagent/attesttask.go— integrity token fileEach site is switched to an octal literal keeping the permissions it already
intended, so there is no change of intent anywhere — only the notation bug.
One extra fix in
vault/key.go: correcting theMkdirAllmode there is notsufficient on its own, because
stageKey()mounts a tmpfs onto that directoryimmediately afterwards and a tmpfs root defaults to
01777:The staging directory was therefore world-writable for the whole time the
unsealed vault key sits in it.
mode=0755is now passed to the mount as well.How to test and validate this PR
The mistake itself is easy to check for statically — this reports nothing after
this PR, and the five call sites above before it:
Also run:
make -C pkg/pillar fmt-check make -C pkg/pillar vet make -C pkg/pillar testOn a device, the permission change can be confirmed directly. Since
MkdirAllonly applies its mode when creating the directory, the vault checks need a
device whose vault does not exist yet (fresh install, or an installation
without TPM where the vault is a plain folder):
drwxr-xr-xrather thand-wxrw--wx:stat -c '%a %A %n' /persist/vaultlonger world-writable.
/TmpVaultDir2(ext4) or/run/TmpVaultDir2(zfs)should be
drwxr-xr-x, notdrwxrwxrwt:stat -c '%a %A %n' /TmpVaultDir2Before this PR the same command reports
1777 drwxrwxrwt.volumes start — all the affected directories are used by root-owned
processes only, so no functional change is expected.
-rw-r--r--rather than--w----r--:stat -c '%a %A %n' /run/eve.integrity_tokenSuggested QA regression focus: vault creation and unlock on a fresh install,
both with and without TPM, on ext4 and zfs; plus one attestation cycle.
Changelog notes
Fixed file permissions on the vault directories, the vault key staging
directory and the attestation integrity token file, which were created with
different permission bits than intended.
PR Backports
All five call sites are present unchanged on all three LTS branches, so the fix
applies to each.
Checklist
check them
Reasons for the unchecked boxes:
nothing to document. The non-obvious part (a tmpfs root defaulting to
01777) is explained in the commit message.changes are architecture-independent, but the vault paths are device
management code, so the on-device steps above still need to be run before
this leaves draft.
stable(backport to all three LTS branches) andsecurity.