auth

package
v0.2.37 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package auth emulates altengine's data-plane authentication: a Bearer API key resolves to an org + a grants map. For local development the emulator runs "dev-open": any non-empty Bearer token is accepted and mapped to the single dev org with full grants on every service. Explicitly minted keys (via the admin console) are still honored with their real grants so a developer can exercise grant-scoping locally.

Index

Constants

View Source
const DevOrgID = "dev"

Variables

This section is empty.

Functions

func Bearer

func Bearer(r *http.Request) string

Bearer extracts the bearer token from a request, or "".

func CarryOnBehalf added in v0.2.34

func CarryOnBehalf(from, to context.Context) context.Context

CarryOnBehalf copies the on-behalf grants of `from`, if any, onto `to` — for a handler that re-dispatches a request in process.

func Require

func Require(id *Identity, service, instance string, need Level) error

Require enforces that the identity's grant for (service, instance) meets need.

func WithOnBehalfGrants added in v0.2.34

func WithOnBehalfGrants(ctx context.Context, g Grants) context.Context

WithOnBehalfGrants marks an in-process request as made for a caller whose grants are narrower than the bearer it carries — a function's env.* binding, whose grants were checked before the request was built. It rides the request context, so nothing outside the process can set it.

Types

type Grants

type Grants map[string]string

Grants maps "service", "service:prefix*" or "service:instance" to a level string.

func (Grants) Effective

func (g Grants) Effective(service, instance string) Level

Effective returns the level for (service, instance), resolved as hosted altengine does: the exact instance entry, else the longest "service:prefix*" entry the name starts with (`*` matches zero or more characters), else the service-wide entry. The most specific entry wins even when it is lower.

type Identity

type Identity struct {
	OrgID  string
	Grants Grants
}

Identity is a resolved caller.

type Level

type Level int

Level is a grant level; read < write < full (full includes delete).

const (
	None Level = iota
	Read
	Write
	Full
)

func EffectiveLevel added in v0.2.34

func EffectiveLevel(r *http.Request, id *Identity, service, instance string) Level

EffectiveLevel is the level a request really holds on (service, instance): the identity's grant, narrowed by the grants of whoever it was made on behalf of. For a handler whose OUTCOME depends on the level beyond the one Require already checked.

type Store

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

Store holds minted API keys (hash -> Identity) for the realism path. Dev-open mode resolves unknown tokens to full access rather than rejecting them.

func NewStore

func NewStore(devOpen bool) *Store

func (*Store) AddKey

func (s *Store) AddKey(plaintext string, grants Grants)

AddKey registers a minted key's plaintext with its grants.

func (*Store) RemoveKey

func (s *Store) RemoveKey(plaintext string)

RemoveKey revokes a minted key by plaintext.

func (*Store) Resolve

func (s *Store) Resolve(r *http.Request) (*Identity, error)

Resolve turns a request's Authorization into an Identity. Missing token -> 401. A minted key resolves to its grants; any other non-empty token resolves to full access in dev-open mode, else 401.

Jump to

Keyboard shortcuts

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