iid

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: AGPL-3.0 Imports: 10 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.

Documentation

Overview

Package iid defines the contract shared between the OpenStack metadata JWT issuer (openstack-spire-issuer) and the openstack_iid SPIRE node attestor plugins: the JWT header and claim schema, the fixed issuer/audience values and the shape of the vendordata response. Both sides must import it rather than re-declaring any of these values.

Index

Constants

View Source
const (
	// TargetName is the name of the Nova DynamicJSON vendordata target; Nova
	// nests this service's response under this key in vendor_data2.json.
	TargetName = "openstack_iid"
	// Issuer is the value of the "iss" claim of every issued token.
	Issuer = "nova-spire-plugin"
	// Audience is the value of the "aud" claim of every issued token.
	Audience = "spire-node-attestation"
	// Algorithm is the default JWS signing algorithm.
	Algorithm = "RS256"
	// TTL is the fixed validity window of every issued token (exp - iat).
	TTL = 5 * time.Minute
	// MaxTagsBytes is the maximum size of the JSON-serialized "tags" claim.
	MaxTagsBytes = 1024
	// MaxCustomClaimsBytes is the maximum size of the operator-configured
	// custom claims, serialized as a JSON object.
	MaxCustomClaimsBytes = 2048
	// MaxTokenBytes is the maximum size of a compact-serialized token: the
	// issuer never mints a larger one, and the SPIRE plugins reject it.
	MaxTokenBytes = 16 << 10
	// MaxJWKSKeys is the maximum number of keys in a JWK Set: a larger set
	// is a failed fetch, never truncated.
	MaxJWKSKeys = 100
)
View Source
const (
	// ClaimAvailabilityZone is the availability zone the instance runs in.
	ClaimAvailabilityZone = "availability_zone"
	// ClaimFlavor is the name of the instance flavor.
	ClaimFlavor = "flavor"
	// ClaimUserID is the ID of the user who booted the instance.
	ClaimUserID = "user_id"
	// ClaimProjectName is the name of the project owning the instance.
	ClaimProjectName = "project_name"
	// ClaimDomainID is the ID of the domain of the project owning the instance.
	ClaimDomainID = "domain_id"
)

Names of the optional enrichment claims, looked up from Nova and Keystone when enabled in the issuer configuration.

View Source
const (

	// MaxKeyIDBytes is the maximum length of a kid.
	MaxKeyIDBytes = 128
)

Variables

View Source
var ErrInvalidClaim = errors.New("invalid claim")

ErrInvalidClaim is returned (wrapped) by the field validators. Their messages describe the problem without naming the field, so that callers can name it in their own terms (e.g. "project-id" in a Nova request, "project_id" in a token).

View Source
var ErrInvalidCustomClaim = errors.New("invalid custom claim")

ErrInvalidCustomClaim is returned (wrapped) when a custom claim has an empty or reserved name, or when the custom claims are too large.

View Source
var ErrInvalidKeyID = errors.New("invalid kid")

ErrInvalidKeyID marks a kid that does not have the issuer's format.

Functions

func CustomClaimsSize

func CustomClaimsSize(custom map[string]string) (int, error)

CustomClaimsSize returns the size of the custom claims serialized as a JSON object, escaping included.

func EnrichmentClaims

func EnrichmentClaims() []string

EnrichmentClaims returns the names of the optional enrichment claims.

func IsReservedClaim

func IsReservedClaim(name string) bool

IsReservedClaim reports whether name is a claim defined by this contract.

func ReservedClaims

func ReservedClaims() []string

ReservedClaims returns the claim names that custom claims must not use.

func ValidateCustomClaims

func ValidateCustomClaims(custom map[string]string) error

ValidateCustomClaims checks that no custom claim has an empty or reserved name, and that the custom claims, serialized as a JSON object, do not exceed MaxCustomClaimsBytes.

func ValidateEnrichmentValue

func ValidateEnrichmentValue(value string) error

ValidateEnrichmentValue checks the value of an enrichment claim: non-empty, at most 255 bytes, with the character rules of ValidateTagValue.

func ValidateHostname

func ValidateHostname(hostname string) error

ValidateHostname checks a hostname: non-empty, at most 255 characters, without control characters.

func ValidateInstanceID

func ValidateInstanceID(id string) error

ValidateInstanceID checks an instance ID: a canonical lowercase UUID.

func ValidateKeyID

func ValidateKeyID(kid string) error

ValidateKeyID checks a kid: at most MaxKeyIDBytes, of the form <YYYY-MM-DD>-<replica-id>-key-<n>, the replica ID being a lowercase DNS label. Until a token's signature is checked its kid is attacker-controlled, so the error never contains it.

