iam

package
v0.1.0-c01.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 9 Imported by: ? 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 iam implements provider-neutral, fail-closed authorization decisions for CloudRING organizations, tenants, projects, support grants, API-token references, break-glass controls, and audit sinks.

A subject or API-token reference never authenticates itself. Policy denies unless its configured AuthenticationVerifier returns matching trusted authentication, MFA, session, credential-class, and bounded proof-freshness evidence. OIDCAuthenticationVerifier is the reference adapter that takes the subject from a signed OIDC token rather than from the authorization request.

A Policy is configured by populating its exported maps before it starts serving requests. Once serving begins, callers must treat that configuration as immutable. Authorize and AuditEvents may then be called concurrently when the configured Clock, AuthenticationVerifier, and AuditSink are themselves safe for concurrent use. MemoryAuditSink is bounded, non-durable, and must be explicitly allowed for synthetic or test-only policy. Production decisions require a ready DurableAuditSink. Authorize samples its clock once and uses that instant for authentication, evaluation, and audit.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownPrincipal = errors.New("iam: unknown principal")
	ErrUnknownAction    = errors.New("iam: unknown action")
	ErrUnknownTenant    = errors.New("iam: unknown tenant")
	ErrUnknownProject   = errors.New("iam: unknown project")
	ErrCrossTenant      = errors.New("iam: cross-tenant access denied")
	ErrObjectScope      = errors.New("iam: object scope denied")
	ErrTenantSuspended  = errors.New("iam: tenant suspended")
	ErrTenantDeleting   = errors.New("iam: tenant deleting")
	ErrTenantState      = errors.New("iam: invalid tenant lifecycle state")
	ErrLastOwner        = errors.New("iam: last owner removal denied")
	ErrReasonRequired   = errors.New("iam: explicit reason required")
	ErrTicketRequired   = errors.New("iam: support ticket reference required")
	ErrAuditRequired    = errors.New("iam: durable audit required")
	ErrTokenExpired     = errors.New("iam: api token expired")
	ErrTokenRevoked     = errors.New("iam: api token revoked")
	ErrTokenScope       = errors.New("iam: api token scope denied")
	ErrSupportGrant     = errors.New("iam: support grant denied")
	ErrRoleDenied       = errors.New("iam: role denied")
	ErrAuthentication   = errors.New("iam: trusted authentication evidence required")
	ErrMFARequired      = errors.New("iam: multi-factor assurance required")
	ErrSessionAssurance = errors.New("iam: fresh session assurance required")
	ErrBreakGlass       = errors.New("iam: break-glass context required")
	ErrTargetPrincipal  = errors.New("iam: target principal is not an owner of the project")
)

Functions

func AppendDurableSecurityEvent

func AppendDurableSecurityEvent(ctx context.Context, sink SecurityAuditSink, event SecurityEvent) error

Types

type APIToken

type APIToken struct {
	Reference     string
	SubjectID     string
	SecretHashRef string
	TenantID      string
	ProjectID     string
	Scopes        []Action
	ExpiresAt     time.Time
	RevokedAt     time.Time
}

type Action

type Action string
const (
	ActionProjectRead   Action = "project.read"
	ActionProjectWrite  Action = "project.write"
	ActionProjectManage Action = "project.manage"
	ActionOwnerRemove   Action = "owner.remove"
	ActionTenantExport  Action = "tenant.export"
	ActionTenantRecover Action = "tenant.recover"
)

type AuditEvent

type AuditEvent struct {
	Actor              string
	RepresentedSubject string
	Action             Action
	Target             TargetRef
	Reason             string
	TicketRef          string
	CorrelationID      string
	Result             AuditResult
	PolicyRule         string
	Timestamp          time.Time
	Error              string
	BreakGlass         bool
	SupportGrantRef    string
	APITokenRef        string
	TargetPrincipal    string
	TargetLifecycle    TenantState
	TargetNamespace    string
	TargetResource     string
	TargetResourceName string
	TargetOrganization string
	TargetTenant       string
	TargetProject      string
	CredentialClass    CredentialClass
	MFA                MFAAssurance
	Session            SessionAssurance
	Proof              AuthenticationProof
}

