authentication

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 40 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.

README

Authentication

Session

The session object is always accompanied by a signature. Anything inspecting the session always verifies the signature to ensure that it's an authentic session object.

External API Key Authentication Interceptor

Looks for an 'api' key and creates a corresponding session.

Internal Authenticator

Verifies that a session exists and that is signed by us.

Session Injector

Copies the session from incoming metadata to a local context value. Also injects some log fields from the session into the ctx for logging purposes.s

Interceptor Flow

  1. Request comes in.
  2. SessionManager.LocalContextInjectorInterceptor grabs an IncomingContext.SignedSession => sets it to local context (if it exists).
  3. ExternalApiKeyAuthentication + (any other authentication interceptor) => can create a signed session and inject it into local context.
  4. PermissionInterceptor => inspects local context and must see a signed session. Verifies the signed session! If session is authorized => let it through If session is not authorized => verify permissions => update session + resign => update in local context.
  5. SessionManager.OutgoingContextInjectorInterceptor => grabs the local session and sets it on outgoing context. Perhaps we should be doing this on a client interceptor?
  6. Request is processed by handler.

Documentation

Overview

permission_interceptor.go

Index

Constants

This section is empty.

Variables

View Source
var ErrMethodNotConfigured = errors.New("method not configured")

ErrMethodNotConfigured indicates no CEL rule exists for the requested method.

View Source
var ErrSignedSessionNotFound = errors.New("session not found in context")

Functions

func CompareClientVersion

func CompareClientVersion(session *authenticationpb.Session, major, minor, patch int32) int

CompareClientVersion compares the session's client version against the given major.minor.patch. Returns -1, 0, or 1 if the client version is less than, equal to, or greater than the specified version. Returns -1 if no version is present.

func GetSession

func GetSession(ctx context.Context) (*authenticationpb.Session, error)

func WithAPIKey

func WithAPIKey(ctx context.Context, headerKey, apiKey string) context.Context

Types

type ExternalApiKeyAuthenticationInterceptor

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

func (*ExternalApiKeyAuthenticationInterceptor) Stream

Stream implements the API key authentication stream interceptor.

func (*ExternalApiKeyAuthenticationInterceptor) Unary

Unary implements the API key authentication unary interceptor.

type ExternalApiKeyAuthenticationInterceptorOpts

type ExternalApiKeyAuthenticationInterceptorOpts struct {
	*ExternalApiKeysOpts
}

type ExternalApiKeysOpts

type ExternalApiKeysOpts struct {
	MetadataHeader string `long:"metadata-header" env:"METADATA_HEADER" description:"The header you wish to use for api keys" default:"x-api-key"`
	APIKeys        string `long:"api-keys" env:"API_KEYS" description:"List of service_account_id:api_key pairs" required:"true"`
	Config         string `long:"config" env:"CONFIG" description:"Path to the authentication configuration file" required:"true"`
}

func (*ExternalApiKeysOpts) ParseAPIKey

func (o *ExternalApiKeysOpts) ParseAPIKey(targetServiceAccountID string) (string, error)

func (*ExternalApiKeysOpts) WithAPIKey

func (o *ExternalApiKeysOpts) WithAPIKey(ctx context.Context, apiKey string) context.Context

WithAPIKey creates a new context with the API key set in outgoing metadata.

type InternalServiceAuthenticationInterceptor

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

func (*InternalServiceAuthenticationInterceptor) Stream

Stream implements the internal service authentication stream interceptor.

func (*InternalServiceAuthenticationInterceptor) Unary

Unary implements the internal service authentication unary interceptor.

type InternalServiceAuthenticationInterceptorOpts

type InternalServiceAuthenticationInterceptorOpts struct {
	MetadataHeader        string `` /* 139-byte string literal not displayed */
	InternalServiceSecret string `` /* 129-byte string literal not displayed */
	Config                string `long:"config" env:"CONFIG" description:"Path to the authentication configuration file" required:"true"`
	// contains filtered or unexported fields
}

func (*InternalServiceAuthenticationInterceptorOpts) WithServiceAccount

