Skip to content

Commit 727b5ec

Browse files
feat: add forceLegacyConfig flag for alphaConfig compatibility (#385)
* feat: add forceLegacyConfig flag for alphaConfig compatibility - 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> * test(ci): update test case files for config testing Signed-off-by: Jan Larwig <jan@larwig.com> * feat(alpha-config): rework forceLegacyConfig flag * 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> * doc: reword how to use the alpha config Signed-off-by: Jan Larwig <jan@larwig.com> * fix: typo in README.md "inot" → "into" Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.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>
1 parent 70f7809 commit 727b5ec

13 files changed

Lines changed: 373 additions & 27 deletions

helm/oauth2-proxy/Chart.yaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: oauth2-proxy
2-
version: 10.3.0
2+
version: 10.4.0
33
apiVersion: v2
44
appVersion: 7.15.0
55
home: https://oauth2-proxy.github.io/oauth2-proxy/
@@ -30,8 +30,23 @@ maintainers:
3030
kubeVersion: ">=1.16.0-0"
3131
annotations:
3232
artifacthub.io/changes: |
33+
- kind: fixed
34+
description: Restructured config.configFile generation to support alphaConfig without conflicts
35+
links:
36+
- name: GitHub Issue
37+
url: https://github.com/oauth2-proxy/manifests/issues/226
38+
- kind: added
39+
description: Added structured configuration with config.emailDomains and config.upstreams for better flexibility
40+
links:
41+
- name: GitHub Issue
42+
url: https://github.com/oauth2-proxy/manifests/issues/226
43+
- kind: added
44+
description: Added config.forceLegacyConfig flag for users with custom configFile when using alphaConfig
45+
links:
46+
- name: GitHub Issue
47+
url: https://github.com/oauth2-proxy/manifests/issues/226
3348
- kind: added
34-
description: Add tpl support for config.cookieName, config.existingSecret, customLabels, image.registry, imagePullSecrets, and networkPolicy.ingress/egress
49+
description: Added comprehensive alphaConfig examples with upstreamConfig configuration
3550
links:
36-
- name: GitHub PR
37-
url: https://github.com/oauth2-proxy/manifests/pull/398
51+
- name: GitHub Issue
52+
url: https://github.com/oauth2-proxy/manifests/issues/311

helm/oauth2-proxy/README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ With above new chart version won't add extra `-ha` suffix to all redis resources
148148
The following table lists the configurable parameters of the oauth2-proxy chart and their default values.
149149

150150
| Parameter | Description | Default |
151-
|-------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|
151+
|-------------------------------------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
152152
| `affinity` | node/pod affinities | None |
153153
| `alphaConfig.annotations` | Configmap annotations | `{}` |
154154
| `alphaConfig.configData` | Arbitrary configuration data to append | `{}` |
@@ -174,11 +174,14 @@ The following table lists the configurable parameters of the oauth2-proxy chart
174174
| `checkDeprecation` | Enable deprecation checks | `true` |
175175
| `config.clientID` | oauth client ID | `""` |
176176
| `config.clientSecret` | oauth client secret | `""` |
177-
| `config.configFile` | custom [oauth2_proxy.cfg](https://github.com/oauth2-proxy/oauth2-proxy/blob/master/contrib/oauth2-proxy.cfg.example) contents for settings not overridable via environment nor command line | `""` |
177+
| `config.configFile` | custom [oauth2_proxy.cfg](https://github.com/oauth2-proxy/oauth2-proxy/blob/master/contrib/oauth2-proxy.cfg.example) contents for settings not overridable via environment nor command line. Ignored when `alphaConfig.enabled=true` and `config.forceLegacyConfig=false` | `""` |
178178
| `config.cookieName` | The name of the cookie that oauth2-proxy will create. | `""` |
179179
| `config.cookieSecret` | server specific cookie for the secret; create a new one with `openssl rand -base64 32 \| head -c 32 \| base64` | `""` |
180-
| `config.existingConfig` | existing Kubernetes configmap to use for the configuration file. See [config template](https://github.com/oauth2-proxy/manifests/blob/master/helm/oauth2-proxy/templates/configmap.yaml) for the required values | `nil` |
180+
| `config.upstreams` | Legacy upstreams used only when the chart generates `oauth2_proxy.cfg` and `alphaConfig` is disabled. Under `alphaConfig`, define upstreams in `alphaConfig.configData.upstreamConfig` | `['file:///dev/null']` |
181+
| `config.emailDomains` | Email domains used when the chart generates `oauth2_proxy.cfg`. This remains the only generated legacy setting when `alphaConfig.enabled=true` | `['*']` |
182+
| `config.existingConfig` | existing Kubernetes configmap to use for the configuration file. Ignored when `alphaConfig.enabled=true` and `config.forceLegacyConfig=false`. See [config template](https://github.com/oauth2-proxy/manifests/blob/master/helm/oauth2-proxy/templates/configmap.yaml) for the required values | `nil` |
181183
| `config.existingSecret` | existing Kubernetes secret to use for OAuth2 credentials. See [oauth2-proxy.secrets helper](https://github.com/oauth2-proxy/manifests/blob/main/helm/oauth2-proxy/templates/_helpers.tpl#L157C13-L157C33) for the required values | `nil` |
184+
| `config.forceLegacyConfig` | When `alphaConfig.enabled=true`, keep using custom legacy `config.configFile` or `config.existingConfig` when `true`; when `false`, ignore both and generate only `email_domains` in `oauth2_proxy.cfg` | `true` |
182185
| `config.google.adminEmail` | user impersonated by the Google service account | `""` |
183186
| `config.google.existingConfig` | existing Kubernetes configmap to use for the service account file. See [Google secret template](https://github.com/oauth2-proxy/manifests/blob/master/helm/oauth2-proxy/templates/google-secret.yaml) for the required values | `nil` |
184187
| `config.google.groups` | restrict logins to members of these Google groups | `[]` |
@@ -373,7 +376,7 @@ gatewayApi:
373376
example.com/annotation: "value"
374377
```
375378
376-
If you don't specify custom rules, the chart will create a default rule that matches all paths with `PathPrefix: /` and routes to the oauth2-proxy service.
379+
If you don't specify custom rules, the chart will create a default rule that matches all paths with `PathPrefix: /` and routes to the oauth2-proxy service.
377380
If you don't specify a sectionName, the rules will be applied to all listeners of the referenced Gateway.
378381

379382
## TLS Configuration
@@ -462,7 +465,11 @@ extraObjects:
462465
```
463466

464467
## Multi whitelist-domain configuration
465-
You must use the config.configFile section for a multi-whitelist-domain configuration for one Oauth2-proxy instance.
468+
Use the structured `config.emailDomains` and `config.upstreams` values when they cover your case.
469+
470+
Use `config.configFile` only when you need legacy `oauth2_proxy.cfg` settings that are not exposed as structured chart values, such as `whitelist_domains`.
471+
472+
When `alphaConfig.enabled=true`, upstreams belong in `alphaConfig.configData.upstreamConfig`. If you also set `config.forceLegacyConfig=false`, the chart ignores both `config.configFile` and `config.existingConfig` and generates a minimal legacy config with only `email_domains`.
466473

467474
It will be overwriting the `/etc/oauth2_proxy/oauth2_proxy.cfg` [configuration file](https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview#config-file).
468475
In this example, Google provider is used, but you can find all other provider configurations here [oauth_provider](https://oauth2-proxy.github.io/oauth2-proxy/configuration/providers/).
@@ -483,5 +490,22 @@ config:
483490
provider = "google"
484491
```
485492

493+
## Alpha config migration
494+
When moving to `alphaConfig`, keep one main config source in mind. The Alpha Config will take precedence and all options
495+
that are already supported by the Alpha Config will need to be removed from the legacy toml config. Have a look at the
496+
[Alpha Config documentation](https://oauth2-proxy.github.io/oauth2-proxy/configuration/alpha-config/).
497+
498+
Keep the following in mind:
499+
500+
- The chart always mounts `/etc/oauth2_proxy/oauth2_proxy.cfg`. (Legacy toml config)
501+
- Per default `config.forceLegacyConfig` is `true`
502+
503+
The evaluation happens in the following order:
504+
505+
1. If `config.forceLegacyConfig=false`, the chart ignores both the `config.configFile` and `config.existingConfig` overrides and only generates a minimal necessary legacy config.
506+
2. If `config.existingConfig` is set and `config.forceLegacyConfig=true`, the external ConfigMap is used as the mounted file.
507+
3. If `config.configFile` is set and `config.forceLegacyConfig=true`, the chart renders that inline content into the mounted file.
508+
4. Reminder: Put your upstream definitions into `alphaConfig.configData.upstreamConfig`, not in the legacy `config.upstreams` or a legacy config file which will cause an error with the alpha config.
509+
486510
## Route requests to sidecar container
487511
You can route requests to a sidecar container first by setting the `service.targetPort` variable. The possible values for the targetPort field of a Kubernetes Service can be either a port number or the name of a port defined in the pod. By default, the service's `targetPort` value equals to `httpSchema`'s.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Test Case 1: alphaConfig enabled with no custom legacy config
2+
# Expected: Default behavior still generates the minimal legacy config with only email_domains.
3+
4+
alphaConfig:
5+
enabled: true
6+
configData:
7+
providers:
8+
- id: google
9+
provider: google
10+
clientID: fake-client-id
11+
clientSecret: fake-client-secret
12+
upstreamConfig:
13+
upstreams:
14+
- id: alpha-service
15+
path: /
16+
uri: http://alpha-backend:8080
17+
18+
# Implicit through default values, but explicitly set here for clarity in the test case
19+
config:
20+
forceLegacyConfig: true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Test Case 2: alphaConfig enabled with forceLegacyConfig=false and no custom legacy config
2+
# Expected: Chart generates the minimal legacy config with only email_domains.
3+
4+
alphaConfig:
5+
enabled: true
6+
configData:
7+
providers:
8+
- id: google
9+
provider: google
10+
clientID: fake-client-id
11+
clientSecret: fake-client-secret
12+
upstreamConfig:
13+
upstreams:
14+
- id: alpha-service
15+
path: /
16+
uri: http://alpha-backend:8080
17+
18+
config:
19+
forceLegacyConfig: false
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Test Case 3: alphaConfig enabled + custom configFile + forceLegacyConfig=true
2+
# Expected: Chart keeps the custom legacy config file content unchanged.
3+
4+
alphaConfig:
5+
enabled: true
6+
configData:
7+
providers:
8+
- id: google
9+
provider: google
10+
clientID: fake-client-id
11+
clientSecret: fake-client-secret
12+
upstreamConfig:
13+
upstreams:
14+
- id: alpha-service
15+
path: /
16+
uri: http://alpha-backend:8080
17+
18+
config:
19+
configFile: |-
20+
email_domains = [ "example.com" ]
21+
encode_state = true
22+
forceLegacyConfig: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Test Case 4: alphaConfig enabled + custom configFile + forceLegacyConfig=false
2+
# Expected: Chart ignores the custom legacy config and generates only email_domains.
3+
4+
alphaConfig:
5+
enabled: true
6+
configData:
7+
providers:
8+
- id: google
9+
provider: google
10+
clientID: fake-client-id
11+
clientSecret: fake-client-secret
12+
upstreamConfig:
13+
upstreams:
14+
- id: alpha-service
15+
path: /
16+
uri: http://alpha-backend:8080
17+
18+
config:
19+
configFile: |-
20+
email_domains = [ "example.com" ]
21+
upstreams = [ "http://ignored-backend:8080" ]
22+
forceLegacyConfig: false
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Test Case 5: alphaConfig enabled + existingConfig + forceLegacyConfig=false
2+
# Expected: Chart ignores the external legacy ConfigMap and generates only email_domains.
3+
4+
alphaConfig:
5+
enabled: true
6+
configData:
7+
providers:
8+
- id: google
9+
provider: google
10+
clientID: fake-client-id
11+
clientSecret: fake-client-secret
12+
upstreamConfig:
13+
upstreams:
14+
- id: alpha-service
15+
path: /
16+
uri: http://alpha-backend:8080
17+
18+
config:
19+
existingConfig: my-external-configmap
20+
forceLegacyConfig: false
21+
22+
extraObjects:
23+
- apiVersion: v1
24+
kind: ConfigMap
25+
metadata:
26+
name: my-external-configmap
27+
data:
28+
oauth2_proxy.cfg: |
29+
email_domains = [ "ignored.example.com" ]
30+
upstreams = [ "http://ignored-backend:8080" ]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Test Case 6: alphaConfig enabled + existingConfig + forceLegacyConfig=true
2+
# Expected: Chart mounts the external legacy ConfigMap as the main config.
3+
4+
alphaConfig:
5+
enabled: true
6+
configData:
7+
providers:
8+
- id: google
9+
provider: google
10+
clientID: fake-client-id
11+
clientSecret: fake-client-secret
12+
upstreamConfig:
13+
upstreams:
14+
- id: alpha-service
15+
path: /
16+
uri: http://alpha-backend:8080
17+
18+
config:
19+
existingConfig: my-external-configmap
20+
forceLegacyConfig: true
21+
22+
extraObjects:
23+
- apiVersion: v1
24+
kind: ConfigMap
25+
metadata:
26+
name: my-external-configmap
27+
data:
28+
oauth2_proxy.cfg: |
29+
email_domains = [ "legacy.example.com" ]
30+
encode_state = true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
config:
2+
existingConfig: "my-external-configmap"
3+
4+
# Create the external ConfigMap that the chart expects
5+
extraObjects:
6+
- apiVersion: v1
7+
kind: ConfigMap
8+
metadata:
9+
name: my-external-configmap
10+
data:
11+
oauth2_proxy.cfg: |
12+
email_domains = [ "*" ]
13+
upstreams = [ "file:///dev/null" ]

0 commit comments

Comments
 (0)