auth

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 17 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

This section is empty.

Variables

This section is empty.

Functions

func ExtractToken

func ExtractToken(ctx context.Context) string

ExtractToken extracts the authentication token from gRPC metadata. Returns empty string if no token is present.

func StreamServerInterceptor

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

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

func UnaryServerInterceptor

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

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

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 {
	// Disabled indicates if authentication is disabled.
	//
	// When true, all requests are treated as anonymous with full permissions.
	Disabled bool `yaml:"disabled"`
	// 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.

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) Authenticate

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

Authenticate attempts to authenticate the given token using registered authenticators.

Returns the authenticated Principal on success.

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.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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