-
Notifications
You must be signed in to change notification settings - Fork 600
Implement SPIFFE Broker Endpoint & API #6594
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
base: main
Are you sure you want to change the base?
Changes from all commits
efc7313
ba52838
237083e
3ef6fbb
2e67e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,30 @@ func (c *agentConfig) hasAdminAddr() bool { | |
| return c.AdminSocketPath != "" | ||
| } | ||
|
|
||
| func (c *agentConfig) getBrokerAddr() (net.Addr, error) { | ||
|
Member
Author
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. For now I'm only supporting UDS, once the Broker API evolves we may allow serving it on TCP too. |
||
| socketPathAbs, err := filepath.Abs(c.SocketPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get absolute path for socket_path: %w", err) | ||
| } | ||
| brokerSocketPathAbs, err := filepath.Abs(c.BrokerSocketPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get absolute path for broker_socket_path: %w", err) | ||
| } | ||
|
|
||
| if strings.HasPrefix(brokerSocketPathAbs, filepath.Dir(socketPathAbs)+"/") { | ||
| return nil, errors.New("broker socket cannot be in the same directory or a subdirectory as that containing the Workload API socket") | ||
| } | ||
|
|
||
| return &net.UnixAddr{ | ||
| Name: brokerSocketPathAbs, | ||
| Net: "unix", | ||
| }, nil | ||
| } | ||
|
|
||
| func (c *agentConfig) hasBrokerAddr() bool { | ||
| return c.BrokerSocketPath != "" | ||
| } | ||
|
|
||
| // validateOS performs posix specific validations of the agent config | ||
| func (c *agentConfig) validateOS() error { | ||
| if c.Experimental.NamedPipeName != "" { | ||
|
|
@@ -88,5 +112,16 @@ func prepareEndpoints(c *agent.Config) error { | |
| } | ||
| } | ||
|
|
||
| if c.BrokerBindAddress != nil { | ||
| // Create uds dir and parents if not exists | ||
| brokerDir := filepath.Dir(c.BrokerBindAddress.String()) | ||
| if _, statErr := os.Stat(brokerDir); os.IsNotExist(statErr) { | ||
| c.Log.WithField("dir", brokerDir).Infof("Creating broker UDS directory") | ||
| if err := os.MkdirAll(brokerDir, 0755); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import ( | |
| admin_api "github.com/spiffe/spire/pkg/agent/api" | ||
| node_attestor "github.com/spiffe/spire/pkg/agent/attestor/node" | ||
| workload_attestor "github.com/spiffe/spire/pkg/agent/attestor/workload" | ||
| "github.com/spiffe/spire/pkg/agent/broker" | ||
| "github.com/spiffe/spire/pkg/agent/catalog" | ||
| "github.com/spiffe/spire/pkg/agent/endpoints" | ||
| "github.com/spiffe/spire/pkg/agent/manager" | ||
|
|
@@ -255,6 +256,24 @@ func (a *Agent) Run(ctx context.Context) error { | |
| tasks = append(tasks, adminEndpoints.ListenAndServe) | ||
| } | ||
|
|
||
| if a.c.BrokerBindAddress != nil { | ||
| brokerEndpoints, err := broker.New(&broker.Config{ | ||
| BindAddr: a.c.BrokerBindAddress, | ||
| Manager: manager, | ||
| Log: a.c.Log, | ||
| Metrics: metrics, | ||
| Attestor: workloadAttestor, | ||
| TrustDomain: a.c.TrustDomain, | ||
| AuthorizedDelegates: a.c.AuthorizedDelegates, | ||
| SVIDSource: as, | ||
| BundleSource: manager.GetX509Bundle(), | ||
|
Member
Author
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. I wasn't sure what's better here, us the attestation result as a bundle source or the one from the manager? |
||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create broker endpoints: %w", err) | ||
| } | ||
| tasks = append(tasks, brokerEndpoints.ListenAndServe) | ||
| } | ||
|
|
||
| if a.c.LogReopener != nil { | ||
| tasks = append(tasks, a.c.LogReopener) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package attestor | ||
|
|
||
| import ( | ||
| "crypto/x509" | ||
| "fmt" | ||
|
|
||
| "github.com/spiffe/go-spiffe/v2/bundle/spiffebundle" | ||
| "github.com/spiffe/go-spiffe/v2/bundle/x509bundle" | ||
| "github.com/spiffe/go-spiffe/v2/spiffeid" | ||
| "github.com/spiffe/go-spiffe/v2/svid/x509svid" | ||
| "github.com/spiffe/spire/pkg/agent/plugin/keymanager" | ||
| ) | ||
|
|
||
| // Allow AttestationResult to be used as go-spiffe SVID and bundle sources. | ||
| // TODO(arndt): Check whether the key of the agent is ok to be exposed to other parties. | ||
|
Member
Author
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. I think this is worth a discussion. |
||
| var ( | ||
| _ x509svid.Source = (*AttestationResult)(nil) | ||
| _ x509bundle.Source = (*AttestationResult)(nil) | ||
| ) | ||
|
|
||
| type AttestationResult struct { | ||
| SVID []*x509.Certificate | ||
| Key keymanager.Key | ||
| Bundle *spiffebundle.Bundle | ||
| Reattestable bool | ||
| } | ||
|
|
||
| func (ar *AttestationResult) GetX509SVID() (*x509svid.SVID, error) { | ||
| return &x509svid.SVID{ | ||
| Certificates: ar.SVID, | ||
| PrivateKey: ar.Key, | ||
| }, nil | ||
| } | ||
|
|
||
| func (ar *AttestationResult) GetX509BundleForTrustDomain(trustDomain spiffeid.TrustDomain) (*x509bundle.Bundle, error) { | ||
| if ar.Bundle.TrustDomain() != trustDomain { | ||
| return nil, fmt.Errorf("bundle for trust domain %q not found", trustDomain) | ||
| } | ||
| return ar.Bundle.X509Bundle(), nil | ||
| } | ||
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.
How do others make images with custom api & plugin packages?