auth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 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

Index

Constants

View Source
const AdmissionMetadataKey = "x-yanet-admission"

AdmissionMetadataKey is the metadata key that names the admission a call was let in with before it reached a server.

View Source
const TokenMetadataKey = "x-yanet-authentication"

TokenMetadataKey is the metadata key a caller sends its authentication token under.

Variables

This section is empty.

Functions

func ExtractCredential added in v0.1.0

func ExtractCredential(ctx context.Context) core.Credential

ExtractCredential collects what the request presents for authentication: the token from gRPC metadata and the TLS state of the peer connection.

A call let in before it reached the server presents the credential it was let in with instead. Either part is left empty when absent.

func StreamServerInterceptor

func StreamServerInterceptor(manager *Manager, log *zap.Logger) grpc.StreamServerInterceptor

StreamServerInterceptor returns a gRPC stream server interceptor that performs authentication and authorization.

It admits a call as UnaryServerInterceptor does.

func UnaryServerInterceptor

func UnaryServerInterceptor(
	manager *Manager,
	log *zap.Logger,
) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a gRPC unary server interceptor that performs authentication and authorization.

A call that carries an admission runs as the admission's principal, authorized again for the method; any other call is checked on the credential it presents.

func WithCredential added in v0.4.0

func WithCredential(ctx context.Context, credential core.Credential) context.Context

WithCredential records in ctx the credential a call was let in with before it reached the server.

Types

type AuthenticatorConfig

type AuthenticatorConfig struct {
	// Type is the authenticator type name.
	Type string `yaml:"type"`
	// Config is the raw YAML node for type-specific configuration.
	Config yaml.Node `yaml:"config"`
}

AuthenticatorConfig is a generic authenticator configuration entry.

The Type field selects the authenticator factory, and Config holds the type-specific YAML configuration decoded by the factory.

type AuthenticatorFactory

type AuthenticatorFactory func(rawCfg *yaml.Node) (core.Authenticator, error)

AuthenticatorFactory creates an Authenticator from a raw YAML config node.

type Authorizer

type Authorizer interface {
	// Authorize checks if the principal has permission to execute the given
	// method.
	Authorize(
		ctx context.Context,
		principal *core.Principal,
		fullMethod string,
	) error
}

Authorizer is the interface for authorization decisions.

type Config

type Config struct {
	// Mode selects an explicit policy; omission uses legacy input or disabled.
	Mode Mode `yaml:"mode,omitempty"`
	// Disabled is the deprecated input alias for the authentication policy.
	Disabled *bool `yaml:"disabled,omitempty"`
	// IdentityProviders is a list of identity providers (chain of responsibility).
	// First match wins.
	IdentityProviders []IdentityProviderConfig `yaml:"identity_providers"`
	// Authenticators is a list of authenticator configurations.
	//
	// Each entry specifies a type and its type-specific config.
	Authenticators []AuthenticatorConfig `yaml:"authenticators"`
	// PermissionsPath is the path to the permissions YAML file.
	PermissionsPath string `yaml:"permissions_path"`
}

Config is the configuration for authentication and authorization.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default authentication configuration.

func (*Config) Validate added in v0.2.0

func (m *Config) Validate() error

Validate rejects ambiguous policies and unsupported authentication modes.

type IdentityProviderConfig

type IdentityProviderConfig struct {
	// Type is the provider type: "file", "pam" (future), etc.
	Type string `yaml:"type"`
	// Path is the file path (for file-based providers).
	Path string `yaml:"path"`
}

IdentityProviderConfig configures a single identity provider.

type Manager

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

Manager orchestrates authentication and authorization.

func NewManager

func NewManager(cfg *Config, options ...ManagerOption) (*Manager, error)

NewManager creates a new auth Manager.

func (*Manager) Admit added in v0.4.0

func (m *Manager) Admit(
	ctx context.Context,
	credential core.Credential,
	fullMethod string,
) (*core.Principal, string, func(), error)

Admit authenticates and authorizes a call to a method before the call reaches a server, and parks the outcome under a fresh id.

The call carries the id to the server under AdmissionMetadataKey, and the server takes the admission once, as the call's credential and principal. The release forgets an admission no server took, and is safe to call after one did.

func (*Manager) Authenticate

func (m *Manager) Authenticate(
	ctx context.Context,
	credential core.Credential,
	reqInfo *core.RequestInfo,
) (*core.Principal, error)

Authenticate attempts to authenticate the given credential using registered authenticators.

Verification remains strict in audit mode; only RPC admission may fall back to an anonymous identity after a verification failure.

func (*Manager) AuthenticateRequest added in v0.2.0

func (m *Manager) AuthenticateRequest(
	ctx context.Context,
	credential core.Credential,
	requestInfo *core.RequestInfo,
) (*core.Principal, error)

AuthenticateRequest applies the admission policy to strict verification.

Audit admits failed credentials as anonymous; introspection must use strict verification instead.

func (*Manager) Authorize

func (m *Manager) Authorize(
	ctx context.Context,
	principal *core.Principal,
	fullMethod string,
) error

Authorize checks if the principal has permission to execute the given method.

func (*Manager) ClientCAs added in v0.1.0

func (m *Manager) ClientCAs() *x509.CertPool

ClientCAs returns the authorities the x509 authenticator verifies client certificates against, nil when none is configured.

A TLS server asks for the pool on every handshake, so a reload of the authenticator's sources takes effect without a restart.

func (*Manager) Collect added in v0.1.0

func (m *Manager) Collect() []*commonpb.Metric

Collect gathers the metrics of every authenticator that reports any.

func (*Manager) Mode added in v0.4.0

func (m *Manager) Mode() Mode

Mode returns the policy the manager applies, with an omitted mode already resolved from the deprecated input or to disabled.

func (*Manager) TakeAdmission added in v0.4.0

func (m *Manager) TakeAdmission(id string) (core.Credential, *core.Principal, bool)

TakeAdmission takes the admission parked under id, which no later call can take again, and reports whether there was one.

type ManagerOption

type ManagerOption func(*managerOptions)

ManagerOption is a function that configures the Manager.

func WithLog

func WithLog(log *zap.Logger) ManagerOption

WithLog sets the logger for the Manager.

type Mode added in v0.2.0

type Mode string

Mode selects RPC authentication and authorization policy.

const (
	ModeDisabled Mode = "disabled"
	ModeAudit    Mode = "audit"
	ModeEnabled  Mode = "enabled"
)

func (*Mode) UnmarshalText added in v0.2.0

func (m *Mode) UnmarshalText(data []byte) error

UnmarshalText rejects an explicitly empty authentication mode.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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