pillar: fix decimal literals used as file modes - #6264
Open
christoph-zededa wants to merge 1 commit into
Open
Conversation
github-actions
Bot
requested review from
OhmSpectator,
eriknordmark,
milan-zededa and
yash-zededa
August 3, 2026 12:07
christoph-zededa
force-pushed
the
fix_dec_perms
branch
from
August 3, 2026 12:11
6cd2852 to
50b15f9
Compare
christoph-zededa
force-pushed
the
fix_dec_perms
branch
3 times, most recently
from
August 3, 2026 12:35
8c36d0b to
7978d0e
Compare
rene
reviewed
Aug 3, 2026
| log.Warnf("[ATTEST] Received empty integrity token") | ||
| } | ||
| err := os.WriteFile(types.ITokenFile, token, 644) | ||
| err := os.WriteFile(types.ITokenFile, token, 0o644) |
Contributor
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...
Contributor
Author
There was a problem hiding this comment.
Sure, fixed :-)
Contributor
Author
|
/rerun red |
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>
christoph-zededa
force-pushed
the
fix_dec_perms
branch
from
August 3, 2026 17:07
7978d0e to
ffad981
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6264 +/- ##
==========================================
+ Coverage 24.13% 24.48% +0.35%
==========================================
Files 512 522 +10
Lines 93537 95253 +1716
==========================================
+ Hits 22575 23324 +749
- Misses 69177 69960 +783
- Partials 1785 1969 +184 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
christoph-zededa
marked this pull request as ready for review
August 4, 2026 09:51
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.
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.