audit

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 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

Index

Constants

View Source
const (
	ActionArtifactUploaded    = "artifact.uploaded"
	ActionArtifactDeleted     = "artifact.deleted"
	ActionArtifactPromoted    = "artifact.promoted"
	ActionArtifactCopied      = "artifact.copied"
	ActionArtifactMoved       = "artifact.moved"
	ActionArtifactQuarantined = "artifact.quarantined"
	ActionArtifactReleased    = "artifact.released"
	ActionArtifactRestored    = "artifact.restored"
	ActionArtifactPurged      = "artifact.purged"

	ActionRepositoryCreated   = "repository.created"
	ActionRepositoryUpdated   = "repository.updated"
	ActionRepositoryDeleted   = "repository.deleted"
	ActionRepositoryBlocked   = "repository.blocked"
	ActionRepositoryUnblocked = "repository.unblocked"
	ActionRepositoryRestored  = "repository.restored"
	ActionRepositoryPurged    = "repository.purged"

	ActionAuthLogin           = "auth.login"
	ActionAuthLogout          = "auth.logout"
	ActionAuthLoginFailed     = "auth.login_failed"
	ActionAuthTokenCreated    = "auth.token_created" //nolint:gosec // action name, not a credential
	ActionAuthTokenRevoked    = "auth.token_revoked" //nolint:gosec // action name, not a credential
	ActionAuthPasswordChanged = "auth.password_changed"
	ActionAuthSSOLogin        = "auth.sso_login"

	ActionAuthOIDCExchange       = "auth.oidc_exchange"
	ActionAuthOIDCExchangeFailed = "auth.oidc_exchange_failed"

	ActionProjectCreated               = "project.created"
	ActionProjectUpdated               = "project.updated"
	ActionProjectDeleted               = "project.deleted"
	ActionProjectPolicyChanged         = "project.policy_changed"
	ActionProjectQuotaChanged          = "project.quota_changed"
	ActionProjectMemberAdded           = "project.member_added"
	ActionProjectMemberRemoved         = "project.member_removed"
	ActionProjectMemberRoleChanged     = "project.member_role_changed"
	ActionProjectGroupAdded            = "project.group_added"
	ActionProjectGroupRemoved          = "project.group_removed"
	ActionProjectGroupRoleChanged      = "project.group_role_changed"
	ActionProjectTokenCreated          = "project.token_created"
	ActionProjectTokenRevoked          = "project.token_revoked"
	ActionProjectRepositoryCreated     = "project.repository_created"
	ActionProjectRepositoryDeleted     = "project.repository_deleted"
	ActionProjectRepositoryTransferred = "project.repository_transferred"
	ActionProjectCleanupPolicyChanged  = "project.cleanup_policy_changed"

	ActionSystemSettingChanged        = "system.setting_changed"
	ActionSystemStorageBackendChanged = "system.storage_backend_changed"

	ActionScanVulnDetected = "scan.vuln_detected"
	ActionScanVulnResolved = "scan.vuln_resolved"

	ActionBundleCreated  = "bundle.created"
	ActionBundleSealed   = "bundle.sealed"
	ActionBundleArchived = "bundle.archived"
	ActionBundlePromoted = "bundle.promoted"
	// ActionBundleCheckReported records a required external check reported
	// against a release bundle.
	ActionBundleCheckReported = "bundle.check_reported"

	ActionHTTPRequest = "http.request"

	ActionUserCreated  = "user.created"
	ActionUserUpdated  = "user.updated"
	ActionUserDisabled = "user.disabled"
	ActionUserDeleted  = "user.deleted"

	ActionServiceAccountCreated = "service_account.created"
	ActionServiceAccountUpdated = "service_account.updated"
	ActionServiceAccountDeleted = "service_account.deleted"

	ActionOIDCPolicyCreated = "oidc_policy.created"
	ActionOIDCPolicyUpdated = "oidc_policy.updated"
	ActionOIDCPolicyDeleted = "oidc_policy.deleted"

	ActionGroupCreated       = "group.created"
	ActionGroupUpdated       = "group.updated"
	ActionGroupDeleted       = "group.deleted"
	ActionGroupMemberAdded   = "group.member_added"
	ActionGroupMemberRemoved = "group.member_removed"
	ActionGroupMembersSet    = "group.members_set"

	ActionPermissionTargetObjCreated    = "permission_target.created"
	ActionPermissionTargetObjUpdated    = "permission_target.updated"
	ActionPermissionTargetObjDeleted    = "permission_target.deleted"
	ActionPermissionTargetObjAssigned   = "permission_target.assigned"
	ActionPermissionTargetObjUnassigned = "permission_target.unassigned"

	ActionSSOProviderCreated = "sso_provider.created"
	ActionSSOProviderUpdated = "sso_provider.updated"
	ActionSSOProviderDeleted = "sso_provider.deleted"

	ActionTokenCreatedForUser = "token.created_for_user"

	ActionGPGKeyCreated     = "gpg_key.created"
	ActionGPGKeyDeleted     = "gpg_key.deleted"
	ActionGPGKeyActivated   = "gpg_key.activated"
	ActionGPGKeyDeactivated = "gpg_key.deactivated"
	ActionGPGKeyExported    = "gpg_key.exported"

	ActionBackupRestoreStarted = "backup.restore_started"

	ActionCleanupPolicyChanged = "cleanup.policy_changed"
	ActionCleanupRunStarted    = "cleanup.run_started"
	ActionCleanupRunCompleted  = "cleanup.run_completed"

	ActionFederationEnabledChanged = "federation.enabled_changed"
	ActionFederationPeerCreated    = "federation.peer_created"
	ActionFederationPeerUpdated    = "federation.peer_updated"
	ActionFederationPeerDeleted    = "federation.peer_deleted"
	ActionFederationPeerResynced   = "federation.peer_resynced"
	ActionFederationTokenCreated   = "federation.token_created"
	ActionFederationTokenRevoked   = "federation.token_revoked"

	ActionDependencyTrackConfigChanged = "dependency_track.config_changed"
	ActionLicensePolicyChanged         = "license.policy_changed"

	ActionCurationRuleCreated = "curation.rule_created"
	ActionCurationRuleUpdated = "curation.rule_updated"
	ActionCurationRuleDeleted = "curation.rule_deleted"

	ActionVEXFeedCreated         = "vex.feed_created"
	ActionVEXFeedUpdated         = "vex.feed_updated"
	ActionVEXFeedDeleted         = "vex.feed_deleted"
	ActionVEXFeedSynced          = "vex.feed_synced"
	ActionVEXSuggestionAccepted  = "vex.suggestion_accepted"
	ActionVEXSuggestionDismissed = "vex.suggestion_dismissed"
)

