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
8 changes: 6 additions & 2 deletions deploy/helm/sie-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1307,19 +1307,23 @@ token-separation check and the upstream-key collision check read this list.
{{- with index $root.Subcharts "kube-prometheus-stack" -}}
{{- with index .Subcharts "grafana" -}}
{{- if eq (include "grafana.namespace" .) (include "sie-cluster.namespace" $root) -}}
{{- $readsUser := and (not .Values.env.GF_SECURITY_ADMIN_USER) (not .Values.env.GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION) -}}
{{- $readsPassword := and (not .Values.env.GF_SECURITY_ADMIN_PASSWORD) (not .Values.env.GF_SECURITY_ADMIN_PASSWORD__FILE) (not .Values.env.GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION) -}}
{{- if or $readsUser $readsPassword -}}
{{- $existingSecret := toString (default "" .Values.admin.existingSecret) -}}
{{- if and (contains "{{" $existingSecret) (not (regexMatch `^([a-z0-9. \t\r\n-]|\{\{-?[ \t\r\n]*\$?\.(Release|Values|Chart)(\.[A-Za-z0-9_]+)+[ \t\r\n]*-?\}\})+$` $existingSecret)) -}}
{{- fail (printf "kube-prometheus-stack.grafana.admin.existingSecret may hold only lowercase letters, digits, '-', '.', whitespace and actions that hold one chain of names on .Release, .Values or .Chart, such as {{ .Release.Name }}, optionally with {{- -}} trim markers or a leading $: the Grafana chart evaluates it in its own templates, so the chart can check the Secret Grafana reads only when it depends on nothing but those objects, got %q" $existingSecret) -}}
{{- end -}}
{{- $template := ternary $existingSecret "" (contains "{{" $existingSecret) -}}
{{- $context := merge (dict "Template" $root.Template) . -}}
{{- $secretName := tpl .Values.admin.existingSecret $context | default (include "grafana.fullname" .) -}}
{{- if and (not .Values.env.GF_SECURITY_ADMIN_USER) (not .Values.env.GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION) -}}
{{- if $readsUser -}}
{{- $keys = append $keys (dict "owner" "the Grafana admin username" "name" "Grafana admin username" "ref" (include "sie-cluster.secretKeyRef" (dict "unquoted" true "name" $secretName "template" $template "key" (default "admin-user" .Values.admin.userKey) "nameField" "kube-prometheus-stack.grafana.admin.existingSecret" "keyField" "kube-prometheus-stack.grafana.admin.userKey"))) -}}
{{- end -}}
{{- if and (not .Values.env.GF_SECURITY_ADMIN_PASSWORD) (not .Values.env.GF_SECURITY_ADMIN_PASSWORD__FILE) (not .Values.env.GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION) -}}
{{- if $readsPassword -}}
{{- $keys = append $keys (dict "owner" "the Grafana admin password" "name" "Grafana admin password" "ref" (include "sie-cluster.secretKeyRef" (dict "unquoted" true "name" $secretName "template" $template "key" (default "admin-password" .Values.admin.passwordKey) "nameField" "kube-prometheus-stack.grafana.admin.existingSecret" "keyField" "kube-prometheus-stack.grafana.admin.passwordKey"))) -}}
{{- end -}}
{{- end -}}
{{- if .Values.smtp.existingSecret -}}
{{- $smtpSecret := .Values.smtp.existingSecret -}}
{{- range $key := list (default "user" .Values.smtp.userKey) (default "password" .Values.smtp.passwordKey) -}}
Expand Down
5 changes: 3 additions & 2 deletions packages/sie_placement/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,9 @@ log. It verifies an https gateway against the CA certificates that
set, or against the default bundle when neither is. `SSL_CERT_DIR` may list
several directories separated by the platform's path separator, `:` on Linux. A
bundle file it cannot load, or an `SSL_CERT_DIR` none of whose directories
holds a file, is refused before any call. A directory the applier may search
but not list is left to OpenSSL, which opens certificates there by name.
the applier may search and finds a file in, is refused before any call. A
directory the applier may search but not list is left to OpenSSL, which opens
certificates there by name.
OpenSSL reads the certificates in a directory only when it verifies a
connection, so a directory whose files it cannot use fails each gateway call
with the TLS error. An http gateway reads none of these variables. Prometheus
Expand Down
4 changes: 3 additions & 1 deletion packages/sie_placement/src/sie_placement/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ def _is_file(entry: os.DirEntry[str]) -> bool:


def _holds_files(path: str) -> bool:
if not os.access(path, os.X_OK, effective_ids=_ACCESS_BY_EFFECTIVE_IDS):
return False
try:
with os.scandir(path) as entries:
return any(_is_file(entry) for entry in entries)
except PermissionError:
return os.access(path, os.X_OK, effective_ids=_ACCESS_BY_EFFECTIVE_IDS)
return True
except OSError:
return False

Expand Down
9 changes: 4 additions & 5 deletions packages/sie_placement/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,11 @@ def test_a_ca_directory_the_applier_cannot_list_is_left_to_openssl(monkeypatch,
assert calls == [{"cafile": None, "capath": str(certs)}]


@pytest.mark.parametrize("location", ["unsearchable", "below-unsearchable-parent"])
@pytest.mark.parametrize("location", ["unsearchable", "listable-unsearchable", "below-unsearchable-parent"])
def test_a_ca_location_the_applier_may_not_search_is_refused_before_any_call(monkeypatch, tmp_path, location):
locked = tmp_path / "locked"
locked.mkdir()
certs = locked if location == "unsearchable" else locked / "certs"
locked.chmod(0o000 if location == "unsearchable" else 0o600)
locked = certificate_directory(tmp_path / "locked")
certs = locked / "certs" if location == "below-unsearchable-parent" else locked
locked.chmod({"unsearchable": 0o000, "listable-unsearchable": 0o600}.get(location, 0o600))
try:
monkeypatch.setenv("SSL_CERT_DIR", str(certs))
with pytest.raises(ValueError, match="the CA certificates that SSL_CERT_DIR names cannot be loaded"):
Expand Down
22 changes: 22 additions & 0 deletions tools/ci/tests/test_helm_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -4900,6 +4900,28 @@ def test_the_notes_name_no_grafana_admin_secret_when_grafana_reads_none(tmp_path
assert "Grafana password" not in notes


@pytest.mark.parametrize(
"env",
[
{"GF_SECURITY_ADMIN_USER": "admin", "GF_SECURITY_ADMIN_PASSWORD": "fixture-password"},
{"GF_SECURITY_ADMIN_USER": "admin", "GF_SECURITY_ADMIN_PASSWORD__FILE": "/etc/grafana/password"},
{"GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION": "true"},
],
ids=["password", "password-file", "no-initial-admin"],
)
@pytest.mark.parametrize(
"existing",
["Graf-{{ .Release.Name }}", "{{ .Capabilities.KubeVersion.Major }}-graf"],
ids=["uppercase", "capabilities"],
)
def test_a_grafana_admin_secret_that_grafana_never_reads_is_not_checked_in_the_release_namespace(
tmp_path: Path, env: dict, existing: str
) -> None:
grafana = {"env": env, "admin": {"existingSecret": existing}}
result = render_chart(tmp_path, {"kube-prometheus-stack": {"install": True, "grafana": grafana}})
assert result.returncode == 0, result.stderr


@pytest.mark.parametrize(
("existing", "grafana", "error"),
[
Expand Down
Loading