Viewer and editor role validation

Scenario - Viewer / Editor difference

There should be a difference between Viewer / Editor roles that we set up in MLOps CP. When set to Viewer user CANNOT:

  1. create model in Model Registry

  2. remove model from Model Registry

  3. remove model’s version

  4. create new notebook

  5. remove notebook

  6. create volume

  7. remove volume

  8. create Katib experiment - currently there’s a bug with this component: https://github.com/kubeflow/katib/issues/1547

  9. remove Katib experiment - currently there’s a bug with this component: https://github.com/kubeflow/katib/issues/1547

  10. create KServe endpoint

  11. remove KServe endpoint

  12. create new pipeline

  13. remove existing pipeline

  14. create new experiment

  15. remove existing experiment

  16. remove existing run

Scenario - Viewer / Editor via kubeconfig

Kubeflow Viewer RBAC Validation

1. Export the kubeconfig and namespace

export KUBECONFIG="/path/to/viewer-kubeconfig.yaml"
export NS="your-kubeflow-namespace"

2. Create the validation script

Save the following content as:

test-kubeflow-viewer-rbac.sh
#!/usr/bin/env bash

set -u
set -o pipefail

: "${KUBECONFIG:?Export KUBECONFIG before running this script}"
: "${NS:?Export NS before running this script}"

PASS_COUNT=0
FAIL_COUNT=0
SKIP_COUNT=0

print_result() {
  local description="$1"
  local expected="$2"
  local actual="$3"

  if [[ "$actual" == "$expected" ]]; then
    printf "PASS | %-55s expected=%-5s actual=%s\n" \
      "$description" "$expected" "$actual"
    PASS_COUNT=$((PASS_COUNT + 1))
  else
    printf "FAIL | %-55s expected=%-5s actual=%s\n" \
      "$description" "$expected" "$actual"
    FAIL_COUNT=$((FAIL_COUNT + 1))
  fi
}

skip_check() {
  local description="$1"
  local reason="$2"

  printf "SKIP | %-55s %s\n" "$description" "$reason"
  SKIP_COUNT=$((SKIP_COUNT + 1))
}

check_can_i() {
  local description="$1"
  local expected="$2"
  local verb="$3"
  local resource="$4"

  local actual

  actual="$(kubectl auth can-i "$verb" "$resource" -n "$NS" 2>/dev/null | tail -n 1)"
  print_result "$description" "$expected" "$actual"
}

check_ssar() {
  local description="$1"
  local expected="$2"
  local verb="$3"
  local group="$4"
  local resource="$5"
  local subresource="${6:-}"

  local actual

  actual="$(
    cat <<EOF | kubectl create --validate=false -f - \
      -o jsonpath='{.status.allowed}' 2>/dev/null
apiVersion: authorization.k8s.io/v1
kind: SelfSubjectAccessReview
spec:
  resourceAttributes:
    namespace: "${NS}"
    verb: "${verb}"
    group: "${group}"
    resource: "${resource}"
    subresource: "${subresource}"
EOF
  )"

  print_result "$description" "$expected" "$actual"
}

echo
echo "=== Identity and namespace ==="
echo "Script version: 2.1"
echo "KUBECONFIG: $KUBECONFIG"
echo "Namespace:  $NS"
echo

kubectl config current-context
kubectl auth whoami 2>/dev/null || true

echo
echo "=== Basic Kubernetes read access ==="

check_can_i "List pods"                              yes list pods
check_can_i "Get pods"                               yes get pods
check_can_i "Read pod logs"                          yes get pods/log
check_can_i "List ConfigMaps"                        yes list configmaps

echo
echo "=== Recommended security restrictions ==="

check_can_i "Create pods"                            no create pods
check_can_i "Delete pods"                            no delete pods
check_can_i "Execute commands in pods"               no create pods/exec
check_can_i "List Secrets"                           no list secrets
check_can_i "Read Secrets"                           no get secrets

echo
echo "=== Kubeflow Notebooks ==="

check_can_i "List notebooks"                         yes list notebooks.kubeflow.org
check_can_i "Get notebooks"                          yes get notebooks.kubeflow.org
check_can_i "Create notebook"                        no create notebooks.kubeflow.org
check_can_i "Update notebook"                        no update notebooks.kubeflow.org
check_can_i "Patch notebook"                         no patch notebooks.kubeflow.org
check_can_i "Delete notebook"                        no delete notebooks.kubeflow.org

echo
echo "=== Volumes / PersistentVolumeClaims ==="

