Documentation
¶
Overview ¶
Package auth contains the authentication logic for the control plane
Index ¶
- Constants
- Variables
- func DeleteAccessToken(ctx context.Context, provider string, token string) error
- func GetUserForGitHubId(ctx context.Context, idClient Resolver, ghUser int64) (string, error)
- func NewProviderHttpClient(provider string) *http.Client
- func WithIdentityContext(ctx context.Context, identity *Identity) context.Context
- type AccountEvent
- type AdminEvent
- type Identity
- type IdentityClient
- func (c *IdentityClient) Register(p IdentityProvider) error
- func (c *IdentityClient) RegisterAlias(aliasURL string, p IdentityProvider) error
- func (c *IdentityClient) Resolve(ctx context.Context, id string) (*Identity, error)
- func (c *IdentityClient) ResolveFederated(ctx context.Context, federatedIdP, id string) (*Identity, error)
- func (c *IdentityClient) Validate(ctx context.Context, token jwt.Token) (*Identity, error)
- type IdentityManager
- type IdentityProvider
- type NoopIdentityManager
- func (*NoopIdentityManager) DeleteUser(_ context.Context, _ string) error
- func (*NoopIdentityManager) GetAdminEvents(_ context.Context, _, _ []string) ([]AdminEvent, error)
- func (*NoopIdentityManager) GetEvents(_ context.Context) ([]AccountEvent, error)
- func (*NoopIdentityManager) Resolve(_ context.Context, _ string) (*Identity, error)
- func (*NoopIdentityManager) ResolveFederated(_ context.Context, _, _ string) (*Identity, error)
- func (*NoopIdentityManager) String() string
- func (*NoopIdentityManager) URL() url.URL
- func (*NoopIdentityManager) Validate(_ context.Context, _ jwt.Token) (*Identity, error)
- type Resolver
Constants ¶
const (
// DeleteAccountEvent represents a user deletion event
DeleteAccountEvent = "DELETE_ACCOUNT"
)
const (
// Github OAuth2 provider
Github = "github"
)
Variables ¶
var ErrNotFound = errors.New("user not found in identity store")
ErrNotFound is returned when an identity cannot be resolved because it doesn't exist.
var OAuthSuccessHtml []byte
OAuthSuccessHtml is the html page sent to the client upon successful enrollment via CLI
Functions ¶
func DeleteAccessToken ¶
DeleteAccessToken deletes the access token for a given provider
func GetUserForGitHubId ¶
GetUserForGitHubId looks up a user in the identity provider by their GitHub ID.
If the user is found, it returns their subject suitable for use in the `sub` claim of a JWT, and in OpenFGA's user field. Note that this function may return a user of "" with no error if no users were found matching the GitHub ID.
func NewProviderHttpClient ¶
NewProviderHttpClient creates a new http client for the given provider
Types ¶
type AccountEvent ¶ added in v0.2.0
AccountEvent is a generic user account event
type AdminEvent ¶ added in v0.2.0
AdminEvent is a generic administrative event
type Identity ¶
type Identity struct {
// UserID is a stable unique identifier for the user. This may be a large
// integer or a UUID, rather than something human-readable.
//
// For KeyCloak, this is `sub`.
UserID string
// HumanName is a human-readable name. Because humans are fickle, these may
// not be unique or stable over time, though they should be unique at any
// particular time. For example, Alex may change their handle from
// "alexsmith" to "alexawesome" after a life change, and someone else might
// enroll the "alexsmith" handle. If you are storing data, you want UserID,
// not HumanName. If you are presenting data, you probably want HumanName.
//
// For KeyCloak, this is `preferred_username`. For some other providers,
// this might be an email address.
HumanName string
// Provider is the identity provider that vended this identity. Note that
// UserID and HumanName are only unique within the context of a single
// identity provider.
Provider IdentityProvider
// FirstName and LastName are optional fields that may be provided by the
// identity provider. These are not guaranteed to be present, and may be
// empty.
FirstName string
LastName string
}
Identity represents a particular user's identity in a particular trust domain (represented by an IdentityProvider).
func IdentityFromContext ¶ added in v0.0.84
IdentityFromContext retrieves the caller's identity from the context. This may return `nil` or an empty Identity if the user is not authenticated.
type IdentityClient ¶
type IdentityClient struct {
// contains filtered or unexported fields
}
IdentityClient supports the ability to look up identities in one or more IdentityProviders.
func NewIdentityClient ¶
func NewIdentityClient(providers ...IdentityProvider) (*IdentityClient, error)
NewIdentityClient creates a new IdentityClient with the supplied providers.
func (*IdentityClient) Register ¶
func (c *IdentityClient) Register(p IdentityProvider) error
Register registers a new identity provider with the client.
func (*IdentityClient) RegisterAlias ¶ added in v0.2.0
func (c *IdentityClient) RegisterAlias(aliasURL string, p IdentityProvider) error
RegisterAlias registers an additional URL mapping for an existing provider. This is useful when the IDP is reachable at different URLs from the server vs the client (e.g. http://keycloak:8080 internally vs http://localhost:8081 externally). Tokens with `iss` matching the alias URL will be routed to the specified provider.
func (*IdentityClient) ResolveFederated ¶ added in v0.2.0
func (c *IdentityClient) ResolveFederated(ctx context.Context, federatedIdP, id string) (*Identity, error)
ResolveFederated implements Resolver.
type IdentityManager ¶ added in v0.2.0
type IdentityManager interface {
IdentityProvider
// DeleteUser deletes a user from the identity provider
DeleteUser(ctx context.Context, userID string) error
// GetEvents returns account events from the identity provider
GetEvents(ctx context.Context) ([]AccountEvent, error)
// GetAdminEvents returns administrative events from the identity provider
GetAdminEvents(ctx context.Context, operationTypes, resourceTypes []string) ([]AdminEvent, error)
}
IdentityManager provides an abstract interface for administrative identity operations.
type IdentityProvider ¶
type IdentityProvider interface {
Resolver
// String returns the name of the identity provider. This should be a short
// one-word string suitable for presentation. As a special case, a _single_
// provider may use the empty string as its name to act as a default / fallback
// provider.
String() string
// URL returns the `iss` URL of the identity provider.
URL() url.URL
}
IdentityProvider provides an abstract interface for looking up identities in a remote identity provider.
type NoopIdentityManager ¶ added in v0.2.0
type NoopIdentityManager struct{}
NoopIdentityManager is a no-op implementation of the IdentityManager interface
func NewNoopIdentityManager ¶ added in v0.2.0
func NewNoopIdentityManager() *NoopIdentityManager
NewNoopIdentityManager creates a new NoopIdentityManager
func (*NoopIdentityManager) DeleteUser ¶ added in v0.2.0
func (*NoopIdentityManager) DeleteUser(_ context.Context, _ string) error
DeleteUser is a no-op implementation of DeleteUser
func (*NoopIdentityManager) GetAdminEvents ¶ added in v0.2.0
func (*NoopIdentityManager) GetAdminEvents(_ context.Context, _, _ []string) ([]AdminEvent, error)
GetAdminEvents is a no-op implementation of GetAdminEvents
func (*NoopIdentityManager) GetEvents ¶ added in v0.2.0
func (*NoopIdentityManager) GetEvents(_ context.Context) ([]AccountEvent, error)
GetEvents is a no-op implementation of GetEvents
func (*NoopIdentityManager) Resolve ¶ added in v0.2.0
Resolve always returns an error as noop manager cannot resolve identities
func (*NoopIdentityManager) ResolveFederated ¶ added in v0.2.0
ResolveFederated always returns an error as noop manager cannot resolve identities
func (*NoopIdentityManager) String ¶ added in v0.2.0
func (*NoopIdentityManager) String() string
String returns the name of the identity manager
func (*NoopIdentityManager) URL ¶ added in v0.2.0
func (*NoopIdentityManager) URL() url.URL
URL returns an empty URL
type Resolver ¶
type Resolver interface {
// Validate validates a token and returns an underlying identity representation
// suitable for use in authz calls. This _probably_ reads data from the token,
// but could fetch from an external provider.
Validate(ctx context.Context, token jwt.Token) (*Identity, error)
// Resolve takes either a human-readable identifier or a stable identifier and
// returns the underlying identity. This may involve looking up or defining
// the identity in the remote identity provider.
//
// For Keycloak + GitHub, this may define a new user in Keycloak based on
// GitHub user data if the user is not already known to Keycloak.
Resolve(ctx context.Context, id string) (*Identity, error)
// ResolveFederated takes a federated identity provider and a stable identifier
// within that provider and returns the underlying identity. This is used
// to look up users by their linked third-party accounts (e.g. GitHub ID).
ResolveFederated(ctx context.Context, federatedIdP, id string) (*Identity, error)
}
Resolver is an interface for resolving human-readable or stable identifiers from either JWTs or stored strings
Directories
¶
| Path | Synopsis |
|---|---|
|
Package githubactions provides an implementation of the GitHub IdentityProvider.
|
Package githubactions provides an implementation of the GitHub IdentityProvider. |
|
Package jwt provides the logic for reading and validating JWT tokens
|
Package jwt provides the logic for reading and validating JWT tokens |
|
dynamic
Package dynamic provides the logic for reading and validating JWT tokens using a JWKS URL from the token's `iss` claim.
|
Package dynamic provides the logic for reading and validating JWT tokens using a JWKS URL from the token's `iss` claim. |
|
merged
Package merged provides the logic for reading and validating JWT tokens
|
Package merged provides the logic for reading and validating JWT tokens |
|
mock
Package mock_jwt is a generated GoMock package.
|
Package mock_jwt is a generated GoMock package. |
|
noop
Package noop provides a no-op implementation of the Validator interface
|
Package noop provides a no-op implementation of the Validator interface |
|
Package keycloak provides an implementation of the Keycloak IdentityProvider.
|
Package keycloak provides an implementation of the Keycloak IdentityProvider. |
|
client
Package client provides primitives to interact with the openapi HTTP API.
|
Package client provides primitives to interact with the openapi HTTP API. |
|
Package mock_auth is a generated GoMock package.
|
Package mock_auth is a generated GoMock package. |