type AuditEventReader

type AuditEventReader interface {
	Events() []AuditEvent
}

type AuditReadiness

type AuditReadiness interface {
	Ready(context.Context) error
}

type AuditResult

type AuditResult string
const (
	AuditResultAllow AuditResult = "allow"
	AuditResultDeny  AuditResult = "deny"
)

type AuditSink

type AuditSink interface {
	Append(AuditEvent) error
}

type AuthenticationFunc

func (AuthenticationFunc) Authenticate

func (verify AuthenticationFunc) Authenticate(ctx context.Context, request AuthorizationRequest, at time.Time) (AuthenticationResult, error)

type AuthenticationProof

type AuthenticationProof struct {
	// VerifiedAt is when the trusted verifier completed credential validation.
	// ExpiresAt is the credential or proof expiry, whichever comes first.
	VerifiedAt time.Time
	ExpiresAt  time.Time
}

type AuthenticationResult

type AuthenticationResult struct {
	SubjectID       string
	APITokenRef     string
	CredentialClass CredentialClass
	MFA             MFAAssurance
	Session         SessionAssurance
	Proof           AuthenticationProof
}

AuthenticationResult is returned only by the trusted verifier configured on Policy. It is deliberately not part of AuthorizationRequest, so callers cannot turn a subject or API-token reference into authentication evidence.

type AuthenticationVerifier

type AuthenticationVerifier interface {
	Authenticate(context.Context, AuthorizationRequest, time.Time) (AuthenticationResult, error)
}

type AuthorizationRequest

type AuthorizationRequest struct {
	Subject         PrincipalRef
	Action          Action
	Target          TargetRef
	Context         RequestContext
	SupportGrantRef string
	BreakGlass      bool
}

type Clock

type Clock interface {
	// Now may be called concurrently by multiple authorization requests.
	Now() time.Time
}

type CredentialClass

type CredentialClass string
const (
	CredentialClassInteractiveSession CredentialClass = "interactive_session"
	CredentialClassShortLivedAPIToken CredentialClass = "short_lived_api_token"
	CredentialClassSupportGrant       CredentialClass = "support_grant"
	CredentialClassBreakGlass         CredentialClass = "break_glass"
)

type Decision

type Decision struct {
	Allowed         bool
	Err             error
	PolicyRule      string
	CredentialClass CredentialClass
	MFA             MFAAssurance
	Session         SessionAssurance
	Proof           AuthenticationProof
}

type DeniedState

type DeniedState struct {
	Code       string `json:"code"`
	Owner      string `json:"owner"`
	Impact     string `json:"impact"`
	NextAction string `json:"nextAction"`
}

func AuthUnavailableDeniedState

func AuthUnavailableDeniedState() DeniedState

func ManagementDeniedState

func ManagementDeniedState() DeniedState

func SessionRequiredDeniedState

func SessionRequiredDeniedState() DeniedState

func TokenRejectedDeniedState

func TokenRejectedDeniedState() DeniedState

type DurableAuditSink

type DurableAuditSink interface {
	AuditSink
	AuditReadiness
	Durable() bool
}

DurableAuditSink promises that a successful Append is durably committed and that Ready checks the usable persistence dependency. Durable returning false is accepted only when PolicyConfig.AllowEphemeralAudit is explicitly set for a synthetic or test-only policy.

type FailingAuditSink

type FailingAuditSink struct{}

func (FailingAuditSink) Append

func (FailingAuditSink) Durable

func (FailingAuditSink) Durable() bool

func (FailingAuditSink) Events

func (FailingAuditSink) Events() []AuditEvent

func (FailingAuditSink) Ready

type FixedClock

type FixedClock struct {
	At time.Time
}

func (FixedClock) Now

func (clock FixedClock) Now() time.Time

type IdentityContract

