config

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config loads and validates runtime configuration for ans-ra and ans-tl from YAML files with environment variable overrides.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttestationKeyCfg

type AttestationKeyCfg struct {
	// KeyID is looked up in the KeyManager. Auto-provisioned on first
	// run at EnsureKey time with the ECDSA_P256 algorithm.
	KeyID string `koanf:"keyId"`
}

AttestationKeyCfg names the KeyManager-managed key the TL uses for every outbound signature: primary C2SP checkpoint signature, JWS additional-signer line, outer envelope attestation, SCITT receipts, and status tokens. Single-key topology matching the reference TL's deployed shape.

type Auth

type Auth struct {
	// Type selects the adapter: "static" or "oidc".
	Type       string      `koanf:"type"`
	Static     *AuthStatic `koanf:"static"`
	OIDC       *AuthOIDC   `koanf:"oidc"`
	PublicRead bool        `koanf:"public-read"` // TL only — allow unauthenticated reads.
}

Auth holds authentication provider configuration.

type AuthOIDC

type AuthOIDC struct {
	IssuerURL   string   `koanf:"issuer-url"`
	Audience    string   `koanf:"audience"`
	ClientID    string   `koanf:"client-id"`
	AdminGroups []string `koanf:"admin-groups"`
}

AuthOIDC configures the OIDC adapter.

AdminGroups is the list of group names — matched against the authenticated token's `groups` claim — whose members should be treated as administrators (`Identity.IsAdmin == true`). Empty or unset means no OIDC user is an admin, which leaves any admin-only route (e.g., the TL's /internal/v1/producer-keys family) closed to all OIDC traffic. Static auth grants admin unconditionally; only the OIDC path needs this list.

type AuthStatic

type AuthStatic struct {
	APIKey    string `koanf:"api-key"`
	APISecret string `koanf:"api-secret"`
}

AuthStatic configures the static API-key adapter.

`APIKey` is always required. `APISecret` is optional:

  • When both are set, the server accepts the reference RA's `Authorization: sso-key <apiKey>:<apiSecret>` header format in addition to the Bearer format. This is the format the ANS SDKs send, so SDK-based tests require the secret to be configured.

  • When only APIKey is set, the server accepts only `Authorization: Bearer <apiKey>`. Good for local curl-based tooling, but SDK-generated clients will not authenticate.

type CA

type CA struct {
	Type   string    `koanf:"type"`
	Self   *CASelf   `koanf:"self"`
	Server *CAServer `koanf:"server"`
}

CA holds identity certificate authority settings.

`Server` is optional: when non-nil it configures the server certificate issuer used for server CSRs submitted at registration or renewal. When nil, the RA only supports the BYOC path for server certs. The identity CA (`Self`) is always required — every agent gets an RA-issued identity cert.

type CASelf

type CASelf struct {
	Org          string `koanf:"org"`
	ValidityDays int    `koanf:"validity-days"`
	DataDir      string `koanf:"data-dir"`
}

CASelf configures the in-process self-signed identity CA.

type CAServer added in v0.1.6

type CAServer struct {
	Type string `koanf:"type"`

	// Self-signed issuer settings (type "self").
	Org          string `koanf:"org"`
	ValidityDays int    `koanf:"validity-days"`
	DataDir      string `koanf:"data-dir"`

	// ACME issuer settings (type "acme").
	ACME *CAServerACME `koanf:"acme"`
}

