Skip to content

Commit

Permalink
cmd/landlock-nonet: WIP: restrict networking using Landlock
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoack committed Jan 9, 2024
1 parent ed097eb commit b81a0e7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/landlock-nonet/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"log"
"os"
"syscall"

"github.com/landlock-lsm/go-landlock/landlock"
)

func main() {
var cmd []string
if len(os.Args) > 1 {
cmd = os.Args[1:]
} else {
log.Println("missing command to call, using /bin/bash")
cmd = []string{"/bin/bash"}
}

if err := landlock.V4.RestrictNet(); err != nil {
log.Fatalf("landlock RestrictNet: %v", err)
}

log.Printf("Starting %v", cmd)
if err := syscall.Exec(cmd[0], cmd, os.Environ()); err != nil {
log.Fatalf("execve: %v", err)
}
}

0 comments on commit b81a0e7

Please sign in to comment.