feat: add forceLegacyConfig flag for alphaConfig compatibility#385
Conversation
2226bf0 to
ed7aef1
Compare
1314875 to
9f00757
Compare
81e4ac9 to
2b757e4
Compare
a7ae6d4 to
9468636
Compare
e9822cd to
9683e02
Compare
|
Hey @JoelSpeed @desaintmartin @jkroepke — just a gentle nudge on this one. @tuunit raised a question about whether this could be a breaking change, and I provided a detailed explanation back in January, but we haven't had a chance to reach consensus yet. Would any of you have a moment to take a look and share your thoughts? I'd really appreciate a second pair of eyes on this. No rush at all — just want to make sure it doesn't fall through the cracks. Thanks! |
|
@pierluigilenoci sorry I lost track of your PR always feel free to give me another nudge on Slack! I'll have another look at it tomorrow |
There was a problem hiding this comment.
Pull request overview
This PR updates the Helm chart’s config generation to support alphaConfig mode without conflicting legacy options, and introduces a config.forceLegacyConfig flag to control compatibility behavior when users provide a custom legacy config file.
Changes:
- Always mount the legacy ConfigMap and always pass
--config, ensuring legacy-required settings (likeemail_domains) are present even withalphaConfigenabled. - Restructure legacy config generation into structured values (
config.emailDomains,config.upstreams) and conditional rendering logic inconfigmap.yamlto avoidupstreamswhenalphaConfigis enabled. - Add multiple
ctinstall scenarios and update chart metadata/changelog entries.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| helm/oauth2-proxy/values.yaml | Introduces structured config fields + forceLegacyConfig and adds documentation/examples. |
| helm/oauth2-proxy/templates/deployment.yaml | Makes legacy --config argument and config mount unconditional. |
| helm/oauth2-proxy/templates/configmap.yaml | Implements the legacy-config rendering matrix for alphaConfig / forceLegacyConfig / configFile. |
| helm/oauth2-proxy/ci/custom-configfile-values.yaml | Adds ct install scenario for custom legacy config (alpha disabled). |
| helm/oauth2-proxy/ci/alphaconfig-legacy-true-values.yaml | Adds ct scenario for alphaConfig with forceLegacyConfig=true. |
| helm/oauth2-proxy/ci/alphaconfig-legacy-false-values.yaml | Adds ct scenario for alphaConfig with forceLegacyConfig=false. |
| helm/oauth2-proxy/ci/alphaconfig-custom-configfile-legacy-true-values.yaml | Adds ct scenario for alphaConfig + custom legacy config honored. |
| helm/oauth2-proxy/ci/alphaconfig-custom-configfile-legacy-false-values.yaml | Adds ct scenario for alphaConfig + custom legacy config ignored. |
| helm/oauth2-proxy/ci/existing-configmap-values.yaml | Adds ct scenario for using an externally provided legacy ConfigMap. |
| helm/oauth2-proxy/Chart.yaml | Bumps chart version and updates Artifact Hub changelog annotations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
25b74b9 to
d8075c2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
87ae0cd to
21be40f
Compare
|
@tuunit in the meantime I've addressed all the Copilot review observations and squashed everything into a single commit. Looking forward to your improvements! |
- Always mount ConfigMap and pass --config flag regardless of alphaConfig - Auto-generate minimal legacy config (email_domains only) when alphaConfig enabled - Add config.forceLegacyConfig flag to control custom configFile behavior - Add structured config fields: emailDomains, upstreams - Fix configmap.yaml YAML rendering (trim markers collapsing data:/key) - Compute checksum/config from rendered configmap for proper rollout detection - Add comprehensive CI test scenarios and documentation Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Jan Larwig <jan@larwig.com>
21be40f to
aa1f3e0
Compare
|
I made a couple larger and minor changes:
|
e62b3f1 to
b8bb546
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b8bb546 to
2010371
Compare
* Refactored config logic into helpers (_helpers.tpl): Moved inline conditionals from configmap.yaml into reusable templates (legacy-config.mode, legacy-config.name, legacy-config.content) for better and more central maintainability * Fixed checksum behavior: Changed deployment annotation to hash actual rendered config content instead of the template file path (this should ensure that pods actually roll when values change, not just when templates change) * Renamed the CI coverage: 6 granular test cases covering all combinations of alphaConfig.enabled + forceLegacyConfig + existingConfig/configFile * Updated the alphaConfig migration guide and precedence rules in Readme and other places like the values yaml and helpers Signed-off-by: Jan Larwig <jan@larwig.com>
2010371 to
de9be5f
Compare
|
@pierluigilenoci please have a look at more improvements. Hope it makes sense to you! I'm not yet 100% happy with the Readme update. it sounds quite convoluted and i think users will be confused. i'll give it another shot to rephrase it differently tomorrow on my way to kubecon |
Signed-off-by: Jan Larwig <jan@larwig.com>
|
Hey @tuunit, thanks for the refactoring — the 1.
|
Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
|
@tuunit this is my PR, is up to you for the final approval 😬 |
| name: {{ template "oauth2-proxy.fullname" . }}-wait-for-redis | ||
| defaultMode: 0775 | ||
| {{- end }} | ||
| {{- if or .Values.config.existingConfig .Values.config.configFile }} |
There was a problem hiding this comment.
What is the reason to remove this line? This breaks my setup as I use oauth2-proxy with CSI SecretStore Driver and I am mounting the config file through the CSI SecretStore driver and not a configmap. In my Helm values I have
config:
configfile: ""
Due to this config and the now removed logic it didn't used tomount the configmap.
There was a problem hiding this comment.
Hi @MattiasGees this is simple a use case we didn't consider during the refactoring.
I think the following fix should help resolve your problem:
#402
Please have a look at it :)
When alphaConfig.enabled=false and forceLegacyConfig=false, the chart now skips ConfigMap generation, volume mount, and --config flag entirely. This restores support for users managing oauth2-proxy configuration via external means (e.g., CSI SecretStore Driver) that was broken by oauth2-proxy#385. Closes oauth2-proxy#385 (discussion_r3001082837)
When alphaConfig.enabled=false and forceLegacyConfig=false, the chart now skips ConfigMap generation, volume mount, and --config flag entirely. This restores support for users managing oauth2-proxy configuration via external means (e.g., CSI SecretStore Driver) that was broken by oauth2-proxy#385. Closes oauth2-proxy#385 (discussion_r3001082837) Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Summary
This PR fixes critical bugs in alphaConfig integration and introduces the
forceLegacyConfigflag 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:oauth2_proxy.cfg) via--configflagoauth2_proxy.yml) via--alpha-configflagHowever, alphaConfig removed support for the
upstreamsoption. If the legacy config containsupstreams, oauth2-proxy fails with:Critical Bug: Missing email_domains validation
When
alphaConfig.enabled=truewith default values, the deployment was not mounting the ConfigMap or adding the--configflag, causing oauth2-proxy to fail with: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
upstreamConfigin alphaConfig mode, particularly for multi-upstream scenarios with path-based routing.Solution
1. Fixed Critical Bug: Always mount ConfigMap
Fixed deployment template to ALWAYS mount the ConfigMap and add
--configflag, regardless of alphaConfig settings. This ensuresemail_domainsis always provided to oauth2-proxy.2. Fixed alphaConfig Incompatibility
Changed the auto-generated legacy config logic:
email_domains+upstreamsemail_domainsONLY (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
Added
config.forceLegacyConfig(default:true) to control whether customconfigFileshould 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 configIMPORTANT: 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.configFileto 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.yamltemplate implements this logic:email_domains+upstreamsemail_domainsONLY (no upstreams)email_domainsONLY (ignores custom)Key Points:
upstreams(regardless of forceLegacyConfig)forceLegacyConfigonly controls whether to use or ignore custom configFile when alphaConfig is enabled--configflag is ALWAYS added6. Fixed ConfigMap YAML rendering
Fixed aggressive Go template trim markers (
{{- ... -}}) inconfigmap.yamlthat collapseddata:andoauth2_proxy.cfg:onto a single line, producing invalid YAML. This caused the config file to be mounted as a directory instead of a file, resulting in CrashLoopBackOff:7. Fixed checksum/config for rollout detection
The
checksum/configpod annotation was only computed whenconfig.configFilewas set. Changes to auto-generated config (viaemailDomains,upstreams,alphaConfig.enabled, orforceLegacyConfig) would update the ConfigMap but NOT trigger a pod rollout, leaving pods with stale config. Now the checksum is computed from the full renderedconfigmap.yamlwheneverexistingConfigis not set.8. Comprehensive Documentation
Added examples for:
extraEnvto load secrets from Azure Key Vault CSI DriverMigration 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)
Option B: Use custom configFile with forceLegacyConfig
If you have a custom
config.configFilethat includesupstreams:For users with custom configFile (backward compatibility)
If you have a custom
config.configFilethat does NOT contain removed alphaConfig options:Testing
Created comprehensive CI test suite covering all configuration scenarios:
All test cases pass successfully.
Breaking Changes
None. This is a non-breaking change.
forceLegacyConfigdefaults totruefor backward compatibility with custom configFilesChecklist
Related Issues