Skip to content

Commit

Permalink
Pass egid and euid to osascript
Browse files Browse the repository at this point in the history
  • Loading branch information
ravicious committed Jul 29, 2024
1 parent f114ecb commit 5eb5a5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/vnet/setup_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ do shell script quoted form of executableName & `+
`" %s -d --socket " & quoted form of socketPath & `+
`" --ipv6-prefix " & quoted form of ipv6Prefix & `+
`" --dns-addr " & quoted form of dnsAddr & `+
`" --egid %d --euid %d" & `+
`" >/var/log/vnet.log 2>&1" `+
`with prompt "Teleport VNet wants to set up a virtual network device." with administrator privileges`,
executableName, config.SocketPath, config.IPv6Prefix, config.DNSAddr, teleport.VnetAdminSetupSubCommand)
executableName, config.SocketPath, config.IPv6Prefix, config.DNSAddr, teleport.VnetAdminSetupSubCommand,
os.Getegid(), os.Geteuid())

// The context we pass here has effect only on the password prompt being shown. Once osascript spawns the
// privileged process, canceling the context (and thus killing osascript) has no effect on the privileged
Expand Down
12 changes: 12 additions & 0 deletions tool/tsh/common/vnet_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ type vnetAdminSetupCommand struct {
ipv6Prefix string
// dnsAddr is the IP address for the VNet DNS server.
dnsAddr string
// egid of the user starting VNet. Unsafe for production use, as the egid comes from an unstrusted
// source.
egid int
// euid of the user starting VNet. Unsafe for production use, as the euid comes from an unstrusted
// source.
euid int
}

func newVnetAdminSetupCommand(app *kingpin.Application) *vnetAdminSetupCommand {
Expand All @@ -89,6 +95,8 @@ func newVnetAdminSetupCommand(app *kingpin.Application) *vnetAdminSetupCommand {
cmd.Flag("socket", "unix socket path").StringVar(&cmd.socketPath)
cmd.Flag("ipv6-prefix", "IPv6 prefix for the VNet").StringVar(&cmd.ipv6Prefix)
cmd.Flag("dns-addr", "VNet DNS address").StringVar(&cmd.dnsAddr)
cmd.Flag("egid", "effective group ID of the user starting VNet").IntVar(&cmd.egid)
cmd.Flag("euid", "effective user ID of the user starting VNet").IntVar(&cmd.euid)
return cmd
}

Expand All @@ -104,6 +112,10 @@ func (c *vnetAdminSetupCommand) run(cf *CLIConf) error {
IPv6Prefix: c.ipv6Prefix,
DNSAddr: c.dnsAddr,
HomePath: homePath,
ClientCred: &daemon.ClientCred{
Egid: c.egid,
Euid: c.euid,
},
}

return trace.Wrap(vnet.AdminSetup(cf.Context, config))
Expand Down

0 comments on commit 5eb5a5b

Please sign in to comment.