Skip to content

feat: Add forceLegacyConfig flag for alphaConfig compatibility#385

Open
pierluigilenoci wants to merge 20 commits intooauth2-proxy:mainfrom
pierluigilenoci:fix/alphaconfig-unified-improvements
Open

feat: Add forceLegacyConfig flag for alphaConfig compatibility#385
pierluigilenoci wants to merge 20 commits intooauth2-proxy:mainfrom
pierluigilenoci:fix/alphaconfig-unified-improvements

Conversation

@pierluigilenoci
Copy link
Member

@pierluigilenoci pierluigilenoci commented Jan 6, 2026

Summary

This PR fixes critical bugs in alphaConfig integration and introduces the forceLegacyConfig flag to provide backward compatibility for users with custom configuration files.

Problem Statement

Issue #226: alphaConfig fails with "invalid keys: upstreams"

When alphaConfig.enabled = true, oauth2-proxy loads BOTH configuration files:

  • The legacy config file (oauth2_proxy.cfg) via --config flag
  • The alpha config file (oauth2_proxy.yml) via --alpha-config flag

However, alphaConfig removed support for the upstreams option. If the legacy config contains upstreams, oauth2-proxy fails with:

failed to load core options: failed to load config: error unmarshalling config: '' has invalid keys: upstreams

Critical Bug: Missing email_domains validation

When alphaConfig.enabled=true with default values, the deployment was not mounting the ConfigMap or adding the --config flag, causing oauth2-proxy to fail with:

missing setting for email validation

Issue #302: Difficulty using external secrets with alphaConfig

Users wanting to load secrets from external sources (e.g., Azure Key Vault CSI Driver) lacked clear documentation on how to inject secrets via environment variables.

Issue #311: Missing alphaConfig documentation

Users needed examples showing how to configure upstreamConfig in alphaConfig mode, particularly for multi-upstream scenarios with path-based routing.

Solution

1. Fixed Critical Bug: Always mount ConfigMap

Commit: 7e6bd35

Fixed deployment template to ALWAYS mount the ConfigMap and add --config flag, regardless of alphaConfig settings. This ensures email_domains is always provided to oauth2-proxy.

2. Fixed alphaConfig Incompatibility

Commit: 9f00757

Changed the auto-generated legacy config logic:

  • When alphaConfig DISABLED → Full legacy config with email_domains + upstreams
  • When alphaConfig ENABLED → Minimal legacy config with email_domains ONLY (no upstreams)

This is because when alphaConfig is enabled, oauth2-proxy loads BOTH config files, and the legacy config CANNOT contain options removed by alphaConfig.

3. Introduced forceLegacyConfig Flag

Commit: 4a7c93a

Added config.forceLegacyConfig (default: true) to control whether custom configFile should be used when alphaConfig is enabled:

  • forceLegacyConfig = true (default): Use custom configFile as-is (backward compatible)
  • forceLegacyConfig = false: Ignore custom configFile and auto-generate minimal config

IMPORTANT: This flag ONLY affects custom configFile behavior. It does NOT control whether upstreams are included in auto-generated configs.

4. Structured Configuration

Changed from hardcoded config.configFile to structured fields:

  • config.emailDomains: Email domains allowed to authenticate (default: [ "*" ])
  • config.upstreams: Legacy upstream configuration (default: [ "file:///dev/null" ])
  • config.configFile: Custom config template (empty by default)

5. Configuration Generation Logic

The configmap.yaml template now implements this logic:

alphaConfig forceLegacyConfig configFile Generated Config
disabled any empty email_domains + upstreams
disabled any custom Uses custom configFile as-is
enabled any empty email_domains ONLY (no upstreams)
enabled true custom Uses custom configFile as-is
enabled false custom email_domains ONLY (ignores custom)

Key Points:

  • When alphaConfig is enabled, auto-generated config NEVER includes upstreams (regardless of forceLegacyConfig)
  • forceLegacyConfig only controls whether to use or ignore custom configFile when alphaConfig is enabled
  • ConfigMap is ALWAYS mounted and --config flag is ALWAYS added

