Skip to content

Commit

Permalink
pledge yggdrasilctl
Browse files Browse the repository at this point in the history
The CLI is simple, but parses config files and communicates over the network
with arbitrary endpoints.

Limit system operations to that is needed before doing anything and drop all
priviledges after config file and socket handling is done, i.e. do parse and
speak over the network completely unprivileged.
  • Loading branch information
klemensn committed Oct 22, 2024
1 parent c27e3f4 commit 9e1efc2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/yggdrasilctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strings"
"time"

"suah.dev/protect"

"github.com/olekukonko/tablewriter"
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
Expand All @@ -22,6 +24,11 @@ import (
)

func main() {
// read config, speak DNS/TCP and/or over a UNIX socket
if err := protect.Pledge("stdio rpath inet unix dns"); err != nil {
panic(err)
}

// makes sure we can use defer and still return an error code to the OS
os.Exit(run())
}
Expand Down Expand Up @@ -78,6 +85,11 @@ func run() int {
panic(err)
}

// config and socket are done, work without unprivileges
if err := protect.Pledge("stdio"); err != nil {
panic(err)
}

logger.Println("Connected")
defer conn.Close()

Expand Down

0 comments on commit 9e1efc2

Please sign in to comment.