Skip to content

Commit da043cb

Browse files
jadonnfreyes
authored andcommitted
Fix reversed values, add config options
The values of the protocol ID and identity provider ID are reversed in the charm's code. This causes the mod_auth_openidc config to render incorrectly in the Apache template. This change fixes the reversed values and adds a config option for defining the identity provider ID. This change also adds new config options for enabling using mod_auth_openidc with multiple Keystone units and with proxies. Closes-Bug: #2065590 Func-Test-Pr: openstack-charmers/zaza-openstack-tests#1235 Change-Id: Ie7da5f9a85027a287aad9958c54848a948f8495c
1 parent ba5cd15 commit da043cb

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

config.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ options:
6666
(e.g. https://example.com/idp/userinfo.openid). Used when
6767
oidc-provider-metadata-url is not set or the metadata obtained from that
6868
URL does not set it.
69+
oidc-x-forwarded-headers:
70+
default: ''
71+
type: string
72+
description: |
73+
X-Forwarded-* headers from reverse proxies that mod_auth_openidc should
74+
look for. Must be one or more of "X-Forwarded-Host", "X-Forwarded-Port",
75+
"X-Forwarded-Proto", "Forwarded", or "none". mod_auth_openidc ignores
76+
this setting if it is "none" or undefined. Use this setting when using
77+
a proxy that changes the protocol, host, or port when handling the
78+
authentication workflow.
79+
oidc-state-input-headers:
80+
default: 'user-agent'
81+
type: string
82+
description: |
83+
Define the headers mod_auth_openidc uses to calculate the browser
84+
fingerprint during authentication. Set to "none" if using multiple
85+
units of Keystone behind a load balancer or proxy.
86+
oidc-session-type:
87+
default: 'server-cache'
88+
type: string
89+
description: |
90+
Set where OpenID Connect session cookies are stored. BY default cookies
91+
are stored on the web server. Can be one of 'server-cache',
92+
'server-cache:persistent', 'client-cookie', 'client-cookie:persistent',
93+
'client-cookie:store_id_token', or
94+
'client-cookie:persistent:store_id_token'. When using multiple units
95+
of Keystone behind a proxy, use 'client-cookie:persistent' if you are
96+
not using shared session storage for Keystone.
6997
auth-type:
7098
default: 'auth-openidc'
7199
type: string
@@ -74,6 +102,11 @@ options:
74102
by applications that do not adopt the browser flow, such the OpenStack
75103
CLI, the auth-type must be set to auth-openidc (the default) otherwise
76104
to openid-connect.
105+
idp_id:
106+
default: ''
107+
type: string
108+
description: |
109+
The ID of the Identity Provider defined in Keystone.
77110
protocol_id:
78111
default: 'openid'
79112
type: string

src/charm.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ def oidc_auth_path(self) -> str:
9494
return (f'/v3/OS-FEDERATION/identity_providers/{self.idp_id}'
9595
f'/protocols/openid/auth')
9696

97-
@property
98-
def idp_id(self) -> str:
99-
"""Identity provider name to use for URL generation."""
100-
return 'openid'
101-
10297
@property
10398
def scheme(self) -> Optional[str]:
10499
data = self._get_principal_data()
@@ -186,7 +181,7 @@ class KeystoneOpenIDCCharm(ops_openstack.core.OSBaseCharm):
186181
'cluster']
187182

188183
REQUIRED_KEYS = ['oidc_crypto_passphrase', 'oidc_client_id',
189-
'hostname', 'port', 'scheme']
184+
'hostname', 'port', 'scheme', 'idp_id', 'protocol_id']
190185
APACHE2_MODULE = 'auth_openidc'
191186

192187
CONFIG_FILE_OWNER = 'root'
@@ -261,7 +256,7 @@ def update_principal_data(self):
261256
# When (if) this patch is merged, we can use auth-method
262257
# https://review.opendev.org/c/openstack/charm-keystone/+/852601
263258
# data['auth-method'] = json.dumps(self.auth_method)
264-
data['protocol-name'] = json.dumps(self.options.idp_id)
259+
data['protocol-name'] = json.dumps(self.options.protocol_id)
265260
data['remote-id-attribute'] = json.dumps(
266261
self.options.remote_id_attribute)
267262

