Documentation
¶
Overview ¶
Package relations is the client for auth-api's POST /authz/check-relation (PADR-0035).
The caller's own bearer token is forwarded on every call (PADR-0037, no service tokens), so a check only answers for the user holding that token. Only positive decisions are cached, for a few seconds, so a removal takes effect within positiveTTL and a new grant at once. Any failure to get a decision is an error: session data fails closed (503), never open.
Index ¶
- Variables
- type Client
- func (c *Client) Check(ctx context.Context, user, token, object, relation string) (bool, error)
- func (c *Client) EndSession(ctx context.Context, token, sessionID string) error
- func (c *Client) Mint(ctx context.Context, token string) (string, error)
- func (c *Client) WriteTuples(ctx context.Context, token, sessionID string, writes, deletes []Tuple) error
- type Tuple
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnavailable = errors.New("relations: authorization unavailable") ErrUnauthorized = errors.New("relations: token rejected") // ErrDenied means auth-api refused the change: the caller lacks the relation, or is denied // the service. Callers answer 403. ErrDenied = errors.New("relations: not permitted") // ErrLimited means auth-api's mint or tuple limits stopped the call. Callers answer 429. ErrLimited = errors.New("relations: rate limited") // ErrConflict means auth-api refused the change as conflicting (the session's tuple cap). // Callers answer 409. ErrConflict = errors.New("relations: conflict") // ErrRejected means auth-api answered 400: this service sent a malformed request, so retrying // the same call never helps. Callers answer 500. ErrRejected = errors.New("relations: request rejected as malformed") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls auth-api. The zero value is not usable; use New.
func (*Client) Check ¶
Check reports whether the holder of token has relation on object (for example "session:abc", "can_view"). user is the verified caller ID and only keys the cache; auth-api decides from the token. A deny is (false, nil).
func (*Client) EndSession ¶ added in v0.3.0
EndSession deletes every tuple on the session and closes its mint. Only the GM may.
func (*Client) Mint ¶ added in v0.3.0
Mint asks auth-api for a new session ID and writes the caller's gm tuple on it. The ID comes from auth-api, never from the client (PADR-0040).
func (*Client) WriteTuples ¶ added in v0.3.0
func (c *Client) WriteTuples(ctx context.Context, token, sessionID string, writes, deletes []Tuple) error
WriteTuples applies membership tuple changes on one session in a single atomic write. Writing a tuple that exists and deleting one that does not are no-ops, so a retry is safe.