Documentation
¶
Overview ¶
Package accessintent owns PostgreSQL persistence and transactional River outbox scheduling for durable access-control intents (grants, adapter enrollments, and post-deactivation agent cleanup).
Index ¶
- Constants
- Variables
- func DeterministicCertificateRequestName(sessionUID, serverUID, csrSHA256 string) string
- type ReconcileAgentCleanupJob
- type ReconcileEnrollmentJob
- type ReconcileGrantJob
- type Writer
- func (w *Writer) ActivateEnrollment(ctx context.Context, opID string, req apikit.EnrollmentIntentActivateRequest) (apikit.EnrollmentIntent, error)
- func (w *Writer) ClaimAgentCleanupFence(ctx context.Context, agentID, workerID string) (apikit.AgentCleanupFenceResponse, error)
- func (w *Writer) ClaimEnrollmentFence(ctx context.Context, opID, workerID string) (apikit.EnrollmentIntentFenceResponse, error)
- func (w *Writer) ClaimGrantFence(ctx context.Context, grantID, workerID string) (apikit.GrantIntentFenceResponse, error)
- func (w *Writer) ClaimObserverLease(ctx context.Context, clusterKey, observerID string) (apikit.AccessIntentObserverLeaseResponse, error)
- func (w *Writer) CreateEnrollmentIntent(ctx context.Context, req apikit.EnrollmentIntentCreateRequest) (apikit.EnrollmentIntent, bool, error)
- func (w *Writer) GetAgentCleanupIntent(ctx context.Context, agentID string) (apikit.AgentCleanupIntent, bool, error)
- func (w *Writer) GetEnrollmentIntent(ctx context.Context, opID string) (apikit.EnrollmentIntent, bool, error)
- func (w *Writer) GetGrantIntent(ctx context.Context, grantID string) (apikit.GrantIntent, bool, error)
- func (w *Writer) ListEnrollmentIntents(ctx context.Context) ([]apikit.EnrollmentIntent, error)
- func (w *Writer) ListGrantIntents(ctx context.Context) ([]apikit.GrantIntent, error)
- func (w *Writer) RecordAgentCleanupReceipt(ctx context.Context, agentID string, req apikit.AgentCleanupReceiptRequest) (apikit.AgentCleanupReceipt, error)
- func (w *Writer) RecordAgentDeactivationTx(ctx context.Context, tx *sql.Tx, agentID, teamID string, ...) error
- func (w *Writer) RecordEnrollmentReceipt(ctx context.Context, opID string, req apikit.EnrollmentIntentReceiptRequest) (apikit.EnrollmentReceipt, error)
- func (w *Writer) RecordGrantObservation(ctx context.Context, grantID string, req apikit.GrantIntentObservationRequest) (apikit.GrantObservation, error)
- func (w *Writer) RecordGrantReceipt(ctx context.Context, grantID string, req apikit.GrantIntentReceiptRequest) (apikit.GrantReceipt, error)
- func (w *Writer) RevokeGrantIntent(ctx context.Context, grantID string, deleteGrant bool) (apikit.GrantIntent, error)
- func (w *Writer) UpsertGrantIntent(ctx context.Context, req apikit.GrantIntentUpsertRequest) (apikit.GrantIntent, error)
Constants ¶
const ( // QueueSchema is the PostgreSQL schema hosting River tables for access intent jobs. QueueSchema = "access_intent_queue" // QueueAccessControl is the River queue name for access-control reconciliation jobs. QueueAccessControl = "access_control" // KindReconcileGrant reconciles a grant incarnation to Kubernetes. KindReconcileGrant = "reconcile_grant" // KindReconcileEnrollment reconciles an adapter certificate enrollment operation. KindReconcileEnrollment = "reconcile_enrollment" // KindReconcileAgentCleanup reconciles post-deactivation agent cleanup follow-up. KindReconcileAgentCleanup = "reconcile_agent_cleanup" )
Variables ¶
var ( // ErrDisabled is returned when PLATFORM_ACCESS_INTENT_JOURNAL is not enabled. ErrDisabled = errors.New("access intent journal is disabled") // ErrStaleReceipt is returned when a worker receipt fails fence, revision, // or state ownership validation. ErrStaleReceipt = errors.New("stale access intent receipt") // ErrStaleObservation is returned when an observer epoch, revision, UID, or // propagation assertion fails conditional validation. ErrStaleObservation = errors.New("stale access intent observation") // ErrAuthorityRevoked is returned when conditional enrollment activation sees // a revoked/expired session, inactive agent, or retired/mismatched server. ErrAuthorityRevoked = errors.New("enrollment authority revoked or inactive") // ErrInvalidInput is returned when an access intent API request is malformed. ErrInvalidInput = errors.New("invalid access intent request") )
Functions ¶
func DeterministicCertificateRequestName ¶
DeterministicCertificateRequestName computes a stable, DNS-1123 compliant Kubernetes CertificateRequest name derived solely from the immutable enrollment key (sessionUID, serverUID, csrSHA256).
Types ¶
type ReconcileAgentCleanupJob ¶
type ReconcileAgentCleanupJob struct {
AgentID string `json:"agentId"`
RevisionID string `json:"revisionId"`
RequestID string `json:"requestId,omitempty"`
Traceparent string `json:"traceparent,omitempty"`
Tracestate string `json:"tracestate,omitempty"`
}
ReconcileAgentCleanupJob is the River job payload for post-deactivation agent cleanup.
func (ReconcileAgentCleanupJob) Kind ¶
func (ReconcileAgentCleanupJob) Kind() string
type ReconcileEnrollmentJob ¶
type ReconcileEnrollmentJob struct {
OperationID string `json:"operationId"`
RevisionID string `json:"revisionId"`
RequestID string `json:"requestId,omitempty"`
Traceparent string `json:"traceparent,omitempty"`
Tracestate string `json:"tracestate,omitempty"`
}
ReconcileEnrollmentJob is the River job payload for adapter certificate enrollment.
func (ReconcileEnrollmentJob) Kind ¶
func (ReconcileEnrollmentJob) Kind() string
type ReconcileGrantJob ¶
type ReconcileGrantJob struct {
GrantID string `json:"grantId"`
RevisionID string `json:"revisionId"`
RequestID string `json:"requestId,omitempty"`
Traceparent string `json:"traceparent,omitempty"`
Tracestate string `json:"tracestate,omitempty"`
}
ReconcileGrantJob is the River job payload for grant reconciliation.
func (ReconcileGrantJob) Kind ¶
func (ReconcileGrantJob) Kind() string
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer owns access-control durable intent storage and insert-only River job scheduling inside PostgreSQL transactions.
func Open ¶
Open prepares storage for the opt-in access intent journal. The DSN must point to the same PostgreSQL database as db and support session-level advisory locks.
func (*Writer) ActivateEnrollment ¶
func (w *Writer) ActivateEnrollment(ctx context.Context, opID string, req apikit.EnrollmentIntentActivateRequest) (apikit.EnrollmentIntent, error)
ActivateEnrollment atomically verifies that the target session is still active and non-revoked, the bound agent is still active, and the server UID still matches and is not retired before activating the enrollment. Lock order preserves session_sync_state -> agents -> enrollment_intent.
func (*Writer) ClaimAgentCleanupFence ¶
func (w *Writer) ClaimAgentCleanupFence(ctx context.Context, agentID, workerID string) (apikit.AgentCleanupFenceResponse, error)
ClaimAgentCleanupFence increments the per-agent execution fence and returns the current post-deactivation cleanup intent.
func (*Writer) ClaimEnrollmentFence ¶
func (w *Writer) ClaimEnrollmentFence(ctx context.Context, opID, workerID string) (apikit.EnrollmentIntentFenceResponse, error)
ClaimEnrollmentFence atomically increments the per-operation execution fence and returns the authoritative enrollment operation.
func (*Writer) ClaimGrantFence ¶
func (w *Writer) ClaimGrantFence(ctx context.Context, grantID, workerID string) (apikit.GrantIntentFenceResponse, error)
ClaimGrantFence atomically increments the per-grant worker execution fence and returns the authoritative current desired intent.
func (*Writer) ClaimObserverLease ¶
func (w *Writer) ClaimObserverLease(ctx context.Context, clusterKey, observerID string) (apikit.AccessIntentObserverLeaseResponse, error)
ClaimObserverLease atomically increments the monotonic observer epoch for clusterKey so older observers cannot overwrite fresher observations.
func (*Writer) CreateEnrollmentIntent ¶
func (w *Writer) CreateEnrollmentIntent(ctx context.Context, req apikit.EnrollmentIntentCreateRequest) (apikit.EnrollmentIntent, bool, error)
CreateEnrollmentIntent idempotently creates a durable adapter enrollment operation keyed to (session_uid, server_uid, csr_sha256) with a deterministic CertificateRequest name and schedules reconcile_enrollment in ONE transaction. Private keys and raw certificate secrets are never accepted or persisted.
func (*Writer) GetAgentCleanupIntent ¶
func (w *Writer) GetAgentCleanupIntent(ctx context.Context, agentID string) (apikit.AgentCleanupIntent, bool, error)
GetAgentCleanupIntent returns the durable post-deactivation cleanup intent for one agent.
func (*Writer) GetEnrollmentIntent ¶
func (w *Writer) GetEnrollmentIntent(ctx context.Context, opID string) (apikit.EnrollmentIntent, bool, error)
GetEnrollmentIntent returns one durable adapter enrollment operation.
func (*Writer) GetGrantIntent ¶
func (w *Writer) GetGrantIntent(ctx context.Context, grantID string) (apikit.GrantIntent, bool, error)
GetGrantIntent returns one durable grant incarnation.
func (*Writer) ListEnrollmentIntents ¶
ListEnrollmentIntents returns all durable adapter enrollment operations.
func (*Writer) ListGrantIntents ¶
ListGrantIntents returns all durable grant intents with receipts, independent observations, and separated gateway propagation milestones.
func (*Writer) RecordAgentCleanupReceipt ¶
func (w *Writer) RecordAgentCleanupReceipt(ctx context.Context, agentID string, req apikit.AgentCleanupReceiptRequest) (apikit.AgentCleanupReceipt, error)
RecordAgentCleanupReceipt persists a fenced post-deactivation cleanup receipt.
func (*Writer) RecordAgentDeactivationTx ¶
func (w *Writer) RecordAgentDeactivationTx(ctx context.Context, tx *sql.Tx, agentID, teamID string, deactivatedAt time.Time, revokedSessionsCount int64) error
RecordAgentDeactivationTx records post-deactivation follow-up cleanup intent and enqueues reconcile_agent_cleanup inside the caller's existing atomic agent deactivation + session revocation transaction. Authoritative session revocation MUST have already executed in tx before calling this helper.
func (*Writer) RecordEnrollmentReceipt ¶
func (w *Writer) RecordEnrollmentReceipt(ctx context.Context, opID string, req apikit.EnrollmentIntentReceiptRequest) (apikit.EnrollmentReceipt, error)
RecordEnrollmentReceipt persists bounded enrollment execution progress conditional on operation fence epoch and desired revision. Activation must go through ActivateEnrollment so authority checks run atomically.
func (*Writer) RecordGrantObservation ¶
func (w *Writer) RecordGrantObservation(ctx context.Context, grantID string, req apikit.GrantIntentObservationRequest) (apikit.GrantObservation, error)
RecordGrantObservation persists independently observed Kubernetes CR and gateway replica propagation state without modifying desired intent or River jobs.
func (*Writer) RecordGrantReceipt ¶
func (w *Writer) RecordGrantReceipt(ctx context.Context, grantID string, req apikit.GrantIntentReceiptRequest) (apikit.GrantReceipt, error)
RecordGrantReceipt persists a worker execution receipt conditional on the grant incarnation, current desired revision, state, and fence epoch.
func (*Writer) RevokeGrantIntent ¶
func (w *Writer) RevokeGrantIntent(ctx context.Context, grantID string, deleteGrant bool) (apikit.GrantIntent, error)
RevokeGrantIntent commits authoritative grant revocation or deletion synchronously in PostgreSQL FIRST and enqueues Kubernetes cleanup/projection in the same transaction.
func (*Writer) UpsertGrantIntent ¶
func (w *Writer) UpsertGrantIntent(ctx context.Context, req apikit.GrantIntentUpsertRequest) (apikit.GrantIntent, error)
UpsertGrantIntent atomically records desired grant intent and schedules a reconcile_grant River job in one PostgreSQL transaction.