Documentation
¶
Overview ¶
Package audit implements the default append-only audit sink (project.md §5).
Two tables are written in one transaction: `dilion_audit.events` (one row per access event) and `dilion_audit.subjects` (the subject manifest, §5.3) so that "who accessed subject X" stays answerable without embedding N user ids in the event row. Personal data values are never written here (§5.1).
Index ¶
Constants ¶
const ( ActionUserListRead = "USER_LIST_READ" ActionUserDetailRead = "USER_DETAIL_READ" ActionUserCreated = "USER_CREATED" ActionUserUpdated = "USER_UPDATED" ActionUserDeleted = "USER_DELETED" ActionPIIMaskedRead = "PII_MASKED_READ" ActionPIIFullRead = "PII_FULL_READ" ActionPIIUpdate = "PII_UPDATE" ActionPIIExport = "PII_EXPORT" ActionPrivacyRequestCreated = "PRIVACY_REQUEST_CREATED" ActionPrivacyRequestCanceled = "PRIVACY_REQUEST_CANCELED" ActionPrivacyRequestListRead = "PRIVACY_REQUEST_LIST_READ" ActionPrivacyRequestDetailRead = "PRIVACY_REQUEST_DETAIL_READ" ActionConsentChanged = "CONSENT_CHANGED" ActionConsentRead = "CONSENT_READ" // CONSENT_SEGMENT_READ is the cross-user consent projection (ids only); // CONSENT_AUDIENCE_EXPORT joins it with contact identifiers and is a // "매우 민감" export with a mandatory reason (use-cases.md P1). ActionConsentSegmentRead = "CONSENT_SEGMENT_READ" ActionConsentAudienceExport = "CONSENT_AUDIENCE_EXPORT" // USER_SEARCH is the exact-match lookup by email/phone/profile field. The // search value itself is never recorded (§5.1) — only the matched subjects. ActionUserSearch = "USER_SEARCH" ActionHoldCreated = "HOLD_CREATED" ActionHoldReleased = "HOLD_RELEASED" ActionHoldListRead = "LEGAL_HOLD_LIST_READ" ActionDestinationChanged = "DESTINATION_CHANGED" ActionDestinationRead = "DESTINATION_READ" // AUTH_HOOK_CHANGED is an instance's auth hook setting being set or removed // (/auth/v1/admin/hooks): the hook then receives user data. ActionAuthHookChanged = "AUTH_HOOK_CHANGED" ActionRoleGranted = "ROLE_GRANTED" ActionRoleRevoked = "ROLE_REVOKED" // Definition changes are permission changes too ("매우 민감", §5.2). ActionRoleCreated = "ROLE_CREATED" ActionRoleUpdated = "ROLE_UPDATED" ActionPermissionCreated = "PERMISSION_CREATED" ActionAPIKeyCreated = "API_KEY_CREATED" ActionAPIKeyRevoked = "API_KEY_REVOKED" // IAM_READ covers reads of the authorization configuration itself // (roles, assignments, permissions, holders, api keys). ActionIAMRead = "IAM_READ" ActionServiceRoleUse = "SERVICE_ROLE_USED" ActionPermissionDenied = "PERMISSION_DENIED" )
Action constants (§5.2). The management plane only ever appends these.
Read actions name the RECORD KIND that was read, not the credential or the screen. USER_* is reserved for the account directory itself (the Supabase compatible /auth/v1/admin/users surface); subject-scoped records under /privacy/v1 have their own actions so that filtering by action stays meaningful and §5.2 sensitivity grading survives. Every subject-scoped read still records the subject manifest, so reverse lookup ("who accessed user X?", §5.3) works regardless of action.
const ( AccessMasked = "masked" AccessFull = "full" AccessNA = "n/a" )
Access levels recorded on the event row (§5.1 "어떤 권한으로").
Variables ¶
This section is empty.
Functions ¶
func NewSink ¶
NewSink returns the Postgres-backed audit sink over one fixed pool. The sink is append-only: it issues INSERTs and nothing else.
func NewSinkFor ¶
NewSinkFor returns the audit sink over a per-request pool provider.
Types ¶
type Event ¶
type Event struct {
ID string `json:"id"`
ActorID *string `json:"actor_id"`
ActorType *string `json:"actor_type"`
Action string `json:"action"`
Resource *string `json:"resource"`
AccessLevel *string `json:"access_level"`
RequestID *string `json:"request_id"`
ResultCount *int `json:"result_count"`
Reason *string `json:"reason"`
IP *string `json:"ip"`
UserAgent *string `json:"user_agent"`
CreatedAt time.Time `json:"created_at"`
// SubjectIDs is the subject manifest (§5.3). It is populated by GetEvent
// only: a list response must not inline N subject ids per row.
SubjectIDs []string `json:"subject_ids"`
}
Event is one recorded access event. Field values that were not supplied are null rather than empty, so "not recorded" stays distinguishable from "empty string" in the evidence (§5.1).
type EventFilter ¶
type EventFilter struct {
ActorID *string
Action *string
SubjectID *string // reverse lookup against the subject manifest (§5.3)
From *time.Time // created_at >= (inclusive) — 정기 점검 리포트용 기간 창
To *time.Time // created_at < (exclusive)
}
EventFilter narrows ListEvents. A nil field means "no filter"; the zero value lists every event newest-first.
type NopSink ¶
type NopSink struct{}
NopSink discards events. Intended for spec generation and tests only — never wire it into a deployment, audit logging is a compliance obligation (§5).
type PoolFunc ¶
PoolFunc resolves the database pool for a request, so that in a multi-instance deployment an event is written to the database of the instance selected on the context (ports.ContextWithInstance, internal/instances). It is structurally identical to instances.PoolFunc; declared locally to keep this package's imports narrow.
func StaticPool ¶
StaticPool is the single-instance PoolFunc over one fixed pool.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is the read side of the audit log. It issues SELECTs only.
func NewReader ¶
NewReader returns the Postgres-backed audit reader over one fixed pool. Constructing it performs no I/O, so it is safe to build with a nil pool (spec generation).
func NewReaderFor ¶
NewReaderFor returns the audit reader over a per-request pool provider.
func (*Reader) ListEvents ¶
func (r *Reader) ListEvents(ctx context.Context, f EventFilter, p httpapi.ListParams) (httpapi.Page[Event], error)
ListEvents returns one page of events, newest first. The subject manifest is not inlined (§5.3) — use GetEvent for a single event's full subject list.