Skip to content

Commit 782c025

Browse files
authored
Use pledge(2) on OpenBSD (#1215)
Straight forward thanks to all privileged operations being done early enough during startup.
1 parent 213f72b commit 782c025

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmd/yggdrasil/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,21 @@ 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+
//
320+
// Peers, InterfacePeers, Listen can be UNIX sockets;
321+
// Go's net.Listen.Close() deletes files on shutdown.
322+
promises := []string{"stdio", "cpath", "inet", "unix", "dns"}
323+
if len(cfg.MulticastInterfaces) > 0 {
324+
promises = append(promises, "mcast")
325+
}
326+
if err := protect.Pledge(strings.Join(promises, " ")); err != nil {
327+
panic(fmt.Sprintf("pledge: %v: %v", promises, err))
328+
}
329+
315330
// Block until we are told to shut down.
316331
<-ctx.Done()
317332

0 commit comments

Comments
 (0)