-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[agent] Serve API over Unix domain sockets #16884
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,10 @@ type Config struct { | |
// Use normalizedAddrs if you need the host+port to bind to. | ||
Addresses *Addresses `hcl:"addresses"` | ||
|
||
// APISocket is used to configure a unix domain socket listener for the | ||
// HTTP API | ||
APISocket *SocketConfig `hcl:"api_socket"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pedant in me wants to name this That being said if you don't think anyone wants to type that many characters I will shutup. It is nbd. 😅 |
||
|
||
// normalizedAddr is set to the Address+Port by normalizeAddrs() | ||
normalizedAddrs *NormalizedAddrs | ||
|
||
|
@@ -1089,6 +1093,57 @@ func (n *NormalizedAddrs) Copy() *NormalizedAddrs { | |
return &nn | ||
} | ||
|
||
// SocketConfig contains the path and configuration for a unix domain socket | ||
// listener. | ||
type SocketConfig struct { | ||
Path string `hcl:"path"` | ||
User string `hcl:"user"` | ||
Mode string `hcl:"mode"` | ||
Group string `hcl:"group"` | ||
Comment on lines
+1100
to
+1102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Letting the administrator set user/group/mode is really interesting, in that I'd have expected us to use Nomad's own user/group and a restrictive mode. But this lets the administrator run a client as root and use a non-root user to talk to it (so long as you've got ACLs in place, I suppose). This should definitely come with some notes about recommended usage in the docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some prior art:
|
||
} | ||
|
||
func (s *SocketConfig) Copy() *SocketConfig { | ||
if s == nil { | ||
return nil | ||
} | ||
ns := *s | ||
return &ns | ||
} | ||
|
||
// Merge merges two SocketConfigs together, preferring values from the argument. | ||
func (s *SocketConfig) Merge(b *SocketConfig) *SocketConfig { | ||
if b == nil { | ||
return s | ||
} | ||
var result SocketConfig | ||
if s != nil { | ||
result = *s | ||
} | ||
Comment on lines
+1119
to
+1121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just declared |
||
if b.Path != "" { | ||
result.Path = b.Path | ||
} | ||
if b.User != "" { | ||
result.User = b.User | ||
} | ||
if b.Group != "" { | ||
result.Group = b.Group | ||
} | ||
if b.Mode != "" { | ||
result.Mode = b.Mode | ||
} | ||
Comment on lines
+1122
to
+1133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field merges can be 1-liners with https://github.com/hashicorp/nomad/blob/main/helper/funcs.go#L492-L500 |
||
return &result | ||
} | ||
|
||
// UnixSocketsConfig extracts user, group, and mode into a UnixSocketsConfig | ||
// suitable for listenerutil.UnixSocketListener | ||
func (s *SocketConfig) UnixSocketsConfig() *listenerutil.UnixSocketsConfig { | ||
return &listenerutil.UnixSocketsConfig{ | ||
User: s.User, | ||
Group: s.Group, | ||
Mode: s.Mode, | ||
} | ||
} | ||
|
||
// AdvertiseAddrs is used to control the addresses we advertise out for | ||
// different network services. All are optional and default to BindAddr and | ||
// their default Port. | ||
|
@@ -1264,6 +1319,7 @@ func DefaultConfig() *Config { | |
}, | ||
Addresses: &Addresses{}, | ||
AdvertiseAddrs: &AdvertiseAddrs{}, | ||
APISocket: &SocketConfig{}, | ||
Consul: config.DefaultConsulConfig(), | ||
Vault: config.DefaultVaultConfig(), | ||
UI: config.DefaultUIConfig(), | ||
|
@@ -1501,6 +1557,13 @@ func (c *Config) Merge(b *Config) *Config { | |
result.AdvertiseAddrs = result.AdvertiseAddrs.Merge(b.AdvertiseAddrs) | ||
} | ||
|
||
// Apply the api_socket config | ||
if result.APISocket == nil && b.APISocket != nil { | ||
result.APISocket = b.APISocket.Copy() | ||
} else if b.APISocket != nil { | ||
result.APISocket = result.APISocket.Merge(b.APISocket) | ||
} | ||
|
||
// Apply the Consul Configuration | ||
if result.Consul == nil && b.Consul != nil { | ||
result.Consul = b.Consul.Copy() | ||
|
@@ -1576,6 +1639,7 @@ func (c *Config) Copy() *Config { | |
nc.Addresses = c.Addresses.Copy() | ||
nc.normalizedAddrs = c.normalizedAddrs.Copy() | ||
nc.AdvertiseAddrs = c.AdvertiseAddrs.Copy() | ||
nc.APISocket = c.APISocket.Copy() | ||
nc.Client = c.Client.Copy() | ||
nc.Server = c.Server.Copy() | ||
nc.ACL = c.ACL.Copy() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
api-unix-*
makes more sense here (see below for discussion).