mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 14:39:23 -05:00
Multiple access tokens can be valid for one session, for example after a refresh. A logout only removed the cached claims of the token in the session lookup, so older tokens stayed accepted. With PROXY_OIDC_SKIP_USER_INFO=true, even the removed token was accepted again, because a still valid JWT was verified anew. Write a marker on every verified logout and check it on every authenticated request, for cached and uncached tokens. This also covers tokens the proxy has not seen before the logout. If the marker store cannot be read, the cached claims are not used and the userinfo endpoint decides about the token. With PROXY_OIDC_SKIP_USER_INFO=true there is no such check, so the request is rejected. A corrupt marker always rejects. The cached record now keeps the verified subject, session and issue time, because a userinfo response can overwrite them in the claims. The cache database is renamed to start with a fresh cache. Markers get their own database because nats-js-kv only supports one TTL per bucket. They are kept for the new PROXY_OIDC_MAX_ACCESS_TOKEN_LIFETIME plus a buffer. A JWT access token with a longer lifetime or without an expiration can outlive its marker, so the proxy logs a warning for it. Logout tokens without iat are now rejected, as the spec requires the claim. Publishing the logout event and removing cached records are now best effort, so a failed publish no longer prevents the logout.
91 lines
3.0 KiB
Go
91 lines
3.0 KiB
Go
package parser
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
occfg "github.com/opencloud-eu/opencloud/pkg/config"
|
|
"github.com/opencloud-eu/opencloud/pkg/middleware"
|
|
"github.com/opencloud-eu/opencloud/pkg/shared"
|
|
"github.com/opencloud-eu/opencloud/services/proxy/pkg/config"
|
|
"github.com/opencloud-eu/opencloud/services/proxy/pkg/config/defaults"
|
|
|
|
"github.com/opencloud-eu/opencloud/pkg/config/envdecode"
|
|
)
|
|
|
|
// ParseConfig loads configuration from known paths.
|
|
func ParseConfig(cfg *config.Config) error {
|
|
err := occfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defaults.EnsureDefaults(cfg)
|
|
// load all env variables relevant to the config in the current context.
|
|
if err := envdecode.Decode(cfg); err != nil {
|
|
// no environment variable set for this config is an expected "error"
|
|
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
|
|
return err
|
|
}
|
|
}
|
|
|
|
defaults.Sanitize(cfg)
|
|
|
|
return Validate(cfg)
|
|
}
|
|
|
|
func Validate(cfg *config.Config) error {
|
|
if cfg.MachineAuthAPIKey == "" {
|
|
return shared.MissingMachineAuthApiKeyError(cfg.Service.Name)
|
|
}
|
|
|
|
if cfg.TransferSecret == "" {
|
|
return shared.MissingRevaTransferSecretError(cfg.Service.Name)
|
|
}
|
|
|
|
if cfg.OIDC.AccessTokenVerifyMethod != config.AccessTokenVerificationNone &&
|
|
cfg.OIDC.AccessTokenVerifyMethod != config.AccessTokenVerificationJWT {
|
|
return fmt.Errorf(
|
|
"Invalid value '%s' for 'access_token_verify_method' in service %s. Possible values are: '%s' or '%s'.",
|
|
cfg.OIDC.AccessTokenVerifyMethod, cfg.Service.Name,
|
|
config.AccessTokenVerificationJWT, config.AccessTokenVerificationNone,
|
|
)
|
|
}
|
|
if cfg.OIDC.AccessTokenVerifyMethod == "none" && cfg.OIDC.SkipUserInfo {
|
|
return fmt.Errorf(
|
|
"Incompatible value '%t' for 'skip_user_info' in service %s. Must be false when 'access_token_verify_method' is 'none'.",
|
|
cfg.OIDC.SkipUserInfo, cfg.Service.Name,
|
|
)
|
|
}
|
|
if cfg.OIDC.MaxAccessTokenLifetime <= 0 {
|
|
return fmt.Errorf("The maximum access token lifetime (PROXY_OIDC_MAX_ACCESS_TOKEN_LIFETIME) in service %s must be greater than 0.", cfg.Service.Name)
|
|
}
|
|
if len(cfg.OIDC.Audiences) > 0 && cfg.OIDC.AccessTokenVerifyMethod != config.AccessTokenVerificationJWT {
|
|
return fmt.Errorf("OIDC audiences (PROXY_OIDC_AUDIENCES) in service %s require access_token_verify_method to be 'jwt'", cfg.Service.Name)
|
|
}
|
|
for _, audience := range cfg.OIDC.Audiences {
|
|
if strings.TrimSpace(audience) == "" {
|
|
return fmt.Errorf("OIDC audiences (PROXY_OIDC_AUDIENCES) in service %s must not contain empty or whitespace-only entries", cfg.Service.Name)
|
|
}
|
|
}
|
|
|
|
if _, err := middleware.ParseTrustedProxies(cfg.ClientIP.TrustedProxies); err != nil {
|
|
return fmt.Errorf("invalid PROXY_TRUSTED_PROXIES in service %s: %w", cfg.Service.Name, err)
|
|
}
|
|
|
|
if cfg.ServiceAccount.ServiceAccountID == "" {
|
|
return shared.MissingServiceAccountID(cfg.Service.Name)
|
|
}
|
|
|
|
if cfg.ServiceAccount.ServiceAccountSecret == "" {
|
|
return shared.MissingServiceAccountSecret(cfg.Service.Name)
|
|
}
|
|
|
|
if cfg.Commons.URLSigningSecret == "" {
|
|
return shared.MissingURLSigningSecret(cfg.Service.Name)
|
|
}
|
|
|
|
return nil
|
|
}
|