Skip to content

Commit ba74344

Browse files
fix(site-router)!: put the guest console switch out of tenant reach
The console carries whatever the guest prints, and giving tenants logs safely is separate work that does not exist yet, so a tenant must not be able to turn a serial console on for their own site-router. Round 1 made this a tenant-facing chart value, copying the convention packages/apps/kubernetes already uses. That was the wrong call. The switch is now `_logSerialConsole`, and the underscore is the access control rather than a naming style. The aggregated apps.cozystack.io API reserves every top-level values key beginning with `_`: validateNoInternalKeys rejects one with a 400 on both Create (rest.go ~200) and Update (rest.go ~546), and filterInternalKeys strips them from what a tenant reads back. Templates read only the reserved form, so the un-prefixed name a tenant can actually submit is read by nothing. That pairing is the whole boundary: the key that works cannot be submitted, and the key that can be submitted does not work. Dropping the field from the generated schema is NOT what protects it, and it is worth being precise because the opposite is easy to assume. Application.Spec is a raw apiextensionsv1.JSON so no Go struct prunes an undeclared field; the generated values.schema.json carries no additionalProperties so Helm accepts extras; and pkg/cmd/server/openapi.go deliberately re-opens the published spec so undocumented Helm values are accepted rather than rejected. Removing it from the schema hides it from the dashboard and the published OpenAPI. validateNoInternalKeys is the part with teeth. This follows the existing platform-injected-value convention rather than inventing one. `_cluster` and `_namespace` are written into app HelmReleases by the tenant chart and the platform, consumed as `.Values._cluster` / `.Values._namespace`, and declared in no values.yaml anywhere in the tree. The key is likewise absent from values.yaml, not merely un-annotated: cozyvalues-gen errors on an annotation-less key, and hack/update-crd.sh builds the dashboard's keysOrder from values.yaml content rather than from annotations, so a present-but-unannotated key would leave a dangling dashboard hint pointing at a field the schema does not describe. The e2e suite is unaffected in capability. It sets `_logSerialConsole` on the HelmRelease directly, which is an admin write to a resource the tenant ClusterRoles grant no access to at all: cozy:tenant* grant `siterouters` on the aggregated API and nothing on helm.toolkit.fluxcd.io. B's raw KubeVirt VM keeps the un-prefixed spec.template.spec.domain.devices .logSerialConsole, which is KubeVirt's own device field and not a chart value. Round 2's collection is untouched. The flag is still opt-in and still rendered only when true, so the kubevirt/kubevirt#15989 exposure stays behind an explicit choice. Tests prove the boundary rather than asserting it. The chart-side pair supplies the un-prefixed key exactly as a tenant would and observes that the rendered VM has no console and the cloud-init installs no emitter; the API-side trio drives Create and Update and pins that the reserved key is refused while the un-prefixed one is accepted-but-inert. Red phases: point the templates back at the un-prefixed key and the tenant-supplied assertions fail; remove the API guard and the Create assertion fails. BREAKING CHANGE: the site-router `logSerialConsole` chart value is removed from the tenant-facing API, schema and ApplicationDefinition. It was never released, so no tenant can be relying on it; anything setting it must move to `_logSerialConsole` on the HelmRelease, which requires platform privileges by design. Assisted-By: LLM Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent f7d0c6b commit ba74344

12 files changed

Lines changed: 363 additions & 42 deletions

File tree

‎api/apps/v1alpha1/siterouter/types.go‎

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎hack/e2e-chainsaw/site-router/remote-site-b.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ stringData:
103103
// Release version: 1.5-rolling-20260802
104104
# Bring-up diagnostics, the same emitter A gets from the chart
105105
# (packages/apps/site-router/templates/_helpers.tpl gates it on
106-
# values.logSerialConsole). B is a raw manifest with no templating, so the
106+
# values._logSerialConsole). B is a raw manifest with no templating, so the
107107
# script body is injected by the bring-up step from the ONE copy in the
108108
# tree, packages/apps/site-router/files/guest-diag.sh — B and A must report
109109
# in the same format or the symmetry that made the last diagnosis credible

‎hack/e2e-chainsaw/site-router/site-router-a.yaml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,10 @@ spec:
7979
# default in the chart because it overrides the platform's cluster-wide
8080
# disableSerialConsoleLog (see the value's own doc); on here because a failed
8181
# e2e run that cannot say what the guest was doing costs a whole run.
82-
logSerialConsole: true
82+
#
83+
# Underscore-prefixed because this switch is not tenant-reachable: the
84+
# aggregated API reserves top-level `_` keys and rejects them from a tenant.
85+
# The suite writes the HelmRelease directly, which is an admin write to a
86+
# resource tenants have no RBAC for, so setting it here is legitimate and a
87+
# tenant doing the same through apps.cozystack.io is a 400.
88+
_logSerialConsole: true

‎hack/site-router-guest-diag.bats‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ strip_trailing_blanks() {
6666
}
6767

