agentidentity

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 23 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 agentidentity implements opt-in, tenant-scoped service grants. Hosts supply durable adapters and Workflow's managed issuer; no human sessions or issuer/private keys are created by this package.

Index

Constants

View Source
const (
	PagesRead            = "admin:multisite.pages:read"
	HistoryRead          = "admin:multisite.pages:history:read"
	PagesUpdate          = "admin:multisite.pages:update"
	PreviewRead          = "admin:multisite.preview:read"
	MaxGrantLifetime     = 30 * 24 * time.Hour
	MaxTokenLifetime     = 15 * time.Minute
	MaxAssertionLifetime = time.Minute
)

Variables

View Source
var (
	ErrDenied      = errors.New("agent access denied")
	ErrUnavailable = errors.New("agent access unavailable")
	ErrConflict    = errors.New("agent grant conflict")
)

Functions

func ValidateGrantForStorage

func ValidateGrantForStorage(g Grant) error

ValidateGrantForStorage checks the structural grant and resource bounds. It permits expired or revoked rows so durable adapters can load historical state; it does not authorize access, apply the host policy, or approve a new grant. Create adapters must additionally require Version 1 and !Revoked.

Types

type AssertionUse

type AssertionUse struct {
	GrantID      string
	GrantVersion int64
	JTIHash      string
	ExpiresAt    time.Time
	Now          time.Time
}

type Audit

type Audit struct {
	At           time.Time `json:"at"`
	Operation    string    `json:"operation"`
	Decision     string    `json:"decision"`
	Reason       string    `json:"reason"`
	Subject      string    `json:"subject,omitempty"`
	GrantID      string    `json:"grant_id,omitempty"`
	GrantVersion int64     `json:"grant_version,omitempty"`
	TenantID     int64     `json:"tenant_id,omitempty"`
	OwnerID      string    `json:"owner_id,omitempty"`
	PageID       string    `json:"page_id,omitempty"`
	Scope        string    `json:"scope,omitempty"`
	JTIHash      string    `json:"jti_hash,omitempty"`
}

Audit contains fixed reason codes and verified metadata, never raw tokens, assertions, keys, headers, bodies, arbitrary error strings or human emails.

type Auditor

type Auditor interface {
	Record(context.Context, Audit) error
}

type ExchangeRequest

type ExchangeRequest struct {
	GrantID   string
	Assertion string
	Audience  string
	Scopes    []string
}

type Grant

type Grant struct {
	ID              string           `json:"id"`
	Subject         string           `json:"subject"`
	AssertionIssuer string           `json:"assertion_issuer"`
	KeyID           string           `json:"key_id"`
	PublicKey       *ecdsa.PublicKey `json:"-"`
	Version         int64            `json:"version"`
	TenantID        int64            `json:"tenant_id"`
	ApprovedBy      string           `json:"approved_by"`
	CreatedAt       time.Time        `json:"created_at"`
	ExpiresAt       time.Time        `json:"expires_at"`
	Revoked         bool             `json:"revoked"`
	APIAudience     string           `json:"api_audience"`
	Scopes          []string         `json:"scopes"`
	UpdatePageIDs   []string         `json:"update_page_ids,omitempty"`
	Preview         *PreviewGrant    `json:"preview,omitempty"`
}

Grant is a host-owned durable row. Rotation and any permission edit MUST increment Version atomically; revocation must not delete the audit record. The public assertion key is not issuer key material or a human credential.

type GrantManager

type GrantManager interface {
	CreateGrant(context.Context, Grant) error
	RevokeGrant(context.Context, string, int64, string, time.Time) error
	ListGrants(context.Context, Owner) ([]Grant, error)
}

type IssueRequest

type IssueRequest struct {
	Subject, Audience, GrantID string
	GrantVersion, TenantID     int64
	Scopes                     []string
	IssuedAt, ExpiresAt        time.Time
}

type Issuer

type Issuer interface {
	IssueAgentToken(context.Context, IssueRequest) (string, error)
}

Issuer is an adapter to Workflow M2M IssueManagedToken with managed-only issuance and an explicitly configured stable ES256 key. Hosts map this typed request; never implement this with a human cookie/HMAC or generic OAuth route.

type IssuerFunc

type IssuerFunc func(context.Context, IssueRequest) (string, error)

func (IssuerFunc) IssueAgentToken

func (f IssuerFunc) IssueAgentToken(ctx context.Context, r IssueRequest) (string, error)

type ManagementOptions

type ManagementOptions struct {
	Path        string
	OwnerOrigin string
	PagePath    string
	Owners      OwnerPolicy
	// Tenants supplies immutable owner-UI declarations when Policy is wrapped
	// by a host's current preview gate. It confers no authority: every visible
	// proposal must also pass the service's required Policy and OwnerPolicy.
	// If omitted, the UI uses Policy directly when it is a *TenantPolicy.
	Tenants *TenantPolicy
}

type Options

type Options struct {
	IssuerURL     string
	TokenEndpoint string
	IssuerKeys    map[string]*ecdsa.PublicKey
	Store         Store
	Issuer        Issuer
	Policy        Policy
	Audit         Auditor
	// Clock is for deterministic tests; production hosts normally omit it.
	Clock func() time.Time
}

