Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(placement): close the deferred review items on the applier and the Grafana Secret check (#1028)

Krisztian Gajdar30ac75544e9f
diff --git a/deploy/helm/sie-cluster/templates/_helpers.tpl b/deploy/helm/sie-cluster/templates/_helpers.tpl
index 99816ea43..1e1019bc3 100644
--- a/deploy/helm/sie-cluster/templates/_helpers.tpl
+++ b/deploy/helm/sie-cluster/templates/_helpers.tpl
@@ -1307,6 +1307,9 @@ 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) -}}
@@ -1314,12 +1317,13 @@ token-separation check and the upstream-key collision check read this list.
{{- $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) -}}
diff --git a/packages/sie_placement/README.md b/packages/sie_placement/README.md
index 8419567a9..c21c29308 100644
--- a/packages/sie_placement/README.md
+++ b/packages/sie_placement/README.md
@@ -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
diff --git a/packages/sie_placement/src/sie_placement/pools.py b/packages/sie_placement/src/sie_placement/pools.py
index 8a4325e4d..ff270444d 100644
--- a/packages/sie_placement/src/sie_placement/pools.py
+++ b/packages/sie_placement/src/sie_placement/pools.py
@@ -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
diff --git a/packages/sie_placement/tests/test_cli.py b/packages/sie_placement/tests/test_cli.py
index 05633a306..de1a62e7b 100644
--- a/packages/sie_placement/tests/test_cli.py
+++ b/packages/sie_placement/tests/test_cli.py
@@ -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)}]
[email protected]("location", ["unsearchable", "below-unsearchable-parent"])
[email protected]("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"):
diff --git a/tools/ci/tests/test_helm_render.py b/tools/ci/tests/test_helm_render.py
index 5166daec1..f1b57426d 100644
--- a/tools/ci/tests/test_helm_render.py
+++ b/tools/ci/tests/test_helm_render.py
@@ -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
+ "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"],
+)
+ "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"),
[