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
- Variables
- func ValidateGrantForStorage(g Grant) error
- type AssertionUse
- type Audit
- type Auditor
- type ExchangeRequest
- type Grant
- type GrantManager
- type IssueRequest
- type Issuer
- type IssuerFunc
- type ManagementOptions
- type Options
- type Owner
- type OwnerPolicy
- type Policy
- type PreviewGrant
- type Principal
- type Resource
- type Service
- func (s *Service) Authorize(ctx context.Context, raw string, r Resource) (Principal, error)
- func (s *Service) Exchange(ctx context.Context, in ExchangeRequest) (TokenResponse, error)
- func (s *Service) ExchangeHandler() http.Handler
- func (s *Service) ManagementHandler(o ManagementOptions) (http.Handler, error)
- type Store
- type TenantConfig
- type TenantPolicy
- type TokenResponse
Constants ¶
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 ¶
var ( ErrDenied = errors.New("agent access denied") ErrConflict = errors.New("agent grant conflict") )
Functions ¶
func ValidateGrantForStorage ¶
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 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 ExchangeRequest ¶
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 IssueRequest ¶
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 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 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 (*Service) Exchange ¶
func (s *Service) Exchange(ctx context.Context, in ExchangeRequest) (TokenResponse, error)
func (*Service) ExchangeHandler ¶
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