Commit Graph
104 Commits
Author SHA1 Message Date
Trong Huu Nguyen 8fbd4656db fix(session): refresh tokens 30s before expiry instead of 5m
Refreshes are activity-based and synchronous-on-expiry, so the proactive
leeway only hides refresh latency and provides retry headroom; it is not
what prevents serving expired tokens. Shrink it from 5m to 30s to align
with identity provider guidance against refreshing long before expiry,
while keeping decent end-user UX.
2026-06-10 16:57:54 +02:00
Trong Huu Nguyen a820dc5b9b perf(session/redis): disable caller tracing
This drops the calling function, filepath and line number attributes
for redisotel tracing. The underlying implementation here calls
runtime.Callers, which are more expensive than we'd like.
2025-07-01 14:03:04 +02:00
Trong Huu Nguyen 4bf3b1bdd4 refactor: move string generator to crypto package 2025-06-16 09:55:44 +02:00
Trong Huu Nguyen a156c11ace refactor(session): use SetSpanAttributes on refresh 2025-06-16 09:55:43 +02:00
Trong Huu Nguyen 1a138c66a3 refactor: move retry package 2025-06-16 09:55:42 +02:00
Trong Huu Nguyen bf2f97f400 feat: set more session and token-related span attributes 2025-06-10 13:51:15 +02:00
Trong Huu NguyenandThomas Krampl c5ec362e60 feat(session): update id_token in session if returned from refresh grant
Co-authored-by: Thomas Krampl <thomas.siegfried.krampl@nav.no>
2025-05-22 15:52:15 +02:00
Trong Huu Nguyen 259bf635d1 chore(deps): bump github.com/lestrrat-go/jwx from v2 to v3 2025-05-21 10:38:26 +02:00
Trong Huu Nguyen 12f6ce57aa feat(redis): register prometheus metrics 2025-03-06 10:05:57 +01:00
Trong Huu Nguyen 7c6f9d6f70 feat(session): record id attribute regardless of session validity 2025-01-31 18:52:19 +01:00
Trong Huu Nguyenandsindrerh2 79ac15d455 feat(otel): consistency passthrough for spans and attributes
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
2025-01-30 14:03:39 +01:00
Trong Huu Nguyenandsindrerh2 475fe25100 feat(session): add even more tracing
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
2025-01-30 14:03:36 +01:00
Trong Huu Nguyenandsindrerh2 787b54beeb refactor(crypto): move to internal
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
2025-01-30 14:03:36 +01:00
Trong Huu Nguyenandsindrerh2 85230d5403 feat(session): add trace spans and attributes
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
2025-01-30 14:03:35 +01:00
Trong Huu Nguyenandsindrerh2 57f5bf951e fix(config): set correct defaults for resolving version
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
2025-01-30 14:03:23 +01:00
Trong Huu Nguyen f2def8d00d fix(session/data): next refresh time should account for inactivity timeouts
The default auto-refresh behaviour occurs 5 minutes before tokens
expire, at the earliest. Without inactivity however, tokens are still
refreshed at any point after this, as long as the session has not ended.

This however, means that refreshes don't occur often enough when inactivity
timeouts are enabled. In practice, the session is only refreshed if a
request is received within the 5 minute leeway window between a token's expiry
and the inactivity timeout.

This commit will apply auto-refreshes at the half-life of the inactivity
timeout instead, so that users' sessions and timeouts are properly
extended on activity.
2025-01-22 15:58:53 +01:00
Trong Huu Nguyen 3143940b08 feat: remove feature flags for session refresh
These feature flags were enabled by default. We specifically disallowed
the use of automatic refresh with the SSO mode, though this poses some
complexity if using the forward-auth feature.

To simplify configuration and code, we remove the flags in their
entirety as session refresh behaviour is mostly already handled by the
implementation of GetSession() in the handlers. Specifically:

- the Standalone handler needs to refresh sessions when reverse-proxying
  to the upstream.
- the SSO server handler needs to refresh sessions only when using the
  forward-auth feature. It does not have an upstream to reverse proxy
  to.
- the SSO proxy handler is a read-only upstream proxy and does not
  possess the ability to refresh sessions itself, though it will
  delegate traffic for the session endpoints to the configured SSO server.

Automatic refreshing is thus only disabled when running in SSO mode
without the forward-auth feature.
2025-01-16 10:14:15 +01:00
Trong Huu Nguyen b7b43e9793 refactor(openid): remove more indirection layers 2024-11-05 21:58:38 +01:00
Trong Huu Nguyen 3876820aee refactor(retry): use DoValue 2024-08-23 13:55:51 +02:00
Trong Huu Nguyen 584f58bb6d refactor(retry): use functional opts, proxy to external lib 2024-05-08 08:39:43 +02:00
Trong Huu Nguyen 10e71a7bb5 feat(handler/reverseproxy): remove x-wonderwall headers
The use of these headers in upstreams may be risky, espeically
if Wonderwall is accidentally misconfigured or disabled, or requests
are performed directly to the upstream circumventing Wonderwall.

