Skip to content

Commit d8be462

Browse files
lmicciniclaude
authored andcommitted
Fix Keystone Memcached endpoints for TLS and IPv6
The [keystone_authtoken] section configured memcached independently of the Memcached TLS status, which caused three problems: - memcached_servers was always rendered from MemcachedServers (the TLS listener list). For a non-TLS Memcached this used the wrong list and dropped the inet/inet6 prefix needed for correct IPv6 formatting. It now branches on .MemcachedTLS and uses MemcachedServersWithInet when base TLS is disabled, mirroring the [cache] section. - memcache_tls_enabled and the MTLS cert files were gated on MemcachedAuthCert (MTLS presence) instead of .MemcachedTLS (base TLS). memcache_tls_enabled is now emitted whenever Memcached runs with TLS, with the cert files nested inside as an optional MTLS extra. - A stray tls_enabled=true line (a [cache]-only oslo.cache option, not valid in keystone_authtoken) was dropped. Add functional tests covering the non-TLS keystone_authtoken output and the MTLS server list selection. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 174022d commit d8be462

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎templates/00-default.conf‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ heartbeat_in_pthread=false
3939
{{ if (index . "KeystoneAuthURL") }}
4040
[keystone_authtoken]
4141
{{ if (index . "MemcachedServers") }}
42+
{{ if .MemcachedTLS }}
4243
memcached_servers={{ .MemcachedServers }}
43-
{{ end }}
44-
{{ if (index . "MemcachedAuthCert") }}
45-
tls_enabled=true
44+
memcache_tls_enabled = true
45+
{{- if (index . "MemcachedAuthCert") }}
4646
memcache_tls_certfile = {{ .MemcachedAuthCert }}
4747
memcache_tls_keyfile = {{ .MemcachedAuthKey }}
4848
memcache_tls_cafile = {{ .MemcachedAuthCa }}
49-
memcache_tls_enabled = true
49+
{{- end }}
50+
{{ else }}
51+
memcached_servers={{ .MemcachedServersWithInet }}
52+
{{ end }}
5053
{{ end }}
5154
{{ if (index . "ACID") }}
5255
auth_type = v3applicationcredential

‎test/functional/watcherapi_controller_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,28 @@ heartbeat_in_pthread=false`,
12071207
Expect(string(configData)).Should(ContainSubstring(val))
12081208
}
12091209
})
1210+
1211+
It("should configure keystone_authtoken memcached without TLS", func() {
1212+
createdSecret := th.GetSecret(watcherTest.WatcherAPIConfigSecret)
1213+
Expect(createdSecret).ShouldNot(BeNil())
1214+
conf := string(createdSecret.Data["00-default.conf"])
1215+
1216+
// A non-TLS memcached must use the inet-prefixed server list so that
1217+
// IPv6 addresses are formatted correctly.
1218+
memcachedInstance := infra.GetMemcached(watcherTest.MemcachedNamespace)
1219+
Expect(conf).Should(ContainSubstring(
1220+
"memcached_servers=" + memcachedInstance.GetMemcachedServerListWithInetString()))
1221+
1222+
// With base TLS disabled no memcache TLS settings must be rendered.
1223+
Expect(conf).ShouldNot(ContainSubstring("memcache_tls_enabled = true"))
1224+
Expect(conf).ShouldNot(ContainSubstring("memcache_tls_certfile"))
1225+
Expect(conf).ShouldNot(ContainSubstring("memcache_tls_keyfile"))
1226+
Expect(conf).ShouldNot(ContainSubstring("memcache_tls_cafile"))
1227+
// The stray [cache]-only "tls_enabled=true" option must not be
1228+
// emitted in keystone_authtoken, and base TLS off means it appears
1229+
// nowhere.
1230+
Expect(conf).ShouldNot(ContainSubstring("tls_enabled=true"))
1231+
})
12101232
})
12111233

12121234
When("A WatcherAPI instance is created with MTLS memcached", func() {
@@ -1304,6 +1326,11 @@ heartbeat_in_pthread=false`,
13041326
g.Expect(configString).To(ContainSubstring("memcache_tls_cafile"))
13051327
g.Expect(configString).To(ContainSubstring("memcache_tls_enabled = true"))
13061328

1329+
// With TLS enabled keystone_authtoken must use the TLS server list
1330+
memcachedInstance := infra.GetMemcached(watcherTest.MemcachedNamespace)
1331+
g.Expect(configString).To(ContainSubstring(
1332+
"memcached_servers=" + memcachedInstance.GetMemcachedServerListString()))
1333+
13071334
// Check for MTLS configuration in cache section
13081335
g.Expect(configString).To(ContainSubstring("tls_certfile"))
13091336
g.Expect(configString).To(ContainSubstring("tls_keyfile"))

0 commit comments

Comments
 (0)