8000 Follow-up to #2156 by alex-zaitsev · Pull Request #2157 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/model/chi/normalizer/normalizer-configuration-user.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,16 @@ func (n *Normalizer) rejectRemovedSecretRefField(user *api.SettingsUser, name st
)
}

// userNonPasswordAuthMethods lists the top-level user settings that are authentication methods other than a password.
// userNonPasswordAuthMethods lists user settings that prevent adding a flat default password,
// including grouped auth_methods (which may themselves contain password methods).
var userNonPasswordAuthMethods = []string{
"no_password",
"ssl_certificates",
"ssh_keys",
"ldap",
"kerberos",
"http_authentication",
"auth_methods",
}

// userHasNonPasswordAuth checks whether the user has an authentication method other than a password.
Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/manifests/chi/test-011-cert-auth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Regression for #2155: the operator must not inject its default password
# into a user authenticated by an SSL client certificate subjectAltName.
apiVersion: clickhouse.altinity.com/v1
kind: ClickHouseInstallation
metadata:
name: test-011-cert-auth
spec:
useTemplates:
- name: clickhouse-version
configuration:
users:
certuser/networks/ip:
- 127.0.0.1
certuser/ssl_certificates/subject_alt_name:
- "URI:spiffe://example.org/ns/x/sa/y"
# Control: a user without any explicit auth method must still get the
# operator's normal default password.
ordinaryuser/networks/ip:
- 127.0.0.1
clusters:
- name: default
layout:
shardsCount: 1
replicasCount: 1
49 changes: 49 additions & 0 deletions tests/e2e/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,55 @@ def test_010011_5(self, version_from="0.27.3", version_to=None):
with Finally("I clean up"):
delete_test_namespace()

@TestScenario
@Name("test_010011_7. SSL certificate SAN user gets no injected default password (#2155)")
@Requirements(RQ_SRS_026_ClickHouseOperator_DefaultUsers("1.0"))
def test_010011_7(self):
"""A non-password authenticated user must not get a password_sha256_hex from the operator.

Before #2156, the injected password made ClickHouse reject users.xml with
"More than one field ... used to specify authentication info" and the pod
would never become Ready. This exercises the real generated ConfigMap and
ClickHouse startup, not only the user normalizer.
"""
create_shell_namespace_clickhouse_template()
chi = "test-011-cert-auth"

with Given("a CHI with a certificate SAN user and an ordinary password-less user"):
kubectl.create_and_check(
manifest="manifests/chi/test-011-cert-auth.yaml",
check={"pod_count": 1, "do_not_delete": 1},
)

with Then("ClickHouse starts successfully with the generated users.xml"):
result = clickhouse.query_with_error(chi, "SELECT 'OK'")
assert result == "OK", error(f"ClickHouse did not start or load its users: {result}")

with And("the certificate SAN user has no injected password fields"):
certuser = get_user_xml_from_configmap(chi, "certuser")
assert certuser is not None, error("certuser is missing from generated users.xml")
certificates = certuser.find("ssl_certificates")
assert certificates is not None, error("certuser's ssl_certificates auth was lost")
assert "URI:spiffe://example.org/ns/x/sa/y" in etree.tostring(certificates, encoding="unicode"), error(
"the configured certificate subjectAltName was not rendered"
)
for field in ("password", "password_sha256_hex", "password_double_sha1_hex"):
assert certuser.find(field) is None, error(
f"certuser has both ssl_certificates and {field} authentication"
)

with And("an ordinary user still receives the default password"):
ordinary = get_user_xml_from_configmap(chi, "ordinaryuser")
assert ordinary is not None, error("ordinaryuser is missing from generated users.xml")
assert ordinary.find("password_sha256_hex") is not None, error(
"ordinaryuser did not receive the template default password"
)
result = clickhouse.query_with_error(chi, "SELECT 'OK'", user="ordinaryuser", pwd="default")
assert result == "OK", error(f"ordinaryuser cannot use the default password: {result}")

with Finally("I clean up"):
delete_test_namespace()


@TestScenario
@Name("test_010012. Test service templates")
Expand Down
Loading
0