From e0c5f1469c06712631d7fb40b4860d1d4dbff77e Mon Sep 17 00:00:00 2001 From: kylerankin Date: Sun, 20 Sep 2026 10:53:58 +0000 Subject: [PATCH 1/3] fix(kiosk): console shows live local cluster state on first boot On a freshly installed single-node k0s cluster no client kc-agent is connected yet, so the KubeStellar console fell back to mock/demo cards instead of the real cluster. - Set NO_LOCAL_AGENT so the console reads the local embedded k0s API directly from this pod's ServiceAccount instead of waiting for a connected kc-agent. - Set SKIP_ONBOARDING so the kiosk shows the dashboard immediately. - Add a read-only ClusterRole bound to the console ServiceAccount so the in-cluster reads for nodes, namespaces and pods succeed. Assisted-by: lemonade/Ornith-1.5-35B-A3B-GGUF-Q6_K via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: kylerankin --- .../kubestellar/40-kubestellar-console.yaml | 13 ++++ .../42-kubestellar-console-rbac.yaml | 62 +++++++++++++++++++ tests/unit/test_k0s_manifests.py | 1 + tests/unit/test_kubestellar_kiosk.py | 44 +++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml diff --git a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml index fc502bdf..388d3a01 100644 --- a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml +++ b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml @@ -38,6 +38,7 @@ spec: labels: app.kubernetes.io/name: kubestellar-console spec: + serviceAccountName: kubestellar-console containers: - name: console image: ghcr.io/kubestellar/console:v0.3.34 @@ -48,6 +49,18 @@ spec: value: "true" - name: DEV_USER_LOGIN value: "admin" + # First-boot fix (#193): on a freshly installed single-node k0s cluster + # no client kc-agent is connected yet, so the console must read the local + # embedded k0s API directly instead of defaulting to mock/demo cards. + # NO_LOCAL_AGENT makes the in-cluster backend serve live cluster state + # from this pod's ServiceAccount; SKIP_ONBOARDING skips the sign-in flow + # so the kiosk shows the dashboard immediately. + - name: SKIP_ONBOARDING + value: "true" + - name: NO_LOCAL_AGENT + value: "true" + - name: POD_NAMESPACE + value: "kubestellar-console" - name: GITHUB_CLIENT_ID valueFrom: secretKeyRef: diff --git a/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml b/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml new file mode 100644 index 00000000..612608a9 --- /dev/null +++ b/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml @@ -0,0 +1,62 @@ +# First-boot fix (#193): the console pod reads the local embedded k0s cluster +# directly (NO_LOCAL_AGENT). It needs read access to render live nodes, +# namespaces and pods instead of falling back to demo cards. Bound to the +# console's own ServiceAccount so the default account stays unprivileged. +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kubestellar-console + namespace: kubestellar-console + labels: + app.kubernetes.io/name: kubestellar-console +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: kubestellar-console-reader + labels: + app.kubernetes.io/name: kubestellar-console +rules: +- apiGroups: [""] + resources: + - nodes + - namespaces + - pods + - services + - configmaps + - events + - persistentvolumes + - persistentvolumeclaims + - serviceaccounts + - endpoints + - limitquotas + - resourcequotas + verbs: ["get", "list", "watch"] +- apiGroups: ["apps"] + resources: + - deployments + - statefulsets + - daemonsets + - replicasets + - replicationcontrollers + verbs: ["get", "list", "watch"] +- apiGroups: ["batch"] + resources: + - jobs + - cronjobs + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: kubestellar-console-reader + labels: + app.kubernetes.io/name: kubestellar-console +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: kubestellar-console-reader +subjects: +- kind: ServiceAccount + name: kubestellar-console + namespace: kubestellar-console diff --git a/tests/unit/test_k0s_manifests.py b/tests/unit/test_k0s_manifests.py index 149ca421..36d65c73 100644 --- a/tests/unit/test_k0s_manifests.py +++ b/tests/unit/test_k0s_manifests.py @@ -38,6 +38,7 @@ def test_k0s_manifest_files(): assert (ks_dir / "30-kubestellar-core.yaml").is_file() assert (ks_dir / "40-kubestellar-console.yaml").is_file() assert (ks_dir / "41-kubestellar-kiosk-proxy.yaml").is_file() + assert (ks_dir / "42-kubestellar-console-rbac.yaml").is_file() def test_postgres_password_not_hardcoded(): diff --git a/tests/unit/test_kubestellar_kiosk.py b/tests/unit/test_kubestellar_kiosk.py index ec608c72..d74dd0b4 100644 --- a/tests/unit/test_kubestellar_kiosk.py +++ b/tests/unit/test_kubestellar_kiosk.py @@ -2,6 +2,8 @@ from pathlib import Path +import yaml + ROOT = Path(__file__).resolve().parents[2] KIOSK = ROOT / "files" / "k0s" / "kiosk" KIOSK_CONF = KIOSK / "nginx.conf" @@ -87,6 +89,12 @@ def test_console_provides_local_and_oauth_login_options() -> None: assert 'value: "true"' in console assert "name: ALLOW_DEV_MODE_IN_CLUSTER" in console assert "hostPort:" not in console + # #193: on first boot the console must read the local k0s cluster directly + # (no connected kc-agent yet) and skip the sign-in flow. + assert "name: SKIP_ONBOARDING" in console + assert "name: NO_LOCAL_AGENT" in console + assert "name: POD_NAMESPACE" in console + assert "serviceAccountName: kubestellar-console" in console assert "name: GITHUB_CLIENT_ID" in console assert "name: GITHUB_CLIENT_SECRET" in console assert "name: kubestellar-console-github-oauth" in console @@ -107,3 +115,39 @@ def test_proxy_is_the_only_public_console_endpoint() -> None: "nginx@sha256:62223d644fa234c3a1cc785ee14242ec47a77364226f1c811d2f669f96dc2ac8" in proxy ) + + +def test_console_rbac_reads_only_the_local_cluster() -> None: + rbac = ( + ROOT + / "files" + / "k0s" + / "manifests" + / "kubestellar" + / "42-kubestellar-console-rbac.yaml" + ).read_text(encoding="utf-8") + docs = list(yaml.safe_load_all(rbac)) + kinds = [d.get("kind") for d in docs if d] + assert kinds == [ + "ServiceAccount", + "ClusterRole", + "ClusterRoleBinding", + ] + + sa = next(d for d in docs if d["kind"] == "ServiceAccount") + assert sa["metadata"]["namespace"] == "kubestellar-console" + + role = next(d for d in docs if d["kind"] == "ClusterRole") + # Read-only: never grant write verbs to the console's account. + for rule in role["rules"]: + assert set(rule["verbs"]) <= {"get", "list", "watch"} + resources = {r for rule in role["rules"] for r in rule["resources"]} + assert {"nodes", "namespaces", "pods"} <= resources + + binding = next(d for d in docs if d["kind"] == "ClusterRoleBinding") + assert binding["roleRef"]["kind"] == "ClusterRole" + assert binding["roleRef"]["name"] == role["metadata"]["name"] + subject = binding["subjects"][0] + assert subject["kind"] == "ServiceAccount" + assert subject["name"] == "kubestellar-console" + assert subject["namespace"] == "kubestellar-console" From dcdedcd0ea7f5c5abe0575e461a57e90ef220623 Mon Sep 17 00:00:00 2001 From: kylerankin Date: Sun, 20 Sep 2026 11:43:24 +0000 Subject: [PATCH 2/3] fix(kiosk): correct limitranges RBAC resource and SKIP_ONBOARDING doc - 42-kubestellar-console-rbac.yaml: limitquotas is not a Kubernetes resource; the intended grant was limitranges. Misspelled resources are silently ignored in RBAC rules, so LimitRange reads were forbidden. - SKIP_ONBOARDING comment: it skips the onboarding questionnaire, not sign-in (sign-in is bypassed by DEV_MODE/DEV_USER_LOGIN). - NO_LOCAL_AGENT comment: the console forces this in-cluster regardless; the real fix for #193 is the ServiceAccount + read RBAC. Addresses kubestellar-hive review findings on #214. --- files/k0s/manifests/kubestellar/40-kubestellar-console.yaml | 5 +++-- .../manifests/kubestellar/42-kubestellar-console-rbac.yaml | 2 +- tests/unit/test_kubestellar_kiosk.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml index 388d3a01..d00fe552 100644 --- a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml +++ b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml @@ -53,8 +53,9 @@ spec: # no client kc-agent is connected yet, so the console must read the local # embedded k0s API directly instead of defaulting to mock/demo cards. # NO_LOCAL_AGENT makes the in-cluster backend serve live cluster state - # from this pod's ServiceAccount; SKIP_ONBOARDING skips the sign-in flow - # so the kiosk shows the dashboard immediately. + # from this pod's ServiceAccount (the console forces this on when running + # in-cluster regardless); SKIP_ONBOARDING skips the onboarding + # questionnaire so the kiosk shows the dashboard immediately. - name: SKIP_ONBOARDING value: "true" - name: NO_LOCAL_AGENT diff --git a/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml b/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml index 612608a9..288fdc9e 100644 --- a/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml +++ b/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml @@ -29,7 +29,7 @@ rules: - persistentvolumeclaims - serviceaccounts - endpoints - - limitquotas + - limitranges - resourcequotas verbs: ["get", "list", "watch"] - apiGroups: ["apps"] diff --git a/tests/unit/test_kubestellar_kiosk.py b/tests/unit/test_kubestellar_kiosk.py index d74dd0b4..a6601a81 100644 --- a/tests/unit/test_kubestellar_kiosk.py +++ b/tests/unit/test_kubestellar_kiosk.py @@ -90,7 +90,7 @@ def test_console_provides_local_and_oauth_login_options() -> None: assert "name: ALLOW_DEV_MODE_IN_CLUSTER" in console assert "hostPort:" not in console # #193: on first boot the console must read the local k0s cluster directly - # (no connected kc-agent yet) and skip the sign-in flow. + # (no connected kc-agent yet) and skip the onboarding questionnaire. assert "name: SKIP_ONBOARDING" in console assert "name: NO_LOCAL_AGENT" in console assert "name: POD_NAMESPACE" in console From e42b65feef1fd1b1518bbfaf93b11d17eb467c8d Mon Sep 17 00:00:00 2001 From: Copilot <223556219+Copilot@users.noreply.github.com> Date: Sun, 20 Sep 2026 07:55:30 -0400 Subject: [PATCH 3/3] fix(kiosk): scope console RBAC to real resources and correct comments Follow-up to the #214 review findings. - 42-kubestellar-console-rbac.yaml: replicationcontrollers is a core ("") resource, not an apps resource. Listed under apps it was silently ignored in the RBAC rule, exactly like the limitquotas typo, so the grant never applied. Move it to the core group. - Document why the ClusterRole reads configmaps, events, limitranges and resourcequotas: the console dashboard renders them (namespace overview and ConfigMap cards). Record that verbs stay read-only, secrets are excluded, and the console is only reachable via the 127.0.0.1-bound kiosk proxy. - 40-kubestellar-console.yaml: attribute the fix to the ServiceAccount plus read RBAC. The console backend already forces NO_LOCAL_AGENT on in-cluster, so the env var only records intent. Note that SKIP_ONBOARDING skips the questionnaire and DEV_MODE/DEV_USER_LOGIN bypasses sign-in. - tests: pin every ClusterRole resource name to the real resource for its apiGroup and assert secrets are never granted, so a misspelled or misgrouped resource fails the suite instead of silently dropping the grant. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../kubestellar/40-kubestellar-console.yaml | 10 +++--- .../42-kubestellar-console-rbac.yaml | 16 ++++++++-- tests/unit/test_kubestellar_kiosk.py | 31 +++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml index d00fe552..be226493 100644 --- a/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml +++ b/files/k0s/manifests/kubestellar/40-kubestellar-console.yaml @@ -52,10 +52,12 @@ spec: # First-boot fix (#193): on a freshly installed single-node k0s cluster # no client kc-agent is connected yet, so the console must read the local # embedded k0s API directly instead of defaulting to mock/demo cards. - # NO_LOCAL_AGENT makes the in-cluster backend serve live cluster state - # from this pod's ServiceAccount (the console forces this on when running - # in-cluster regardless); SKIP_ONBOARDING skips the onboarding - # questionnaire so the kiosk shows the dashboard immediately. + # The fix is the ServiceAccount above plus the read-only ClusterRole in + # 42-kubestellar-console-rbac.yaml; NO_LOCAL_AGENT is set only to make + # that intent explicit, since the console backend already forces it on + # when it detects it is running in-cluster. SKIP_ONBOARDING skips the + # onboarding questionnaire so the kiosk shows the dashboard immediately + # (sign-in is bypassed separately by DEV_MODE/DEV_USER_LOGIN above). - name: SKIP_ONBOARDING value: "true" - name: NO_LOCAL_AGENT diff --git a/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml b/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml index 288fdc9e..efbc1708 100644 --- a/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml +++ b/files/k0s/manifests/kubestellar/42-kubestellar-console-rbac.yaml @@ -1,7 +1,17 @@ # First-boot fix (#193): the console pod reads the local embedded k0s cluster -# directly (NO_LOCAL_AGENT). It needs read access to render live nodes, -# namespaces and pods instead of falling back to demo cards. Bound to the +# directly, so it needs read access to render live nodes, namespaces and pods +# instead of falling back to demo cards. This ServiceAccount plus the read-only +# ClusterRole below is the actual mechanism behind the fix. Bound to the # console's own ServiceAccount so the default account stays unprivileged. +# +# Scope note: the resource list mirrors what the console dashboard renders -- +# the namespace overview and ConfigMap cards read configmaps, and the resource +# cards read events, limitranges and resourcequotas. Verbs are read-only and +# the console is only reachable through the 127.0.0.1-bound kiosk proxy +# (41-kubestellar-kiosk-proxy.yaml), never from the network. Secrets are +# deliberately excluded. Resource names must be exact: Kubernetes silently +# ignores unknown names in RBAC rules, so a typo removes the grant without any +# error (see tests/unit/test_kubestellar_kiosk.py). apiVersion: v1 kind: ServiceAccount metadata: @@ -31,6 +41,7 @@ rules: - endpoints - limitranges - resourcequotas + - replicationcontrollers verbs: ["get", "list", "watch"] - apiGroups: ["apps"] resources: @@ -38,7 +49,6 @@ rules: - statefulsets - daemonsets - replicasets - - replicationcontrollers verbs: ["get", "list", "watch"] - apiGroups: ["batch"] resources: diff --git a/tests/unit/test_kubestellar_kiosk.py b/tests/unit/test_kubestellar_kiosk.py index a6601a81..1da8f45e 100644 --- a/tests/unit/test_kubestellar_kiosk.py +++ b/tests/unit/test_kubestellar_kiosk.py @@ -91,6 +91,8 @@ def test_console_provides_local_and_oauth_login_options() -> None: assert "hostPort:" not in console # #193: on first boot the console must read the local k0s cluster directly # (no connected kc-agent yet) and skip the onboarding questionnaire. + # SKIP_ONBOARDING skips the questionnaire, not sign-in; sign-in is bypassed + # by DEV_MODE/DEV_USER_LOGIN. assert "name: SKIP_ONBOARDING" in console assert "name: NO_LOCAL_AGENT" in console assert "name: POD_NAMESPACE" in console @@ -143,6 +145,35 @@ def test_console_rbac_reads_only_the_local_cluster() -> None: assert set(rule["verbs"]) <= {"get", "list", "watch"} resources = {r for rule in role["rules"] for r in rule["resources"]} assert {"nodes", "namespaces", "pods"} <= resources + # Kubernetes silently ignores resource names that do not exist in the named + # apiGroup, so a typo (e.g. "limitquotas") drops the grant with no error. + # Pin every name to the real resource for its group. + known_resources = { + "": { + "configmaps", + "endpoints", + "events", + "limitranges", + "namespaces", + "nodes", + "persistentvolumeclaims", + "persistentvolumes", + "pods", + "replicationcontrollers", + "resourcequotas", + "serviceaccounts", + "services", + }, + "apps": {"daemonsets", "deployments", "replicasets", "statefulsets"}, + "batch": {"cronjobs", "jobs"}, + } + for rule in role["rules"]: + for group in rule["apiGroups"]: + assert group in known_resources, f"unexpected apiGroup {group!r}" + unknown = set(rule["resources"]) - known_resources[group] + assert not unknown, f"not real resources in apiGroup {group!r}: {unknown}" + # The kiosk dashboard never needs secrets; keep them out of the grant. + assert "secrets" not in resources binding = next(d for d in docs if d["kind"] == "ClusterRoleBinding") assert binding["roleRef"]["kind"] == "ClusterRole"