6868
# Render the chart's cloud-init Secret into $TMP/ud.yaml (the inner cloud-config
69-
# document), with logSerialConsole set to $1. Chart copied rather than edited in
70-
# place so a failed run cannot leave a fixture reference in the tree; `cp -RL`
71-
# dereferences charts/cozy-lib, a symlink that would dangle once copied.
69+
# document), passing $1 straight to --set so a caller can supply either the
70+
# platform key (_logSerialConsole) or the un-prefixed name a tenant would reach
71+
# for. Chart copied rather than edited in place so a failed run cannot leave a
72+
# fixture reference in the tree; `cp -RL` dereferences charts/cozy-lib, a symlink
73+
# that would dangle once copied.
7274
render_userdata() {
7375
cp -RL "$CHART_SRC" "$TMP/chart"
7476
printf '%s\n' "$FIX_REF" > "$TMP/chart/images/vyos-router-disk.tag"
7577
helm template site-router-test "$TMP/chart" -n tenant-test \
76-
--set "logSerialConsole=$1" -s templates/secret-cloudinit.yaml \
78+
--set "$1" -s templates/secret-cloudinit.yaml \
7779
> "$TMP/rendered.yaml" 2> "$TMP/helm.err" || echo fail > "$TMP/helm.failed"
7880
yq e 'select(.metadata.name == "site-router-test-cloud-init") | .stringData.userdata' \
7981
"$TMP/rendered.yaml" > "$TMP/ud.yaml" 2>/dev/null || true
@@ -180,7 +182,7 @@ STUB
180182

181183
@test "the chart ships the emitter into the guest, uncorrupted, with cron pointed at it" {
182184
TMP=$(mktemp -d)
183-
render_userdata true
185+
render_userdata _logSerialConsole=true
184186
[ ! -f "$TMP/helm.failed" ] || { cat "$TMP/helm.err" >&2; rm -rf "$TMP"; exit 1; }
185187
yq e '.write_files[] | select(.path == "/config/scripts/cozy-guest-diag.sh") | .content' \
186188
"$TMP/ud.yaml" > "$TMP/shipped"
@@ -245,7 +247,7 @@ STUB
245247
# whole change exists to end, and it would arrive with every render green.
246248
: > "$TMP/chart/files/guest-diag.sh"
247249
helm template site-router-test "$TMP/chart" -n tenant-test \
248-
--set logSerialConsole=true -s templates/secret-cloudinit.yaml \
250+
--set _logSerialConsole=true -s templates/secret-cloudinit.yaml \
249251
> "$TMP/rendered.yaml" 2> "$TMP/helm.err" && echo ok > "$TMP/rendered.ok"
250252
[ ! -f "$TMP/rendered.ok" ] || {
251253
echo "an empty emitter file rendered cleanly; the guest would run an empty diagnostic" >&2
@@ -260,9 +262,9 @@ STUB
260262

261263
@test "a gateway that did not ask for the console gets no cron job and no script" {
262264
TMP=$(mktemp -d)
263-
render_userdata false
265+
render_userdata _logSerialConsole=false
264266
[ ! -f "$TMP/helm.failed" ] || { cat "$TMP/helm.err" >&2; rm -rf "$TMP"; exit 1; }
265-
# Off by default is what makes it safe to couple this to logSerialConsole: a
267+
# Off by default is what makes it safe to couple this to the console switch: a
266268
# production gateway that never asked for the console must not acquire a cron
267269
# job that writes to it.
268270
paths=$(yq e '.write_files[].path' "$TMP/ud.yaml")
@@ -278,6 +280,30 @@ STUB
278280
rm -rf "$TMP"
279281
}
280282

283+
@test "a tenant-supplied logSerialConsole ships no emitter into the guest" {
284+
TMP=$(mktemp -d)
285+
# THE BOUNDARY, from the tenant's side. `_logSerialConsole` cannot be submitted
286+
# through the aggregated API at all: validateNoInternalKeys in
287+
# pkg/registry/apps/application/rest.go rejects every top-level `_` key with a
288+
# 400 on Create and Update, which pkg/registry/apps/application/internal_keys_test.go
289+
# pins. So the only thing a tenant can actually get into spec.values is the
290+
# un-prefixed name, and it has to do nothing. Supplied here exactly as a tenant
291+
# would supply it.
292+
render_userdata logSerialConsole=true
293+
[ ! -f "$TMP/helm.failed" ] || { cat "$TMP/helm.err" >&2; rm -rf "$TMP"; exit 1; }
294+
paths=$(yq e '.write_files[].path' "$TMP/ud.yaml")
295+
printf '%s\n' "$paths" | grep -q '^/opt/vyatta/etc/config/config.boot$' || {
296+
echo "the config seed disappeared, which is not what this test is about" >&2
297+
rm -rf "$TMP"; exit 1
298+
}
299+
printf '%s\n' "$paths" | grep -q 'cozy-guest-diag' && {
300+
echo "a TENANT-SUPPLIED logSerialConsole installed the guest emitter; the switch is tenant-reachable again:" >&2
301+
printf '%s\n' "$paths" >&2
302+
rm -rf "$TMP"; exit 1
303+
}
304+
rm -rf "$TMP"
305+
}
306+
281307
@test "remote-site-b is injected with the same emitter, byte for byte" {
282308
TMP=$(mktemp -d)
283309
# Mirrors the bring-up step's own pipeline. awk, not sed: the script contains

0 commit comments

Comments
 (0)