Skip to content

Commit

Permalink
Backport of add noswap to secretdir tmpfs into release/1.9.x (#24782)
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Z. <[email protected]>
  • Loading branch information
hc-github-team-nomad-core and chuckyz authored Jan 6, 2025
1 parent 22a295d commit 93d1d36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/24645.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
client: Add noswap mount option to secrets directory where supported on Linux
```
12 changes: 9 additions & 3 deletions client/allocdir/fs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ func createSecretDir(dir string, size int) error {
}

flags := uintptr(syscall.MS_NOEXEC)
options := fmt.Sprintf("size=%dm", size)
if err := syscall.Mount("tmpfs", dir, "tmpfs", flags, options); err != nil {
return os.NewSyscallError("mount", err)
// Permanently disable swap for tmpfs for SecretDir.
options := fmt.Sprintf("size=%dm,noswap", size)
err := syscall.Mount("tmpfs", dir, "tmpfs", flags, options)
if err != nil {
// Not all kernels support noswap, remove if unsupported.
options = fmt.Sprintf("size=%dm", size)
if fallbackErr := syscall.Mount("tmpfs", dir, "tmpfs", flags, options); fallbackErr != nil {
return os.NewSyscallError("mount", fallbackErr)
}
}

// Create the marker file so we don't try to mount more than once
Expand Down
2 changes: 1 addition & 1 deletion website/content/docs/concepts/filesystem.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ $ mount
...
/dev/mapper/root on /alloc type ext4 (rw,relatime,errors=remount-ro,data=ordered)
tmpfs on /private type tmpfs (rw,noexec,relatime,size=1024k)
tmpfs on /secrets type tmpfs (rw,noexec,relatime,size=1024k)
tmpfs on /secrets type tmpfs (rw,noexec,relatime,size=1024k,noswap)
...
```

Expand Down

0 comments on commit 93d1d36

Please sign in to comment.