2019-04-25 04:52:08 +07:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
2021-09-09 10:08:21 +07:00
|
|
|
"context"
|
2020-05-05 02:39:25 +07:00
|
|
|
"time"
|
|
|
|
|
2021-03-13 12:06:19 +07:00
|
|
|
"github.com/fasthttp/session/v2"
|
|
|
|
"github.com/fasthttp/session/v2/providers/redis"
|
2022-03-04 06:46:38 +07:00
|
|
|
"github.com/go-webauthn/webauthn/webauthn"
|
2021-09-09 10:08:21 +07:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-04-05 19:37:21 +07:00
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/authentication"
|
2021-09-09 10:08:21 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/logging"
|
2022-04-01 18:18:58 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/oidc"
|
2019-04-25 04:52:08 +07: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-10 06:03:05 +07:00
|
|
|
config session.Config
|
|
|
|
redisConfig *redis.Config
|
|
|
|
redisSentinelConfig *redis.FailoverConfig
|
|
|
|
providerName string
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// UserSession is the structure representing the session of a user.
|
|
|
|
type UserSession struct {
|
2020-06-19 17:50:21 +07:00
|
|
|
Username string
|
|
|
|
DisplayName string
|
2019-04-25 04:52:08 +07: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-04 06:44:30 +07:00
|
|
|
FirstFactorAuthnTimestamp int64
|
|
|
|
SecondFactorAuthnTimestamp int64
|
|
|
|
|
2022-04-01 18:18:58 +07:00
|
|
|
AuthenticationMethodRefs oidc.AuthenticationMethodsReferences
|
|
|
|
|
2022-03-03 18:20:43 +07:00
|
|
|
// Webauthn holds the session registration data for this session.
|
|
|
|
Webauthn *webauthn.SessionData
|
2019-04-25 04:52:08 +07:00
|
|
|
|
|
|
|
// This boolean is set to true after identity verification and checked
|
|
|
|
// while doing the query actually updating the password.
|
|
|
|
PasswordResetUsername *string
|
2020-05-05 02:39:25 +07:00
|
|
|
|
|
|
|
RefreshTTL time.Time
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Identity identity of the user who is being verified.
|
|
|
|
type Identity struct {
|
2022-04-03 19:24:51 +07:00
|
|
|
Username string
|
|
|
|
Email string
|
|
|
|
DisplayName string
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
2021-05-05 05:06:05 +07:00
|
|
|
|
2021-09-09 10:08:21 +07: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...)
|
|
|
|
}
|