Documentation
¶
Overview ¶
Package saml authenticates SAML 2.0 Web Browser SSO responses (HTTP-POST binding) for service-provider initiated logins, as an authentication.FederatedProvider.
Begin sends a signed (RSA-SHA256) AuthnRequest with the HTTP-Redirect binding to the single registered ACS URL and stores the request ID and an independent RelayState through a caller-owned RequestStore. Complete consumes that request atomically, then accepts only a response that: is at most Options.MaxResponseBytes, round-trips as XML, has bounded depth and element count, contains exactly one unencrypted assertion and unique IDs, is signed (response or assertion) by a certificate from the IdP metadata, and whose issuer, destination, InResponseTo, audience, bearer subject confirmation, conditions and issue instants all match within Options.AllowedClockSkew. IdP-initiated logins are rejected.
Time checks use this package's own validation with Options.Clock (default time.Now) rather than the process-global clock and skew variables of github.com/crewjam/saml.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct {
NameID string
Attributes map[string][]string
AuthenticatedAt time.Time
ExpiresAt time.Time
}
Claims is the bounded, verified SAML data presented to a ClaimsMapper.
type ClaimsMapper ¶
ClaimsMapper maps verified SAML claims to a protocol-neutral principal.
type MemoryRequestStore ¶
type MemoryRequestStore struct {
// contains filtered or unexported fields
}
MemoryRequestStore is a process-local RequestStore for tests and single-process callers. Distributed deployments should provide a durable atomic implementation.
func NewMemoryRequestStore ¶
func NewMemoryRequestStore() *MemoryRequestStore
NewMemoryRequestStore returns an empty memory-backed request store.
type Options ¶
type Options struct {
// Name identifies the provider (lower-cased and trimmed). Required.
Name string
// EntityID, MetadataURL and ACSURL are the service provider's https
// URLs. Required.
EntityID *url.URL
MetadataURL *url.URL
ACSURL *url.URL
// IDPMetadata describes the identity provider. It must have an https
// entity ID, exactly one HTTP-Redirect SSO endpoint and at least one
// currently valid signing certificate, and must not be past ValidUntil.
IDPMetadata *crewjamsaml.EntityDescriptor
// Key and Certificate are the service provider's signing key pair: RSA
// of at least 2048 bits with a currently valid certificate. Required.
Key *rsa.PrivateKey
Certificate *x509.Certificate
// RequestStore persists pending requests. Required.
RequestStore RequestStore
// Clock returns the current time used to validate key, certificate and
// metadata lifetimes, request expiry and assertion conditions; its result
// is converted to UTC. Defaults to time.Now.
Clock func() time.Time
// MaxResponseBytes bounds the decoded response. Zero selects the default
// of 1 MiB.
MaxResponseBytes int
// AllowedClockSkew is the tolerated clock difference with the identity
// provider. Zero selects the default of two minutes; negative values are
// rejected.
AllowedClockSkew time.Duration
// Mapper maps verified claims to a principal. The default uses ID
// "<idp entity ID>|<NameID>", copies attributes into Traits and sets
// Methods to ["saml"].
Mapper ClaimsMapper
}
Options configures a Provider. The provider deep-copies keys, certificates and metadata, so later changes by the caller have no effect.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is a SAML 2.0 service provider for one identity provider. It is safe for concurrent use when its RequestStore and Mapper are.
func New ¶
New validates options and returns a Provider. It returns authentication.ErrInvalidCredential for invalid options.
func (*Provider) Begin ¶
func (p *Provider) Begin(ctx context.Context, request authentication.BeginRequest) (authentication.Redirect, error)
Begin starts a login. request.RedirectURI must equal the ACS URL. The pending request expires after ten minutes.
func (*Provider) Complete ¶
func (p *Provider) Complete(ctx context.Context, callback authentication.Callback) (authentication.Principal, error)
Complete consumes the pending request and verifies the SAML response in callback.SAMLResponse (base64). It returns authentication.ErrInvalidCallback for malformed or oversized callbacks, authentication.ErrReplay for unknown or reused requests, authentication.ErrExpired for expired requests and authentication.ErrUnauthenticated for every verification failure.
type RequestStore ¶
type RequestStore interface {
Put(context.Context, Request) error
Consume(context.Context, string) (Request, error)
}
RequestStore persists callback state. Put must fail with authentication.ErrReplay when the ID exists. Consume must atomically remove and return the request and return authentication.ErrReplay when none exists, so that concurrent callbacks cannot both consume it.