check_can_i "List volumes"                           yes list persistentvolumeclaims
check_can_i "Get volumes"                            yes get persistentvolumeclaims
check_can_i "Create volume"                          no create persistentvolumeclaims
check_can_i "Update volume"                          no update persistentvolumeclaims
check_can_i "Patch volume"                           no patch persistentvolumeclaims
check_can_i "Delete volume"                          no delete persistentvolumeclaims

echo
echo "=== Katib experiments ==="

skip_check "Katib RBAC validation" \
  "Skipped because this component is excluded from the current acceptance test."

echo
echo "=== KServe endpoints ==="

check_can_i "List KServe endpoints"                  yes list inferenceservices.serving.kserve.io
check_can_i "Get KServe endpoints"                   yes get inferenceservices.serving.kserve.io
check_can_i "Create KServe endpoint"                 no create inferenceservices.serving.kserve.io
check_can_i "Update KServe endpoint"                 no update inferenceservices.serving.kserve.io
check_can_i "Patch KServe endpoint"                  no patch inferenceservices.serving.kserve.io
check_can_i "Delete KServe endpoint"                 no delete inferenceservices.serving.kserve.io

echo
echo "=== Kubeflow Pipelines: pipelines ==="

check_ssar "List pipelines"                          true  list   pipelines.kubeflow.org pipelines
check_ssar "Get pipelines"                           true  get    pipelines.kubeflow.org pipelines
check_ssar "Create pipeline"                         false create pipelines.kubeflow.org pipelines
check_ssar "Update pipeline"                         false update pipelines.kubeflow.org pipelines
check_ssar "Delete pipeline"                         false delete pipelines.kubeflow.org pipelines

echo
echo "=== Kubeflow Pipelines: pipeline versions ==="

check_ssar "List pipeline versions"                  true  list   pipelines.kubeflow.org pipelines versions
check_ssar "Get pipeline versions"                   true  get    pipelines.kubeflow.org pipelines versions
check_ssar "Create pipeline version"                 false create pipelines.kubeflow.org pipelines versions
check_ssar "Delete pipeline version"                 false delete pipelines.kubeflow.org pipelines versions

echo
echo "=== Kubeflow Pipelines: experiments ==="

check_ssar "List pipeline experiments"               true  list      pipelines.kubeflow.org experiments
check_ssar "Get pipeline experiments"                true  get       pipelines.kubeflow.org experiments
check_ssar "Create pipeline experiment"              false create    pipelines.kubeflow.org experiments
check_ssar "Delete pipeline experiment"              false delete    pipelines.kubeflow.org experiments
check_ssar "Archive pipeline experiment"             false archive   pipelines.kubeflow.org experiments
check_ssar "Unarchive pipeline experiment"           false unarchive pipelines.kubeflow.org experiments

echo
echo "=== Kubeflow Pipelines: runs ==="

check_ssar "List pipeline runs"                      true  list         pipelines.kubeflow.org runs
check_ssar "Get pipeline runs"                       true  get          pipelines.kubeflow.org runs
check_ssar "Read pipeline artifacts"                 true  readArtifact pipelines.kubeflow.org runs
check_ssar "Create pipeline run"                     false create       pipelines.kubeflow.org runs
check_ssar "Delete pipeline run"                     false delete       pipelines.kubeflow.org runs
check_ssar "Archive pipeline run"                    false archive      pipelines.kubeflow.org runs
check_ssar "Terminate pipeline run"                  false terminate    pipelines.kubeflow.org runs

echo
echo "=== Model Registry ==="

skip_check "Model Registry create/delete validation" \
  "Requires the authenticated Model Registry UI or API; it cannot be proven with Kubernetes RBAC alone."

echo
echo "=== Summary ==="
echo "PASS: $PASS_COUNT"
echo "FAIL: $FAIL_COUNT"
echo "SKIP: $SKIP_COUNT"

if [[ "$FAIL_COUNT" -gt 0 ]]; then
  echo
  echo "Result: FAILED"
  exit 1
fi

echo
echo "Result: PASSED"

3. Run the script

chmod +x test-kubeflow-viewer-rbac.sh
./test-kubeflow-viewer-rbac.sh

4. Expected result

For a correctly configured Viewer role, the final summary should be:

=== Summary ===
PASS: 49
FAIL: 0
SKIP: 2

Result: PASSED

The two skipped checks are expected:

Katib RBAC validation
Model Registry create/delete validation

Katib is excluded from this acceptance test because of the known component issue.

Model Registry write permissions must be validated separately through its authenticated UI or API.