spiffe

package
v0.136.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

SPIFFE workload identity

This package uses the maintained go-spiffe/v2 Workload API clients. It does not implement SPIFFE token parsing, SVID rotation, trust-bundle validation, or TLS peer authorization itself.

Broker mTLS

Use the exact broker SPIFFE ID allowlist. The endpoint is an HTTPS name on the private service network; do not send the Workload API socket or a task proof through the public gateway.

ctx, cancel := context.WithTimeout(parent, 10*time.Second)
defer cancel()

broker, err := spiffe.NewHTTPClient(ctx,
    "unix:///run/spire/agent.sock",
    []string{"spiffe://0exec.com/ns/fleet/sa/task-credential-broker"},
)
if err != nil {
    return err
}
defer broker.Close()

tasks, err := credentiallease.NewTaskManager(credentiallease.TaskManagerConfig{
    Endpoint:       "https://task-credential-broker:8443",
    BrokerAudience: "task-credential-broker",
    SPIFFEClient:   broker,
})
if err != nil {
    return err
}
defer tasks.Close()

The broker maps the verified client SPIFFE ID to one exact policy principal. The returned task proof remains required for lease acquire/revoke and is bound to that principal. Invalid SVIDs, wrong server identities, and unmapped client IDs fail closed; there is no API-key fallback on this mTLS path.

Keep the TaskManager alive while its tasks and task clients are active. Close tasks before closing the manager so the rotating SVID source remains available for task cleanup. Do not log SVIDs, task proofs, authenticated headers, or the Workload API response.

JWT-SVIDs

spiffe.Source fetches short-lived JWT-SVIDs for exactly one requested audience. Prefer broker-validated JWT-SVIDs only where mTLS is unavailable; use the X.509 path above for direct service-to-service calls inside the private mesh. Do not reuse a token across audiences or silently switch to a static key when the Workload API is unavailable.

Documentation

Overview

Package spiffe adapts the SPIFFE Workload API to credentiallease identities.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("credentiallease/spiffe: workload identity unavailable")

Functions

func ValidateSocket added in v0.113.0

func ValidateSocket(socket string) bool

ValidateSocket reports whether socket is a Workload API address this package accepts (a unix:// URL with an absolute path and nothing else).

Types

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient contains a redirect-disabled HTTP client and the X.509 source it uses. The transport does not honor HTTP proxy environment variables because proxying would cross the configured SPIFFE peer-authentication boundary.

func NewHTTPClient

func NewHTTPClient(ctx context.Context, socket string, allowedServerIDs []string) (*HTTPClient, error)

func NewHTTPClientWithTimeout

func NewHTTPClientWithTimeout(ctx context.Context, socket string, allowedServerIDs []string, timeout time.Duration) (*HTTPClient, error)

NewHTTPClientWithTimeout creates the same redirect-disabled, proxy-free SPIFFE mTLS client as NewHTTPClient with an explicit total and response header timeout. The upper bound prevents callers from creating unbounded requests while allowing control-plane calls with bounded evidence checks.

func (*HTTPClient) Close

func (c *HTTPClient) Close() error

func (*HTTPClient) CloseIdleConnections

func (c *HTTPClient) CloseIdleConnections()

func (*HTTPClient) Do

func (c *HTTPClient) Do(req *http.Request) (*http.Response, error)

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source obtains short-lived JWT-SVIDs for one requested audience. It must be closed when the owning service shuts down.

func New

func New(ctx context.Context, socket string) (*Source, error)

New creates a Workload API JWT source. socket must be a validated SPIFFE Workload API address, normally unix:///run/spire/agent.sock.

func (*Source) Close

func (s *Source) Close() error

func (*Source) GetJWTBundleForTrustDomain added in v0.113.0

func (s *Source) GetJWTBundleForTrustDomain(td spiffeid.TrustDomain) (*jwtbundle.Bundle, error)

GetJWTBundleForTrustDomain makes Source a jwtbundle.Source: the trust bundle's JWT authorities the Workload API delivers, kept current by the source, for verifying a peer's JWT-SVID (package spiffeauth).

func (*Source) Token

func (s *Source) Token(ctx context.Context, audience string) (string, error)

Token returns a compact JWT-SVID minted for exactly audience. No token or Workload API error details are included in errors.

type X509Identity

type X509Identity struct {
	// contains filtered or unexported fields
}

X509Identity owns a rotating X.509-SVID source used to build mutually authenticated TLS configurations. Close it when the process shuts down.

func NewX509Identity

func NewX509Identity(ctx context.Context, socket string) (*X509Identity, error)

NewX509Identity connects to the local Unix Workload API and waits for the first SVID and trust bundle. It never accepts a remote TCP endpoint.

func (*X509Identity) BundleSource added in v0.113.0

func (i *X509Identity) BundleSource() x509bundle.Source

BundleSource is the rotating X.509 trust bundle set (nil on a nil identity), for verifying a peer's X.509-SVID.

func (*X509Identity) ClientTLSConfig

func (i *X509Identity) ClientTLSConfig(allowedServerIDs []string) (*tls.Config, error)

ClientTLSConfig presents this workload's SVID and authorizes only the configured server identities.

func (*X509Identity) Close

func (i *X509Identity) Close() error

func (*X509Identity) SVIDSource added in v0.113.0

func (i *X509Identity) SVIDSource() x509svid.Source

SVIDSource is the rotating X.509-SVID of this workload (nil on a nil identity).

func (*X509Identity) ServerTLSConfig

func (i *X509Identity) ServerTLSConfig(allowedClientIDs []string) (*tls.Config, error)

ServerTLSConfig presents this workload's SVID and requires clients to prove one of the exact configured SPIFFE identities.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL