profile

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: 11 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 profile defines the immutable credential-profile model for the PR-4 MCP credential broker (Capability B — the MCP Security Gateway). A profile binds a credential to a tenant, environment, registered server, tool class and resource scope, and declares the credential kind, power ceiling, permitted operations, cache/rotation/failure policy and lease bound — WITHOUT ever carrying credential plaintext.

The package is listener-independent and performs no network I/O: it validates caller-supplied trusted configuration into immutable snapshots. It never materializes a secret (that is the broker's scoped callback) and holds no mutable global state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScopeSubset

func ScopeSubset(a, b ResourceScope) bool

ScopeSubset reports whether every selector in a is permitted by b (a ⊆ b). It is the exported form of the subset check used by the broker when validating a requested resource scope against the profile scope.

func ValidateEffectiveScope

func ValidateEffectiveScope(eff EffectiveScope, bound ScopeBound) error

ValidateEffectiveScope verifies that eff does not exceed bound. It returns a stable sanitized reason on any broadening. It NEVER makes a policy decision; it only proves the provider's material is within the already-selected plan.

Types

type CachePolicy

type CachePolicy struct {
	Enabled   bool          // may the broker cache an encrypted envelope for this profile?
	Freshness time.Duration // maximum age of a low-risk cache hit (0 ⇒ no low-risk fallback)
}

CachePolicy controls whether a profile's material may be cached (encrypted) and, for low-risk operations only, whether a still-valid cached entry may satisfy a request without a fresh provider fetch. Freshness bounds how old such a low-risk cache hit may be.

type CredentialKind

type CredentialKind uint8

CredentialKind enumerates the shape of the upstream credential. The broker's scoped materialization callback receives the kind plus a lifetime-bounded view of only the secret fields the kind requires. PR-4 never constructs an HTTP header or upstream request from any kind.

const (
	// KindUnset is the invalid zero value (fails closed).
	KindUnset CredentialKind = iota
	// KindBearerToken — a bearer token secret field.
	KindBearerToken
	// KindAPIKey — an API-key secret field.
	KindAPIKey
	// KindUsernamePassword — a username (non-secret) + password (secret) pair.
	KindUsernamePassword
	// KindClientCertificate — a client certificate + private-key material.
	KindClientCertificate
	// KindWorkloadIdentity — a short-lived workload-identity assertion (no long-lived
	// static secret); modelled through the same lease/scope/rotation contracts.
	KindWorkloadIdentity
	// KindOpaque — provider-defined opaque material.
	KindOpaque
)

func (CredentialKind) String

func (k CredentialKind) String() string

String returns the stable kind label.

func (CredentialKind) Valid

func (k CredentialKind) Valid() bool

Valid reports whether the kind is a defined non-zero kind.

type CredentialPower

type CredentialPower uint8

CredentialPower is the privilege ceiling of a credential, ordered from least to most powerful. It is the ceiling dimension of scope validation: a provider's effective power must never exceed the plan's power ceiling.

const (
	// PowerUnset is the invalid zero value.
	PowerUnset CredentialPower = iota
	// PowerReadOnly — read-only access.
	PowerReadOnly
	// PowerWrite — write / mutate access.
	PowerWrite
	// PowerAdmin — administrative access.
	PowerAdmin
	// PowerDestructive — destructive access (delete/purge).
	PowerDestructive
)

func MinPower

func MinPower(a, b CredentialPower) CredentialPower

MinPower returns the lower of two powers (used to compute a plan's least-privilege power ceiling from the profile ceiling and the operation ceiling).

func (CredentialPower) String

func (p CredentialPower) String() string

String returns the stable power label.

func (CredentialPower) Valid

func (p CredentialPower) Valid() bool

Valid reports whether the power is a defined non-zero level.

type CredentialVersion

type CredentialVersion string

CredentialVersion is an opaque provider-assigned credential version token. It is never parsed for meaning; equality and revocation-tombstone matching only.

type EffectiveScope

type EffectiveScope struct {
	Tenant      identity.TenantID
	Environment Environment
	Server      registry.ServerID
	Tools       []string // tool names the credential is scoped to (subset of the plan's)
	Resources   ResourceScope
	Power       CredentialPower
	// HasScopeProof reports whether the provider supplied effective-scope metadata.
	// A profile that requires proof rejects material lacking it.
	HasScopeProof bool
}

EffectiveScope is the scope + power a PROVIDER reports for the material it returned. The broker validates it against the plan (never broadening): tenant, environment, server, tools and resources must all be within the plan, and the power must not exceed the plan's power ceiling.

type Environment

type Environment string

Environment is an opaque deployment-environment token (e.g. "prod", "staging").

type FailurePolicy

type FailurePolicy struct {
	HighRiskFailClosed         bool // must be true; a profile that sets false is rejected
	AllowLowRiskCachedFallback bool // low-risk requests may use a valid, fresh cache entry
}

FailurePolicy captures the profile's failure posture. High-risk operations ALWAYS fail closed (this is not configurable — it is asserted true). The only discretionary control is whether a low-risk operation may fall back to a valid, fresh cached credential.

type ID

type ID string

ID is an opaque, stable credential-profile identifier. Profiles are ALWAYS selected by this opaque id, never by display name, hostname or free text.

type Input

type Input struct {
	ID          ID
	Provider    ProviderID
	Tenant      identity.TenantID
	Environment Environment
	Server      registry.ServerID
	Tools       []string
	Fingerprint *catalog.Fingerprint
	Resources   ResourceScope
	Operations  []OperationClass
	Kind        CredentialKind
	Power       CredentialPower
	MaxTTL      time.Duration
	Cache       CachePolicy
	Rotation    RotationPolicy
	Failure     FailurePolicy
	Enabled     bool
}

Input is the caller-supplied trusted configuration for a profile.

type OperationClass

type OperationClass uint8

OperationClass is the class of upstream operation a plan is for. It determines the risk class and the least-privilege power ceiling for that plan.

const (
	// OpUnset is the invalid zero value.
	OpUnset OperationClass = iota
	// OpRead — a read / low-risk operation.
	OpRead
	// OpWrite — a write / mutate operation (high risk).
	OpWrite
	// OpAdmin — an administrative operation (high risk).
	OpAdmin
	// OpDestructive — a destructive operation (high risk).
	OpDestructive
)

func (OperationClass) CeilingPower

func (o OperationClass) CeilingPower() CredentialPower

CeilingPower is the least-privilege power ceiling implied by an operation class: a read plan may carry at most read-only power, a write plan at most write power, and so on. The plan's effective ceiling is min(profile ceiling, this).

func (OperationClass) Risk

func (o OperationClass) Risk() RiskClass

Risk returns the risk class of an operation. Only reads are low risk.

func (OperationClass) String

func (o OperationClass) String() string

String returns the stable operation-class label.

func (OperationClass) Valid

func (o OperationClass) Valid() bool

Valid reports whether the operation class is a defined non-zero class.

type Profile

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

Profile is one immutable credential profile. All fields are unexported and read through accessors; slices/maps are copied out so no caller alias can mutate live state. A Profile NEVER contains credential plaintext.

func NewProfile

func NewProfile(in Input, reg *registry.Snapshot, lim limits.CredentialLimits, revision uint64) (Profile, error)

NewProfile validates in against the live registry snapshot and the credential limits, returning an immutable Profile at the given revision or a stable sanitized rejection. reg must be the CURRENT registry snapshot: the bound server must exist, be Gateway capability (never Management), be usable (enabled + verified), and — when it carries an owner scope — be owned by the profile's tenant (no cross-tenant server ownership).

func (Profile) Cache

func (p Profile) Cache() CachePolicy

Cache returns the profile field.

func (Profile) Enabled

func (p Profile) Enabled() bool

Enabled returns the profile field.

func (Profile) Environment

func (p Profile) Environment() Environment

Environment returns the profile field.

func (Profile) Failure

func (p Profile) Failure() FailurePolicy

Failure returns the profile field.

func (Profile) Fingerprint

func (p Profile) Fingerprint() (catalog.Fingerprint, bool)

Fingerprint returns a copy of the optional catalog fingerprint binding.

func (Profile) ID

func (p Profile) ID() ID

ID returns the profile field.

func (Profile) Kind

func (p Profile) Kind() CredentialKind

Kind returns the profile field.

func (Profile) MaxTTL

func (p Profile) MaxTTL() time.Duration

MaxTTL returns the profile field.

func (Profile) Operations

func (p Profile) Operations() []OperationClass

Operations returns a copy of the permitted operation classes.

func (Profile) Permits

func (p Profile) Permits(op OperationClass) bool

Permits reports whether the profile permits the operation class.

func (Profile) Power

func (p Profile) Power() CredentialPower

Power returns the profile field.

func (Profile) Provider

func (p Profile) Provider() ProviderID

Provider returns the profile field.

func (Profile) Resources

func (p Profile) Resources() ResourceScope

Resources returns the profile field.

func (Profile) Revision

func (p Profile) Revision() uint64

Revision returns the profile field.

func (Profile) Rotation

func (p Profile) Rotation() RotationPolicy

Rotation returns the profile field.

func (Profile) Server

func (p Profile) Server() registry.ServerID

Server returns the profile field.

func (Profile) Tenant

func (p Profile) Tenant() identity.TenantID

Tenant returns the profile field.

func (Profile) Tools

func (p Profile) Tools() []string

Tools returns a copy of the permitted tool names (empty ⇒ whole-server scope).

type ProviderID

type ProviderID string

ProviderID is an opaque, stable credential-provider identifier.

type ResourceScope

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

ResourceScope is the resource dimension of a profile's grant: a set of EXACT resource selectors (no wildcards). It is deliberately narrow — server, tool, tenant and environment are separate scalar dimensions on the profile itself.

func NewResourceScope

func NewResourceScope(selectors []string) (ResourceScope, error)

NewResourceScope validates and normalizes exact resource selectors into an immutable ResourceScope. It rejects an empty set and any unsafe wildcard.

func (ResourceScope) Len

func (r ResourceScope) Len() int

Len returns the selector count.

func (ResourceScope) Selectors

func (r ResourceScope) Selectors() []string

Selectors returns a copy of the exact resource selectors.

type RiskClass

type RiskClass uint8

RiskClass is the coarse risk of an operation. Only OpRead is low risk; every mutating class is high risk and fails closed on any provider/cache uncertainty.

const (
	// RiskLow — cached low-risk fallback MAY apply when the profile explicitly
	// enables it and the entry is still valid/fresh.
	RiskLow RiskClass = iota
	// RiskHigh — always fail closed; no stale fallback.
	RiskHigh
)

func (RiskClass) String

func (r RiskClass) String() string

String returns the stable risk label.

type RotationPolicy

type RotationPolicy struct {
	Enabled     bool
	Grace       time.Duration
	MaxAttempts int
}

RotationPolicy controls rotation. Grace is the bounded window during which the previous version stays usable AFTER a validated successor becomes active.

type ScopeBound

type ScopeBound struct {
	Tenant       identity.TenantID
	Environment  Environment
	Server       registry.ServerID
	Tools        []string // permitted tool names ("" ⇒ any tool under the plan's server is allowed)
	Resources    ResourceScope
	PowerFloor   CredentialPower // least power required by the operation
	PowerCeiling CredentialPower // most power the operation permits
	RequireProof bool
}

ScopeBound is the plan-side bound the effective scope is checked against. The broker builds it from the immutable plan (never from the provider). The credential power must be exactly within [PowerFloor, PowerCeiling]: at least the floor (a read-only credential is NOT suitable for a write operation) and at most the ceiling (a credential must not be more powerful than the operation needs).

type Snapshot

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

Snapshot is an immutable set of credential profiles at a revision. Its map is never mutated after publication, so any number of readers use it lock-free while a writer publishes a newer one (copy-on-write).

func (*Snapshot) Get

func (s *Snapshot) Get(id ID) (Profile, bool)

Get returns the profile for id and whether it is present. The returned Profile is immutable (its slices/maps are reachable only through copying accessors).

func (*Snapshot) Len

func (s *Snapshot) Len() int

Len returns the number of profiles.

func (*Snapshot) Revision

func (s *Snapshot) Revision() uint64

Revision returns the monotonically increasing snapshot revision.

type Store

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

Store holds credential profiles as immutable snapshots. Writers serialize on mu and publish a new snapshot via an atomic pointer; readers load the current snapshot without locking. A failed update leaves the current snapshot unchanged (no partial publication).

func NewStore

func NewStore(lim limits.CredentialLimits) *Store

NewStore returns an empty profile store bounded by lim.

func (*Store) Add

func (s *Store) Add(in Input, reg *registry.Snapshot) (Profile, error)

Add validates in against reg and the store's limits and publishes a new snapshot containing the profile. It rejects a duplicate/conflicting id, and global / per-tenant / per-server capacity exhaustion. On any error the current snapshot is unchanged.

func (*Store) Current

func (s *Store) Current() *Snapshot

Current returns the current immutable snapshot.

func (*Store) SetEnabled

func (s *Store) SetEnabled(id ID, enabled bool, baseRev uint64) (Profile, error)

SetEnabled toggles a profile's enabled state, publishing a new snapshot. baseRev must equal the current snapshot revision (optimistic concurrency): a stale base is rejected so a concurrent update cannot be silently clobbered.

type ToolBinding

type ToolBinding struct {
	Server registry.ServerID
	Name   string
}

ToolBinding references a catalog tool by its PR-2 key (server + name). A binding is authorized only via this exact key, never by name alone.

Jump to

Keyboard shortcuts

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