We should prefer using a signed token or similar that can be verified by
the upstreams.
2024-01-16 08:57:07 +01:00
Trong Huu Nguyen 55839d72f0 feat(handler/login): log existing sid on prompt 2023-12-19 12:19:39 +01:00
Trong Huu Nguyen c3904433f2 feat: log and propagate session metadata
- stop using jti, use sid instead
- store amr and auth_time from id_token in session
- log more metadata on login callback
- log session id where possible
- propagate acr, amr, auth_time, sid to upstreams in headers
- log authenticated reverseproxy requests
2023-12-19 08:46:02 +01:00
Trong Huu Nguyen 35e4953557 fix(session/redis): skip setup if otel is not enabled 2023-11-28 10:08:31 +01:00
J-K. Solbakken 894cc35e47 telemetry for redis 2023-11-23 13:16:43 +01:00
Trong Huu Nguyen 1b3ba8a7ad refactor(session): skip logging for client context cancellations
We use the context from the inbound http.Request, which means that this
error generally occurs due to the user agent disconnecting mid-request.
Skip logging these errors as they're not really actionable.
2023-11-16 14:52:10 +01:00
Trong Huu Nguyen 8bbd947d5b feat(config): add support for Redis URI 2023-10-10 14:48:50 +02:00
Trong Huu Nguyen af6642fe90 refactor(openid): use pkce implementation from golang.org/x/oauth2 2023-10-10 10:18:01 +02:00
Trong Huu Nguyen c4911b1344 feat(session): add feature toggle for automatic refreshing 2023-09-15 09:08:42 +02:00
Trong Huu Nguyen 2a8d410425 feat(session/reader): return session on validation error 2023-06-09 13:52:35 +02:00
Trong Huu Nguyen cbfa3fe2e2 refactor(session): extract inactive session error 2023-06-09 13:52:33 +02:00
Trong Huu Nguyen 3a239a95c3 feat(reverseproxy): validate acr and redirect if applicable 2023-04-29 11:54:53 +02:00
Trong Huu Nguyen d76e9ebbb5 feat(session): store acr 2023-04-29 10:27:53 +02:00
Trong Huu Nguyen 08c6e96670 refactor(session): wrap error for decrypt 2023-02-23 14:29:49 +01:00
Trong Huu Nguyen afc8fd6962 style: formatting 2023-02-21 15:37:48 +01:00
Trong Huu Nguyen 2796e1c9bc refactor(session): remove duplicate method, token expiry must be shorter than inactivity timeout 2023-02-21 15:34:50 +01:00
Trong Huu Nguyen ec572db957 refactor(session): remove internal method from Reader interface 2023-02-21 15:12:45 +01:00
Trong Huu Nguyen 59a2e7b7a0 refactor(session): simplify AccessToken method, don't export methods that are only used within package 2023-02-21 14:40:27 +01:00
Trong Huu Nguyen 5b33313ccb feat(session): add GetOrRefresh method 2023-02-21 14:12:56 +01:00
Trong Huu Nguyen 820fb733e6 refactor(session): separate handler into manager and reader, use session struct to avoid polluting exported methods 2023-02-21 13:25:07 +01:00
Trong Huu Nguyen 49a90f3dbf refactor(session/ticket): rename method for clarity, add doc comments, clean up error handling 2023-02-21 12:28:21 +01:00
Trong Huu Nguyen db391a9e44 refactor(session/store): consolidate session errors and use multi-error wrapping 2023-02-21 10:06:44 +01:00
Trong Huu Nguyen 17f39f8c5f feat(session/data): add more validation methods 2023-02-21 09:59:38 +01:00
Trong Huu Nguyen 94d4b1a524 refactor(session): extract external ID function to separate file 2023-02-20 12:40:23 +01:00
Trong Huu Nguyen 0537c8172f feat(session): use tickets for per-session data encryption
Replace the usage of a single application-wide session crypter
with per-session crypters.

The application is no longer able to decrypt any session
encrypted with its symmetric key alone. Instead, a session ticket
with its associated data encryption key (DEK) is also required in order
to decrypt the associated session data. The ticket itself is
encrypted with the application's crypter; the latter of which is
effectively a key-encryption key (KEK).

Fixes #49.
2023-02-14 21:50:19 +01:00
Trong Huu Nguyen 1b2234f875 refactor(session/data): skip unnecessary base64 (un)marshalling 2023-02-13 20:14:38 +01:00
Trong Huu Nguyen c81297c401 build(deps): various bumps, use go-redis v9 2023-02-10 14:58:15 +01:00
Trong Huu Nguyen bd748b9cef refactor(openid/provider): use name from config instead of indirection layer 2023-02-10 14:57:56 +01:00
Trong Huu Nguyen 61a7a8f161 refactor: clean up errors and reverseproxy logging 2023-02-10 14:57:53 +01:00
Trong Huu Nguyen 6a142cf5a5 refactor(handler): use session cookie for frontchannel logout if available, clean up logout handlers 2023-02-10 14:57:48 +01:00