Files
OpenShell/deploy/helm/openshell/tests/rbac_test.yaml
ansjindal d009f30121 feat(helm): make cluster-scoped RBAC optional (#3459)
The gateway chart always rendered the ClusterRole and ClusterRoleBinding, so
every install and upgrade required cluster-admin even when only namespaced
objects were needed. Installers that are namespace-admin GitOps or platform
controllers could not run the release at all, and clusters where cluster-scoped
RBAC is owned by a separate team had no supported way to split the install.

Add an rbac values block so a cluster-admin can apply the cluster-scoped objects
once and a namespace-admin can install and upgrade the release without
cluster-scoped permissions:

  rbac:
    create: true
    clusterScoped:
      create: true
      clusterRoleName: ""
      clusterRoleBindingName: ""

rbac.clusterScoped.create gates the ClusterRole and ClusterRoleBinding, and is
independent of the workspace mode. rbac.create additionally gates the namespaced
sandbox Role and RoleBinding, which matters because Kubernetes escalation
prevention stops an installer holding only the built-in admin role from creating
a Role that grants agents.x-k8s.io verbs it does not itself hold. The certgen
hook and credential driver RBAC keep their existing flags.

Both flags default to true, so current installs are unchanged. The helpers treat
a missing rbac block as enabled so upgrades with --reuse-values do not drop RBAC,
matching the existing workspaceResources pattern. The ClusterRoleBinding roleRef
follows clusterRoleName so a separately applied ClusterRole can carry a name the
cluster-admin chooses.

Document the migration for a release that already owns the cluster-scoped
objects: Helm deletes objects that leave the manifest, so annotate them with
helm.sh/resource-policy=keep before setting the flag, otherwise the gateway
loses TokenReview until a cluster-admin re-applies them.

Signed-off-by: ansjindal <ansjindal@nvidia.com>
2026-09-28 05:50:07 +00:00

96 lines
2.4 KiB
YAML

# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
suite: Gateway RBAC creation
templates:
- templates/role.yaml
- templates/rolebinding.yaml
- templates/peer-role.yaml
release:
name: openshell
namespace: my-namespace
tests:
- it: creates the namespaced sandbox Role by default
template: templates/role.yaml
asserts:
- hasDocuments:
count: 1
- equal:
path: metadata.name
value: openshell-sandbox
- it: creates the namespaced sandbox RoleBinding by default
template: templates/rolebinding.yaml
asserts:
- hasDocuments:
count: 1
- equal:
path: metadata.name
value: openshell-sandbox
- it: creates the gateway peer Role and RoleBinding by default
template: templates/peer-role.yaml
asserts:
- hasDocuments:
count: 2
- equal:
path: metadata.name
value: openshell-peer
- it: keeps the namespaced RBAC when only cluster-scoped RBAC is disabled
set:
rbac.clusterScoped.create: false
asserts:
- hasDocuments:
count: 1
template: templates/role.yaml
- it: keeps the peer RBAC when only cluster-scoped RBAC is disabled
template: templates/peer-role.yaml
set:
rbac.clusterScoped.create: false
asserts:
- hasDocuments:
count: 2
- it: omits the namespaced sandbox Role when chart-managed RBAC is disabled
template: templates/role.yaml
set:
rbac.create: false
asserts:
- hasDocuments:
count: 0
- it: omits the namespaced sandbox RoleBinding when chart-managed RBAC is disabled
template: templates/rolebinding.yaml
set:
rbac.create: false
asserts:
- hasDocuments:
count: 0
- it: omits the gateway peer Role and RoleBinding when chart-managed RBAC is disabled
template: templates/peer-role.yaml
set:
rbac.create: false
asserts:
- hasDocuments:
count: 0
- it: creates the namespaced sandbox Role when legacy values omit the rbac block
template: templates/role.yaml
set:
rbac: null
asserts:
- hasDocuments:
count: 1
- it: creates the peer Role and RoleBinding when legacy values omit the rbac block
template: templates/peer-role.yaml
set:
rbac: null
asserts:
- hasDocuments:
count: 2