provider

package
v1.0.310 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 9 Imported by: 0 modules, 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 provider defines the narrow, listener-independent credential-provider boundary for the PR-4 MCP credential broker. A provider models Vault / KMS / workload-identity / secret-manager semantics but performs NO network I/O in PR-4: fetch/rotate/revoke/inspect are in-memory contracts exercised by deterministic test providers. A provider returns an OPAQUE single-use secret handle (secret.Sealed) plus non-secret lease metadata — never raw bytes, strings, or secret-bearing errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewError

func NewError(reason mcperr.Reason, retryable bool) error

NewError returns a sanitized, classified provider error carrying only a reason code and a retryable flag — never secret text. Provider adapters should return this instead of a raw errors.New so their failures are safe to surface.

func SealFields

func SealFields(fields []Field) *secret.Sealed

SealFields encodes fields into a single opaque secret.Sealed handle. It COPIES each field value into one length-prefixed blob, ZEROIZES the source field values (so the provider adapter retains no plaintext), and wraps the blob via secret.NewSealed (which takes ownership and redacts/zeroizes it). The names are not secret and are carried in the blob so the broker can present typed fields to the materialization callback.

Types

type Capabilities

type Capabilities struct {
	CanRotate  bool
	CanRevoke  bool
	CanInspect bool
}

Capabilities declares, explicitly, which operations a provider supports. The broker never calls an unsupported operation — it returns ReasonProviderUnsupportedOperation instead.

type Classified

type Classified interface {
	error
	// Reason returns a stable, non-secret classification reason.
	Reason() mcperr.Reason
	// Retryable reports whether the broker may retry (bounded).
	Retryable() bool
}

Classified is the OPTIONAL interface a well-behaved provider error implements so the broker can classify it WITHOUT reading its message text. The broker maps Reason() to a stable mcperr reason and honors Retryable(); it NEVER embeds the provider's Error() string (which may contain secret canaries) into the returned error.

type Field

type Field struct {
	Name  FieldName
	Value []byte
}

Field is a transient (name, value) secret field used by provider adapters to build sealed material. The Value bytes are owned by the caller until SealFields takes ownership.

type FieldName

type FieldName string

FieldName is the stable, non-secret name of a secret field within a credential (e.g. "token", "username", "password", "private_key"). The NAME is not secret; the value is.

const (
	FieldToken       FieldName = "token"
	FieldAPIKey      FieldName = "api_key"
	FieldUsername    FieldName = "username"
	FieldPassword    FieldName = "password"
	FieldCertificate FieldName = "certificate"
	FieldPrivateKey  FieldName = "private_key"
	FieldAssertion   FieldName = "assertion"
	FieldOpaque      FieldName = "opaque"
)

Well-known field names. Providers may use others (opaque kinds).

type InMemoryProvider

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

InMemoryProvider is a deterministic, in-memory test/reference provider. It holds template secret fields and returns a FRESH sealed handle on every Fetch/Rotate (a Sealed is single-use). It is used by the broker's tests, fuzz targets and benchmarks. It performs no network I/O and no randomness. Configure it via the exported setters; it is safe for concurrent use.

func NewInMemory

func NewInMemory(id profile.ProviderID, caps Capabilities) *InMemoryProvider

NewInMemory returns a provider with the given id and capabilities.

func (*InMemoryProvider) Calls

func (p *InMemoryProvider) Calls() (fetch, rotate, revoke int)

Calls returns the fetch/rotate/revoke call counts (for asserting a gate failure left the provider untouched).

func (*InMemoryProvider) Capabilities

func (p *InMemoryProvider) Capabilities() Capabilities

Capabilities returns the declared capabilities.

func (*InMemoryProvider) Fetch

func (p *InMemoryProvider) Fetch(ctx context.Context, _ Request) (*Result, error)

Fetch returns a fresh sealed handle from the configured template, or the configured error. It honors context cancellation (fail as retryable-unavailable).

func (*InMemoryProvider) ID

ID returns the provider id.

func (*InMemoryProvider) Inspect

func (p *InMemoryProvider) Inspect(_ context.Context, _ Request) (Lease, error)

Inspect returns the configured lease metadata, or unsupported.

func (*InMemoryProvider) Revoke

Revoke revokes a version, or returns unsupported/error.

func (*InMemoryProvider) Rotate

func (p *InMemoryProvider) Rotate(ctx context.Context, _ Request) (*Result, error)

Rotate returns a fresh successor handle, or unsupported/error.

func (*InMemoryProvider) SetFetchError

func (p *InMemoryProvider) SetFetchError(err error) *InMemoryProvider

SetFetchError makes Fetch return err (verbatim — used to test broker sanitization of untrusted, possibly canary-bearing provider errors).

func (*InMemoryProvider) SetMaterial

func (p *InMemoryProvider) SetMaterial(kind profile.CredentialKind, fields map[FieldName][]byte, lease Lease) *InMemoryProvider