6. Comprehensive Documentation

Added examples for:

  • alphaConfig upstreams: Multi-upstream configuration with path-based routing, rewriteTarget, injectResponseHeaders
  • External secrets: Using extraEnv to load secrets from Azure Key Vault CSI Driver
  • forceLegacyConfig usage: Clear instructions on when and how to use the flag

Migration Guide

For most users (NOT experiencing issue #226)

No action required. The chart now works correctly with alphaConfig enabled using default values.

For users experiencing "invalid keys: upstreams" error

If you're getting this error with alphaConfig enabled, you have two options:

Option A: Use alphaConfig upstreams (RECOMMENDED)

config:
  emailDomains: [ "*" ]
  # Remove upstreams from config - let chart auto-generate minimal legacy config

alphaConfig:
  enabled: true
  configData:
    upstreamConfig:
      upstreams:
        - id: backend
          path: /
          uri: http://backend:8080

Option B: Use custom configFile with forceLegacyConfig
If you have a custom config.configFile that includes upstreams:

config:
  forceLegacyConfig: false  # Ignore custom configFile
  emailDomains: [ "*" ]

alphaConfig:
  enabled: true
  configData:
    upstreamConfig:
      upstreams:
        - id: backend
          path: /
          uri: http://backend:8080

For users with custom configFile (backward compatibility)

If you have a custom config.configFile that does NOT contain removed alphaConfig options:

config:
  forceLegacyConfig: true  # Use custom configFile (default)
  configFile: |
    email_domains = [ "*" ]
    # Your other legacy config options

alphaConfig:
  enabled: true
  configData:
    upstreamConfig:
      upstreams:
        - id: backend
          path: /
          uri: http://backend:8080

Testing

Commit: 88ae305

Created comprehensive CI test suite covering all configuration scenarios:

All test cases pass successfully.

Breaking Changes

None. This is a non-breaking change.

  • ConfigMap is now always mounted (fixes bug, doesn't break existing deployments)
  • Default behavior with alphaConfig now works correctly
  • forceLegacyConfig defaults to true for backward compatibility with custom configFiles

Checklist

  • Chart version bumped to 10.1.0 (minor version for new feature)
  • Changelog updated in Chart.yaml
  • Comprehensive test suite created with 6 CI test scenarios
  • Documentation added with examples
  • DCO sign-off included in all commits
  • Zero breaking changes confirmed via testing

Related Issues

When a GitHub release already exists, the chart-releaser-action fails
with a "422 Validation Failed" error, preventing the subsequent
"Push Charts to GHCR and Sign" step from executing. This causes
OCI artifacts to not be published to GHCR.

This fix adds `skip_existing: true` to the chart-releaser-action
configuration, which allows the workflow to skip the GitHub release
creation if it already exists and continue to the GHCR push step.

Fixes oauth2-proxy#380

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
…sting-releases

fix: add skip_existing to chart-releaser to prevent workflow failures
@pierluigilenoci pierluigilenoci force-pushed the fix/alphaconfig-unified-improvements branch 6 times, most recently from 2226bf0 to ed7aef1 Compare January 6, 2026 21:21
@pierluigilenoci pierluigilenoci changed the title feat: Add forceLegacyConfig flag for alphaConfig compatibility [WIP] feat: Add forceLegacyConfig flag for alphaConfig compatibility Jan 6, 2026
@pierluigilenoci pierluigilenoci force-pushed the fix/alphaconfig-unified-improvements branch from 1314875 to 9f00757 Compare January 7, 2026 09:10
@pierluigilenoci pierluigilenoci requested a review from tuunit January 7, 2026 09:14
@pierluigilenoci pierluigilenoci changed the title [WIP] feat: Add forceLegacyConfig flag for alphaConfig compatibility feat: Add forceLegacyConfig flag for alphaConfig compatibility Jan 7, 2026
Comment on lines +78 to +95
# IMPORTANT: If you have a custom configFile with 'upstreams',
# you MUST:
# 1. Remove 'upstreams' from your custom configFile
# 2. Define upstreams in alphaConfig.configData.upstreamConfig
# (see examples below)
# 3. Set forceLegacyConfig: false
forceLegacyConfig: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change?

Copy link
Member Author

@pierluigilenoci pierluigilenoci Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not a breaking change. Here's why:

The Scenario Didn't Work Before

When alphaConfig.enabled=true without a custom configFile, the old chart:

  • Did not generate a ConfigMap (required configFile to exist)
  • Did not mount the config or add --config flag
  • Failed with error: missing setting for email validation

This scenario was broken before this PR.

This PR Fixes That Bug

Now with this PR, the same scenario:

What forceLegacyConfig: true Does

The default forceLegacyConfig: true preserves behavior for users who DO have a custom configFile:

Before PR (with custom configFile):

config:
  configFile: |
    email_domains = ["*"]
    upstreams = ["http://backend"]
alphaConfig:
  enabled: true

→ Uses the custom configFile

After PR (with custom configFile + default):

config:
  forceLegacyConfig: true  # DEFAULT
  configFile: |
    email_domains = ["*"]
    upstreams = ["http://backend"]
alphaConfig:
  enabled: true

→ Still uses the custom configFile (identical behavior)

Not Breaking Because

  1. The scenario without custom configFile didn't work before → now it works (bug fix)
  2. The scenario with custom configFile works the same with the default (backward compatible)
  3. All CI tests pass, confirming no regressions

The tests validate both scenarios work correctly.

@pierluigilenoci pierluigilenoci requested a review from tuunit January 7, 2026 10:34
lilioid and others added 2 commits January 14, 2026 14:26
A previous template error still mentioned the old "redis.enabled" value
even though that has been renamed to redis-ha.enabled in v10.0.0.

Signed-off-by: Lilly Sell <sell@b1-systems.de>
…t-in-fail-msg

doc: Fix mention of old `redis.enabled` value in failure message
@pierluigilenoci pierluigilenoci force-pushed the fix/alphaconfig-unified-improvements branch from 81e4ac9 to 2b757e4 Compare January 15, 2026 09:23
pierluigilenoci and others added 6 commits January 15, 2026 16:14
* fix: correct image registry priority order

Local image.registry setting should take precedence over global.imageRegistry
to allow proper configuration when oauth2-proxy is used as a subchart.

Previous behavior:
1. global.imageRegistry (highest priority)
2. image.registry
3. quay.io (default in values.yaml)

New behavior:
1. image.registry (highest priority)
2. global.imageRegistry
3. quay.io (default in template)

This aligns with standard Helm chart behavior where local settings
override global settings.

Changes:
- Updated deployment.yaml template to prioritize local over global registry
- Removed default registry value from values.yaml (now defaults in template)
- Bumped chart version to 10.1.0 (minor version for behavior change)

Fixes oauth2-proxy#379

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

* Downgrade oauth2-proxy version to 10.0.1

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

* Bump oauth2-proxy version to 10.0.3

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

---------

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Added config.secretKeys option to provide granular control over which
secrets are included in the Kubernetes secret and exposed as environment
variables. This addresses scenarios where certain authentication methods
don't require all secrets (e.g., Azure Entra ID federated token authentication
doesn't need client-secret).

Implementation:
- Added config.secretKeys list in values.yaml (defaults to empty list)
- When empty, defaults to all three secrets: [client-id, client-secret, cookie-secret]
- Modified _helpers.tpl to conditionally include secrets based on allowlist
- Modified deployment.yaml to conditionally set environment variables

Example usage to exclude client-secret:
config:
  requiredSecretKeys:
    - client-id
    - cookie-secret

This provides explicit control and future extensibility for additional
secrets while maintaining full backward compatibility.

Fixes oauth2-proxy#376

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Address maintainer feedback from PR review:
- Renamed config.secretKeys to config.requiredSecretKeys for clarity
- Moved default values from template to values.yaml as suggested
- Removed the '| default' logic from templates

Changes:
- values.yaml: Define requiredSecretKeys with explicit defaults:
  [client-id, client-secret, cookie-secret]
- _helpers.tpl: Use requiredSecretKeys directly without fallback
- deployment.yaml: Use requiredSecretKeys directly without fallback

This makes the configuration more explicit and easier to understand,
following Helm best practices of defining defaults in values.yaml
rather than in templates.

Addresses: oauth2-proxy#384 (review comments)
Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Update changelog annotation to use the correct field name
'requiredSecretKeys' instead of 'secretKeys' to match the
implemented changes.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
…client-secret-federated-auth

feat: add config.secretKeys to selectively include secrets
…uth2-proxy#382)

* docs: add explicit warning for redis single replica configuration

When using redis-ha with a single replica (replicas: 1), Redis requires
min-replicas-to-write to be set to 0, otherwise write operations fail
with 'NOREPLICAS Not enough good replicas to write' error.

This change adds an explicit IMPORTANT note in the values.yaml
documentation, positioned immediately after the replicas setting to
make the requirement clear to users.

This configuration is already used in the CI tests
(helm/oauth2-proxy/ci/redis-standalone-values.yaml:29) and is
documented in the Redis documentation.

Supersedes oauth2-proxy#359

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

* Bump oauth2-proxy version to 10.0.2

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>

* docs: remove release for a pure documentation change

Signed-off-by: Jan Larwig <jan@larwig.com>

---------

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Jan Larwig <jan@larwig.com>
Co-authored-by: Jan Larwig <jan@larwig.com>
@tuunit tuunit force-pushed the fix/alphaconfig-unified-improvements branch from 1692125 to a7ae6d4 Compare January 16, 2026 07:59
Introduces structured configuration to resolve conflicts between
legacy config and alphaConfig modes when upstreams option is used.

Fixes: oauth2-proxy#226
Closes: oauth2-proxy#302
Closes: oauth2-proxy#311

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Add comprehensive test cases covering:
- Custom configFile with alphaConfig disabled
- alphaConfig with forceLegacyConfig=true (backward compatible)
- alphaConfig with forceLegacyConfig=false (fix for oauth2-proxy#226)
- alphaConfig + custom configFile + forceLegacyConfig=true
- alphaConfig + custom configFile + forceLegacyConfig=false
- Existing external ConfigMap via extraObjects

These tests ensure all configuration scenarios work correctly and
prevent regressions in the forceLegacyConfig feature.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
When alphaConfig.enabled=true and forceLegacyConfig=false, the
deployment was not mounting the ConfigMap or adding the --config flag
because the condition checked for existingConfig OR configFile.

Since configFile defaults to empty string, the condition was false
and oauth2-proxy failed with 'missing setting for email validation'.

Fixed by removing the conditions entirely:
- ConfigMap volume is always created (using existingConfig if specified)
- ConfigMap is always mounted
- --config flag is always added

This ensures email_domains is always provided to oauth2-proxy,
whether using the generated ConfigMap or an existingConfig.

This is NOT a breaking change - it fixes a bug where the app didn't
work with default values when using alphaConfig.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
When alphaConfig is enabled, oauth2-proxy loads BOTH config files
(--alpha-config and --config) but the legacy config CANNOT contain
options that were removed by alphaConfig like 'upstreams'.

This is true ALWAYS when alphaConfig is enabled, regardless of
forceLegacyConfig value.

Changed logic:
- When alphaConfig DISABLED → full legacy config (email_domains + upstreams)
- When alphaConfig ENABLED → minimal legacy config (only email_domains)

The forceLegacyConfig flag now only controls whether to use a custom
configFile when alphaConfig is enabled (not whether to include upstreams
in auto-generated config).

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@tuunit tuunit force-pushed the fix/alphaconfig-unified-improvements branch from a7ae6d4 to 9468636 Compare January 16, 2026 08:00
renovate bot and others added 3 commits January 23, 2026 19:28
…tch-updates

chore(deps): update helm release redis-ha to v4.35.6
Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@pierluigilenoci pierluigilenoci force-pushed the fix/alphaconfig-unified-improvements branch 2 times, most recently from e9822cd to 9683e02 Compare January 24, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants