Skip to content

Commit 2a85595

Browse files
CarliJoyclaude
authored andcommitted
fix(keycloak): disable SSL requirement for master realm after start
Keycloak 26+ enforces SSL by default even for localhost, causing client connections over plain HTTP to fail. Disable it via kcadm.sh post-start. Also add user_realm_name to get_client() kwargs to fix authentication against the master realm. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2940501 commit 2a85595

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎src/testcontainers/community/keycloak/__init__.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,31 @@ def _readiness_probe(self) -> None:
112112
def start(self) -> "KeycloakContainer":
113113
super().start()
114114
self._readiness_probe()
115+
self._disable_ssl_required()
115116
return self
116117

118+
def _disable_ssl_required(self) -> None:
119+
result = self.get_wrapped_container().exec_run(
120+
[
121+
"/opt/keycloak/bin/kcadm.sh",
122+
"update",
123+
"realms/master",
124+
"-s",
125+
"sslRequired=none",
126+
"--no-config",
127+
"--server",
128+
f"http://localhost:{self.port}",
129+
"--realm",
130+
"master",
131+
"--user",
132+
self.username,
133+
"--password",
134+
self.password,
135+
]
136+
)
137+
if result.exit_code != 0:
138+
raise RuntimeError(f"Failed to disable SSL for master realm: {result.output.decode()}")
139+
117140
def with_realm_import_file(self, realm_import_file: str) -> "KeycloakContainer":
118141
file = os.path.abspath(realm_import_file)
119142
if not os.path.exists(file):
@@ -136,6 +159,7 @@ def get_client(self, **kwargs) -> KeycloakAdmin:
136159
"username": self.username,
137160
"password": self.password,
138161
"realm_name": "master",
162+
"user_realm_name": "master",
139163
"verify": True,
140164
}
141165
kwargs = {**default_kwargs, **kwargs}

0 commit comments

Comments
 (0)