type IdentityContract struct {
	AuthenticatedSubjectCovered bool `json:"authenticatedSubjectCovered"`
	MFAEnforcementCovered       bool `json:"mfaEnforcementCovered"`
	SessionEnforcementCovered   bool `json:"sessionEnforcementCovered"`
}

type LifecycleClaims

type LifecycleClaims struct {
	SuspendedWriteDenied bool `json:"suspendedWriteDenied"`
	DeletingWriteDenied  bool `json:"deletingWriteDenied"`
	LastOwnerGuard       bool `json:"lastOwnerGuard"`
}

type MFAAssurance

type MFAAssurance struct {
	Required    bool
	Satisfied   bool
	MethodClass MFAMethodClass
}

type MFAMethodClass

type MFAMethodClass string
const (
	MFAMethodNone        MFAMethodClass = "none"
	MFAMethodTOTP        MFAMethodClass = "totp"
	MFAMethodWebAuthn    MFAMethodClass = "webauthn"
	MFAMethodHardwareKey MFAMethodClass = "hardware_key"
	MFAMethodExternalIDP MFAMethodClass = "external_idp"
)

type Membership

type Membership struct {
	OrgID     string
	TenantID  string
	ProjectID string
	Role      Role
}

type MemoryAuditSink

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

func NewBoundedMemoryAuditSink

func NewBoundedMemoryAuditSink(maxEvents int) *MemoryAuditSink

func NewMemoryAuditSink

func NewMemoryAuditSink() *MemoryAuditSink

func (*MemoryAuditSink) Append

func (sink *MemoryAuditSink) Append(event AuditEvent) error

func (*MemoryAuditSink) AppendSecurityEvent

func (sink *MemoryAuditSink) AppendSecurityEvent(_ context.Context, event SecurityEvent) error

func (*MemoryAuditSink) Durable

func (*MemoryAuditSink) Durable() bool

func (*MemoryAuditSink) Events

func (sink *MemoryAuditSink) Events() []AuditEvent

func (*MemoryAuditSink) Ready

func (*MemoryAuditSink) SecurityEvents

func (sink *MemoryAuditSink) SecurityEvents() []SecurityEvent

type NamespaceScope

type NamespaceScope struct {
	Namespace string
	Actions   []Action
}

type OIDCAuthenticationVerifier

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

OIDCAuthenticationVerifier is the reference adapter from a verified OIDC ID token to Policy authentication evidence. The subject always comes from the signed token; Policy separately requires it to match the requested subject and the configured role/scope directory.

func NewOIDCAuthenticationVerifier

func NewOIDCAuthenticationVerifier(runtime *identity.Runtime, source OIDCProofSource) (*OIDCAuthenticationVerifier, error)

func (*OIDCAuthenticationVerifier) Authenticate

type OIDCProof

type OIDCProof struct {
	IDToken string
	Nonce   string
	MFA     MFAAssurance
	Session SessionAssurance
}

type OIDCProofFunc

type OIDCProofFunc func(context.Context) (OIDCProof, error)

func (OIDCProofFunc) OIDCProof

func (source OIDCProofFunc) OIDCProof(ctx context.Context) (OIDCProof, error)

type OIDCProofSource

type OIDCProofSource interface {
	OIDCProof(context.Context) (OIDCProof, error)
}

OIDCProofSource reads browser/session proof from trusted transport context. It must not derive a subject from AuthorizationRequest.

type Organization

type Organization struct {
	ID   string
	Name string
}

type Policy

type Policy struct {
	Organizations map[string]Organization
	Tenants       map[string]Tenant
	Projects      map[string]Project
	Principals    map[string]Principal
	APITokens     map[string]APIToken
	SupportGrants map[string]SupportGrant

	AuditSink AuditSink
	// contains filtered or unexported fields
}

func NewPolicy

func NewPolicy(config PolicyConfig) *Policy

func NewPolicyFromState

func NewPolicyFromState(ctx context.Context, config PolicyConfig, loader PolicyStateLoader) (*Policy, error)

