API Reference¶
Complete reference for the aims package.
SPIFFE ID¶
Types¶
SPIFFEID¶
type SPIFFEID struct {
TrustDomain string // e.g., "example.com"
Path string // e.g., "/agent/calendar-bot"
}
Functions¶
ParseSPIFFEID¶
Parses a SPIFFE ID string into its components.
MustParseSPIFFEID¶
Parses a SPIFFE ID string, panicking on error. Use for constants.
NewSPIFFEID¶
Creates a SPIFFE ID from trust domain and path components.
Methods¶
String¶
Returns the SPIFFE ID as a URI string.
URI¶
Returns the SPIFFE ID as a *url.URL.
IsAgent / IsWorkload / IsService / IsUser¶
func (s *SPIFFEID) IsAgent() bool
func (s *SPIFFEID) IsWorkload() bool
func (s *SPIFFEID) IsService() bool
func (s *SPIFFEID) IsUser() bool
Returns true if the path indicates the identity type.
Name¶
Returns the final component of the path (workload name).
Equal¶
Returns true if two SPIFFE IDs are equal.
InTrustDomain¶
Returns true if this SPIFFE ID belongs to the given trust domain.
Constants¶
const SPIFFEScheme = "spiffe"
const (
PathPrefixAgent = "/agent/"
PathPrefixWorkload = "/workload/"
PathPrefixService = "/service/"
PathPrefixUser = "/user/"
)
Workload Identity Token (WIT)¶
Types¶
WorkloadIdentityToken¶
type WorkloadIdentityToken struct {
Issuer string `json:"iss"` // Trust domain issuer
Subject string `json:"sub"` // SPIFFE ID
Audience []string `json:"aud"` // Intended recipients
Expiry time.Time `json:"exp"`
IssuedAt time.Time `json:"iat"`
NotBefore time.Time `json:"nbf,omitempty"`
JWTID string `json:"jti,omitempty"`
CNF *CNF `json:"cnf,omitempty"` // Confirmation key
}
CNF¶
type CNF struct {
JWK json.RawMessage `json:"jwk,omitempty"` // Embedded JWK
Kid string `json:"kid,omitempty"` // Key ID reference
X5T string `json:"x5t#S256,omitempty"` // X.509 thumbprint
}
Functions¶
NewWIT¶
func NewWIT(spiffeID *SPIFFEID, audience []string, ttl time.Duration, opts ...WITOption) *WorkloadIdentityToken
Creates a new Workload Identity Token.
GenerateJTI¶
Generates a random JWT ID.
WITOption Functions¶
func WithWITJTI(jti string) WITOption
func WithWITNotBefore(nbf time.Time) WITOption
func WithWITCNF(cnf *CNF) WITOption
Methods¶
Sign¶
Creates a signed JWT string from this WIT.
Validate¶
Checks if the WIT has all required fields and is temporally valid.
SPIFFEID¶
Returns the SPIFFE ID from the subject claim.
IsExpired¶
Returns true if the token has expired.
TimeToExpiry¶
Returns the duration until this token expires.
WIMSE Proof Token (WPT)¶
Types¶
WIMSEProofToken¶
type WIMSEProofToken struct {
Issuer string `json:"iss"` // Must match WIT subject
Audience string `json:"aud"` // Target service
IssuedAt time.Time `json:"iat"`
Expiry time.Time `json:"exp,omitempty"`
JWTID string `json:"jti,omitempty"`
Nonce string `json:"nonce,omitempty"`
HTM string `json:"htm"` // HTTP method
HTU string `json:"htu"` // HTTP URI
ATH string `json:"ath,omitempty"` // Access token hash
}
Constants¶
Functions¶
NewWPT¶
Creates a new WIMSE Proof Token for an HTTP request.
NewWPTFromWIT¶
func NewWPTFromWIT(wit *WorkloadIdentityToken, audience, method, uri string, opts ...WPTOption) *WIMSEProofToken
Creates a WPT bound to a WIT.
NewWPTForRequest¶
Creates a WPT bound to an http.Request.
WPTFromHeader¶
Extracts a WPT JWT from an HTTP header.
WPTOption Functions¶
func WithWPTNonce(nonce string) WPTOption
func WithWPTJTI(jti string) WPTOption
func WithWPTExpiry(exp time.Time) WPTOption
func WithWPTAccessToken(accessToken string) WPTOption
Methods¶
Sign¶
Creates a signed JWT string from this WPT.
BindToRequest¶
Adds the WPT to an HTTP request header.
Validate¶
Checks if the WPT has all required fields.
MatchesRequest¶
Checks if this WPT matches the given HTTP request.
IsExpired¶
Returns true if the proof token has expired.
Credentials¶
Interfaces¶
Credential¶
type Credential interface {
Type() CredentialType
SPIFFEID() *SPIFFEID
IsExpired() bool
ExpiresAt() time.Time
}
Types¶
CredentialType¶
type CredentialType string
const (
CredentialX509SVID CredentialType = "x509-svid"
CredentialJWTSVID CredentialType = "jwt-svid"
CredentialWIT CredentialType = "wit"
)
X509SVID¶
X.509 SPIFFE Verifiable Identity Document for mTLS authentication.
JWTSVID¶
JWT-based SPIFFE Verifiable Identity Document.
Functions¶
NewX509SVID¶
Creates an X509SVID from a certificate chain and private key.
NewJWTSVID¶
Creates a JWTSVID from its components.
X509SVID Methods¶
LeafCertificate¶
Returns the leaf (end-entity) certificate.
Agent Identity¶
Types¶
AgentIdentity¶
type AgentIdentity struct {
SPIFFEID *SPIFFEID
Credential Credential
Attestation *Attestation
Metadata map[string]string
CreatedAt time.Time
}
Represents a fully-attested agent identity.
Functions¶
NewAgentIdentity¶
Creates an agent identity from a SPIFFE ID and credential.
IdentityOption Functions¶
func WithAttestation(att *Attestation) IdentityOption
func WithMetadata(key, value string) IdentityOption
Methods¶
IsValid¶
Checks if the identity is currently valid.
ExpiresAt¶
Returns when this identity expires.
TimeToExpiry¶
Returns the duration until this identity expires.
Attestation¶
Types¶
AttestationType¶
type AttestationType string
const (
AttestationTPM AttestationType = "tpm"
AttestationSGX AttestationType = "sgx"
AttestationSEVSNP AttestationType = "sev-snp"
AttestationTDX AttestationType = "tdx"
AttestationKubernetes AttestationType = "kubernetes"
AttestationAWS AttestationType = "aws"
AttestationGCP AttestationType = "gcp"
AttestationAzure AttestationType = "azure"
AttestationGitHub AttestationType = "github"
AttestationUnix AttestationType = "unix"
AttestationDocker AttestationType = "docker"
)
Attestation¶
type Attestation struct {
Type AttestationType
Evidence []byte
Timestamp time.Time
Attributes map[string]string
}
Functions¶
NewAttestation¶
Creates a new attestation with the given type and evidence.
NewAttestationWithOptions¶
func NewAttestationWithOptions(attestType AttestationType, evidence []byte, opts ...AttestationOption) *Attestation
Creates an attestation with options.
AttestationOption Functions¶
func WithAttestationTimestamp(t time.Time) AttestationOption
func WithAttribute(key, value string) AttestationOption
Methods¶
Age¶
Returns how old the attestation is.
IsFresh¶
Returns true if the attestation is younger than the given duration.
GetAttribute¶
Returns an attestation attribute value.
AttestationType Methods¶
Description¶
Returns a human-readable description.
IsHardware¶
Returns true for hardware-based attestation (TPM, SGX, SEV-SNP, TDX).
IsCloud¶
Returns true for cloud provider attestation (AWS, GCP, Azure).
Attribute Keys¶
const (
AttrInstanceID = "instance-id"
AttrRegion = "region"
AttrAccountID = "account-id"
AttrNamespace = "namespace"
AttrServiceAccount = "service-account"
AttrPodName = "pod-name"
AttrContainerID = "container-id"
AttrImageDigest = "image-digest"
AttrPCR0 = "pcr0"
AttrMRENCLAVE = "mrenclave"
AttrMRSIGNER = "mrsigner"
)
AIMS Layers¶
Types¶
Layer¶
type Layer int
const (
LayerIdentifiers Layer = iota + 1
LayerCredentials
LayerAttestation
LayerProvisioning
LayerAuthentication
LayerAuthorization
LayerMonitoring
LayerPolicy
LayerCompliance
)
Functions¶
AllLayers¶
Returns all 9 AIMS layers in order.
Methods¶
String¶
Returns the human-readable name of the layer.
Description¶
Returns a brief description of the layer's purpose.
Errors¶
var (
// SPIFFE ID errors
ErrInvalidSPIFFEID error
ErrEmptyTrustDomain error
ErrInvalidScheme error
ErrPathContainsQuery error
ErrPathContainsFragment error
ErrTrustDomainHasPort error
ErrTrustDomainHasUserInfo error
// WIT errors
ErrWITMissingSubject error
ErrWITMissingIssuer error
ErrWITMissingAudience error
ErrWITExpired error
ErrWITNotYetValid error
// WPT errors
ErrWPTMissingIssuer error
ErrWPTMissingAudience error
ErrWPTMissingHTM error
ErrWPTMissingHTU error
ErrWPTExpired error
)