@@ -283,8 +278,8 @@ def _update_websso_data(self):
283278
return
284279

285280
data = relation.data[self.unit]
286-
data['protocol-name'] = json.dumps(self.options.idp_id)
287-
data['idp-name'] = json.dumps(self.options.protocol_id)
281+
data['protocol-name'] = json.dumps(self.options.protocol_id)
282+
data['idp-name'] = json.dumps(self.options.idp_id)
288283
data['user-facing-name'] = json.dumps(self.options.user_facing_name)
289284

290285
def _on_config_changed(self, event):

templates/apache-openidc-location.conf

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ OIDCClaimPrefix "OIDC-"
33
OIDCResponseType "id_token"
44
OIDCScope "openid email profile"
55

6+
{% if options.oidc_session_type -%}
7+
OIDCSessionType {{ options.oidc_session_type }}
8+
{% endif -%}
9+
{% if options.oidc_state_input_headers -%}
10+
OIDCStateInputHeaders {{ options.oidc_state_input_headers }}
11+
{% endif -%}
12+
{% if options.oidc_x_forwarded_headers -%}
13+
OIDCXForwardedHeaders {{ options.oidc_x_forwarded_headers }}
14+
{% endif -%}
615
{% if options.oidc_provider_metadata_url -%}
716
OIDCProviderMetadataURL {{ options.oidc_provider_metadata_url }}
817
{% endif -%}
@@ -57,10 +66,6 @@ OIDCOAuthClientSecret {{ options.oidc_client_secret }}
5766
{%- endif %}
5867
</LocationMatch>
5968

60-
# Support for websso from Horizon
61-
OIDCRedirectURI "{{ options.scheme }}://{{ options.hostname }}:{{ options.port }}/v3/auth/OS-FEDERATION/identity_providers/{{ options.idp_id }}/protocols/{{ options.protocol_id }}/websso"
62-
OIDCRedirectURI "{{ options.scheme }}://{{ options.hostname }}:{{ options.port }}/v3/auth/OS-FEDERATION/websso/{{ options.protocol_id }}"
63-
6469
<Location /v3/auth/OS-FEDERATION/websso/{{ options.protocol_id }}>
6570
Require valid-user
6671
AuthType openid-connect

tests/tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tests:
2626
target_deploy_status:
2727
keystone-openidc:
2828
workload-status: blocked
29-
workload-status-message-prefix: 'required keys: oidc_client_id, oidc_provider_metadata_url'
29+
workload-status-message-prefix: 'required keys: oidc_client_id, idp_id, oidc_provider_metadata_url'
3030
openidc-test-fixture:
3131
workload-status: active
3232
workload-status-message-prefix: 'ready'

unit_tests/test_charm.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ def test_find_missing_keys_no_metadata_url(self):
128128
missing_keys = self.harness.charm.find_missing_keys()
129129
missing_keys.sort()
130130

131-
expected = ['oidc_client_id', 'oidc_provider_metadata_url']
131+
expected = ['idp_id',
132+
'oidc_client_id',
133+
'oidc_provider_metadata_url']
132134
expected.sort()
133135
self.assertEqual(missing_keys, expected)
134136

@@ -142,7 +144,8 @@ def test_find_missing_keys_manual_configuration(self):
142144
missing_keys = self.harness.charm.find_missing_keys()
143145
missing_keys.sort()
144146

145-
expected = ['oidc_provider_auth_endpoint',
147+
expected = ['idp_id',
148+
'oidc_provider_auth_endpoint',
146149
'oidc_provider_token_endpoint',
147150
'oidc_provider_token_endpoint_auth',
148151
'oidc_provider_user_info_endpoint',
@@ -186,8 +189,8 @@ def test_update_websso_data(self):
186189
self.harness.charm._update_websso_data()
187190
data = self.harness.get_relation_data(rid, 'keystone-openidc/0')
188191
options = self.harness.charm.options
189-
expected = {'protocol-name': json.dumps(options.idp_id),
190-
'idp-name': json.dumps(options.protocol_id),
192+
expected = {'protocol-name': json.dumps(options.protocol_id),
193+
'idp-name': json.dumps(options.idp_id),
191194
'user-facing-name': json.dumps(options.user_facing_name)}
192195
self.assertDictEqual(data, expected)
193196

0 commit comments

Comments
 (0)