Skip to content

Commit 82b673d

Browse files
JAORMXclaude
andcommitted
Set no_new_privs in guest boot after capability drop
Call harden.SetNoNewPrivs() after DropBoundingCaps in the boot sequence. The bit is inherited by all descendants via fork, so every SSH session and its children are prevented from gaining privileges through execve (setuid binaries, file capabilities). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b3b67e6 commit 82b673d

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

internal/guest/boot/boot.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ func Run(logger *slog.Logger) (shutdown func(), err error) {
8181
return nil, fmt.Errorf("dropping capabilities: %w", err)
8282
}
8383

84+
// 8b. Set no_new_privs to prevent any child process from gaining
85+
// privileges through execve (setuid binaries, file capabilities).
86+
// This is inherited by all descendants via fork, so every SSH
87+
// session and its children are covered. Called after DropBoundingCaps
88+
// because credential switching via SysProcAttr.Credential uses
89+
// setresuid/setresgid syscalls (not execve), so it is unaffected.
90+
logger.Info("setting no_new_privs")
91+
if err := harden.SetNoNewPrivs(); err != nil {
92+
return nil, fmt.Errorf("setting no_new_privs: %w", err)
93+
}
94+
8495
// 9. Start SSH server — bind synchronously so listen errors surface
8596
// immediately rather than being swallowed in a goroutine.
8697
cfg := sshd.Config{

0 commit comments

Comments
 (0)