authz

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClaimsFromStruct added in v0.1.11

func ClaimsFromStruct(s any) map[string]any

ClaimsFromStruct converts a struct (or pointer to struct) into a map used as OPA `input.claims`. Key resolution order per field:

  1. `authz:"<key>"` struct tag (JWT claim key from manifest.auth.claims config)
  2. fallback: snake_case version of field name

"ID"(tag:user_id) → "user_id"; "OrgID"(no tag) → "org_id"; "Role" → "role".

func Init

func Init(db *sql.DB, ownerships []OwnershipMapping) error

Init initializes the global authz state. OPA policy source resolution:

  1. OPA_POLICY_PATH env — file or directory (directory loads all *.rego)
  2. fallback: ./internal/authz, ./authz, ./policy (first existing directory)

DISABLE_AUTHZ=1 전체 skip.

Types

type CheckRequest

type CheckRequest struct {
	Action     string
	Resource   string
	UserID     int64
	Role       string
	ResourceID int64
	Claims     map[string]any
}

CheckRequest holds the inputs for an authorization check.

Claims map (when non-nil) passes arbitrary JWT claims to OPA under input.claims. When nil, Check() falls back to {"user_id": UserID, "role": Role} for backward compat. Generator is expected to populate Claims from CurrentUser fields per manifest.auth.claims config.

type CheckResponse

type CheckResponse struct{}

CheckResponse is the result of an authorization check.

func Check

func Check(req CheckRequest) (CheckResponse, error)

Check evaluates the OPA policy. Returns error if denied or evaluation fails. Set DISABLE_AUTHZ=1 to bypass authorization checks.

type OwnershipMapping

type OwnershipMapping struct {
	Resource string // "gig", "proposal"
	Table    string // "gigs", "proposals"
	Column   string // "client_id", "freelancer_id"
}

OwnershipMapping represents a resource-to-table ownership mapping from @ownership annotations.

Jump to

Keyboard shortcuts

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