Skip to content

Commit

Permalink
fix: only allow setting custom hostname if running as root
Browse files Browse the repository at this point in the history
This is match access level to `/etc/hostname` of `0644`. If only root
can change system hostname, then only root should be able to change the
hostname of the inventory that is used to enroll in the configuration
management system.
  • Loading branch information
tjhop committed Jul 1, 2023
1 parent bc1e2f3 commit 46c8d5c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/mango/mango.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,17 @@ func main() {
log.Fatal("Inventory not defined, please set `inventory.path` flag or config variable to the path to the inventory")
}

// run mango daemon
me := viper.GetString("hostname")
if me == "" {
me = self.GetHostname()
// get hostname for inventory
me := self.GetHostname()

// only allow setting custom hostname if running as root
if os.Geteuid() == 0 {
customHostname := viper.GetString("hostname")
if customHostname != "" {
me = customHostname
}
}

// run mango daemon
mango(inventoryPath, me)
}

0 comments on commit 46c8d5c

Please sign in to comment.