func ValidateProjectID

func ValidateProjectID(id string) error

ValidateProjectID checks a project ID: 1 to 64 characters from [A-Za-z0-9_-]. Project IDs end up in SPIFFE ID paths.

func ValidateReplicaID

func ValidateReplicaID(id string) error

ValidateReplicaID checks a replica ID: a lowercase DNS label, since it ends up in every kid the replica issues.

func ValidateTagKey

func ValidateTagKey(key string) error

ValidateTagKey checks the key of a "tags" entry: non-empty, without ':', which would make the "tag:<key>:<value>" selector ambiguous, and with the character rules of ValidateTagValue.

func ValidateTagValue

func ValidateTagValue(value string) error

ValidateTagValue checks the value of a "tags" entry: valid UTF-8, without control (Cc) or format (Cf) characters, which could make selectors that look alike differ, or forge log lines. Empty values are valid.

Types

type Claims

type Claims struct {
	// Issuer is always Issuer.
	Issuer string `json:"iss"`
	// Audience is always Audience.
	Audience string `json:"aud"`
	// Subject is the instance ID.
	Subject string `json:"sub"`
	// IssuedAt is the issuance time, in seconds since the Unix epoch.
	IssuedAt int64 `json:"iat"`
	// NotBefore is the start of validity, in seconds since the Unix epoch.
	NotBefore int64 `json:"nbf"`
	// Expiry is the end of validity, in seconds since the Unix epoch.
	Expiry int64 `json:"exp"`
	// ID is a UUID freshly generated for every token.
	ID string `json:"jti"`
	// ProjectID is the project owning the instance, as reported by Nova.
	ProjectID string `json:"project_id"`
	// InstanceID is the instance UUID, as reported by Nova.
	InstanceID string `json:"instance_id"`
	// Hostname is the instance hostname, as reported by Nova.
	Hostname string `json:"hostname"`
	// Tags holds the filtered, string-only instance metadata.
	Tags map[string]string `json:"tags"`
	// AvailabilityZone is the instance's availability zone (optional
	// enrichment claim, from the Nova server record).
	AvailabilityZone string `json:"availability_zone,omitempty"`
	// Flavor is the name of the instance's flavor (optional enrichment
	// claim, from the Nova server record).
	Flavor string `json:"flavor,omitempty"`
	// UserID is the ID of the user who booted the instance (optional
	// enrichment claim, from the Nova server record).
	UserID string `json:"user_id,omitempty"`
	// ProjectName is the name of the project owning the instance (optional
	// enrichment claim, from Keystone).
	ProjectName string `json:"project_name,omitempty"`
	// DomainID is the ID of the domain of the project owning the instance
	// (optional enrichment claim, from Keystone).
	DomainID string `json:"domain_id,omitempty"`
	// Custom holds the operator-configured static claims, serialized as
	// top-level claims. Custom claims must not use reserved names: issuers
	// must check them with ValidateCustomClaims; in addition, marshaling
	// fails if one collides with an always-emitted claim. On unmarshal it
	// collects every claim not otherwise modelled here.
	Custom map[string]string `json:",embed"`
}

Claims is the payload of an issued token.

func ParseClaims

func ParseClaims(payload []byte) (Claims, error)

ParseClaims decodes a token payload. Unlike a plain decode into Claims, it skips claims it does not model whose values are not strings, so that a claim added later by the issuer never breaks parsing; unknown string claims are collected into Custom. Duplicate claim names are rejected, and an enrichment claim, when present, must be a non-empty string: the issuer never emits an empty one.

type Header struct {
	// Algorithm is the JWS signing algorithm (e.g. "RS256").
	Algorithm string `json:"alg"`
	// KeyID identifies the signing key in the JWKS.
	KeyID string `json:"kid"`
	// Type is the media type of the token, always "JWT".
	Type string `json:"typ"`
}

Header is the JOSE header of an issued token.

type VendorData

type VendorData struct {
	// JWT is the compact-serialized signed token.
	JWT string `json:"jwt"`
}

VendorData is the body the issuer returns to Nova for the TargetName target.

type VendorDataResponse

type VendorDataResponse struct {
	Target VendorData `json:"openstack_iid"`
}

VendorDataResponse is the part of vendor_data2.json the agent plugin reads: Nova nests every DynamicJSON target's response under the target's name, so the issuer's VendorData appears under TargetName. Other targets may sit next to it.

func NewVendorDataResponse

func NewVendorDataResponse(token string) VendorDataResponse

NewVendorDataResponse returns the vendor_data2.json content an instance sees for a token (e.g. to fake Nova's metadata service in tests).

Jump to

Keyboard shortcuts

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