Documentation
¶
Overview ¶
Package identity holds the use cases of the identity context: the auth providers an instance admin configures and, as they arrive, the sign-ins, identities and directory provisioning built on them.
Index ¶
- Variables
- type ACSCommand
- type AccessChange
- type AccessCommand
- type AdoptUser
- type AttemptStore
- type AuditLog
- type CallbackCommand
- type CompleteACS
- type CompleteCallback
- type CompleteCertificateRotation
- type CompleteCommand
- type CompleteSignIn
- type CreateProvider
- type CreateProviderCommand
- type CreateSCIMGroup
- type CreateSCIMToken
- type CreateSCIMTokenCommand
- type CreateSCIMUser
- type CreatedSCIMToken
- type DeleteProvider
- type DeleteSCIMGroup
- type DeleteSCIMUser
- type DisableProvider
- type EnableProvider
- type FailureCode
- type GetGroupMappings
- type GetProvider
- type GetSCIMGroup
- type GetSCIMUser
- type GroupClaim
- type GroupMappingDeps
- type GroupMappingsList
- type GroupMappingsRun
- type GroupPage
- type GroupRef
- type HeldMember
- type LinkStore
- type LinkedIdentity
- type ListEnabledProviders
- type ListMemberAuthMethods
- type ListProviderSCIMGroups
- type ListProviders
- type ListSCIMGroups
- type ListSCIMTokens
- type ListSCIMUsers
- type MappingStore
- type MemberAuthMethods
- type MemberRecord
- type Members
- type MetadataRefreshDeps
- type MetadataRefreshStore
- type MetadataRefreshed
- type OIDCClient
- type OIDCConfig
- type OIDCDiscoverer
- type OIDCDiscovery
- type Opener
- type Page
- type PatchSCIMGroup
- type PatchSCIMUser
- type ProjectDirectory
- type ProviderAccess
- type ProviderCommand
- type ProviderDeps
- type ProviderRef
- type ProviderReference
- type ProviderSettings
- type ProviderStore
- type ProviderTested
- type ProvisionUser
- type ProvisionedMember
- type RefreshMetadata
- type ReplaceGroupMappings
- type ReplaceGroupMappingsCommand
- type ReplaceSCIMGroup
- type ReplaceSCIMUser
- type ReplayStore
- type RevokeSCIMToken
- type RotateCertificate
- type SAMLAssertion
- type SAMLClient
- type SAMLConfig
- type SAMLMetadataReader
- type SCIMAuthenticator
- type SCIMCaller
- type SCIMGroupDeps
- type SCIMGroupRecord
- type SCIMGroupStore
- type SCIMGroupSummary
- type SCIMMembers
- type SCIMRequest
- type SCIMTokenDeps
- type SCIMTokenRecord
- type SCIMTokenStore
- type SCIMUserDeps
- type SPKeyGenerator
- type SealedSCIMToken
- type Sealer
- type ServeMetadata
- type SessionRequest
- type SessionResolver
- type SetUserActive
- type SettingsOfProvider
- type SignInDeps
- type SignInFailure
- type SignedIn
- type SourceThrottle
- type StartCommand
- type StartLink
- type StartLinkCommand
- type StartSignIn
- type Started
- type TestProvider
- type Transactor
- type UnlinkCommand
- type UnlinkIdentity
- type UpdateProvider
- type UpdateProviderCommand
- type UpdateUser
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGroupNameTaken refuses a display name another group of the provider // has. ErrGroupNameTaken = apperrors.Conflict("group_name_taken", "another group of this provider has this displayName") // ErrGroupExternalIDTaken refuses an external ID another group of the // provider holds. ErrGroupExternalIDTaken = apperrors.Conflict("group_external_id_taken", "another group of this provider holds this externalId") )
Refusals of a SCIM group write, which the SCIM adapter answers 409 `uniqueness`.
var ( // ErrEmailTaken refuses an email another member holds, that may not be // adopted. ErrEmailTaken = apperrors.Conflict("already_exists", "a member with this email exists and cannot be taken over by this provider") // ErrExternalIDTaken refuses an external ID another member of the // provider holds. ErrExternalIDTaken = apperrors.Conflict("external_id_taken", "another member of this provider holds this externalId") )
Refusals a SCIM write meets, which the SCIM adapter answers 409 `uniqueness`.
var ( // ErrBaseURLRequired refuses configuring a provider on an instance that // does not know its own public address: the provider's redirect URI, which // the identity provider is told, is built from it. ErrBaseURLRequired = apperrors.Invalid("base_url_required", "an auth provider's URLs are built from the instance's public URL; set FLAGNETIC_BASE_URL") )
var ErrIDPRefused = errors.New("the identity provider refused the sign-in")
ErrIDPRefused is what verifying a SAML response fails with when the identity provider answered that the sign-in failed, rather than with an assertion.
var ErrIdentityLinked = errors.New("identity: the subject is already linked")
ErrIdentityLinked refuses linking a subject that is linked to a member at its provider already.
var ErrNotFound = errors.New("identity: not found")
ErrNotFound is what a store answers for a provider it does not hold.
var ErrSCIMTokenNotFound = apperrors.NotFound("not_found", "no unrevoked SCIM token has this identifier")
ErrSCIMTokenNotFound answers a SCIM token that is not an unrevoked one.
Functions ¶
This section is empty.
Types ¶
type ACSCommand ¶
type ACSCommand struct {
Slug string
RelayState string
// Response is the base64 encoded SAML response.
Response string
}
ACSCommand is what the identity provider posted to the ACS.
type AccessChange ¶
AccessChange is what replacing a member's access changed; see the access context for what each counts.
type AccessCommand ¶
type AccessCommand struct {
Provider identity.Provider
Member identity.MemberID
Grants []identity.ProjectRole
InstanceAdmin bool
// Actor is who the audit trail names for the changes: the provider when
// it is the zero actor, the SCIM token for a SCIM group change.
Actor governance.Actor
RequestID string
}
AccessCommand is the access a provider's mappings give a member now.
type AdoptUser ¶
type AdoptUser struct {
Provider ProviderRef
Member identity.MemberID
Email string
DisplayName string
ExternalID string
Request governance.Request
}
AdoptUser makes a member one of a provider's.
type AttemptStore ¶
type AttemptStore interface {
// CreateAttempt stores a, and deletes the attempts that expired before
// now, so abandoned ones do not pile up.
CreateAttempt(ctx context.Context, a identity.Attempt, now time.Time) error
// TakeCallback marks the live attempt with the state's hash as answered
// at now and returns it, in one step; ErrNotFound when there is none, it
// was answered already or it expired.
TakeCallback(ctx context.Context, state identity.SecretHash, now time.Time) (identity.Attempt, error)
// StoreClaims stores the verified claims on the attempt and the hash of
// the token its browser completes with.
StoreClaims(ctx context.Context, attempt identity.AttemptID, completion identity.SecretHash, c identity.VerifiedClaims) error
DeleteAttempt(ctx context.Context, attempt identity.AttemptID) error
// TakeCompletion deletes the attempt completing with the token's hash and
// returns it, claims included; ErrNotFound when there is none.
TakeCompletion(ctx context.Context, completion identity.SecretHash) (identity.Attempt, error)
}
AttemptStore keeps sign-in attempts.
type AuditLog ¶
type AuditLog interface {
Record(ctx context.Context, e governance.Entry) error
}
AuditLog records the audit entry of a change, in the unit of work of the change.
type CallbackCommand ¶
type CallbackCommand struct {
Slug string
State string
Code string
// IDPError is the provider's error parameter, when it refused the sign-in.
IDPError string
}
CallbackCommand is what the identity provider's redirect to the callback carried.
type CompleteACS ¶
type CompleteACS struct {
// contains filtered or unexported fields
}
CompleteACS takes the response of a SAML identity provider.
func NewCompleteACS ¶
func NewCompleteACS(d SignInDeps) *CompleteACS
NewCompleteACS returns the handler.
func (*CompleteACS) Handle ¶
func (h *CompleteACS) Handle(ctx context.Context, cmd ACSCommand) (token string, err error)
Handle verifies the identity provider's response and stores the person's claims on the attempt, changing nothing about any member, and returns the token the browser completes the sign-in with. The attempt's RelayState names it and is taken once: a RelayState seen again, unknown or expired is SignInFailure sso_failed, as is a response that does not verify, which ends the attempt. So is an assertion accepted before.
type CompleteCallback ¶
type CompleteCallback struct {
// contains filtered or unexported fields
}
CompleteCallback takes the answer of an identity provider.
func NewCompleteCallback ¶
func NewCompleteCallback(d SignInDeps) *CompleteCallback
NewCompleteCallback returns the handler.
func (*CompleteCallback) Handle ¶
func (h *CompleteCallback) Handle(ctx context.Context, cmd CallbackCommand) (token string, err error)
Handle verifies the provider's answer and stores the person's claims on the attempt, changing nothing about any member, and returns the token the browser completes the sign-in with. The attempt is answered once: a state seen again, unknown or expired is SignInFailure sso_failed, and an answer that does not verify ends the attempt.
type CompleteCertificateRotation ¶
type CompleteCertificateRotation struct {
// contains filtered or unexported fields
}
CompleteCertificateRotation completes the rotation of a SAML provider's SP certificate.
func NewCompleteCertificateRotation ¶
func NewCompleteCertificateRotation(d ProviderDeps) *CompleteCertificateRotation
NewCompleteCertificateRotation returns the handler.
func (*CompleteCertificateRotation) Handle ¶
func (h *CompleteCertificateRotation) Handle(ctx context.Context, cmd ProviderCommand) (identity.Provider, error)
Handle makes the next key pair current, destroys the retired private key, and records auth_provider.certificate_rotation_completed. A provider that is not SAML is refused 422 not_saml, one with no rotation pending 409 no_rotation_pending.
type CompleteCommand ¶
type CompleteCommand struct {
Token string
// Cookie is the value of the attempt cookie the browser sent, "" for none.
Cookie string
// SessionCookie is the value of the session cookie the browser sent, ""
// for none: a link completes only in the session that started it.
SessionCookie string
ClientIP netip.Addr
UserAgent string
RequestID string
}
CompleteCommand completes the sign-in the token names, presenting the browser's attempt cookie.
type CompleteSignIn ¶
type CompleteSignIn struct {
// contains filtered or unexported fields
}
CompleteSignIn completes a sign-in in the browser that started it.
func NewCompleteSignIn ¶
func NewCompleteSignIn(d SignInDeps) *CompleteSignIn
NewCompleteSignIn returns the handler.
func (*CompleteSignIn) Handle ¶
func (h *CompleteSignIn) Handle(ctx context.Context, cmd CompleteCommand) (signed SignedIn, err error)
Handle deletes the attempt, so it completes once, and checks the browser's cookie against the one the attempt was bound to, in constant time: another browser changes nothing. Then, in one transaction, it resolves the verified person to a member, provisions or links as the provider allows, and opens the session. A person who matches no member who may sign in is SignInFailure member_not_found or member_deactivated; one whose email's domain is enforced to another provider is sso_required, naming it.
type CreateProvider ¶
type CreateProvider struct {
// contains filtered or unexported fields
}
CreateProvider creates an auth provider.
func NewCreateProvider ¶
func NewCreateProvider(d ProviderDeps) *CreateProvider
NewCreateProvider returns the handler.
func (*CreateProvider) Handle ¶
func (h *CreateProvider) Handle(ctx context.Context, cmd CreateProviderCommand) (identity.Provider, error)
Handle checks the provider, seals its client secret, stores it and records auth_provider.created without the secret.
type CreateProviderCommand ¶
type CreateProviderCommand struct {
Input identity.ProviderInput
Request governance.Request
}
CreateProviderCommand asks for an auth provider.
type CreateSCIMGroup ¶
type CreateSCIMGroup struct {
// contains filtered or unexported fields
}
CreateSCIMGroup creates a group of the caller's provider.
func NewCreateSCIMGroup ¶
func NewCreateSCIMGroup(d SCIMGroupDeps) *CreateSCIMGroup
NewCreateSCIMGroup returns the handler.
func (*CreateSCIMGroup) Handle ¶
func (h *CreateSCIMGroup) Handle(ctx context.Context, req SCIMRequest, state identity.GroupState) (SCIMGroupRecord, error)
Handle creates the group with its members, who must be members the caller's provider provisions (invalidValue otherwise), runs the provider's group mappings for them, and records scim_group.created.
type CreateSCIMToken ¶
type CreateSCIMToken struct {
// contains filtered or unexported fields
}
CreateSCIMToken creates a SCIM token.
func NewCreateSCIMToken ¶
func NewCreateSCIMToken(d SCIMTokenDeps) *CreateSCIMToken
NewCreateSCIMToken returns the handler.
func (*CreateSCIMToken) Handle ¶
func (h *CreateSCIMToken) Handle(ctx context.Context, cmd CreateSCIMTokenCommand) (CreatedSCIMToken, error)
Handle creates the token and records scim_token.created with its hint and provider. A provider that does not exist, or an expiry that is not in the future, is refused invalid_scim_token, naming the field.
type CreateSCIMTokenCommand ¶
type CreateSCIMTokenCommand struct {
Provider string
ExpiresAt *time.Time
Request governance.Request
}
CreateSCIMTokenCommand asks for a SCIM token bound to the provider with Provider as its slug.
type CreateSCIMUser ¶
type CreateSCIMUser struct {
// contains filtered or unexported fields
}
CreateSCIMUser provisions or adopts a member.
func NewCreateSCIMUser ¶
func NewCreateSCIMUser(d SCIMUserDeps) *CreateSCIMUser
NewCreateSCIMUser returns the handler.
func (*CreateSCIMUser) Handle ¶
func (h *CreateSCIMUser) Handle(ctx context.Context, req SCIMRequest, attrs identity.UserAttributes) (ProvisionedMember, error)
Handle creates the member, or adopts the one holding the email, when the email is in the provider's domains (otherwise invalidValue); the adopted one is no instance admin, is active, and nobody provisions them; any other holder of the email is ErrEmailTaken. It records member.provisioned or member.adopted, and, for a user stated inactive, member.deactivated.
type CreatedSCIMToken ¶
type CreatedSCIMToken struct {
Token SCIMTokenRecord
Value secret.String
}
CreatedSCIMToken is a SCIM token just created, with its value, shown this once.
type DeleteProvider ¶
type DeleteProvider struct {
// contains filtered or unexported fields
}
DeleteProvider deletes an auth provider.
func NewDeleteProvider ¶
func NewDeleteProvider(d ProviderDeps) *DeleteProvider
NewDeleteProvider returns the handler.
func (*DeleteProvider) Handle ¶
func (h *DeleteProvider) Handle(ctx context.Context, cmd ProviderCommand) error
Handle deletes the provider and records auth_provider.deleted, unless something refers to it: then it is refused provider_in_use, naming what does in used_by, such as an enforced domain or its being the only enabled provider while local login is disabled. A provider in use is disabled instead, where the auth settings allow it.
type DeleteSCIMGroup ¶
type DeleteSCIMGroup struct {
// contains filtered or unexported fields
}
DeleteSCIMGroup removes a group.
func NewDeleteSCIMGroup ¶
func NewDeleteSCIMGroup(d SCIMGroupDeps) *DeleteSCIMGroup
NewDeleteSCIMGroup returns the handler.
func (*DeleteSCIMGroup) Handle ¶
func (h *DeleteSCIMGroup) Handle(ctx context.Context, req SCIMRequest, group identity.SCIMGroupID) error
Handle removes the group, runs the provider's group mappings for its members, who are in it no longer, and records scim_group.deleted.
type DeleteSCIMUser ¶
type DeleteSCIMUser struct {
// contains filtered or unexported fields
}
DeleteSCIMUser deprovisions a member.
func NewDeleteSCIMUser ¶
func NewDeleteSCIMUser(d SCIMUserDeps) *DeleteSCIMUser
NewDeleteSCIMUser returns the handler.
func (*DeleteSCIMUser) Handle ¶
func (h *DeleteSCIMUser) Handle(ctx context.Context, req SCIMRequest, member identity.MemberID) error
Handle deactivates the member, who keeps none of the provider's mapped grants; none is ever removed. A member the caller's provider does not provision is not found.
type DisableProvider ¶
type DisableProvider struct {
// contains filtered or unexported fields
}
DisableProvider disables an auth provider.
func NewDisableProvider ¶
func NewDisableProvider(d ProviderDeps) *DisableProvider
NewDisableProvider returns the handler.
func (*DisableProvider) Handle ¶
func (h *DisableProvider) Handle(ctx context.Context, cmd ProviderCommand) (identity.Provider, error)
Handle disables the provider, which stops its sign-ins, ends the sessions it opened and leaves its members, identities and grants as they are, and records auth_provider.disabled; a disabled provider is returned as it is and nothing is recorded. A provider an enforced domain names, or the only enabled one while local login is disabled, is refused provider_in_use: nobody could sign in where the settings send them.
type EnableProvider ¶
type EnableProvider struct {
// contains filtered or unexported fields
}
EnableProvider enables an auth provider.
func NewEnableProvider ¶
func NewEnableProvider(d ProviderDeps) *EnableProvider
NewEnableProvider returns the handler.
func (*EnableProvider) Handle ¶
func (h *EnableProvider) Handle(ctx context.Context, cmd ProviderCommand) (identity.Provider, error)
Handle enables the provider and records auth_provider.enabled; an enabled provider is returned as it is and nothing is recorded.
type FailureCode ¶
type FailureCode string
FailureCode is why a sign-in did not end with a session, as the sign-in page is told.
const ( // CodeSSOFailed: the sign-in could not be verified (protocol, signature, // state, an attempt gone) or the instance could not carry it out. CodeSSOFailed FailureCode = "sso_failed" // CodeIDPError: the identity provider refused the sign-in itself. CodeIDPError FailureCode = "idp_error" // CodeMemberNotFound: no member matches the person. CodeMemberNotFound FailureCode = "member_not_found" // CodeMemberDeactivated: the member was deactivated. CodeMemberDeactivated FailureCode = "member_deactivated" // CodeAttemptMismatch: the browser completing the sign-in is not the one // that started it. CodeAttemptMismatch FailureCode = "attempt_mismatch" // CodeIdentityLinked: linking an identity found its subject linked to // another member. CodeIdentityLinked FailureCode = "identity_linked" // CodeSSORequired: the person's email domain is enforced to another // provider, which the failure names. CodeSSORequired FailureCode = "sso_required" )
The codes the sign-in page is redirected with.
type GetGroupMappings ¶
type GetGroupMappings struct {
// contains filtered or unexported fields
}
GetGroupMappings answers a provider's group mappings.
func NewGetGroupMappings ¶
func NewGetGroupMappings(providers ProviderStore, mappings MappingStore) *GetGroupMappings
NewGetGroupMappings returns the query.
func (*GetGroupMappings) Handle ¶
func (h *GetGroupMappings) Handle(ctx context.Context, slug string) (GroupMappingsList, error)
Handle returns the mappings of the provider with slug, in order, with their version; an unknown provider is not found.
type GetProvider ¶
type GetProvider struct {
// contains filtered or unexported fields
}
GetProvider answers one auth provider.
func NewGetProvider ¶
func NewGetProvider(store ProviderStore) *GetProvider
NewGetProvider returns the query.
type GetSCIMGroup ¶
type GetSCIMGroup struct {
// contains filtered or unexported fields
}
GetSCIMGroup reads one of a provider's groups.
func NewGetSCIMGroup ¶
func NewGetSCIMGroup(d SCIMGroupDeps) *GetSCIMGroup
NewGetSCIMGroup returns the handler.
func (*GetSCIMGroup) Handle ¶
func (h *GetSCIMGroup) Handle(ctx context.Context, caller SCIMCaller, group identity.SCIMGroupID) (SCIMGroupRecord, error)
Handle returns the group; identity.ErrGroupNotFound when the caller's provider does not hold it.
type GetSCIMUser ¶
type GetSCIMUser struct {
// contains filtered or unexported fields
}
GetSCIMUser reads one member a provider provisions.
func NewGetSCIMUser ¶
func NewGetSCIMUser(d SCIMUserDeps) *GetSCIMUser
NewGetSCIMUser returns the handler.
func (*GetSCIMUser) Handle ¶
func (h *GetSCIMUser) Handle(ctx context.Context, caller SCIMCaller, member identity.MemberID) (ProvisionedMember, error)
Handle returns the member; identity.ErrUserNotFound when the caller's provider does not provision them.
type GroupClaim ¶
GroupClaim is the groups a member is in at a provider.
type GroupMappingDeps ¶
type GroupMappingDeps struct {
Tx Transactor
Providers ProviderStore
Mappings MappingStore
Projects ProjectDirectory
Access ProviderAccess
Audit AuditLog
Clock clock.Clock
IDs *id.Source
Logger *slog.Logger
}
GroupMappingDeps are what the group mapping use cases run on.
type GroupMappingsList ¶ added in v0.4.0
type GroupMappingsList struct {
Items []identity.GroupMapping
Version int64
}
GroupMappingsList is a provider's mappings in order, with the version of the list a replacement names.
type GroupMappingsRun ¶
type GroupMappingsRun struct {
Granted, Revoked, KeptInstanceAdmin int
// Version is the version of the list after the replacement.
Version int64
}
GroupMappingsRun is what replacing the mappings did to the members: the access made and removed, and the members kept as instance admin because they are the last active one.
type GroupPage ¶
type GroupPage struct {
Groups []SCIMGroupRecord
Total int
}
GroupPage is a page of SCIM groups and how many match in all.
type GroupRef ¶
type GroupRef struct {
ID identity.SCIMGroupID
DisplayName string
}
GroupRef names a SCIM group a member is in.
type HeldMember ¶
HeldMember is a member the instance holds, as adopting one needs to judge them.
type LinkStore ¶
type LinkStore interface {
// IdentityBySubject returns the identity linking subject at provider,
// locked until the unit of work ends; ErrNotFound when there is none.
IdentityBySubject(ctx context.Context, provider identity.ProviderID, subject string) (identity.Identity, error)
// CreateIdentity stores i; ErrIdentityLinked when its subject is linked at
// its provider already.
CreateIdentity(ctx context.Context, i identity.Identity) error
// RecordIdentitySignIn stores that the identity signed in at at.
RecordIdentitySignIn(ctx context.Context, i identity.ID, at time.Time) error
// MemberIdentities returns the identities member holds, oldest first, each
// with the provider it is at.
MemberIdentities(ctx context.Context, member identity.MemberID) ([]LinkedIdentity, error)
// DeleteIdentity deletes the identity.
DeleteIdentity(ctx context.Context, i identity.ID) error
}
LinkStore keeps identities.
type LinkedIdentity ¶
type LinkedIdentity struct {
identity.Identity
ProviderSlug string
ProviderName string
Kind identity.Kind
// ProviderEnabled is whether the provider is enabled: an identity at a
// disabled one signs nobody in.
ProviderEnabled bool
}
LinkedIdentity is an identity with the provider it is at.
type ListEnabledProviders ¶
type ListEnabledProviders struct {
// contains filtered or unexported fields
}
ListEnabledProviders answers the providers the sign-in page offers.
func NewListEnabledProviders ¶
func NewListEnabledProviders(store ProviderStore) *ListEnabledProviders
NewListEnabledProviders returns the query.
type ListMemberAuthMethods ¶
type ListMemberAuthMethods struct {
// contains filtered or unexported fields
}
ListMemberAuthMethods answers a member's password status and identities.
func NewListMemberAuthMethods ¶
func NewListMemberAuthMethods(d SignInDeps) *ListMemberAuthMethods
NewListMemberAuthMethods returns the query.
func (*ListMemberAuthMethods) Handle ¶
func (h *ListMemberAuthMethods) Handle(ctx context.Context, member identity.MemberID) (MemberAuthMethods, error)
Handle returns the ways member holds to sign in, the identities oldest first; not found when no member has the identifier.
type ListProviderSCIMGroups ¶
type ListProviderSCIMGroups struct {
// contains filtered or unexported fields
}
ListProviderSCIMGroups lists the groups an auth provider's directory pushed, for an instance admin to read.
func NewListProviderSCIMGroups ¶
func NewListProviderSCIMGroups(providers ProviderStore, groups SCIMGroupStore) *ListProviderSCIMGroups
NewListProviderSCIMGroups returns the query.
func (*ListProviderSCIMGroups) Handle ¶
func (h *ListProviderSCIMGroups) Handle(ctx context.Context, slug string) ([]SCIMGroupSummary, error)
Handle returns the groups of the provider with slug, ordered by name; an unknown provider is not found.
type ListProviders ¶
type ListProviders struct {
// contains filtered or unexported fields
}
ListProviders answers the instance's auth providers.
func NewListProviders ¶
func NewListProviders(store ProviderStore) *ListProviders
NewListProviders returns the query.
type ListSCIMGroups ¶
type ListSCIMGroups struct {
// contains filtered or unexported fields
}
ListSCIMGroups lists a provider's groups.
func NewListSCIMGroups ¶
func NewListSCIMGroups(d SCIMGroupDeps) *ListSCIMGroups
NewListSCIMGroups returns the handler.
func (*ListSCIMGroups) Handle ¶
func (h *ListSCIMGroups) Handle(ctx context.Context, caller SCIMCaller, rawFilter string, startIndex, count int) (GroupPage, error)
Handle returns the page of the caller's provider's groups the filter selects. The filter is judged before anything is read: invalidFilter.
type ListSCIMTokens ¶
type ListSCIMTokens struct {
// contains filtered or unexported fields
}
ListSCIMTokens answers the instance's SCIM tokens.
func NewListSCIMTokens ¶
func NewListSCIMTokens(store SCIMTokenStore) *ListSCIMTokens
NewListSCIMTokens returns the query.
func (*ListSCIMTokens) Handle ¶
func (h *ListSCIMTokens) Handle(ctx context.Context) ([]SCIMTokenRecord, error)
Handle returns every SCIM token, the newest first, revoked ones included.
type ListSCIMUsers ¶
type ListSCIMUsers struct {
// contains filtered or unexported fields
}
ListSCIMUsers lists the members a provider provisions.
func NewListSCIMUsers ¶
func NewListSCIMUsers(d SCIMUserDeps) *ListSCIMUsers
NewListSCIMUsers returns the handler.
func (*ListSCIMUsers) Handle ¶
func (h *ListSCIMUsers) Handle(ctx context.Context, caller SCIMCaller, rawFilter string, startIndex, count int) (Page, error)
Handle returns the page of the caller's provider's members the filter selects. The filter is judged before anything is read: invalidFilter.
type MappingStore ¶
type MappingStore interface {
// GroupMappings returns the provider's mappings in order.
GroupMappings(ctx context.Context, provider identity.ProviderID) ([]identity.GroupMapping, error)
// GroupMappingsVersion returns the version of the provider's list, which
// starts at 1.
GroupMappingsVersion(ctx context.Context, provider identity.ProviderID) (int64, error)
// AdvanceGroupMappingsVersion moves the version of the provider's list on
// and returns the new one.
AdvanceGroupMappingsVersion(ctx context.Context, provider identity.ProviderID) (int64, error)
// ReplaceGroupMappings stores mappings as the provider's whole list.
ReplaceGroupMappings(ctx context.Context, provider identity.ProviderID, mappings []identity.GroupMapping) error
// StoreGroupClaim stores groups as what member claimed at provider at at,
// replacing the claim before.
StoreGroupClaim(ctx context.Context, provider identity.ProviderID, member identity.MemberID, groups []string, at time.Time) error
// DeleteGroupClaim deletes what member last claimed at provider, and
// reports whether they had claimed anything.
DeleteGroupClaim(ctx context.Context, provider identity.ProviderID, member identity.MemberID) (bool, error)
// HasGroupClaim reports whether the provider ever stored a groups claim
// for member, an empty one included.
HasGroupClaim(ctx context.Context, provider identity.ProviderID, member identity.MemberID) (bool, error)
// KnownGroups returns the groups of every member who claimed groups at the
// provider or is a member of one of its SCIM groups: the union of both.
KnownGroups(ctx context.Context, provider identity.ProviderID) ([]GroupClaim, error)
// GroupsOf returns the groups member is in at provider: the union of what
// they last claimed there and the names of its SCIM groups they are
// members of.
GroupsOf(ctx context.Context, provider identity.ProviderID, member identity.MemberID) ([]string, error)
}
MappingStore keeps the group mappings of auth providers and the groups the members last claimed at them, and reads the groups a member is in at a provider: those they last claimed and the provider's SCIM groups they are members of.
type MemberAuthMethods ¶
type MemberAuthMethods struct {
// PasswordSetAt is when the member set the password they hold, nil when
// they hold none.
PasswordSetAt *time.Time
Identities []LinkedIdentity
}
MemberAuthMethods are the ways a member holds to sign in.
type MemberRecord ¶
type MemberRecord struct {
identity.KnownMember
Email string
DisplayName string
// Provider is the slug of the auth provider whose SCIM token provisioned
// the member, "" for one it did not.
Provider string
}
MemberRecord is a member as the identity context sees them.
type Members ¶
type Members interface {
// MemberByEmail returns the member holding email whatever its case; false
// when none does.
MemberByEmail(ctx context.Context, email string) (MemberRecord, bool, error)
// MemberByID returns the member; false when none has the identifier.
MemberByID(ctx context.Context, member identity.MemberID) (MemberRecord, bool, error)
// MemberByExternalID returns the member the provider with this slug
// provisioned with externalID as their external ID; false when none.
MemberByExternalID(ctx context.Context, provider, externalID string) (MemberRecord, bool, error)
// ProvisionMember creates an active member without a password and records
// that provider provisioned them.
ProvisionMember(ctx context.Context, email, displayName string, kind identity.Kind, provider, requestID string) (MemberRecord, error)
// ActivateInvited makes the invited member active through provider, as
// accepting their invitation would, redeeming it and the grant it carries
// while it is open; identity.ErrMemberNotFound when they are no longer
// invited.
ActivateInvited(ctx context.Context, member identity.MemberID, kind identity.Kind, provider, requestID string) (MemberRecord, error)
// OpenSession opens a session of member signed in through provider and
// returns the value of its cookie.
OpenSession(ctx context.Context, s SessionRequest) (secret.String, error)
// RevokeProviderSessions ends every session of member opened through the
// provider with this slug, and returns how many it ended.
RevokeProviderSessions(ctx context.Context, member identity.MemberID, provider string) (int, error)
// RecordFailedSignIn records that member could not sign in through
// provider, and why.
RecordFailedSignIn(ctx context.Context, member MemberRecord, kind identity.Kind, provider, reason, requestID string) error
// LockMember returns the member, locked until the unit of work ends, so
// the changes to their ways in are made one at a time; false when none has
// the identifier.
LockMember(ctx context.Context, member identity.MemberID) (MemberRecord, bool, error)
// LockInstanceAdmins serializes, until the unit of work ends, every
// change that could leave the instance without an active instance admin.
// A unit of work that may change a member's access takes it before the
// member's lock, the order every change of access takes, so two of them
// never wait on each other.
LockInstanceAdmins(ctx context.Context) error
// PasswordSetAt returns when the member set the password they hold, nil
// when they hold none.
PasswordSetAt(ctx context.Context, member identity.MemberID) (*time.Time, error)
// EnforcedProvider returns the slug of the auth provider email's domain
// is enforced to; "" when it is not.
EnforcedProvider(ctx context.Context, email string) (string, error)
// EnsureWayIn refuses, with the conflict last_auth_method, unlinking the
// identity without ("" for none) when no other usable way in would remain
// to member, whom the caller holds locked.
EnsureWayIn(ctx context.Context, member MemberRecord, without identity.ID) error
}
Members is what the identity context asks of the access context, acting in the unit of work the context it is given carries.
type MetadataRefreshDeps ¶
type MetadataRefreshDeps struct {
Deps ProviderDeps
Store MetadataRefreshStore
Logger *slog.Logger
}
MetadataRefreshDeps are what the metadata refresh runs on. Providers is the ProviderStore of Deps; Deps.SAML fetches and reads the metadata.
type MetadataRefreshStore ¶
type MetadataRefreshStore interface {
// TryLockMetadataRefresh takes, until release is called, the lock that
// lets one replica refresh at a time; held is false when another holds it.
TryLockMetadataRefresh(ctx context.Context) (release func(), held bool, err error)
// MetadataRefreshCandidates returns the enabled SAML providers whose
// metadata comes from a URL and was read at or before cutoff.
MetadataRefreshCandidates(ctx context.Context, cutoff time.Time) ([]identity.Provider, error)
// UpdateIDPMetadata stores the identity provider metadata, the time it
// was read, the update time and the version of p.
UpdateIDPMetadata(ctx context.Context, p identity.Provider) error
}
MetadataRefreshStore is what refreshing SAML identity provider metadata reads and writes beside the providers themselves.
type MetadataRefreshed ¶
type MetadataRefreshed struct {
// Changed providers had their certificates or single sign-on address
// replaced; Unchanged ones were read and said the same; Refused ones named
// another entity; Failed ones could not be fetched or read.
Changed, Unchanged, Refused, Failed int
}
MetadataRefreshed counts what one round of the refresh did.
type OIDCClient ¶
type OIDCClient interface {
// AuthorizationURL returns where a browser is sent to authenticate, for
// an attempt with this state, nonce and code verifier.
AuthorizationURL(ctx context.Context, cfg OIDCConfig, state, nonce, codeVerifier string) (string, error)
// Exchange trades code for tokens and verifies the ID token: signature,
// issuer, audience, expiry and nonce. It reads the claims cfg names,
// asking the provider's UserInfo for the email when the token holds none.
Exchange(ctx context.Context, cfg OIDCConfig, code, codeVerifier, nonce string) (identity.VerifiedClaims, error)
}
OIDCClient speaks the OpenID Connect authorization code flow with PKCE.
type OIDCConfig ¶
type OIDCConfig struct {
Issuer string
ClientID string
ClientSecret secret.String
RedirectURL string
Scopes []string
Claims identity.Claims
}
OIDCConfig is what the instance presents to an OIDC provider as a client.
type OIDCDiscoverer ¶
type OIDCDiscoverer interface {
// Discover fetches the document of issuer and checks it names issuer
// itself. It answers an error for a provider that cannot be reached, that
// answers anything but a document, or whose document is another's.
Discover(ctx context.Context, issuer string) (OIDCDiscovery, error)
}
OIDCDiscoverer fetches and reads an OIDC provider's discovery document.
type OIDCDiscovery ¶
type OIDCDiscovery struct {
Issuer string
AuthorizationEndpoint string
TokenEndpoint string
JWKSURI string
// UserinfoEndpoint is empty when the provider offers none.
UserinfoEndpoint string
// ScopesSupported and CodeChallengeMethodsSupported are empty when the
// document does not list them.
ScopesSupported []string
CodeChallengeMethodsSupported []string
}
OIDCDiscovery is what an OIDC provider's discovery document says about where and how to talk to it.
type Opener ¶
type Opener interface {
Open(purpose secret.Purpose, sealed string, binding secret.Binding) ([]byte, error)
}
Opener opens a value sealed under the instance's secret key.
type Page ¶
type Page struct {
Members []ProvisionedMember
Total int
}
Page is a page of provisioned members and how many match in all.
type PatchSCIMGroup ¶
type PatchSCIMGroup struct {
// contains filtered or unexported fields
}
PatchSCIMGroup applies a PatchOp to a group.
func NewPatchSCIMGroup ¶
func NewPatchSCIMGroup(d SCIMGroupDeps) *PatchSCIMGroup
NewPatchSCIMGroup returns the handler.
func (*PatchSCIMGroup) Handle ¶
func (h *PatchSCIMGroup) Handle(ctx context.Context, req SCIMRequest, group identity.SCIMGroupID, ops []identity.PatchOperation) (SCIMGroupRecord, error)
Handle applies the operations, in order, to the group as one change; a patch that fails changes nothing.
type PatchSCIMUser ¶
type PatchSCIMUser struct {
// contains filtered or unexported fields
}
PatchSCIMUser applies a PatchOp to a member.
func NewPatchSCIMUser ¶
func NewPatchSCIMUser(d SCIMUserDeps) *PatchSCIMUser
NewPatchSCIMUser returns the handler.
func (*PatchSCIMUser) Handle ¶
func (h *PatchSCIMUser) Handle(ctx context.Context, req SCIMRequest, member identity.MemberID, ops []identity.PatchOperation) (ProvisionedMember, error)
Handle applies the operations, in order, to the member: their email, name, external ID and whether they are active. The operations are judged before anything is read or written.
type ProjectDirectory ¶
type ProjectDirectory interface {
// ProjectIDs returns the identifier of each project with one of keys; a
// key no project has is absent.
ProjectIDs(ctx context.Context, keys []string) (map[string]workspace.ProjectID, error)
}
ProjectDirectory finds projects by key.
type ProviderAccess ¶
type ProviderAccess interface {
// KnownRole reports whether name is a built-in role.
KnownRole(name string) bool
// ReplaceAccess makes the access the provider's mappings give the member
// as listed, in the unit of work ctx carries.
ReplaceAccess(ctx context.Context, cmd AccessCommand) (AccessChange, error)
}
ProviderAccess is what the identity context asks of the access context to give members what a provider's group mappings give them.
type ProviderCommand ¶
type ProviderCommand struct {
Slug string
Request governance.Request
}
ProviderCommand names the provider Slug, acted on in Request.
type ProviderDeps ¶
type ProviderDeps struct {
Tx Transactor
Store ProviderStore
Audit AuditLog
Clock clock.Clock
IDs *id.Source
// Sealer seals client secrets.
Sealer Sealer
// BaseURL is the instance's public origin, nil when not configured.
BaseURL *url.URL
// SAML reads the metadata of SAML identity providers and SPKeys makes the
// key pairs the instance presents to them; both are unused until a SAML
// provider is written.
SAML SAMLMetadataReader
SPKeys SPKeyGenerator
// References are what keeps a provider from being deleted.
References []ProviderReference
// Settings tell what the auth settings ask of a provider: the domains
// enforced to it, and whether local login leaves another way in.
Settings ProviderSettings
}
ProviderDeps are what the auth provider use cases run on.
type ProviderRef ¶
type ProviderRef struct {
ID identity.ProviderID
Slug string
}
ProviderRef names the provider a SCIM token is bound to.
type ProviderReference ¶
type ProviderReference interface {
// ProviderUses names what refers to provider, such as "identities";
// nothing when nothing does. It reads in the unit of work ctx carries.
ProviderUses(ctx context.Context, provider identity.ProviderID) ([]string, error)
}
ProviderReference is something that depends on an auth provider, such as the identities linked through it. Each context that holds one adds its own to the deletion check.
type ProviderSettings ¶
type ProviderSettings interface {
// LockProviderSettings locks the auth settings until the unit of work
// ends and returns what they ask of the provider with the slug. It is
// taken before the provider's own lock, as changing the settings takes
// it before reading the providers they name, so neither change can
// leave the settings sending people to a provider that let them down.
LockProviderSettings(ctx context.Context, slug string) (SettingsOfProvider, error)
// RevokeProviderSessions ends, at at, every session opened through the
// provider with the slug and not ended yet, whoever holds it, and
// returns how many it ended.
RevokeProviderSessions(ctx context.Context, slug string, at time.Time) (int, error)
}
ProviderSettings is what changing an auth provider asks of the auth settings, which the access context keeps.
type ProviderStore ¶
type ProviderStore interface {
// Providers returns every provider, ordered by display name.
Providers(ctx context.Context) ([]identity.Provider, error)
// EnabledProviders returns the enabled providers, ordered by display name.
EnabledProviders(ctx context.Context) ([]identity.Provider, error)
// Provider returns the provider with slug, or ErrNotFound.
Provider(ctx context.Context, slug string) (identity.Provider, error)
// ProviderByID returns the provider with the identifier, or ErrNotFound.
ProviderByID(ctx context.Context, provider identity.ProviderID) (identity.Provider, error)
// LockProvider is Provider, locking the provider's row until the unit of
// work ctx carries ends.
LockProvider(ctx context.Context, slug string) (identity.Provider, error)
// CreateProvider stores p, answering a taken slug as a conflict.
CreateProvider(ctx context.Context, p identity.Provider) error
// UpdateProvider stores p in place of the provider with its identifier:
// everything an edit changes, and the sealed client secret.
UpdateProvider(ctx context.Context, p identity.Provider) error
// SetProviderEnabled stores p's enabled flag, update time and version.
SetProviderEnabled(ctx context.Context, p identity.Provider) error
DeleteProvider(ctx context.Context, provider identity.ProviderID) error
// HasIdentities reports whether any identity is linked through provider,
// reading in the unit of work ctx carries.
HasIdentities(ctx context.Context, provider identity.ProviderID) (bool, error)
}
ProviderStore keeps auth providers.
type ProviderTested ¶
type ProviderTested struct {
OIDC *OIDCDiscovery
SAML *identity.IDPMetadata
}
ProviderTested is what testing an auth provider found: the discovery document of an OIDC provider, the metadata of a SAML one.
type ProvisionUser ¶
type ProvisionUser struct {
Provider ProviderRef
Email string
DisplayName string
ExternalID string
Request governance.Request
}
ProvisionUser creates a member.
type ProvisionedMember ¶
type ProvisionedMember struct {
ID identity.MemberID
Email string
DisplayName string
// Active is whether the member can sign in: not deactivated.
Active bool
// ExternalID is the provider's identifier of the person, "" for none.
ExternalID string
CreatedAt time.Time
// Groups are the provider's SCIM groups the member is in, by name.
Groups []GroupRef
}
ProvisionedMember is a member an identity provider provisions, as SCIM reads them.
type RefreshMetadata ¶
type RefreshMetadata struct {
// contains filtered or unexported fields
}
RefreshMetadata reads again, once a day, the metadata of the SAML providers whose identity provider publishes it at a URL, so the certificates it rotates reach the instance without anyone swapping the identity provider silently.
func NewRefreshMetadata ¶
func NewRefreshMetadata(d MetadataRefreshDeps) *RefreshMetadata
NewRefreshMetadata returns the handler.
func (*RefreshMetadata) Handle ¶
func (h *RefreshMetadata) Handle(ctx context.Context) (MetadataRefreshed, error)
Handle refreshes each enabled SAML provider whose metadata comes from a URL and was read a day ago or more, under a lock only one replica holds: another replica's round does nothing. A provider whose metadata cannot be fetched or read keeps what it has, is logged, and is tried again in the next round. A provider whose metadata names another entity, or holds none of the certificates it trusts, is refused: logged, and recorded as auth_provider.metadata_refresh_refused, every round until an instance admin deals with it. New certificates or a new single sign-on address are applied and recorded as auth_provider.metadata_refreshed; metadata that says what the provider holds only moves the time it was read.
type ReplaceGroupMappings ¶
type ReplaceGroupMappings struct {
// contains filtered or unexported fields
}
ReplaceGroupMappings replaces a provider's group mappings.
func NewReplaceGroupMappings ¶
func NewReplaceGroupMappings(d GroupMappingDeps) *ReplaceGroupMappings
NewReplaceGroupMappings returns the handler.
func (*ReplaceGroupMappings) Handle ¶
func (h *ReplaceGroupMappings) Handle(ctx context.Context, cmd ReplaceGroupMappingsCommand) (GroupMappingsRun, error)
Handle replaces the provider's mappings and, in the same unit of work, runs them again for every member who claimed groups at the provider or is in one of its SCIM groups, so a mapping removed stops granting at once. An unknown provider is not found; mappings that break a rule, or name a project no instance holds, are invalid_group_mappings. A replacement that names no version is precondition.ErrRequired, and one based on a version the list has moved on from is version_mismatch: the list is then not stored and nothing runs. It records group_mappings.updated and moves the version on unless nothing changed.
type ReplaceGroupMappingsCommand ¶
type ReplaceGroupMappingsCommand struct {
Slug string
Items []identity.GroupMappingInput
// Expected is the version of the list the replacement is based on.
Expected precondition.Version
Request governance.Request
}
ReplaceGroupMappingsCommand replaces the mappings of the provider Slug with Items.
type ReplaceSCIMGroup ¶
type ReplaceSCIMGroup struct {
// contains filtered or unexported fields
}
ReplaceSCIMGroup replaces a group's name, external ID and members.
func NewReplaceSCIMGroup ¶
func NewReplaceSCIMGroup(d SCIMGroupDeps) *ReplaceSCIMGroup
NewReplaceSCIMGroup returns the handler.
func (*ReplaceSCIMGroup) Handle ¶
func (h *ReplaceSCIMGroup) Handle(ctx context.Context, req SCIMRequest, group identity.SCIMGroupID, state identity.GroupState, keepExternalID bool) (SCIMGroupRecord, error)
Handle makes the group state, keeping its external ID when keepExternalID (the request did not send one). Members who join must be provisioned by the caller's provider.
type ReplaceSCIMUser ¶
type ReplaceSCIMUser struct {
// contains filtered or unexported fields
}
ReplaceSCIMUser replaces a member's mapped attributes.
func NewReplaceSCIMUser ¶
func NewReplaceSCIMUser(d SCIMUserDeps) *ReplaceSCIMUser
NewReplaceSCIMUser returns the handler.
func (*ReplaceSCIMUser) Handle ¶
func (h *ReplaceSCIMUser) Handle(ctx context.Context, req SCIMRequest, member identity.MemberID, attrs identity.UserAttributes) (ProvisionedMember, error)
Handle replaces the member's email, name and, when stated, external ID with the attributes', and deactivates or reactivates them when active is stated. A member the caller's provider does not provision is not found; an email that is new to the member and outside the provider's domains is invalidValue.
type ReplayStore ¶
type ReplayStore interface {
// RecordAssertion remembers the assertion until expires and reports
// whether it was new; those expired before now are forgotten.
RecordAssertion(ctx context.Context, provider identity.ProviderID, assertionID string, expires, now time.Time) (bool, error)
}
ReplayStore remembers the SAML assertions accepted.
type RevokeSCIMToken ¶
type RevokeSCIMToken struct {
// contains filtered or unexported fields
}
RevokeSCIMToken revokes a SCIM token.
func NewRevokeSCIMToken ¶
func NewRevokeSCIMToken(d SCIMTokenDeps) *RevokeSCIMToken
NewRevokeSCIMToken returns the handler.
func (*RevokeSCIMToken) Handle ¶
func (h *RevokeSCIMToken) Handle(ctx context.Context, token identity.SCIMTokenID, req governance.Request) error
Handle revokes the token and records scim_token.revoked; a token already revoked, or unknown, is ErrSCIMTokenNotFound.
type RotateCertificate ¶
type RotateCertificate struct {
// contains filtered or unexported fields
}
RotateCertificate starts the rotation of a SAML provider's SP certificate.
func NewRotateCertificate ¶
func NewRotateCertificate(d ProviderDeps) *RotateCertificate
NewRotateCertificate returns the handler.
func (*RotateCertificate) Handle ¶
func (h *RotateCertificate) Handle(ctx context.Context, cmd ProviderCommand) (identity.Provider, error)
Handle generates the provider's next key pair, seals its private key and stores it beside the current pair, and records auth_provider.certificate_rotation_started with the certificates' fingerprints and never a key. A provider that is not SAML is refused 422 not_saml, one whose rotation is pending 409 rotation_pending.
type SAMLAssertion ¶
type SAMLAssertion struct {
// ID identifies the assertion; one is accepted once.
ID string
// ValidUntil is the last moment the assertion could be accepted, the
// clock skew included; it is remembered until then.
ValidUntil time.Time
// Claims are read from the verified assertion only. Their email is not yet
// verified: the provider's domains decide that.
Claims identity.VerifiedClaims
}
SAMLAssertion is what a verified SAML response asserts of a person.
type SAMLClient ¶
type SAMLClient interface {
// AuthnRequestURL returns where a browser is sent to authenticate: the
// identity provider's single sign-on endpoint with an AuthnRequest with
// this ID, signed when cfg says so, and this RelayState.
AuthnRequestURL(cfg SAMLConfig, requestID, relayState string) (string, error)
// VerifyResponse checks a base64 encoded SAML response posted to the
// ACS: that it was signed by one of the identity provider's certificates,
// is from its entity, is addressed to the ACS and the audience, answers
// the request with requestID, and is within its validity. It decrypts an
// encrypted assertion with the instance's key. ErrIDPRefused when the
// identity provider answered that the sign-in failed.
VerifyResponse(cfg SAMLConfig, response, requestID string) (SAMLAssertion, error)
// Metadata returns the instance's SAML metadata for the provider, to import
// into the identity provider.
Metadata(cfg SAMLConfig) ([]byte, error)
}
SAMLClient is the instance as a SAML service provider.
type SAMLConfig ¶
type SAMLConfig struct {
// EntityID is the instance's entity ID for the provider: the issuer of its
// requests and the audience its responses must name.
EntityID string
// ACSURL is where the identity provider posts its response.
ACSURL string
// IDPEntityID is the identity provider's, IDPSSOURL its HTTP-Redirect
// single sign-on endpoint and IDPCertificates, PEM encoded, the
// certificates its signatures are checked against.
IDPEntityID string
IDPSSOURL string
IDPCertificates []string
SignRequests bool
NameIDFormat string
Claims identity.Claims
// SPCertificate is the instance's certificate for the provider, SPKey its
// private key, both PEM encoded.
SPCertificate string
SPKey secret.String
// NextSPCertificate and NextSPKey are the pair a pending rotation will make
// current, both empty when none is pending. The SP metadata lists the
// certificate and an assertion encrypted to it is accepted; requests are
// still signed with the current pair.
NextSPCertificate string
NextSPKey secret.String
// Now is the time responses are judged at.
Now time.Time
}
SAMLConfig is what the instance presents to a SAML identity provider as a service provider, and what it trusts of it.
type SAMLMetadataReader ¶
type SAMLMetadataReader interface {
// Fetch returns the document at rawURL, at most a megabyte.
Fetch(ctx context.Context, rawURL string) ([]byte, error)
// Parse reads the identity provider's entity ID, HTTP-Redirect single
// sign-on endpoint and signing certificates from a metadata document; an
// *identity.MetadataError says why it cannot be used.
Parse(raw []byte) (identity.IDPMetadata, error)
}
SAMLMetadataReader fetches and reads an identity provider's metadata.
type SCIMAuthenticator ¶
type SCIMAuthenticator struct {
// contains filtered or unexported fields
}
SCIMAuthenticator resolves a bearer value presented to /scim/v2.
func NewAuthenticateSCIM ¶
func NewAuthenticateSCIM(d SCIMTokenDeps, throttle SourceThrottle, opener Opener, logger *slog.Logger) *SCIMAuthenticator
NewAuthenticateSCIM returns the authenticator.
func (*SCIMAuthenticator) Handle ¶
func (h *SCIMAuthenticator) Handle(ctx context.Context, value string, ip netip.Addr) (SCIMCaller, error)
Handle returns the caller presenting value from ip. The value is compared with every token before anything is counted: one that matches a live token is accepted whatever the source's failures, since it proves its presenter knows it; one that matches a token that is revoked, expired or of a disabled provider is refused ErrInvalidSCIMToken without counting, since its presenter knew a token once. Every other value, unknown or malformed, counts as a failure of ip's source and is refused ErrInvalidSCIMToken, or rate_limited once the source is throttled. A token accepted has its use recorded, at most once a minute.
type SCIMCaller ¶
type SCIMCaller struct {
Token identity.SCIMTokenID
Hint string
Provider identity.ProviderID
// ProviderSlug names the provider in audit entries.
ProviderSlug string
}
SCIMCaller is the SCIM token that was accepted and its provider.
type SCIMGroupDeps ¶
type SCIMGroupDeps struct {
Tx Transactor
Providers ProviderStore
Groups SCIMGroupStore
Members SCIMMembers
Mappings MappingStore
Access ProviderAccess
Audit AuditLog
Clock clock.Clock
IDs *id.Source
Logger *slog.Logger
}
SCIMGroupDeps are what the SCIM Groups use cases run on.
type SCIMGroupRecord ¶
type SCIMGroupRecord struct {
ID identity.SCIMGroupID
Provider identity.ProviderID
identity.GroupState
CreatedAt time.Time
UpdatedAt time.Time
}
SCIMGroupRecord is a SCIM group as it is stored: its members ordered by their identifier.
type SCIMGroupStore ¶
type SCIMGroupStore interface {
// CreateSCIMGroup stores g; a taken name or external ID is
// ErrGroupNameTaken or ErrGroupExternalIDTaken.
CreateSCIMGroup(ctx context.Context, g SCIMGroupRecord) error
// SCIMGroup returns the provider's group; identity.ErrGroupNotFound when
// the provider holds none with the identifier.
SCIMGroup(ctx context.Context, provider identity.ProviderID, group identity.SCIMGroupID) (SCIMGroupRecord, error)
// SCIMGroups returns the page of the provider's groups satisfying the
// filter, ordered by name, from the 1-based startIndex, count at most,
// and how many satisfy it in all.
SCIMGroups(ctx context.Context, provider identity.ProviderID, f identity.GroupFilter, startIndex, count int) ([]SCIMGroupRecord, int, error)
// SaveSCIMGroup stores g in place of the group with its identifier, its
// members replaced; refusals as CreateSCIMGroup's.
SaveSCIMGroup(ctx context.Context, g SCIMGroupRecord) error
// DeleteSCIMGroup removes the group and its memberships.
DeleteSCIMGroup(ctx context.Context, group identity.SCIMGroupID) error
// SCIMGroupSummaries returns every group of the provider, ordered by
// name, with how many members each holds.
SCIMGroupSummaries(ctx context.Context, provider identity.ProviderID) ([]SCIMGroupSummary, error)
// GroupsOfMembers returns the provider's groups each of members is in,
// ordered by name; a member in none is absent.
GroupsOfMembers(ctx context.Context, provider identity.ProviderID, members []identity.MemberID) (map[identity.MemberID][]GroupRef, error)
}
SCIMGroupStore keeps the SCIM groups of auth providers. A group of another provider is never found.
type SCIMGroupSummary ¶
type SCIMGroupSummary struct {
ID identity.SCIMGroupID
DisplayName string
ExternalID string
MemberCount int
}
SCIMGroupSummary is a SCIM group as an instance admin sees it: without its members, which are counted.
type SCIMMembers ¶
type SCIMMembers interface {
// Get returns the member of provider with the identifier;
// identity.ErrUserNotFound when none is.
Get(ctx context.Context, provider string, member identity.MemberID) (ProvisionedMember, error)
// List returns the page of provider's members satisfying the filter,
// ordered by email, from the 1-based startIndex, count at most, and how
// many satisfy it in all.
List(ctx context.Context, provider string, f identity.UserFilter, startIndex, count int) ([]ProvisionedMember, int, error)
// ByEmail returns the member holding email, whatever their provider;
// false when none does.
ByEmail(ctx context.Context, email string) (HeldMember, bool, error)
// Provision creates an active member of the provider without a
// password. An email another member holds is ErrEmailTaken, an external
// ID another member of the provider holds ErrExternalIDTaken.
Provision(ctx context.Context, cmd ProvisionUser) (ProvisionedMember, error)
// Adopt makes the member the instance holds one of the provider's;
// ErrEmailTaken when they may not be adopted.
Adopt(ctx context.Context, cmd AdoptUser) (ProvisionedMember, error)
// Update changes the member's email, name and external ID.
Update(ctx context.Context, cmd UpdateUser) (ProvisionedMember, error)
// SetActive deactivates or reactivates the member.
SetActive(ctx context.Context, cmd SetUserActive) (ProvisionedMember, error)
}
SCIMMembers is what the identity context asks of the access context to provision members, acting in the unit of work the context it is given carries. A member of another provider is never found.
type SCIMRequest ¶
type SCIMRequest struct {
Caller SCIMCaller
RequestID string
}
SCIMRequest is a request of a SCIM token: the caller and the request it made.
type SCIMTokenDeps ¶
type SCIMTokenDeps struct {
Tx Transactor
Providers ProviderStore
Store SCIMTokenStore
Audit AuditLog
Clock clock.Clock
IDs *id.Source
Random io.Reader
Sealer Sealer
}
SCIMTokenDeps are what the SCIM token use cases run on.
type SCIMTokenRecord ¶
SCIMTokenRecord is a SCIM token with the slug of the provider it is bound to.
type SCIMTokenStore ¶
type SCIMTokenStore interface {
// CreateSCIMToken stores t with its hash sealed.
CreateSCIMToken(ctx context.Context, t identity.SCIMToken, sealedHash string) error
// SCIMTokens returns every SCIM token, the newest first.
SCIMTokens(ctx context.Context) ([]SCIMTokenRecord, error)
// RevokeSCIMToken revokes the token at at and returns it; ErrNotFound
// unless it exists unrevoked.
RevokeSCIMToken(ctx context.Context, token identity.SCIMTokenID, at time.Time) (SCIMTokenRecord, error)
// AuthenticableSCIMTokens returns every token not revoked, and those
// revoked at or after revokedSince, with its sealed
// hash: the few an instance holds, all of which authentication opens.
AuthenticableSCIMTokens(ctx context.Context, revokedSince time.Time) ([]SealedSCIMToken, error)
// RecordSCIMTokenUse records that token was presented at at, unless a use
// not before notBefore is recorded already, so replicas coalesce.
RecordSCIMTokenUse(ctx context.Context, token identity.SCIMTokenID, at, notBefore time.Time) error
}
SCIMTokenStore keeps SCIM tokens.
type SCIMUserDeps ¶
type SCIMUserDeps struct {
Tx Transactor
Providers ProviderStore
Members SCIMMembers
Groups SCIMGroupStore
// Mappings and Access run the provider's group mappings for a member
// deactivated or reactivated, so their mapped access follows their
// status.
Mappings MappingStore
Access ProviderAccess
Logger *slog.Logger
}
SCIMUserDeps are what the SCIM Users use cases run on.
type SPKeyGenerator ¶
type SPKeyGenerator interface {
// GenerateSPKey returns a new RSA-2048 key and a self-signed certificate
// over it valid for three years from now, both PEM encoded.
GenerateSPKey(now time.Time) (certificatePEM string, keyPEM []byte, err error)
}
SPKeyGenerator makes the key pair the instance presents to an identity provider.
type SealedSCIMToken ¶
type SealedSCIMToken struct {
SCIMTokenRecord
SealedHash string
ProviderEnabled bool
}
SealedSCIMToken is a live SCIM token as authentication reads it: its hash still sealed, and whether its provider is enabled.
type Sealer ¶
type Sealer interface {
Seal(purpose secret.Purpose, plaintext []byte, binding secret.Binding) (string, error)
// Rebind returns sealed bound to binding, sealing again a value sealed
// before rows were bound.
Rebind(purpose secret.Purpose, sealed string, binding secret.Binding) (string, error)
}
Sealer seals a value under the instance's secret key.
type ServeMetadata ¶
type ServeMetadata struct {
// contains filtered or unexported fields
}
ServeMetadata answers the instance's SAML metadata for a provider.
func NewServeMetadata ¶
func NewServeMetadata(d SignInDeps) *ServeMetadata
NewServeMetadata returns the query.
type SessionRequest ¶
type SessionRequest struct {
Member MemberRecord
// Kind is the protocol of the provider, Provider its slug.
Kind identity.Kind
Provider string
ClientIP netip.Addr
UserAgent string
RequestID string
}
SessionRequest asks for the session of a member who signed in.
type SessionResolver ¶
type SessionResolver interface {
// SessionOf returns the member and the session the cookie signs in; false
// when it signs nobody in.
SessionOf(ctx context.Context, cookie string) (identity.MemberID, identity.SessionID, bool, error)
}
SessionResolver tells who a session cookie signs in.
type SetUserActive ¶
type SetUserActive struct {
Provider ProviderRef
Member identity.MemberID
Active bool
Request governance.Request
}
SetUserActive deactivates or reactivates a member.
type SettingsOfProvider ¶
type SettingsOfProvider struct {
// LocalLoginEnabled is whether members may sign in with a password.
LocalLoginEnabled bool
// EnforcedDomains are the email domains enforced to the provider.
EnforcedDomains []string
}
SettingsOfProvider is what the auth settings ask of one auth provider.
type SignInDeps ¶
type SignInDeps struct {
Tx Transactor
Providers ProviderStore
Attempts AttemptStore
Identities LinkStore
Members Members
// Sessions tells who the session a link completes in belongs to.
Sessions SessionResolver
// Mappings and Access give a member what the provider's group mappings
// map the groups they claim to.
Mappings MappingStore
Access ProviderAccess
Logger *slog.Logger
OIDC OIDCClient
SAML SAMLClient
Replays ReplayStore
Opener Opener
Audit AuditLog
Clock clock.Clock
IDs *id.Source
Random io.Reader
// BaseURL is the instance's public origin, nil when not configured.
BaseURL *url.URL
}
SignInDeps are what the sign-in use cases run on.
type SignInFailure ¶
type SignInFailure struct {
Code FailureCode
Cause error
// Kind is the protocol of the provider the sign-in was through, empty
// when it failed before the provider was known.
Kind identity.Kind
// Intent is what the attempt was for, empty when it failed before the
// attempt was known. The browser of a link lands on the page the member
// started it from; one that signs in lands on the sign-in page.
Intent identity.Intent
// Provider is the slug of the provider to sign in through instead, for
// CodeSSORequired.
Provider string
}
SignInFailure ends a sign-in with a code for the sign-in page.
func (*SignInFailure) Error ¶
func (f *SignInFailure) Error() string
func (*SignInFailure) Unwrap ¶
func (f *SignInFailure) Unwrap() error
type SignedIn ¶
type SignedIn struct {
// Cookie is the value of the session cookie.
Cookie secret.String
ReturnTo string
// Kind is the protocol of the provider the member signed in through.
Kind identity.Kind
// Linked is true when the attempt linked an identity to the member signed
// in already, who needs no session: Cookie is then empty.
Linked bool
}
SignedIn is the session a sign-in opened and where its browser goes next.
type SourceThrottle ¶
type SourceThrottle interface {
// Reserve counts one failure of the source ip comes from at at, for a
// value that matched nothing. A throttled source is refused rate_limited,
// its failure taken back.
Reserve(ctx context.Context, ip netip.Addr, at time.Time) error
}
SourceThrottle counts a source's failed attempts, shared with sign-in, invitation acceptance and password reset, so that guessing at one cannot be traded for guessing at another.
type StartCommand ¶
StartCommand asks to sign in through the provider Slug and return to ReturnTo afterwards.
type StartLink ¶
type StartLink struct {
// contains filtered or unexported fields
}
StartLink begins linking an identity to the member signed in.
func (*StartLink) Handle ¶
Handle creates an attempt bound to the member, their session and a new cookie, and answers the provider's authorization address. A disabled or unknown provider is not found; one the instance cannot reach is 502 provider_unreachable; a session that opened more than 15 minutes ago is 403 recent_sign_in_required.
type StartLinkCommand ¶
type StartLinkCommand struct {
Slug string
ReturnTo string
Member identity.MemberID
Session identity.SessionID
SessionOpenedAt time.Time
}
StartLinkCommand asks to link an identity at the provider Slug to Member, signed in in Session, which opened at SessionOpenedAt, and to return to ReturnTo afterwards.
type StartSignIn ¶
type StartSignIn struct {
// contains filtered or unexported fields
}
StartSignIn begins a sign-in through an auth provider.
func NewStartSignIn ¶
func NewStartSignIn(d SignInDeps) *StartSignIn
NewStartSignIn returns the handler.
func (*StartSignIn) Handle ¶
func (h *StartSignIn) Handle(ctx context.Context, cmd StartCommand) (Started, error)
Handle creates an attempt bound to a new cookie and answers the provider's authorization address. A disabled or unknown provider is not found; one the instance cannot reach is SignInFailure sso_failed.
type Started ¶
type Started struct {
RedirectURL string
// Cookie is the value of the cookie to set; the attempt keeps only its
// hash.
Cookie secret.String
// Lifetime is how long the cookie lives.
Lifetime time.Duration
}
Started is where the browser goes, and the cookie that binds the attempt to it.
type TestProvider ¶
type TestProvider struct {
// contains filtered or unexported fields
}
TestProvider checks an auth provider can be reached.
func NewTestProvider ¶
func NewTestProvider(store ProviderStore, discoverer OIDCDiscoverer, saml SAMLMetadataReader) *TestProvider
NewTestProvider returns the query.
func (*TestProvider) Handle ¶
func (h *TestProvider) Handle(ctx context.Context, slug string) (ProviderTested, error)
Handle fetches the discovery document of the OIDC provider with slug, or fetches again the metadata of the SAML provider, or reads the metadata pasted, enabled or not, and answers what it found, or refuses provider_unreachable with why. Nothing is stored.
type Transactor ¶
Transactor runs a unit of work.
type UnlinkCommand ¶
type UnlinkCommand struct {
Member identity.MemberID
Identity string
Request governance.Request
}
UnlinkCommand unlinks the identity Identity from Member, on behalf of the actor Request names: the member themself, or an instance admin.
type UnlinkIdentity ¶
type UnlinkIdentity struct {
// contains filtered or unexported fields
}
UnlinkIdentity unlinks an identity from a member.
func NewUnlinkIdentity ¶
func NewUnlinkIdentity(d SignInDeps) *UnlinkIdentity
NewUnlinkIdentity returns the handler.
func (*UnlinkIdentity) Handle ¶
func (h *UnlinkIdentity) Handle(ctx context.Context, cmd UnlinkCommand) error
Handle deletes the member's identity and records identity.unlinked, in one unit of work that holds the member, so unlinking two identities at once cannot leave them without a way in. An identity that is not the member's, or whose identifier names none, is not found. An identity that is a usable way in, at an enabled provider, is refused with the conflict last_auth_method when no other usable way in remains; a deactivated member signs in nowhere and needs none. The identity of a provisioned member at the provider that provisions them is the directory's, and is refused with the conflict member_provisioned; the identity at the provider the member's email domain is enforced to is the only way in enforcement leaves them, and is refused with the conflict provider_enforced. Unlinking what is no usable way in, such as an identity at a disabled provider, never leaves a member without one. When no identity of the member remains at the provider, what it brought them is taken back in the same unit of work, and identity.unlinked records it: see takeBack.
type UpdateProvider ¶
type UpdateProvider struct {
// contains filtered or unexported fields
}
UpdateProvider edits an auth provider.
func NewUpdateProvider ¶
func NewUpdateProvider(d ProviderDeps) *UpdateProvider
NewUpdateProvider returns the handler.
func (*UpdateProvider) Handle ¶
func (h *UpdateProvider) Handle(ctx context.Context, cmd UpdateProviderCommand) (identity.Provider, error)
Handle applies the change to the provider read under its lock, sealing a new client secret, and records auth_provider.updated; an edit that changes nothing stores and records nothing. Enabling and disabling are operations of their own.
type UpdateProviderCommand ¶
type UpdateProviderCommand struct {
Slug string
Change identity.ProviderChange
Expected precondition.Version
Request governance.Request
}
UpdateProviderCommand is an edit of the provider Slug, based on its version Expected.
type UpdateUser ¶
type UpdateUser struct {
Provider ProviderRef
Member identity.MemberID
Email *string
DisplayName *string
ExternalID *string
ClearExternalID bool
Request governance.Request
}
UpdateUser changes a member; a nil field is left as it is.