CAServer selects and configures the server certificate issuer behind `port.ServerCertificateIssuer`.

  • Type "self" (default, including when omitted — backwards compatible with pre-issuer configs): the in-process self-signed server CA. Same shape as the identity CA but kept distinct so operators can rotate the two roots independently.
  • Type "acme": an external RFC 8555 CA (Let's Encrypt et al.) configured by the nested `acme` block. Selecting this type is the operator's consent to the provider's terms of service — account registration auto-accepts them, per standard ACME automation practice.

func (*CAServer) IsACME added in v0.1.6

func (s *CAServer) IsACME() bool

IsACME reports whether the server issuer is the ACME adapter.

type CAServerACME added in v0.1.6

type CAServerACME struct {
	// DirectoryURL is the provider's directory endpoint, e.g.
	// https://acme-staging-v02.api.letsencrypt.org/directory for
	// Let's Encrypt staging. Use staging for testing — production
	// rate limits are unforgiving.
	DirectoryURL string `koanf:"directory-url"`
	// Email becomes the ACME account contact for expiry and incident
	// notices. Optional.
	Email string `koanf:"email"`
	// DataDir persists the ACME account key across restarts.
	DataDir string `koanf:"data-dir"`
}

CAServerACME configures the RFC 8555 issuer.

type DNS

type DNS struct {
	// Type selects the verifier adapter. "noop" accepts any DNS
	// state; "lookup" queries a real nameserver via miekg/dns and
	// validates TXT, TLSA, and HTTPS records, surfacing the DNSSEC
	// AuthenticatedData bit on TLSA responses.
	Type string `koanf:"type"` // "noop" | "lookup"

	// Server is an optional "host:port" override for the nameserver
	// the "lookup" verifier queries. When empty the system resolver
	// (/etc/resolv.conf) is used. Point at the local `ans-dns` dev
	// server (e.g. "127.0.0.1:15353") for self-contained local
	// testing.
	Server string `koanf:"server"`
}

DNS holds DNS verifier configuration.

type Identity added in v0.1.6

type Identity struct {
	// Resolver selects the did:web document fetcher.
	Resolver IdentityResolver `koanf:"resolver"`
	// ChallengeTTL bounds the verify-control nonce (default 1h; 5m
	// is the design floor for high-assurance deployments).
	ChallengeTTL time.Duration `koanf:"challenge-ttl"`
	// RegisterRateLimit is the per-owner register/rotate budget per
	// minute (default 10) — each call can trigger an outbound
	// did:web fetch before any proof exists.
	RegisterRateLimit int `koanf:"register-rate-limit"`
	// LinkRateLimit is the per-owner link/unlink budget per minute
	// (default 60) — operational hardening on the link route
	// (design §4.3).
	LinkRateLimit int `koanf:"link-rate-limit"`
	// SealTimeout bounds the inline TL seal call identity operations
	// make before reporting success (seal-before-success, design
	// §5.6.1). Default 5s.
	SealTimeout time.Duration `koanf:"seal-timeout"`
}

Identity holds Verified Identity (the "who") configuration — the /v2/ans/identities surface (RA only).

type IdentityResolver added in v0.1.6

type IdentityResolver struct {
	Type string `koanf:"type"` // "noop" | "web"
}

IdentityResolver selects the did:web resolver adapter. "noop" performs no I/O and synthesizes the DID document from the keys embedded in the submitted proofs (quickstart — signature verification still genuinely runs, only the live-document binding is waived; NOT for production); "web" performs the hardened HTTPS fetch with WebPKI validation and SSRF dialer guards.

type Keys

type Keys struct {
	Type string    `koanf:"type"` // "file"
	File *KeysFile `koanf:"file"`
}

Keys holds key-manager configuration.

type KeysFile

type KeysFile struct {
	Path string `koanf:"path"`
}

KeysFile configures the filesystem key manager.

type Log

type Log struct {
	Level  string `koanf:"level"`  // trace|debug|info|warn|error
	Format string `koanf:"format"` // "text" | "json"
}

Log holds logging configuration.

type Merkle

type Merkle struct {
	Origin             string        `koanf:"origin"`
	TileStorage        TileStorage   `koanf:"tile-storage"`
	CheckpointInterval time.Duration `koanf:"checkpoint-interval"`
}

Merkle holds Transparency Log Merkle tree configuration (TL only).

type ProducerKeyCfg

type ProducerKeyCfg struct {
	RaID         string `koanf:"raId"`
	KeyID        string `koanf:"keyId"`
	Algorithm    string `koanf:"algorithm"`
	PublicKeyPEM string `koanf:"publicKeyPem"`
}

ProducerKeyCfg is one trusted RA public key as declared in config. Stage 1 ships this as the sole source of producer trust; Stage 3 swaps it for a SQLite store with admin-routed CRUD.

type RAConfig

type RAConfig struct {
	Server   Server    `koanf:"server"`
	Auth     Auth      `koanf:"auth"`
	CA       CA        `koanf:"ca"`
	DNS      DNS       `koanf:"dns"`
	Identity Identity  `koanf:"identity"`
	Keys     Keys      `koanf:"keys"`
	Store    Store     `koanf:"store"`
	TLClient TLClient  `koanf:"tl-client"`
	Signer   SignerCfg `koanf:"signer"`
	Log      Log       `koanf:"log"`
}

RAConfig is the full configuration for ans-ra.

func LoadRA

func LoadRA(path string) (*RAConfig, error)

LoadRA loads and validates ans-ra configuration from the given YAML path. Environment variables prefixed with ANS_RA_ override file values; nested keys use double underscores (ANS_RA_AUTH__STATIC__API_KEY).

func (*RAConfig) Validate

func (c *RAConfig) Validate() error

Validate ensures the RA config is internally consistent.

type Server

type Server struct {
	Host string `koanf:"host"`
	Port int    `koanf:"port"`
}

Server holds HTTP server settings.

type SignerCfg

type SignerCfg struct {
	KeyID string `koanf:"keyId"`
	RaID  string `koanf:"raId"`
}

SignerCfg names the KeyManager-managed key the RA uses to sign outbox events before they're POSTed to the TL. The RaID identifies this RA instance to the TL's producer-key trust store.

type StatusTokenCfg

type StatusTokenCfg struct {
	TTL time.Duration `koanf:"ttl"`
}

StatusTokenCfg controls the /v1/agents/{id}/status-token endpoint.

`ttl` defaults to 1h when zero; shorter TTLs tighten revocation propagation at the cost of more AHP↔TL traffic. The signing key is the single TL signing key declared under `attestation.keyId`; status-token rotation is tied to the log's signing-key lifecycle.

type Store

type Store struct {
	Type   string       `koanf:"type"` // "sqlite"
	SQLite *StoreSQLite `koanf:"sqlite"`
}

Store holds persistence adapter configuration.

type StoreSQLite

type StoreSQLite struct {
	Path string `koanf:"path"`
}

StoreSQLite configures the SQLite store.

type TLClient

type TLClient struct {
	// BaseURL is the TL's listen URL, e.g. "http://localhost:18081".
	BaseURL string `koanf:"base-url"`
	// PublicBaseURL is the TL's externally-reachable URL used in
	// _ans-badge DNS TXT records. Required — must be an https:// URL
	// with no query string, fragment, or userinfo.
	PublicBaseURL string `koanf:"public-base-url"`
	// APIKey is the bearer token the TL's static auth accepts.
	APIKey string `koanf:"api-key"`
	// Timeout is the per-request HTTP timeout.
	Timeout time.Duration `koanf:"timeout"`
	// BatchSize is how many outbox rows each worker tick claims at
	// once. Larger batches reduce DB roundtrips but delay shutdown.
	BatchSize int `koanf:"batch-size"`
	// PollInterval is how often the worker polls the outbox for
	// newly-enqueued events.
	PollInterval time.Duration `koanf:"poll-interval"`
	// MaxBackoff caps the per-row exponential backoff on failure.
	// A permanently-broken event re-enters the claim list at this
	// cadence.
	MaxBackoff time.Duration `koanf:"max-backoff"`
	// Disabled turns the worker off entirely. Events still accumulate
	// in the outbox; useful for tests and for operators who want to
	// run the worker as a separate process.
	Disabled bool `koanf:"disabled"`
}

TLClient holds RA→TL HTTP client and outbox-worker configuration (RA only).

The outbox worker runs as a background goroutine in ans-ra. It claims batches of pending events from the outbox table, POSTs each to the TL, and marks them sent or failed. Failed rows are retried with capped exponential backoff.

type TLConfig

type TLConfig struct {
	Server       Server            `koanf:"server"`
	Auth         Auth              `koanf:"auth"`
	Keys         Keys              `koanf:"keys"`
	Store        Store             `koanf:"store"`
	Merkle       Merkle            `koanf:"merkle"`
	Attestation  AttestationKeyCfg `koanf:"attestation"`
	StatusToken  StatusTokenCfg    `koanf:"statusToken"`
	ProducerKeys []ProducerKeyCfg  `koanf:"producerKeys"`
	Log          Log               `koanf:"log"`
}

TLConfig is the full configuration for ans-tl.

func LoadTL

func LoadTL(path string) (*TLConfig, error)

LoadTL loads and validates ans-tl configuration from the given YAML path.

func (*TLConfig) Validate

func (c *TLConfig) Validate() error

Validate ensures the TL config is internally consistent.

type TileStorage

type TileStorage struct {
	Type       string                 `koanf:"type"` // "filesystem"
	Filesystem *TileStorageFilesystem `koanf:"filesystem"`
}

TileStorage configures Merkle tile storage (TL only).

type TileStorageFilesystem

type TileStorageFilesystem struct {
	Path string `koanf:"path"`
}

TileStorageFilesystem configures filesystem tile storage.

Jump to

Keyboard shortcuts

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