principal

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package principal interprets who an authenticated caller is.

Index

Constants

View Source
const (
	// APIKeyIDExtra and APIKeyNameExtra carry the non-secret credential
	// attribution established by the API-key authenticator. Downstream code
	// must use APIKeyAttributionFromUser instead of interpreting these values.
	APIKeyIDExtra   = "api_key_id"
	APIKeyNameExtra = "api_key_name"
	// APIKeyRawNameExtra preserves the actual name separately from the audit display fallback.
	APIKeyRawNameExtra = "api_key_raw_name"
)
View Source
const (
	// UserStatusExtra carries the lifecycle status of the user a principal acts for, as its authenticator read it
	// from the gateway database. Code must use RecordUserStatus and
	// UserStatus instead of this key.
	UserStatusExtra = "obot_user_status"
)

Variables

This section is empty.

Functions

func AdmittedActiveUser added in v0.27.0

func AdmittedActiveUser(ctx context.Context, userID string) bool

AdmittedActiveUser reports whether ctx carries an admitted principal that acts for the user with userID, and that user was active when the request arrived. A principal acts for its own user.

func MaskedAPIKeyName

func MaskedAPIKeyName(userID string, keyID uint) string

MaskedAPIKeyName returns the non-secret identifier for an API key.

func RecordUserStatus added in v0.27.0

func RecordUserStatus(extra map[string][]string, status types.UserStatus)

RecordUserStatus records the lifecycle status of the user a principal acts for. It always replaces any value already in extra, so that no auth provider can supply one.

func UserStatus added in v0.27.0

func UserStatus(user kuser.Info) (types.UserStatus, bool)

UserStatus returns the lifecycle status recorded on a principal, and whether its authenticator recorded one.

func WithAdmittedPrincipal added in v0.27.0

func WithAdmittedPrincipal(ctx context.Context, user kuser.Info) context.Context

WithAdmittedPrincipal returns ctx carrying the principal of a request that the admission check let through. Work done for the request can then trust the lifecycle status recorded on the principal.

Types

type APIKeyAttribution

type APIKeyAttribution struct {
	ID   uint
	Name string
}

APIKeyAttribution identifies the API key that authenticated a request.

func APIKeyAttributionFromUser

func APIKeyAttributionFromUser(user kuser.Info) (APIKeyAttribution, bool)

APIKeyAttributionFromUser returns the API key that authenticated a caller. A missing or malformed ID means the caller did not authenticate with an API key. The authenticator supplies a display name, including the masked fallback for an unnamed key; an empty name indicates a legacy or malformed principal.

func NewAPIKeyAttribution

func NewAPIKeyAttribution(id, ownerUserID uint, name string) APIKeyAttribution

NewAPIKeyAttribution creates event-time display attribution for an API key. Unnamed keys use the reconstructable, non-secret masked key identifier so audit consumers never need to join back to the API-key table to label them.

Jump to

Keyboard shortcuts

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