Skip to content

Commit 0b5f891

Browse files
committed
Use pledge(2) on OpenBSD
Straight forward thanks to all privileged operations being done early enough during startup. Basically forbid all groups of syscalls except for networking, so no fileystem access, signals, process management, etc.
1 parent 7adf5f1 commit 0b5f891

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/yggdrasil/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,22 @@ func main() {
312312
}
313313
}
314314

315+
// Promise final modes of operation. At this point, if at all:
316+
// - raw socket is created/open
317+
// - admin socket is created/open
318+
// - privileges are dropped to non-root user
319+
promises := []string{"stdio", "inet", "dns"}
320+
if usesUnixSocket {
321+
// Go's net.Listen.Close() itself will delete the file on shutdown.
322+
promises = append(promises, "cpath")
323+
}
324+
if len(cfg.MulticastInterfaces) > 0 {
325+
promises = append(promises, "mcast")
326+
}
327+
if err := protect.Pledge(strings.Join(promises, " ")); err != nil {
328+
panic(fmt.Sprintf("pledge: %v: %v", promises, err))
329+
}
330+
315331
// Block until we are told to shut down.
316332
<-ctx.Done()
317333

0 commit comments

Comments
 (0)