Skip to content

Commit

Permalink
Merge pull request #5 from muzzammilshahid/run-as-root-only
Browse files Browse the repository at this point in the history
Run service as root only
  • Loading branch information
muzzammilshahid authored Sep 30, 2024
2 parents 1d31c60 + dba8834 commit 9bf47ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/http-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type DeviceRequest struct {
}

func main() {
if !wireguard_admin_service.IsRoot() {
log.Fatalln("You need to run this service as root")
}

r := gin.Default()

const qrDir = "./qr-codes"
Expand Down
14 changes: 14 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package wireguard_admin_service

import (
"os/user"
)

func IsRoot() bool {
currentUser, err := user.Current()
if err != nil {
return false
}

return currentUser.Uid == "0"
}

0 comments on commit 9bf47ad

Please sign in to comment.