auth

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package auth provides the role-based access model shared by tie-triplestore and tie-filehost: read/write roles, per-request access classification, and HTTP Basic Auth resolution with constant-time password comparison.

Passwords are stored in plaintext in each server's config (operator-managed secrecy); only the wire comparison is hardened. A Store is read-only after construction and safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access

type Access int

Access classifies a request by the tier it requires.

const (
	AccessRead Access = iota
	AccessWrite
)

type Role

type Role int

Role is an access tier. Roles are totally ordered (RoleNone < RoleRead < RoleWrite) and a higher role subsumes every lower one: write implies read.

const (
	RoleNone Role = iota
	RoleRead
	RoleWrite
)

func ParseAnonAccess

func ParseAnonAccess(s string, def Role) (Role, error)

ParseAnonAccess parses the AnonymousAccess config value — the role granted to a request that presents no valid credentials. An empty string returns def, the per-server default.

func ParseUserRole

func ParseUserRole(s string) (Role, error)

ParseUserRole parses a per-user Role config value. An empty string defaults to RoleWrite so accounts predating roles keep full read+write access.

func (Role) Allows

func (r Role) Allows(a Access) bool

Allows reports whether a role is sufficient for an access level.

type Store

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

Store resolves a request's role from HTTP Basic Auth credentials.

func NewStore

func NewStore(users map[string]User, anon Role) *Store

NewStore builds a Store from a username->User map and the anonymous role granted to unauthenticated or invalid requests.

func (*Store) Authorize

func (s *Store) Authorize(r *http.Request, a Access) (ok bool, status int)

Authorize reports whether a request may perform access a. When it may not, status is the HTTP status to return: 401 when authentication is missing or failed (no credentials, unknown user, wrong password), or 403 when a valid user authenticated but its role is too low.

func (*Store) Require

func (s *Store) Require(a Access, h http.HandlerFunc) http.HandlerFunc

Require wraps h so it runs only when the request satisfies the access level. A 401 rejection carries a Basic-Auth challenge.

func (*Store) Resolve

func (s *Store) Resolve(r *http.Request) Role

Resolve returns the role a request is authorized as (see resolve).

type User

type User struct {
	Password string
	Role     Role
}

User is a resolved account: its plaintext password and granted role.

Jump to

Keyboard shortcuts

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