NewPolicyFromState is the production-oriented construction path. It requires a ready durable audit dependency, a trusted verifier with bounded proof policy, and a structurally consistent role/scope directory.

func (*Policy) AuditEvents

func (policy *Policy) AuditEvents() []AuditEvent

func (*Policy) Authorize

func (policy *Policy) Authorize(request AuthorizationRequest) Decision

func (*Policy) AuthorizeContext

func (policy *Policy) AuthorizeContext(ctx context.Context, request AuthorizationRequest) Decision

AuthorizeContext lets a trusted AuthenticationVerifier consume transport-specific proof from ctx without placing bearer material in the authorization request or audit record.

type PolicyConfig

type PolicyConfig struct {
	Clock                         Clock
	AuditSink                     AuditSink
	AuthenticationVerifier        AuthenticationVerifier
	AuthenticationProofMaxAge     time.Duration
	AuthenticationProofFutureSkew time.Duration
	AllowEphemeralAudit           bool
}

type PolicyState

type PolicyState struct {
	Organizations map[string]Organization
	Tenants       map[string]Tenant
	Projects      map[string]Project
	Principals    map[string]Principal
	APITokens     map[string]APIToken
	SupportGrants map[string]SupportGrant
}

type PolicyStateLoader

type PolicyStateLoader interface {
	Ready(context.Context) error
	LoadPolicyState(context.Context) (PolicyState, error)
}

type Principal

type Principal struct {
	ID          string
	Groups      []string
	Memberships []Membership
	Support     bool
}

type PrincipalRef

type PrincipalRef struct {
	ID          string
	APITokenRef string
}

type Project

type Project struct {
	ID        string
	TenantID  string
	OrgID     string
	Namespace string
	Scopes    []NamespaceScope
}

type Quotas

type Quotas struct {
	Projects int
	CPU      int
	MemoryGB int
}

type RequestContext

type RequestContext struct {
	TicketRef     string
	CorrelationID string
	Reason        string
	// Now is retained for wire compatibility but is never trusted for policy
	// evaluation. PolicyConfig.Clock is the authoritative time source.
	Now             time.Time
	TargetPrincipal string
}

type Role

type Role string
const (
	RoleOwner         Role = "owner"
	RoleTenantAdmin   Role = "tenant_admin"
	RoleTenantViewer  Role = "tenant_viewer"
	RoleSupport       Role = "support"
	RolePlatformAdmin Role = "platform_admin"
)

type RoleCoverage

type RoleCoverage struct {
	TenantAdmin bool `json:"tenantAdmin"`
	Owner       bool `json:"owner"`
	Viewer      bool `json:"viewer"`
}

type Scenario

type Scenario string
const (
	ScenarioHappy Scenario = "happy"
	ScenarioEdge  Scenario = "edge"
)

type SecurityAuditSink

type SecurityAuditSink interface {
	AuditReadiness
	Durable() bool
	AppendSecurityEvent(context.Context, SecurityEvent) error
}

SecurityAuditSink lets authentication, login, logout, registration, and bootstrap boundaries use the same durable dependency as authorization.

type SecurityEvent

type SecurityEvent struct {
	Type          string
	Actor         string
	Subject       string
	Result        AuditResult
	Reason        string
	CorrelationID string
	Timestamp     time.Time
}

type SessionAssurance

type SessionAssurance struct {
	State SessionState
	// MaxAgeSeconds is the verifier-declared maximum age of Proof.VerifiedAt
	// for this session. Policy also applies its own stricter maximum.
	MaxAgeSeconds            int64
	ReauthenticationRequired bool
}

type SessionState

type SessionState string
const (
	SessionStateFresh   SessionState = "fresh"
	SessionStateStale   SessionState = "stale"
	SessionStateAbsent  SessionState = "absent"
	SessionStateRevoked SessionState = "revoked"
)

type SourceSafetyClaims

type SourceSafetyClaims struct {
	NoPlaintextSecrets bool     `json:"noPlaintextSecrets"`
	SyntheticIDsOnly   bool     `json:"syntheticIdsOnly"`
	NoTenantData       bool     `json:"noTenantData"`
	LinkedRequirements []string `json:"linkedRequirements"`
}

