secretref

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 2 modules, 3 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 secretref is the one definition of how a secret reaches a tool a sensor runs for the platform: the references a signed job carries, the per-task fetch that turns them into values, and the rules every value must meet. The platform and the sensor SDK both validate with this code, so a sensor never accepts what the platform would not have sent.

The model:

  • When a sensor claims a job, the platform lists in the job's payload (member "secrets", a Set) the secrets the job may use: an id, a kind, the stored row it names, the tool slot it fills, where its value may be sent (its audience) and whether the sensor's own local value may stand in (Local). The list is part of the payload before the job is signed, so the job signature covers it. A Set carries names, never values.
  • For each task, the sensor asks for the values of the refs that task needs (FetchRequest), in an RFC 9421-signed request that also carries the lease epoch and a single-use HPKE public key. The platform answers only the live lease holder, only refs of that job, sealed to that key (SealedAnswer); the HPKE info binds the answer to the sensor, the command, the epoch and the exact request (Info). A TLS terminator, a request log or a replayed request never holds a value.
  • Every kind declares its consumer (the tool, or the sensor's egress forwarder) and its audience. A provider key may be sent only to the hosts of its provider in the registry (Providers), so the sensor narrows the task's network scope to them.

This package defines the shapes and the validators; the transport, the sealing and the storage live in the platform and the SDK.

Index

Constants

View Source
const (
	// MaxReplyKeyLen bounds FetchRequest.ReplyKey (base64url text).
	MaxReplyKeyLen = 4096
	// MaxSealedLen bounds SealedAnswer.Sealed (base64url text).
	MaxSealedLen = 1 << 20
	// MaxAnswerSkew is how far an Answer's IssuedAt may be from the
	// sensor's clock.
	MaxAnswerSkew = 10 * time.Minute
)

Bounds of the fetch.

View Source
const (
	// FormatKey is a single key or token.
	FormatKey = "key"
	// FormatPair is two parts joined by one colon (PairHint names them).
	FormatPair = "pair"
)

Key formats.

View Source
const (
	// EndpointHost: "HOST:KEY", HOST a DNS name HostRule accepts.
	EndpointHost = "host"
	// EndpointURL: "https://HOST/PATH:KEY", HOST a DNS name HostRule
	// accepts; no port, user information, query or fragment.
	EndpointURL = "url"
)

Endpoint kinds of a key whose first part names where the tool sends it.

View Source
const (
	// MaxKeyLen bounds a key.
	MaxKeyLen = 1024
	// MinSecretLen is the shortest secret part of a key: shorter values are
	// not real keys, and a sensor scrubs only values of at least this
	// length from a task's output reliably.
	MinSecretLen = 8
)

Key bounds.

View Source
const (
	KeyEmpty    = "empty"
	KeyTooLong  = "too_long"
	KeyInvalid  = "invalid"
	KeyFormat   = "format"
	KeyEndpoint = "endpoint"
	KeyTooShort = "too_short"
)

Key error codes (KeyError.Code).

View Source
const (
	// KindProviderKey is a key of a third-party data source a tool queries
	// (a passive source of subfinder, for one). Ref is the provider id in
	// the registry; the value is a ProviderKey.
	KindProviderKey = "provider_key"
	// KindEgressProxy is the credentials of the job's proxy pool. Ref is the
	// pool id of the job's egress block; the value is an EgressProxy. The
	// sensor's egress forwarder consumes it; it never reaches a tool.
	KindEgressProxy = "egress_proxy"
)

Kinds of secret. A sensor that meets a kind it does not know on a required ref refuses the job (RefusalKindUnsupported); an unknown kind on an optional ref is skipped.

View Source
const (
	// ClassProvider: access to a third-party data service a tool consults
	// (a passive DNS or search API), or the infrastructure the sensor's
	// traffic goes through (the job's proxy pool). Chosen automatically by
	// the tool's provider slots; its audience is the provider registry's
	// hosts (or the pool).
	ClassProvider = "provider"
	// ClassTarget: the organization's credentials to its own systems (a web
	// login, an API token of the target). Chosen by a person per scan, step
	// or asset, never automatically; it needs the sensor's grant to use
	// credentials, is refused on a shared sensor unless the organization
	// allows that sensor, and its audience is the task's own targets
	// (AudienceTargets) intersected with the credential's asset binding.
	ClassTarget = "target"
)

Classes of secret: what a value opens. The class, not the vendor or the tool, decides the gates the platform applies when it lists a ref at claim and when it answers a fetch, and what the sensor lets the task reach.

View Source
const (
	// ConsumerTool: the task's tool, through its declared slot.
	ConsumerTool = "tool"
	// ConsumerForwarder: the sensor's egress forwarder of the job.
	ConsumerForwarder = "forwarder"
)

Consumers: who on the sensor receives a value.

View Source
const (
	// LocalAllow: the platform's value wins; the local value fills the slot
	// when the platform has none (the organization's own sensor).
	LocalAllow = "allow"
	// LocalNever: only the platform's value; the local value is never used
	// (a shared sensor: its operator's keys are never spent on a tenant).
	LocalNever = "never"
	// LocalOnly: the platform is not asked; only the local value is used.
	LocalOnly = "only"
)

Local policies: whether a value the sensor's operator stored locally may fill a slot. The sensor applies LocalNever regardless of the job when its own identity says it is a shared sensor.

View Source
const (
	AudienceProviderPrefix = "provider:"
	AudiencePool           = "pool"
	AudienceTargets        = "targets"
)

Audiences. A provider key's audience is AudienceProviderPrefix + its provider id; the egress pool's audience is AudiencePool (the forwarder sends the credentials to the pool's endpoints only); a target credential's audience is AudienceTargets (the task's own targets that are also in the credential's asset binding).

View Source
const (
	// MaxRefs is the most refs one job carries.
	MaxRefs = 64
	// MaxRefLen bounds Ref.Ref.
	MaxRefLen = 128
	// MaxTaskLen bounds FetchRequest.Task.
	MaxTaskLen = 64
)

Bounds.

View Source
const (
	// RefusalKindUnsupported is the reason a sensor refuses a job with a
	// required ref of a kind it does not know.
	RefusalKindUnsupported = "secret_kind_unsupported"
	// RefusalSecretMissing is the reason a task fails when a required ref
	// has no value.
	RefusalSecretMissing = "secret_missing"
)

Refusal and missing reasons.

View Source
const (
	MissingDisabled       = "disabled"
	MissingNotSet         = "not_set"
	MissingQuotaExhausted = "quota_exhausted"
	MissingUndecryptable  = "undecryptable"
	MissingNotTrusted     = "not_trusted"
)

Missing reasons (Missing.Reason): why the platform holds no value for a ref it was asked for.

View Source
const (
	// MaxProxyEndpoints bounds EgressProxy.Endpoints.
	MaxProxyEndpoints = 64
	// MaxProxyCredentialLen bounds a proxy user name or password.
	MaxProxyCredentialLen = 1024
)

Bounds of values.

View Source
const Action = "secrets"

Action is the last path segment of the fetch route.

View Source
const ContentType = "application/vnd.openctem.secrets+sealed"

ContentType is the content type of a SealedAnswer.

View Source
const InfoLabel = "openctem-task-secrets/v1"

InfoLabel starts the HPKE info of a SealedAnswer.

View Source
const PayloadField = "secrets"

PayloadField is the job payload member that carries the Set.

View Source
const (
	// ProvenanceTenant: the organization's value stored on the platform.
	ProvenanceTenant = "platform:tenant"
)

Provenances of a value.

View Source
const SuiteHybridV1 = 1

SuiteHybridV1 is the HPKE suite of a SealedAnswer: KEM ML-KEM-768+X25519, KDF HKDF-SHA256, AEAD ChaCha20-Poly1305 (the suite of the sealed-envelope format the platform and the sensor already share).

View Source
const Version = 1

Version is the version of a Set (Set.V) and of an Answer.

Variables

View Source
var ErrInvalid = errors.New("secretref: invalid")

ErrInvalid is wrapped by every validation error of this package. Errors never repeat a secret value.

Functions

func AudienceProvider

func AudienceProvider(id string) string

AudienceProvider is the audience of provider id's key.

func ClassOf

func ClassOf(kind string) string

ClassOf is the class of a known kind ("" for an unknown kind).

func ConsumerOf

func ConsumerOf(kind string) string

ConsumerOf is the consumer of a known kind ("" for an unknown kind).

func Info

func Info(sensorID, commandID string, leaseEpoch int64, requestBody []byte) []byte

Info is the HPKE info of the answer to one request:

InfoLabel 0x00 ||
u16 len || sensor id || u16 len || command id ||
u64 lease epoch || SHA-256 of the exact request body bytes

(lengths and the epoch big-endian). An answer moved to another sensor, command, epoch or request does not open.

func KeyID

func KeyID(pub []byte) string

KeyID is the hex of the first 16 bytes of the SHA-256 of a public key: the SealedAnswer's KeyID for the reply key.

func KnownClass

func KnownClass(class string) bool

KnownClass reports whether class is a class of this version.

func KnownKind

func KnownKind(kind string) bool

KnownKind reports whether kind is a kind of this version.

func KnownMissing

func KnownMissing(reason string) bool

KnownMissing reports whether reason is a missing reason of this version.

func ProvidersForTool

func ProvidersForTool(tool string) []string

ProvidersForTool returns the ids of the providers tool queries with a key.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a valid ref id (1 to 8 lower-case letters or digits).

func ValidateValue

func ValidateValue(ref Ref, raw json.RawMessage) error

ValidateValue checks the value of ref against its kind's rules (the same rules the platform applies when the value is saved). An unknown kind is refused.

Types

type Answer

type Answer struct {
	CommandID  string    `json:"command_id"`
	LeaseEpoch int64     `json:"lease_epoch"`
	IssuedAt   time.Time `json:"issued_at"`
	Secrets    []Secret  `json:"secrets"`
	Missing    []Missing `json:"missing,omitempty"`
}

Answer is the plaintext of a SealedAnswer.

func (Answer) Check

func (a Answer) Check(set Set, commandID string, leaseEpoch int64, asked []string, now time.Time) error

Check is the sensor's check of an opened answer: it is for commandID at leaseEpoch, recent, and every value answers a ref the request asked for, once, with the ref's kind and a value the kind's validator accepts. The values are not repeated in an error.

type EgressProxy

type EgressProxy struct {
	Endpoints []ProxyEndpoint `json:"endpoints"`
}

EgressProxy is the value of a KindEgressProxy ref: the credentials of the pool's endpoints that have some.

func DecodeEgressProxy

func DecodeEgressProxy(raw json.RawMessage) (EgressProxy, error)

DecodeEgressProxy decodes and validates the value of an egress proxy ref.

type FetchRequest

type FetchRequest struct {
	// LeaseEpoch is the epoch of the lease the sensor holds on the command.
	// It is inside the signed body: a header the signature does not cover
	// never decides the lease.
	LeaseEpoch int64 `json:"lease_epoch"`
	// Task names the task the values are for (audit only).
	Task string `json:"task,omitempty"`
	// Refs are the ids of the job's refs the task needs: a subset of the
	// job's Set, at least one, no duplicates.
	Refs []string `json:"refs"`
	// ReplyKey is the base64url (no padding) of the single-use HPKE public
	// key the answer is sealed to. The sensor makes a new key pair for every
	// request and drops the private half once the answer is open.
	ReplyKey string `json:"reply_key"`
}

FetchRequest is the signed body of a fetch.

func (FetchRequest) ReplyKeyBytes

func (f FetchRequest) ReplyKeyBytes() ([]byte, error)

ReplyKeyBytes decodes ReplyKey.

func (FetchRequest) Validate

func (f FetchRequest) Validate() error

Validate checks the request's shape. It does not check the refs against a job (the platform does).

type KeyError

type KeyError struct {
	Code string
	Msg  string
}

KeyError is a key that a provider's rules refuse. It never holds the key.

func (*KeyError) Error

func (e *KeyError) Error() string

func (*KeyError) Unwrap

func (e *KeyError) Unwrap() error

Unwrap makes a KeyError match ErrInvalid.

type Missing

type Missing struct {
	ID     string `json:"id"`
	Reason string `json:"reason"`
}

Missing is a ref the platform holds no value for.

type Provider

type Provider struct {
	// ID is the provider id: the Ref of a provider key ref, and the tool's
	// credential slot name.
	ID string `json:"id"`
	// Display is the provider's name for people.
	Display string `json:"display"`
	// Format is FormatKey or FormatPair.
	Format string `json:"format"`
	// PairHint names the two parts of a pair ("TOKEN:ORG_ID").
	PairHint string `json:"pair_hint,omitempty"`
	// Hosts are the hosts a tool sends the key to.
	Hosts []string `json:"hosts"`
	// Endpoint is EndpointHost or EndpointURL when the key's first part
	// names the host the tool connects to; "" otherwise.
	Endpoint string `json:"endpoint,omitempty"`
	// HostRule is the anchored pattern that host must match.
	HostRule string `json:"host_rule,omitempty"`
	// HostPrefix is put before the key's host to give the host the tool
	// connects to ("api." for a key naming "zoomeye.ai").
	HostPrefix string `json:"host_prefix,omitempty"`
	// Tools are the tools that query the provider with the key.
	Tools []string `json:"tools"`
	// contains filtered or unexported fields
}

Provider is one entry of the registry.

func LookupProvider

func LookupProvider(id string) (Provider, bool)

LookupProvider returns the provider id names.

func Providers

func Providers() []Provider

Providers returns every provider, ordered by id.

func (Provider) Audience

func (p Provider) Audience(v string) ([]string, error)

Audience returns the hosts a tool may send key v to: the provider's fixed hosts and, for a key that names its endpoint, that host (with HostPrefix). v must pass ValidateKey.

func (Provider) Last4

func (p Provider) Last4(v string) string

Last4 is the part of a key shown after it is saved: the last four characters of its secret part (never a user name or app id), nothing when that part is shorter than 12 characters.

func (Provider) SecretPart

func (p Provider) SecretPart(v string) string

SecretPart is the part of a key that is the secret: the whole key, or the last part of a pair.

func (Provider) ValidateKey

func (p Provider) ValidateKey(v string) error

ValidateKey checks a key: 1 to MaxKeyLen visible ASCII characters (no spaces or line breaks: a key reaches a tool's configuration file, never a command line), a secret part of at least MinSecretLen characters, for a pair exactly one colon between two non-empty parts, and for a key whose first part names where the tool connects, a host on the provider's own service only (never an IP address, port, user information or other host). Errors never repeat the key.

type ProviderKey

type ProviderKey struct {
	Key string `json:"key"`
}

ProviderKey is the value of a KindProviderKey ref: the key written in its provider's format (Provider.ValidateKey).

func DecodeProviderKey

func DecodeProviderKey(ref Ref, raw json.RawMessage) (ProviderKey, error)

DecodeProviderKey decodes and validates the value of a provider key ref.

type ProxyEndpoint

type ProxyEndpoint struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
}

ProxyEndpoint is one pool endpoint's credentials.

type Ref

type Ref struct {
	// ID is the ref's id within the job (1 to 8 lower-case letters or
	// digits), what a FetchRequest names.
	ID string `json:"id"`
	// Kind is the secret kind (Kind* constants).
	Kind string `json:"kind"`
	// Class is the kind's class (Class* constants): ClassOf a known kind.
	Class string `json:"class"`
	// Ref names the stored value: the provider id for KindProviderKey, the
	// pool id for KindEgressProxy.
	Ref string `json:"ref"`
	// Slot is the tool's credential slot the value fills (the name the
	// tool's manifest declares); empty for a forwarder kind.
	Slot string `json:"slot,omitempty"`
	// Audience is where the value may be sent (Audience* forms).
	Audience []string `json:"audience,omitempty"`
	// Consumer is who receives the value (ConsumerOf the kind).
	Consumer string `json:"consumer"`
	// Required: the task fails, naming the slot, when the value is missing.
	Required bool `json:"required,omitempty"`
	// Local is the local policy of this slot (Local* constants).
	Local string `json:"local"`
}

Ref is one secret a job may use. It names a value, never carries one.

func (Ref) Validate

func (r Ref) Validate() error

Validate checks a ref: the id, kind-independent bounds and, for a known kind, the kind's own rules. An unknown kind passes when the generic rules hold; whether to use it is the sensor's decision (RefusalKindUnsupported).

type SealedAnswer

type SealedAnswer struct {
	// Suite is SuiteHybridV1.
	Suite int `json:"suite"`
	// KeyID is KeyID of the reply key the answer is sealed to.
	KeyID string `json:"key_id"`
	// Sealed is the base64url (no padding) of the HPKE single-shot output
	// (encapsulated key followed by the ciphertext).
	Sealed string `json:"sealed"`
}

SealedAnswer is the body of a fetch's 200 answer.

func (SealedAnswer) SealedBytes

func (a SealedAnswer) SealedBytes() ([]byte, error)

SealedBytes decodes Sealed.

func (SealedAnswer) Validate

func (a SealedAnswer) Validate(replyKey []byte) error

Validate checks the answer's shape against the reply key it should be sealed to.

type Secret

type Secret struct {
	// ID is the ref's id.
	ID string `json:"id"`
	// Kind is the ref's kind.
	Kind string `json:"kind"`
	// Value is the kind's value shape (ProviderKey, EgressProxy).
	Value json.RawMessage `json:"value"`
	// Provenance is where the value comes from (Provenance* constants).
	Provenance string `json:"provenance"`
	// ExpiresAt is when the value stops working (nil: not known).
	ExpiresAt *time.Time `json:"expires_at,omitempty"`
}

Secret is one value.

type Set

type Set struct {
	// V is Version.
	V int `json:"v"`
	// Local is the local policy of a tool slot no ref names: LocalAllow on
	// the organization's own sensor, LocalNever on a shared sensor. It is
	// never LocalOnly.
	Local string `json:"local"`
	// Refs are the job's refs, at most MaxRefs, ids unique.
	Refs []Ref `json:"refs"`
}

Set is the payload member PayloadField of a job: the refs the job may use.

func (Set) ForSlot

func (s Set) ForSlot(slot string) (Ref, bool)

ForSlot returns the ref that fills slot.

func (Set) Lookup

func (s Set) Lookup(id string) (Ref, bool)

Lookup returns the ref with id.

func (Set) Validate

func (s Set) Validate() error

Validate checks the set and each ref.

Jump to

Keyboard shortcuts

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