auth

package
v0.0.0-pre.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DriverTLS is the default TLS authorization driver. It is not compatible with OIDC authentication.
	DriverTLS string = "tls"

	// DriverOpenFGA provides fine-grained authorization. It is compatible with any authentication method.
	DriverOpenFGA string = "openfga"
)

Variables

View Source
var ErrUnknownDriver = fmt.Errorf("Unknown driver")

ErrUnknownDriver is the "Unknown driver" error.

Functions

func WithConfig

func WithConfig(c map[string]any) func(*Opts)

WithConfig can be passed into LoadAuthorizer to pass in driver specific configuration.

Types

type Authorizer

type Authorizer interface {
	Driver() string
	StopService(ctx context.Context) error

	CheckPermission(ctx context.Context, r *http.Request, object Object, entitlement Entitlement) error
}

Authorizer is the primary external API for this package.

func LoadAuthorizer

func LoadAuthorizer(ctx context.Context, driver string, l logger.Logger, certificateFingerprints []string, options ...func(opts *Opts)) (Authorizer, error)

LoadAuthorizer instantiates, configures, and initializes an Authorizer.

type Entitlement

type Entitlement string

Entitlement is a type representation of a permission as it applies to a particular ObjectType.

const (
	// Entitlements that apply to all resources.
	EntitlementCanCreate Entitlement = "can_create"
	EntitlementCanDelete Entitlement = "can_delete"
	EntitlementCanEdit   Entitlement = "can_edit"
	EntitlementCanView   Entitlement = "can_view"
)

type FGA

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

FGA represents an OpenFGA authorizer.

func (*FGA) CheckPermission

func (f *FGA) CheckPermission(ctx context.Context, r *http.Request, object Object, entitlement Entitlement) error

CheckPermission returns an error if the user does not have the given Entitlement on the given Object.

func (*FGA) Driver

func (c *FGA) Driver() string

func (*FGA) StopService

func (f *FGA) StopService(ctx context.Context) error

StopService stops the authorizer gracefully.

type Object

type Object string

Object is a string alias that represents an authorization object. These are formatted strings that uniquely identify an API resource, and can be constructed/deconstructed reliably. An Object is always of the form <ObjectType>:<identifier> where the identifier is a "/" delimited path containing elements that uniquely identify a resource. If the resource is defined at the project level, the first element of this path is always the project. Some example objects would be:

  • `instance:default/c1`: Instance object in project "default" and name "c1".
  • `storage_pool:local`: Storage pool object with name "local".
  • `storage_volume:default/local/custom/vol1`: Storage volume object in project "default", storage pool "local", type "custom", and name "vol1".

func NewObject

func NewObject(objectType ObjectType, identifierElements ...string) (Object, error)

NewObject returns an Object of the given type. The passed in arguments must be in the correct order (as found in the URL for the resource). This function will error if an invalid object type is given, or if the correct number of arguments is not passed in.

func ObjectServer

func ObjectServer() Object

ObjectServer represents a server.

func ObjectUser

func ObjectUser(userName string) Object

ObjectUser represents a user.

func (Object) Elements

func (o Object) Elements() []string

Elements returns the elements that uniquely identify the authorization Object.

func (Object) String

func (o Object) String() string

String implements fmt.Stringer for Object.

func (Object) Type

func (o Object) Type() ObjectType

Type returns the ObjectType of the Object.

type ObjectType

type ObjectType string

ObjectType is a type of resource within the migration manager.

const (
	// ObjectTypeUser represents a user.
	ObjectTypeUser ObjectType = "user"

	// ObjectTypeServer represents a server.
	ObjectTypeServer ObjectType = "server"
)

type Opts

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

Opts is used as part of the LoadAuthorizer function so that only the relevant configuration fields are passed into a particular driver.

type PermissionChecker

type PermissionChecker func(object Object) bool

PermissionChecker is a type alias for a function that returns whether a user has required permissions on an object. It is returned by Authorizer.GetPermissionChecker.

type RequestDetails

type RequestDetails struct {
	Username string
	Protocol string
}

RequestDetails is a type representing an authorization request.

type TLS

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

TLS represents a TLS authorizer.

func (*TLS) CheckPermission

func (t *TLS) CheckPermission(ctx context.Context, r *http.Request, object Object, entitlement Entitlement) error

CheckPermission returns an error if the user does not have the given Entitlement on the given Object.

func (*TLS) Driver

func (c *TLS) Driver() string

func (*TLS) StopService

func (c *TLS) StopService(ctx context.Context) error

StopService is a no-op.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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