type Owner

type Owner struct{ ID string }

type OwnerPolicy

type OwnerPolicy interface {
	ResolveOwner(*http.Request) (Owner, error)
	AuthorizeOwner(context.Context, Owner, string, Grant) error
}

OwnerPolicy must resolve a verified HUMAN owner and explicitly authorize the proposed tenant/resource/field ceiling. Request JSON never supplies identity. A service principal must not be projected into this resolver.

type Policy

type Policy interface {
	AllowGrant(context.Context, Grant) error
	AllowResource(context.Context, Grant, Resource) error
}

Policy is the consuming app's exact tenant/resource allowlist. It is required even for already persisted grants: the library does not know which tenant is live or which routes exist. It must reject live tenants and privileged routes for the preview assistant. An omitted policy never grants access.

type PreviewGrant

type PreviewGrant struct {
	Audience string `json:"audience"`
	Origin   string `json:"origin"`
	// Paths are exact canonical request targets, optionally including a finite
	// literal query. A bare path never grants its query variants.
	Paths []string `json:"paths"`
}

type Principal

type Principal struct {
	Subject, GrantID, JTIHash string
	GrantVersion, TenantID    int64
	Scopes                    []string
}

type Resource

type Resource struct {
	TenantID                int64
	Audience, Scope, PageID string
	Fields                  []string
	ExpectedVersion         uint64
	RootPage                bool
	HasCanonicalBlocks      bool
	Method, Origin, Path    string
	// Query is the raw canonical query of a preview request only. Path stays
	// the matched path; API/history query authorization remains host-owned.
	Query string
}

Resource must be built from the matched route/current saved row by the host, never copied unverified from JSON or X-Tenant/actor headers. All writes are body_html-only root-page CAS; canonical blocks are refused.

type Service

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

func NewService

func NewService(o Options) (*Service, error)

func (*Service) Authorize

func (s *Service) Authorize(ctx context.Context, raw string, r Resource) (Principal, error)

func (*Service) Exchange

func (s *Service) Exchange(ctx context.Context, in ExchangeRequest) (TokenResponse, error)

func (*Service) ExchangeHandler

func (s *Service) ExchangeHandler() http.Handler

ExchangeHandler handles only the exact configured RFC7523 token endpoint. There is no client-secret, cookie, human-session or refresh-token fallback. The TLS/reverse-proxy gate is host-owned and MUST reject untrusted forwarding metadata. Do not mount Workflow's generic OAuth issuer beside this handler.

func (*Service) ManagementHandler

func (s *Service) ManagementHandler(o ManagementOptions) (http.Handler, error)

ManagementHandler owns reusable registration/list/revocation behavior. Mount only behind existing HUMAN owner authorization and CSRF protection. Its typed resolver/policy cannot be replaced with a service principal. Hosts are responsible for a durable transaction plus audit/outbox for management mutations; no rollback can safely erase an already applied revoke.

type Store

type Store interface {
	GetGrant(context.Context, string) (Grant, error)
	ConsumeAssertion(context.Context, AssertionUse) (bool, error)
	IsTokenRevoked(context.Context, string) (bool, error)
}

Store methods MUST use durable state. ConsumeAssertion atomically checks the current grant version, enabled/expiry state AND inserts its globally unique assertion identity hash (issuer/subject/key/JTI binding). Uniqueness MUST NOT be partitioned by grant/version: one assertion cannot be reused on another tenant grant or after a permission edit. Return false for replay or changed/ revoked grants. Create and Revoke must be transactional and never alter a human identity/factor/bootstrap record. No in-memory production fallback is supplied.

type TenantConfig

type TenantConfig struct {
	TenantID      int64         `json:"tenant_id"`
	APIAudience   string        `json:"api_audience"`
	PagesPath     string        `json:"pages_path"`
	HistoryPath   string        `json:"history_path"`
	Scopes        []string      `json:"scopes"`
	UpdatePageIDs []string      `json:"update_page_ids"`
	Preview       *PreviewGrant `json:"preview,omitempty"`
}

TenantConfig is declarative per-preview configuration, independent of keys and grants. Adding a tenant requires a configuration entry and owner-approved grant, not a source fork, implicit enrollment or shared personal credential.

type TenantPolicy

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

TenantPolicy is an immutable allowlist of explicit preview tenants. Never include a live tenant in this configuration. It matches real host routes, field/page ceilings and protected preview origins; it confers no credential.

func NewTenantPolicy

func NewTenantPolicy(config []TenantConfig) (*TenantPolicy, error)

func (*TenantPolicy) AllowGrant

func (p *TenantPolicy) AllowGrant(_ context.Context, g Grant) error

func (*TenantPolicy) AllowResource

func (p *TenantPolicy) AllowResource(ctx context.Context, g Grant, r Resource) error

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int64  `json:"expires_in"`
	Scope       string `json:"scope"`
}

Directories

Path Synopsis
Package postgres persists agentidentity service grants in a host-owned SQL schema.
Package postgres persists agentidentity service grants in a host-owned SQL schema.

Jump to

Keyboard shortcuts

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