auth

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IngestBatchesCreateAttr         = "ingest:batches:create"
	IngestBatchesListAttr           = "ingest:batches:list"
	IngestBatchesReadAttr           = "ingest:batches:read"
	IngestSIPSCreateAttr            = "ingest:sips:create"
	IngestSIPSDownloadAttr          = "ingest:sips:download"
	IngestSIPSListAttr              = "ingest:sips:list"
	IngestSIPSReadAttr              = "ingest:sips:read"
	IngestSIPSReviewAttr            = "ingest:sips:review"
	IngestSIPSUploadAttr            = "ingest:sips:upload"
	IngestSIPSWorkflowsListAttr     = "ingest:sips:workflows:list"
	IngestSIPSourcesObjectsListAttr = "ingest:sipsources:objects:list"
	IngestUsersListAttr             = "ingest:users:list"
	StorageAIPSCreateAttr           = "storage:aips:create"
	StorageAIPSDeletionReportAttr   = "storage:aips:deletion:report"
	StorageAIPSDeletionRequestAttr  = "storage:aips:deletion:request"
	StorageAIPSDeletionReviewAttr   = "storage:aips:deletion:review"
	StorageAIPSDownloadAttr         = "storage:aips:download"
	StorageAIPSListAttr             = "storage:aips:list"
	StorageAIPSMoveAttr             = "storage:aips:move"
	StorageAIPSReadAttr             = "storage:aips:read"
	StorageAIPSReviewAttr           = "storage:aips:review"
	StorageAIPSSubmitAttr           = "storage:aips:submit"
	StorageAIPSWorkflowsListAttr    = "storage:aips:workflows:list"
	StorageLocationsAIPSListAttr    = "storage:locations:aips:list"
	StorageLocationsCreateAttr      = "storage:locations:create"
	StorageLocationsListAttr        = "storage:locations:list"
	StorageLocationsReadAttr        = "storage:locations:read"
)
View Source
const TicketTTL = time.Second * 5

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")
View Source
var ErrUnauthorized error = errors.New("unauthorized")

Functions

func WithUserClaims

func WithUserClaims(ctx context.Context, claims *Claims) context.Context

WithUserClaims puts the user claims into the current context.

Types

type Claims

type Claims struct {
	Email         string `json:"email,omitempty"`
	EmailVerified bool   `json:"email_verified,omitempty"`
	Name          string `json:"name,omitempty"`
	Iss           string `json:"iss,omitempty"`
	Sub           string `json:"sub,omitempty"`
	// The attributes are parsed from a configured claim and added here,
	// they are needed in the JSON representation for the MarshalBinary and
	// UnmarshalBinary methods below. We use the `enduro_internal_attributes`
	// JSON key to reduce the possibility of a conflict when the JWT is parsed.
	Attributes []string `json:"enduro_internal_attributes,omitempty"`
}

func UserClaimsFromContext

func UserClaimsFromContext(ctx context.Context) *Claims

UserClaimsFromContext returns the user claims from the context. A nil value is returned if they are not found.

func (*Claims) CheckAttributes

func (c *Claims) CheckAttributes(required []string) bool

CheckAttributes verifies all required attributes are present in the claim attributes. It always verifies if the claim is nil (authentication disabled) or the attributes are nil (access control disabled). Attributes are verified by exact match or by having an ancestor with wildcard. For example, a claim with "*" or "ingest:*" as one of it's attributes will verify all ingest actions, like "ingest:sips:list", "ingest:sips:read", etc.

func (*Claims) MarshalBinary added in v0.16.0

func (c *Claims) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler for Redis compatibility.

func (*Claims) UnmarshalBinary added in v0.16.0

func (c *Claims) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler for Redis compatibility.

type Config

type Config struct {
	Enabled bool
	OIDC    *OIDCConfig
	Ticket  *TicketConfig
}

func (Config) Validate

func (c Config) Validate() error

Validate implements config.ConfigurationValidator.

type InMemKey

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

type InMemStore

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

func NewInMemStore

func NewInMemStore() *InMemStore

func (*InMemStore) Close

func (s *InMemStore) Close() error

func (*InMemStore) GetDel

func (s *InMemStore) GetDel(ctx context.Context, key string, value any) error

func (*InMemStore) SetEx

func (s *InMemStore) SetEx(ctx context.Context, key string, value any, ttl time.Duration) error

type NoopTokenVerifier

type NoopTokenVerifier struct{}

func (*NoopTokenVerifier) Verify

func (t *NoopTokenVerifier) Verify(ctx context.Context, token string) (*Claims, error)

type OIDCABACConfig

type OIDCABACConfig struct {
	Enabled            bool
	ClaimPath          string
	ClaimPathSeparator string
	ClaimValuePrefix   string
	UseRoles           bool
	RolesMapping       map[string][]string
}

type OIDCConfig

type OIDCConfig struct {
	ProviderURL            string
	ClientID               string
	SkipEmailVerifiedCheck bool

	// Attribute Based Access Control configuration.
	ABAC OIDCABACConfig
}

type OIDCTokenVerifier

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

func NewOIDCTokenVerifier

func NewOIDCTokenVerifier(ctx context.Context, cfg *OIDCConfig) (*OIDCTokenVerifier, error)

func (*OIDCTokenVerifier) Verify

func (t *OIDCTokenVerifier) Verify(ctx context.Context, token string) (*Claims, error)

type RedisConfig

type RedisConfig struct {
	Address string
	Prefix  string
}

type RedisStore

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

RedisStore is an implementation of TicketStore based on Redis.

func NewRedisStore

func NewRedisStore(ctx context.Context, tp trace.TracerProvider, cfg *RedisConfig) (*RedisStore, error)

func (*RedisStore) Close

func (s *RedisStore) Close() error

func (*RedisStore) GetDel

func (s *RedisStore) GetDel(ctx context.Context, key string, value any) error

func (*RedisStore) SetEx

func (s *RedisStore) SetEx(ctx context.Context, key string, value any, ttl time.Duration) error

type TicketConfig

type TicketConfig struct {
	Redis *RedisConfig
}

type TicketProvider

type TicketProvider interface {
	// Request requests a new ticket saving the key/value pair in the store.
	Request(ctx context.Context, value any) (string, error)
	// Check checks that a ticket is known to the provider and scan its value,
	// not including tickets that exceeded the time-to-live attribute.
	Check(ctx context.Context, ticket *string, value any) error
	// Close closes the provider, releasing resources associated to the store.
	Close() error
}

TicketProvider issues tickets used for authentication cookies.

func NewTicketProvider

func NewTicketProvider(ctx context.Context, store TicketStore, rander io.Reader) TicketProvider

NewTicketProvider creates a new TicketProvider. The provider is no-op when the store is nil.

type TicketStore

type TicketStore interface {
	// SetEx persists a key/value pair with a timeout.
	SetEx(ctx context.Context, key string, value any, ttl time.Duration) error
	// GetDel checks whether a key exists in the store and scans the value.
	// It returns ErrKeyNotFound if the key was not found or expired.
	GetDel(ctx context.Context, key string, value any) error
	// Close the client.
	Close() error
}

TicketStore persists expirable tickets.

type TokenVerifier

type TokenVerifier interface {
	Verify(ctx context.Context, token string) (*Claims, error)
}

Directories

Path Synopsis
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.

Jump to

Keyboard shortcuts

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