2019-04-24 21:52:08 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
2021-09-09 03:08:21 +00:00
|
|
|
"context"
|
2020-05-04 19:39:25 +00:00
|
|
|
"time"
|
|
|
|
|
2021-03-13 05:06:19 +00:00
|
|
|
"github.com/fasthttp/session/v2"
|
|
|
|
"github.com/fasthttp/session/v2/providers/redis"
|
2022-03-03 23:46:38 +00:00
|
|
|
"github.com/go-webauthn/webauthn/webauthn"
|
2021-09-09 03:08:21 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-04-05 12:37:21 +00:00
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/authentication"
|
2021-09-09 03:08:21 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/logging"
|
2022-04-01 11:18:58 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/model"
|
|
|
|
"github.com/authelia/authelia/v4/internal/oidc"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ProviderConfig is the configuration used to create the session provider.
|
|
|
|
type ProviderConfig struct {
|
feat(session): add redis sentinel provider (#1768)
* feat(session): add redis sentinel provider
* refactor(session): use int for ports as per go standards
* refactor(configuration): adjust tests and validation
* refactor(configuration): add err format consts
* refactor(configuration): explicitly map redis structs
* refactor(session): merge redis/redis sentinel providers
* refactor(session): add additional checks to redis providers
* feat(session): add redis cluster provider
* fix: update config for new values
* fix: provide nil certpool to affected tests/mocks
* test: add additional tests to cover uncovered code
* docs: expand explanation of host and nodes relation for redis
* ci: add redis-sentinel to suite highavailability, add redis-sentinel quorum
* fix(session): sentinel password
* test: use redis alpine library image for redis sentinel, use expose instead of ports, use redis ip, adjust redis ip range, adjust redis config
* test: make entrypoint.sh executable, fix entrypoint.sh if/elif
* test: add redis failover tests
* test: defer docker start, adjust sleep, attempt logout before login, attempt visit before login and tune timeouts, add additional logging
* test: add sentinel integration test
* test: add secondary node failure to tests, fix password usage, bump test timeout, add sleep
* feat: use sentinel failover cluster
* fix: renamed addrs to sentineladdrs upstream
* test(session): sentinel failover
* test: add redis standard back into testing
* test: move redis standalone test to traefik2
* fix/docs: apply suggestions from code review
2021-03-09 23:03:05 +00:00
|
|
|
config session.Config
|
|
|
|
redisConfig *redis.Config
|
|
|
|
redisSentinelConfig *redis.FailoverConfig
|
|
|
|
providerName string
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UserSession is the structure representing the session of a user.
|
|
|
|
type UserSession struct {
|
2020-06-19 10:50:21 +00:00
|
|
|
Username string
|
|
|
|
DisplayName string
|
2019-04-24 21:52:08 +00:00
|
|
|
// TODO(c.michaud): move groups out of the session.
|
|
|
|
Groups []string
|
|
|
|
Emails []string
|
|
|
|
|
|
|
|
KeepMeLoggedIn bool
|
|
|
|
AuthenticationLevel authentication.Level
|
|
|
|
LastActivity int64
|
|
|
|
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
FirstFactorAuthnTimestamp int64
|
|
|
|
SecondFactorAuthnTimestamp int64
|
|
|
|
|
2022-04-01 11:18:58 +00:00
|
|
|
AuthenticationMethodRefs oidc.AuthenticationMethodsReferences
|
|
|
|
|
2022-03-03 11:20:43 +00:00
|
|
|
// Webauthn holds the session registration data for this session.
|
|
|
|
Webauthn *webauthn.SessionData
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2021-05-04 22:06:05 +00:00
|
|
|
// Represent an OIDC workflow session initiated by the client if not null.
|
2022-04-01 11:18:58 +00:00
|
|
|
OIDCWorkflowSession *model.OIDCWorkflowSession
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
// This boolean is set to true after identity verification and checked
|
|
|
|
// while doing the query actually updating the password.
|
|
|
|
PasswordResetUsername *string
|
2020-05-04 19:39:25 +00:00
|
|
|
|
|
|
|
RefreshTTL time.Time
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Identity identity of the user who is being verified.
|
|
|
|
type Identity struct {
|
|
|
|
Username string
|
|
|
|
Email string
|
|
|
|
}
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2021-09-09 03:08:21 +00:00
|
|
|
func newRedisLogger() *redisLogger {
|
|
|
|
return &redisLogger{logger: logging.Logger()}
|
|
|
|
}
|
|
|
|
|
|
|
|
type redisLogger struct {
|
|
|
|
logger *logrus.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *redisLogger) Printf(_ context.Context, format string, v ...interface{}) {
|
|
|
|
l.logger.Tracef(format, v...)
|
|
|
|
}
|