Audit action names. The audit_logs.chk_audit_action constraint admits exactly the values in KnownActions; every action an emitter can produce MUST be declared here, listed in KnownActions and allowed by the latest migration that rewrites the constraint (see migrations/007_service_accounts_oidc.sql). The integration test TestKnownActionsAcceptedByDatabase inserts each entry of KnownActions into a freshly migrated database.

View Source
const (
	OutcomeSuccess = "success"
	OutcomeFailure = "failure"
)

Outcome values of AuditEvent.Outcome.

View Source
const (
	Scope     = "openartifact.audit"
	EventName = "openartifact.audit"
)

Scope is the instrumentation scope and EventName the event name of every audit event streamed over OTLP. The name is fixed (the action is an attribute): event names must not carry dynamic values.

Variables

View Source
var KnownActions = []string{}/* 104 elements not displayed */

KnownActions lists every action the server emits. The constraint also still admits retired names (artifact.downloaded, org.*, permission.*, ...) so old rows stay valid.

Functions

func SetDefault

func SetDefault(l *Logger)

func WithRequest added in v0.15.0

func WithRequest(ctx context.Context, req Request) context.Context

WithRequest returns ctx carrying req for Log.

Types

type AuditEvent

type AuditEvent struct {
	Action       string  // required; validated action name (e.g. auth.token_validate)
	ActorType    string  // "user", "system", "token", "sso"
	ActorID      *string // UUID of the user/token
	Actor        string  // human-readable identifier (username, token name) — stored in details_json
	RepositoryID *string
	ResourceType *string
	ResourceID   *string
	ProjectID    *string
	IPAddress    *string
	Details      string // free-text; stored in details_json as {"message": "..."}
	// Package and Version name the package version the event concerns and
	// Subject the display name of what it acted on, captured at emit time so
	// the entry stays readable after the subject is gone. They are stored in
	// details_json as "package", "version" and "subject"; the per-package
	// activity filter matches on the first two.
	Package string
	Version string
	Subject string
	// ViaGroup names the group repository a write came through when it was
	// served by the group's deploy target (the event's repository); stored in
	// details_json as "via_group".
	ViaGroup string
	// Outcome is OutcomeSuccess or OutcomeFailure. Log fills an empty one:
	// failure for a Status of 400 and above, success otherwise (an explicit
	// action records something that happened).
	Outcome string
	// Username is the login name of the authenticated user, TokenID the API
	// token the request authenticated with and RequestID its X-Request-ID.
	// Log fills empty ones from the Request attached to its context.
	Username  string
	TokenID   string
	RequestID string
	// Status is the HTTP status of the request, 0 when the event records none.
	// The five fields above are stored in details_json as "outcome",
	// "username", "token_id", "request_id" and "status", omitted when empty.
	Status int
	// Method and Route are the HTTP method and route pattern of the request,
	// set by the audit middleware on its own events. They are only streamed
	// (http.request.method, http.route): the middleware's message already
	// carries them in details_json.
	Method string
	Route  string
}

AuditEvent is the canonical event type sent to the audit logger. Fields correspond to the audit_logs schema.

type Logger

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

func Default

func Default() *Logger

func NewLogger

func NewLogger(db LoggerStore, log *logger.Logger, reg *metrics.Registry, bufferSize int, opts ...Option) *Logger

func (*Logger) Log

func (l *Logger) Log(ctx context.Context, event AuditEvent)

Log streams an event and enqueues it for the database. It never panics, even after Shutdown. If the buffer is full it waits briefly for room rather than dropping the row at once.

func (*Logger) Shutdown

func (l *Logger) Shutdown(ctx context.Context) error

Shutdown stops accepting events, drains the buffer and waits for the writer. Safe to call more than once.

type LoggerStore added in v0.15.0

type LoggerStore interface {
	InsertAuditLog(ctx context.Context, event *models.AuditLog) error
}

LoggerStore is the part of the database Logger needs.

type Option added in v0.15.0

type Option func(*Logger)

Option configures a Logger.

func WithOTLP added in v0.15.0

func WithOTLP() Option

WithOTLP also streams every event as an OpenTelemetry log event on the Scope logger of the global logger provider (otel.GetLoggerProvider), which telemetry.Setup installs when telemetry.otlp.audit is on. The audit_logs table stays the source of truth: the stream is best effort.

type Request added in v0.15.0

type Request struct {
	ID       string
	Username string
	TokenID  string
}

Request identifies the HTTP request events are recorded under. The audit middleware attaches it to the request context (WithRequest) so the events handlers record carry it without each emitter filling it in.

Jump to

Keyboard shortcuts

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