identity

package
v0.25.5 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package identity verifies who sent a request and matches that person against access rules. It knows no grant and no repository store: each service turns a principal and a scope into its own claims.

Index

Constants

View Source
const (
	ScopeRead  = "read"
	ScopeWrite = "write"
	// ScopeAdmin lets its principal create a repository. It names no repository.
	ScopeAdmin = "admin"
)

The scopes that a rule gives.

Variables

View Source
var ErrNoPrincipal = errors.New("identity: no verifier accepts the credential")

ErrNoPrincipal is the answer of Chain when no verifier gives a principal.

Functions

func ValidScope

func ValidScope(scope string, repos []string) bool

ValidScope reports whether a human identity may hold scope on repos: read or write on at least one repository, or admin on none.

Types

type Principal

type Principal struct {
	// Subject is the text that rules match exactly.
	Subject string
	// Email is the email claim. Rules match it without case, and only when EmailVerified is true.
	Email         string
	EmailVerified bool
	// Exp is the end of the credential.
	Exp time.Time
}

Principal is a verified person or service.

type Rule

type Rule struct {
	Principals []string `json:"principals"`
	Repos      []string `json:"repos"`
	Scope      string   `json:"scope"`
}

Rule gives Scope on Repos to Principals. A principal is a subject text, or @domain for every verified email of the domain.

type Rules

type Rules []Rule

Rules is an ordered list of rules.

func (Rules) Match

func (rs Rules) Match(p Principal, repo string) (scope string, ok bool)

Match returns the highest scope that the rules give p on repo. repo is empty for a call that names no repository, and only a rule of scope admin answers it. The subject matches exactly. A verified email matches without case, and a @domain principal matches the domain of a verified email.

func (Rules) Validate

func (rs Rules) Validate() error

Validate checks the rules.

type Verifier

type Verifier interface {
	Verify(r *http.Request) (Principal, error)
}

Verifier reads the credential of r. A credential that is missing, forged, expired or revoked answers an error and no principal.

func Chain

func Chain(vs ...Verifier) Verifier

Chain returns a Verifier that answers with the first principal that one of vs gives.

Directories

Path Synopsis
Package identitytest holds the conformance suite of identity.Verifier and a signer of Access JWTs.
Package identitytest holds the conformance suite of identity.Verifier and a signer of Access JWTs.
Package oidc authenticates a request by a signed OIDC JWT from any issuer, and maps a claim of the JWT to a scope on a repository with rules.
Package oidc authenticates a request by a signed OIDC JWT from any issuer, and maps a claim of the JWT to a scope on a repository with rules.
Package usertoken authenticates a request by a per-user token that an administrator issued.
Package usertoken authenticates a request by a per-user token that an administrator issued.

Jump to

Keyboard shortcuts

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