Documentation
¶
Overview ¶
Package devsvc is the out-of-process, hot-reloadable sibling of the in-process authz.DevAuthorizer (WS-026 P1b): the dev-manipulable OSS reference behind the authz.Authorizer seam. It ships both halves of one wire protocol:
- Client implements authz.Authorizer by calling a running dev authz service over HTTP — the same seam opaauthz (OPA/PARGS) implements for production, so a service swaps dev↔prod with no code change (server.Config.Authorizer).
- [Handler] serves that protocol from a Store of readable authz.Grants, reusing authz.DevAuthorizer for the decision. The store is HOT-RELOADABLE (edit grants on disk and reload, or PUT them via the admin endpoint) so a developer flips a decision live — "make this method allowed/denied" — with no rebuild or restart.
It is dependency-light (stdlib + authz only) and lives in the root module. Production authz stays OPA/PARGS — this is the dev default, not a policy engine.
Index ¶
Constants ¶
const DefaultAuthorizePath = "/v1/authorize"
DefaultAuthorizePath is the decision endpoint the Client posts to and the Handler serves.
Variables ¶
This section is empty.
Functions ¶
func LoadGrantsFile ¶
LoadGrantsFile reads a YAML (or JSON — YAML is a superset) list of authz.Grant from path. It is the on-disk form a developer edits to manipulate dev authorization; YAML is the friendlier hand-edited default.
Example grants.yaml:
- tenant: tenant-a subjects: [group:admin] verbs: ["*"] resource: "*"
- tenant: "*" subjects: [group:viewer] verbs: [get, list] resource: order
The keys are lowercase snake_case (see authz.Grant's struct tags) and are identical whether the file is written as YAML or JSON.
func NewHandler ¶
func NewHandler(store *Store, opts ...HandlerOptions) http.Handler
NewHandler serves the dev authz protocol from store. POST <AuthorizePath> decides one request; when EnableAdmin, PUT <AdminPath> replaces the grants (body: JSON array of authz.Grant) so a developer flips decisions live.
func WatchGrantsFile ¶
func WatchGrantsFile(ctx context.Context, path string, store *Store, interval time.Duration, onErr func(error)) error
WatchGrantsFile reloads store from path whenever the file's modification time changes, polling every interval (zero-dependency hot-reload — no fsnotify). It loads once immediately, then runs until ctx is cancelled. A load error after the initial load is passed to onErr (if non-nil) and the last-good grants are kept — a bad edit never takes the service down. Returns the initial load error so a caller can fail fast on a broken file at startup.
Types ¶
type Client ¶
type Client struct {
// BaseURL is the dev authz service root (e.g. "http://127.0.0.1:8090").
BaseURL string
// AuthorizePath overrides DefaultAuthorizePath.
AuthorizePath string
// HTTP is the client used; nil defaults to http.DefaultClient.
HTTP *http.Client
}
Client is an authz.Authorizer that decides by calling a running dev authz service. It is the dev-time stand-in for opaauthz: the same seam, a different backend. Fail-closed: any transport/decode error denies.
type HandlerOptions ¶
type HandlerOptions struct {
// AuthorizePath overrides DefaultAuthorizePath.
AuthorizePath string
// EnableAdmin mounts a PUT <AuthorizePath>/../grants endpoint that replaces the
// grant set live (dev-manipulability via API). Off by default — the endpoint is
// unauthenticated and dev-only.
EnableAdmin bool
// AdminPath overrides the admin grants endpoint path (default "/v1/grants").
AdminPath string
}
HandlerOptions configures NewHandler.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds the dev authz service's readable authz.Grants behind the decision engine, swappable atomically for hot-reload. Safe for concurrent use.
func (*Store) Authorize ¶
Authorize applies the current grants (implements authz.Authorizer too, so the Store is usable in-process as well as behind the Handler).