SetMaterial configures the fetch material (kind, fields, lease). The field bytes are copied.

func (*InMemoryProvider) SetRevokeError

func (p *InMemoryProvider) SetRevokeError(err error) *InMemoryProvider

SetRevokeError makes Revoke return err.

func (*InMemoryProvider) SetRotateError

func (p *InMemoryProvider) SetRotateError(err error) *InMemoryProvider

SetRotateError makes Rotate return err.

func (*InMemoryProvider) SetRotateMaterial

func (p *InMemoryProvider) SetRotateMaterial(fields map[FieldName][]byte, lease Lease) *InMemoryProvider

SetRotateMaterial configures the successor material returned by Rotate.

type Lease

type Lease struct {
	Version   profile.CredentialVersion
	IssuedAt  time.Time
	Expiry    time.Time
	Scope     profile.EffectiveScope
	Rotatable bool
	Revocable bool
}

Lease is the NON-SECRET metadata a provider returns alongside the sealed material. It contains no secret bytes and no provider secret path.

type Material

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

Material is a lifetime-scoped, read-only view of decoded secret fields. It is valid ONLY inside the broker's materialization callback: its field bytes alias the scoped plaintext buffer that the broker zeroizes on callback return, and a defensive live flag rejects any access after the scope closes. Material exposes NO byte-returning accessor outside a Field lookup by name, and it is never formatted.

func DecodeMaterial

func DecodeMaterial(kind profile.CredentialKind, pt []byte, maxFields, maxFieldBytes int) (*Material, error)

DecodeMaterial decodes a plaintext blob (produced by SealFields) into a Material whose field slices ALIAS pt (so zeroizing pt zeroizes the fields). It bounds the field count and sizes so a corrupted/hostile blob cannot drive unbounded work. The broker calls this ONLY inside secret.WithPlaintext, so pt is a scoped, about-to-be-zeroized buffer.

func (*Material) Close

func (m *Material) Close()

Close marks the material dead so a retained reference cannot read the (now zeroized) buffer. The broker calls it after the scoped callback returns.

func (*Material) Field

func (m *Material) Field(name FieldName) ([]byte, bool)

Field returns the bytes for a named field and whether it is present. The bytes are valid ONLY while the scoped callback runs; the caller MUST NOT retain them. After the scope closes the lookup returns (nil, false).

func (*Material) Kind

func (m *Material) Kind() profile.CredentialKind

Kind returns the credential kind of the material.

type Provider

type Provider interface {
	// ID returns the provider's opaque identifier.
	ID() profile.ProviderID
	// Capabilities declares supported operations.
	Capabilities() Capabilities
	// Fetch materializes credential material for the request.
	Fetch(ctx context.Context, req Request) (*Result, error)
	// Rotate fetches and returns a successor version (only if CanRotate).
	Rotate(ctx context.Context, req Request) (*Result, error)
	// Revoke revokes a version at the provider (only if CanRevoke).
	Revoke(ctx context.Context, req RevokeRequest) error
	// Inspect returns non-secret lease metadata without materializing (only if
	// CanInspect).
	Inspect(ctx context.Context, req Request) (Lease, error)
}

Provider is the narrow, context-aware credential-provider interface. All methods are in-memory in PR-4 (no network). A provider returns an opaque secret handle and non-secret metadata, and NEVER returns raw secret material inside an error, string, metadata, or a loggable struct.

type Request

type Request struct {
	Profile      profile.ID
	Provider     profile.ProviderID
	Tenant       identity.TenantID
	Environment  profile.Environment
	Server       registry.ServerID
	Tools        []string
	Resources    profile.ResourceScope
	Operation    profile.OperationClass
	Kind         profile.CredentialKind
	PowerCeiling profile.CredentialPower
	PlanID       string    // sanitized correlation id
	TokenDigest  string    // PR-3 correlation digest ONLY; never a credential
	Deadline     time.Time // materialization deadline (metadata; no network in PR-4)
}

Request is the NON-SECRET input to a provider fetch/rotate. It is derived from the immutable plan and contains NO raw client token, Authorization header, DPoP proof, or access-token bytes — the upstream material always originates from the provider. The optional TokenDigest is the PR-3 one-way correlation digest, carried for safe correlation only and NEVER used as an upstream credential.

type Result

type Result struct {
	Handle *secret.Sealed
	Kind   profile.CredentialKind
	Lease  Lease
}

Result is a provider fetch/rotate output: an OPAQUE single-use secret handle plus non-secret lease metadata and the credential kind. The handle is the only path to plaintext, and only through the broker's scoped callback.

type RevokeRequest

type RevokeRequest struct {
	Profile  profile.ID
	Provider profile.ProviderID
	Version  profile.CredentialVersion
}

RevokeRequest is the non-secret input to a provider revoke.

Jump to

Keyboard shortcuts

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