func (o *InternalServiceAuthenticationInterceptorOpts) WithServiceAccount(
	serviceAccountID string,
) (func(context.Context) context.Context, error)

WithInternalServiceAuth creates a new context with the internal service auth header in the format service_account_id/secret

type JwtAuthenticationInterceptor

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

func NewJwtAuthenticationInterceptor

func NewJwtAuthenticationInterceptor(
	ctx context.Context,
	opts *JwtAuthenticationInterceptorOpts,
	sessionManager *SessionManager,
) (*JwtAuthenticationInterceptor, error)

func (*JwtAuthenticationInterceptor) Stream

func (*JwtAuthenticationInterceptor) Unary

type JwtAuthenticationInterceptorOpts

type JwtAuthenticationInterceptorOpts struct {
	Config     string `long:"config" env:"CONFIG" description:"Path to the JWT authentication configuration file" required:"true"`
	CookieName string `` /* 137-byte string literal not displayed */
}

type JwtMinter

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

func NewJwtMinter

func NewJwtMinter(issuerConfig *authenticationpb.JwtIssuer) (*JwtMinter, error)

func (*JwtMinter) MintJwt

func (m *JwtMinter) MintJwt(opts MintJwtOpts) (string, error)

type MintJwtOpts

type MintJwtOpts struct {
	Subject  string
	Lifetime time.Duration
	Claims   map[string]any
}

type PermissionAuthenticationInterceptor

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

func (*PermissionAuthenticationInterceptor) Stream

Stream implements the authentication stream interceptor. For all stream types, we peek the first client request so that CEL authorization rules can evaluate against it. The only exception is bidi streams, where we pass a nil request to authenticate() because either side may send first so we cannot reliably peek a request.

func (*PermissionAuthenticationInterceptor) Unary

Unary implements the authentication unary interceptor.

type PermissionAuthenticationInterceptorOpts

type PermissionAuthenticationInterceptorOpts struct {
	Config string `long:"config" env:"CONFIG" description:"Path to the authentication configuration file" required:"true"`
}

type SessionManager

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

func NewSessionManager

func NewSessionManager(opts *SessionManagerOpts) *SessionManager

func (*SessionManager) StreamServerLocalContextInjectorInterceptor

func (s *SessionManager) StreamServerLocalContextInjectorInterceptor() grpc.StreamServerInterceptor

StreamServerLocalContextInjectorInterceptor

  1. parses the session from the incoming context
  2. injects it into the local context

func (*SessionManager) StreamServerLogInjectorInterceptor

func (s *SessionManager) StreamServerLogInjectorInterceptor() grpc.StreamServerInterceptor

StreamServerLogInjectorInterceptor injects session fields into the log context for streaming RPCs

func (*SessionManager) StreamServerOutgoingContextInjectorInterceptor

func (s *SessionManager) StreamServerOutgoingContextInjectorInterceptor() grpc.StreamServerInterceptor

StreamServerOutgoingContextInjectorInterceptor

  1. parses the session from the local context
  2. injects it into the outgoing context

func (*SessionManager) UnaryServerLocalContextInjectorInterceptor

func (s *SessionManager) UnaryServerLocalContextInjectorInterceptor() grpc.UnaryServerInterceptor

UnaryServerLocalContextInjectorInterceptor

  1. parses the session from the incoming context
  2. injects it into the local context

func (*SessionManager) UnaryServerLogInjectorInterceptor

func (s *SessionManager) UnaryServerLogInjectorInterceptor() grpc.UnaryServerInterceptor

UnaryServerLogInjectorInterceptor injects session fields into the log context for unary RPCs

func (*SessionManager) UnaryServerOutgoingContextInjectorInterceptor

func (s *SessionManager) UnaryServerOutgoingContextInjectorInterceptor() grpc.UnaryServerInterceptor

UnaryServerOutgoingContextInjectorInterceptor

  1. parses the session from the local context
  2. injects it into the outgoing context

type SessionManagerOpts

type SessionManagerOpts struct {
	Secret string `long:"secret" env:"SECRET" description:"Secret key for signing sessions" required:"true"`
}

Jump to

Keyboard shortcuts

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