type Status

type Status string
const (
	StatusReady   Status = "ready"
	StatusBlocked Status = "blocked"
)

type SupportGrant

type SupportGrant struct {
	Reference string
	SubjectID string
	TenantID  string
	ProjectID string
	Actions   []Action
	TicketRef string
	Reason    string
	ExpiresAt time.Time
}

type TargetRef

type TargetRef struct {
	OrgID     string
	TenantID  string
	ProjectID string
	Namespace string
	Resource  string
	Name      string
}

type Tenant

type Tenant struct {
	ID     string
	OrgID  string
	State  TenantState
	Quotas Quotas
}

type TenantState

type TenantState string
const (
	TenantStateActive     TenantState = "active"
	TenantStateSuspended  TenantState = "suspended"
	TenantStateDeleting   TenantState = "deleting"
	TenantStateRecovering TenantState = "recovering"
	TenantStateExporting  TenantState = "exporting"
)

type VerifyBlocker

type VerifyBlocker struct {
	ID               string `json:"id"`
	Message          string `json:"message"`
	Expected         string `json:"expected"`
	Observed         string `json:"observed"`
	PolicyRule       string `json:"policyRule"`
	Audited          bool   `json:"audited"`
	ReadinessClaimed bool   `json:"readinessClaimed"`
	Executable       bool   `json:"executable"`
	Err              error  `json:"-"`
}

type VerifyCase

type VerifyCase struct {
	ID               string `json:"id"`
	Expected         string `json:"expected"`
	Observed         string `json:"observed"`
	PolicyRule       string `json:"policyRule"`
	Error            string `json:"error,omitempty"`
	Audited          bool   `json:"audited"`
	ReadinessClaimed bool   `json:"readinessClaimed"`
	Executable       bool   `json:"executable"`
}

type VerifyCoverage

type VerifyCoverage struct {
	Organization                 bool             `json:"organization"`
	ActiveTenant                 bool             `json:"activeTenant"`
	ActiveProject                bool             `json:"activeProject"`
	Roles                        RoleCoverage     `json:"roles"`
	Quotas                       bool             `json:"quotas"`
	APITokenReadScope            bool             `json:"apiTokenReadScope"`
	SupportGrantWithTicketReason bool             `json:"supportGrantWithTicketReason"`
	BreakGlassWithTicketReason   bool             `json:"breakGlassWithTicketReason"`
	AuditAppend                  bool             `json:"auditAppend"`
	Lifecycle                    LifecycleClaims  `json:"lifecycle"`
	IdentityContract             IdentityContract `json:"identityContract"`
	PlaintextSecretsAbsent       bool             `json:"plaintextSecretsAbsent"`
}

type VerifyOptions

type VerifyOptions struct {
	Scenario     Scenario
	EvidencePath string
}

type VerifyReport

type VerifyReport struct {
	SchemaVersion       string             `json:"schemaVersion"`
	GeneratedAt         string             `json:"generatedAt"`
	Scenario            Scenario           `json:"scenario"`
	Status              Status             `json:"status"`
	ReadinessClaimed    bool               `json:"readinessClaimed"`
	Target              string             `json:"target"`
	SyntheticOnly       bool               `json:"syntheticOnly"`
	Requirements        []string           `json:"requirements"`
	Coverage            VerifyCoverage     `json:"coverage"`
	Cases               []VerifyCase       `json:"cases"`
	Blockers            []VerifyBlocker    `json:"blockers,omitempty"`
	AuditEventCount     int                `json:"auditEventCount"`
	SourceSafety        SourceSafetyClaims `json:"sourceSafety"`
	NonClaims           []string           `json:"nonClaims"`
	ControlObservations []string           `json:"controlObservations"`
}

func VerifyContract

func VerifyContract(opts VerifyOptions) (VerifyReport, int, error)

Jump to

Keyboard shortcuts

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