audit

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write added in v1.1.8

func Write(event string, fields map[string]string) error

Write appends a structured JSON entry to the security audit log. event is a machine-readable event type (e.g. "plugin-install-bypass"). fields contains any key/value pairs relevant to the event. A "timestamp" key is always added automatically; callers must not include it. The file is created with 0600 permissions if it does not exist.

Types

type AuditConfig added in v1.1.1

type AuditConfig struct {
	// ProjectRoot is the nSelf project directory. When empty, RunTableAudit walks
	// up from cwd looking for .nself/ or docker-compose.yml.
	ProjectRoot string
	// FilterTable, when non-empty, audits only the named table.
	FilterTable string
}

AuditConfig configures a RunTableAudit call.

type AuditReport added in v1.1.1

type AuditReport struct {
	// AuditAt is the UTC timestamp of the audit run.
	AuditAt string `json:"audit_at"`
	// Tables contains one entry per np_* table found in the public schema.
	Tables []TableAuditResult `json:"tables"`
}

AuditReport is the top-level JSON structure emitted by RunTableAudit.

func RunTableAudit added in v1.1.1

func RunTableAudit(ctx context.Context) (*AuditReport, error)

RunTableAudit connects to Postgres using NSELF_DB_URL (fallback: DATABASE_URL) and returns an AuditReport for every np_* table in the public schema.

ctx is forwarded to every DB call. The function adds a 30-second timeout around the total audit run to keep the doctor check bounded.

func RunTableAuditWithConfig added in v1.1.1

func RunTableAuditWithConfig(ctx context.Context, cfg AuditConfig) (*AuditReport, error)

RunTableAuditWithConfig is RunTableAudit with an explicit AuditConfig.

type HasuraFilterStatus added in v1.1.1

type HasuraFilterStatus string

HasuraFilterStatus represents the result of checking Hasura metadata.

const (
	// HasuraFilterPresent means source_account_id filter was found in select_permissions.
	HasuraFilterPresent HasuraFilterStatus = "present"
	// HasuraFilterMissing means no source_account_id filter was found.
	HasuraFilterMissing HasuraFilterStatus = "missing"
	// HasuraFilterUnknown means Hasura metadata was not found or could not be parsed.
	HasuraFilterUnknown HasuraFilterStatus = "unknown"
)

type TableAuditResult added in v1.1.1

type TableAuditResult struct {
	// Table is the table name (e.g. "np_chat_conversations").
	Table string `json:"table"`
	// HasSourceAccountID reports whether source_account_id exists in the table.
	HasSourceAccountID bool `json:"has_source_account_id"`
	// HasHasuraFilter reports whether Hasura metadata contains a source_account_id
	// filter for this table. "present", "missing", or "unknown" (metadata not found).
	HasHasuraFilter HasuraFilterStatus `json:"has_hasura_filter"`
	// TotalRows is the row count across all source_account_id values.
	TotalRows int64 `json:"total_rows"`
	// Accounts maps source_account_id → row count. Nil when HasSourceAccountID is false.
	Accounts map[string]int64 `json:"accounts,omitempty"`
	// Warning is non-empty when a problem is detected (missing column or multi-account).
	Warning string `json:"warning,omitempty"`
}

TableAuditResult holds the audit result for a single table.

Jump to

Keyboard shortcuts

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