From 66fe3138831a2b1b96c8064717700f62a6ba646f Mon Sep 17 00:00:00 2001 From: avijra Date: Mon, 2 Nov 2026 10:44:21 +0800 Subject: [PATCH] feat: add OpenShell AI agent sandbox as Layer 2 use case Add NVIDIA OpenShell integration demonstrating zero trust for AI coding agents on top of the ZTVP foundation. The Pi coding agent runs inside a secure sandbox with: - Network: allowlist-only (3 hosts), binary-level enforcement, ~2ms denial - Filesystem: Landlock LSM kernel enforcement (/sandbox + /tmp writable only) - Credentials: boundary resolver tokens (real keys never enter sandbox) - Identity: SPIFFE workload identity, Keycloak OIDC user auth - Secrets: Vault storage, ESO sync, automatic rotation Components: - charts/openshell-ztm/ - Helm chart wrapping NVIDIA OpenShell subchart with ZTVP integration (Vault, ESO, Keycloak, SPIFFE, ACS) - values-hub.yaml - Commented-out opt-in namespace + application entries - values-secret.yaml.template - MAAS API key secret entry Tested: 3 full E2E walkthroughs on ROSA 4.22 + ZTVP (chart v1.3.1) Lab guide: https://avijra.github.io/openshell-ztm-lab/ Closes: #190 Co-authored-by: Cursor --- charts/openshell-ztm/Chart.yaml | 28 +++ charts/openshell-ztm/templates/NOTES.txt | 56 ++++++ charts/openshell-ztm/templates/_helpers.tpl | 95 +++++++++ .../templates/deepseek-secret.yaml | 12 ++ .../templates/external-secret.yaml | 45 +++++ .../templates/image-pull-secret.yaml | 12 ++ .../templates/keycloak-client.yaml | 33 ++++ .../openshell-ztm/templates/maas-secret.yaml | 12 ++ .../templates/pi-sandbox-create-job.yaml | 184 ++++++++++++++++++ .../templates/pi-sandbox-policy-cm.yaml | 150 ++++++++++++++ .../openshell-ztm/templates/setup-rbac.yaml | 38 ++++ .../templates/spiffe-registration.yaml | 17 ++ .../templates/vault-secret-job.yaml | 72 +++++++ .../templates/vault-secret-maas-job.yaml | 72 +++++++ .../templates/vault-seed-sa.yaml | 13 ++ charts/openshell-ztm/values.yaml | 168 ++++++++++++++++ values-hub.yaml | 19 ++ values-secret.yaml.template | 18 ++ 18 files changed, 1044 insertions(+) create mode 100644 charts/openshell-ztm/Chart.yaml create mode 100644 charts/openshell-ztm/templates/NOTES.txt create mode 100644 charts/openshell-ztm/templates/_helpers.tpl create mode 100644 charts/openshell-ztm/templates/deepseek-secret.yaml create mode 100644 charts/openshell-ztm/templates/external-secret.yaml create mode 100644 charts/openshell-ztm/templates/image-pull-secret.yaml create mode 100644 charts/openshell-ztm/templates/keycloak-client.yaml create mode 100644 charts/openshell-ztm/templates/maas-secret.yaml create mode 100644 charts/openshell-ztm/templates/pi-sandbox-create-job.yaml create mode 100644 charts/openshell-ztm/templates/pi-sandbox-policy-cm.yaml create mode 100644 charts/openshell-ztm/templates/setup-rbac.yaml create mode 100644 charts/openshell-ztm/templates/spiffe-registration.yaml create mode 100644 charts/openshell-ztm/templates/vault-secret-job.yaml create mode 100644 charts/openshell-ztm/templates/vault-secret-maas-job.yaml create mode 100644 charts/openshell-ztm/templates/vault-seed-sa.yaml create mode 100644 charts/openshell-ztm/values.yaml diff --git a/charts/openshell-ztm/Chart.yaml b/charts/openshell-ztm/Chart.yaml new file mode 100644 index 00000000..e24fcfeb --- /dev/null +++ b/charts/openshell-ztm/Chart.yaml @@ -0,0 +1,28 @@ +apiVersion: v2 +name: openshell-ztm +description: | + NVIDIA OpenShell AI Agent Sandbox with Zero Trust integration. + Wraps the official NVIDIA OpenShell Helm chart and adds ZTVP + integration (Vault, ESO, Keycloak, SPIFFE/SPIRE, ACS) plus a + pre-configured Pi agent sandbox with zero-trust policies. +version: 1.3.1 +appVersion: "0.1.6" +type: application +keywords: + - zero-trust + - ai-agents + - openshell + - security + - sandbox + - maas +maintainers: + - name: Zero Trust Validated Patterns Team + email: ztvp-arch-group@redhat.com +sources: + - https://github.com/NVIDIA/OpenShell + - https://github.com/validatedpatterns/layered-zero-trust +dependencies: + - name: helm-chart + version: "0.1.6" + repository: "oci://ghcr.io/nvidia/openshell" + alias: openshell diff --git a/charts/openshell-ztm/templates/NOTES.txt b/charts/openshell-ztm/templates/NOTES.txt new file mode 100644 index 00000000..81f744e8 --- /dev/null +++ b/charts/openshell-ztm/templates/NOTES.txt @@ -0,0 +1,56 @@ +╔═══════════════════════════════════════════════════════════════════╗ +║ OpenShell + Pi AI Agent on Zero Trust Mesh — v{{ .Chart.Version }} ║ +╚═══════════════════════════════════════════════════════════════════╝ + +Gateway URL: + https://{{ include "ztm.routeHostname" . }} + +Pi Sandbox: {{ .Values.pi.sandbox.name }} +Namespace: {{ .Values.namespace }} + +── Quick Start ───────────────────────────────────────────────────── + +1. Install the OpenShell CLI: + curl -LsSf https://raw.githubusercontent.com/NVIDIA/OpenShell/main/install.sh | sh + +2. Point to the gateway: + export OPENSHELL_GATEWAY="https://{{ include "ztm.routeHostname" . }}" + +3. Verify sandbox is ready: + openshell sandbox list + +4. Connect: + openshell sandbox exec {{ .Values.pi.sandbox.name }} + +5. Inside the sandbox, run Pi: + pi "Write a hello world in Python" + +── Demo Scenarios ────────────────────────────────────────────────── + +A) Network Deny — try reaching an unauthorized host: + curl https://evil.example.com + → BLOCKED. Only maas-rhdp.apps.maas..., github.com, npm are allowed. + +B) Filesystem Deny — try writing outside allowed paths: + touch /etc/shadow + → DENIED by Landlock LSM. Only /sandbox and /tmp are writable. + +C) Credential Security — API key never visible inside sandbox: + env | grep MAAS + → Shows openshell:resolve:... not the real key. + +D) Dynamic Policy Update — add access on the fly: + openshell policy update --sandbox {{ .Values.pi.sandbox.name }} \ + --add-endpoint "https://pypi.org:443" + +── Clean Uninstall ───────────────────────────────────────────────── + + helm uninstall {{ .Release.Name }} -n {{ .Values.namespace }} + + To also remove the namespace: + oc delete namespace {{ .Values.namespace }} + + To reinstall fresh: + helm install {{ .Release.Name }} openshell-ztm-demo/openshell-ztm-demo \ + -n {{ .Values.namespace }} --create-namespace \ + --set maas.apiKey= diff --git a/charts/openshell-ztm/templates/_helpers.tpl b/charts/openshell-ztm/templates/_helpers.tpl new file mode 100644 index 00000000..ef465ccd --- /dev/null +++ b/charts/openshell-ztm/templates/_helpers.tpl @@ -0,0 +1,95 @@ +{{/* +Cluster domain — uses the VP framework's global.localClusterDomain, +with fallback to OpenShift Ingress auto-detection. +*/}} +{{- define "ztm.clusterDomain" -}} +{{- if .Values.global.localClusterDomain -}} +{{- .Values.global.localClusterDomain -}} +{{- else -}} +{{- $ing := (lookup "config.openshift.io/v1" "Ingress" "" "cluster") -}} +{{- if and $ing $ing.spec $ing.spec.domain -}} +{{- $ing.spec.domain -}} +{{- else -}} +{{- fail "Cannot auto-detect cluster domain. Set global.localClusterDomain" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Default OpenShift Route hostname for OpenShell gateway. +When spec.host is empty, OpenShift auto-generates: {route-name}-{namespace}.{cluster-domain} +*/}} +{{- define "ztm.routeHostname" -}} +{{- if .Values.openshell.openshiftRoute.host -}} +{{- .Values.openshell.openshiftRoute.host -}} +{{- else -}} +{{ include "ztm.gatewayServiceName" . }}-{{ .Values.namespace }}.{{ include "ztm.clusterDomain" . }} +{{- end -}} +{{- end -}} + +{{/* +Keycloak base URL derived from cluster domain. +*/}} +{{- define "ztm.keycloakUrl" -}} +https://keycloak.{{ include "ztm.clusterDomain" . }} +{{- end -}} + +{{/* +SPIFFE trust domain derived from cluster domain. +*/}} +{{- define "ztm.trustDomain" -}} +{{- if .Values.spiffe.trustDomain -}} +{{- .Values.spiffe.trustDomain -}} +{{- else -}} +{{ include "ztm.clusterDomain" . }} +{{- end -}} +{{- end -}} + +{{/* +Vault internal (in-cluster) URL. +*/}} +{{- define "ztm.vaultInternalUrl" -}} +{{- if .Values.vault.internalUrl -}} +{{- .Values.vault.internalUrl -}} +{{- else -}} +https://vault.{{ .Values.vault.namespace }}.svc.cluster.local:8200 +{{- end -}} +{{- end -}} + +{{/* +Vault external URL derived from cluster domain. +*/}} +{{- define "ztm.vaultExternalUrl" -}} +https://vault-vault.{{ include "ztm.clusterDomain" . }} +{{- end -}} + +{{/* +Gateway in-cluster service name — mirrors the subchart's openshell.fullname logic. +*/}} +{{- define "ztm.gatewayServiceName" -}} +{{- $name := .Values.openshell.nameOverride | default "openshell" -}} +{{- if contains $name .Release.Name -}} +{{ .Release.Name }} +{{- else -}} +{{ .Release.Name }}-{{ $name }} +{{- end -}} +{{- end -}} + +{{/* +Gateway in-cluster gRPC endpoint (used by openshell CLI in hook jobs). +*/}} +{{- define "ztm.gatewayEndpoint" -}} +https://{{ include "ztm.gatewayServiceName" . }}.{{ .Values.namespace }}.svc.cluster.local:8080 +{{- end -}} + +{{/* +Standard labels for ZTM resources. +*/}} +{{- define "ztm.labels" -}} +app.kubernetes.io/name: openshell-ztm +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +app.kubernetes.io/part-of: layered-zero-trust +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} +{{- end -}} diff --git a/charts/openshell-ztm/templates/deepseek-secret.yaml b/charts/openshell-ztm/templates/deepseek-secret.yaml new file mode 100644 index 00000000..051291a2 --- /dev/null +++ b/charts/openshell-ztm/templates/deepseek-secret.yaml @@ -0,0 +1,12 @@ +{{- if and .Values.deepseek.enabled .Values.deepseek.apiKey }} +apiVersion: v1 +kind: Secret +metadata: + name: deepseek-api-key + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +type: Opaque +stringData: + api_key: {{ .Values.deepseek.apiKey | quote }} +{{- end }} diff --git a/charts/openshell-ztm/templates/external-secret.yaml b/charts/openshell-ztm/templates/external-secret.yaml new file mode 100644 index 00000000..afe17144 --- /dev/null +++ b/charts/openshell-ztm/templates/external-secret.yaml @@ -0,0 +1,45 @@ +{{- if .Values.vault.enabled }} +apiVersion: external-secrets.io/v1 +kind: ExternalSecret +metadata: + name: maas-api-key-es + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +spec: + refreshInterval: 1h + secretStoreRef: + name: {{ .Values.vault.clusterSecretStoreName }} + kind: ClusterSecretStore + target: + name: maas-api-key + creationPolicy: Merge + data: + - secretKey: api_key + remoteRef: + key: {{ .Values.vault.secretPath | trimPrefix "secret/data/" }} + property: api_key +{{- end }} +{{- if and .Values.deepseek.enabled .Values.vault.enabled }} +--- +apiVersion: external-secrets.io/v1 +kind: ExternalSecret +metadata: + name: deepseek-api-key-es + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +spec: + refreshInterval: 1h + secretStoreRef: + name: {{ .Values.vault.clusterSecretStoreName }} + kind: ClusterSecretStore + target: + name: deepseek-api-key + creationPolicy: Merge + data: + - secretKey: api_key + remoteRef: + key: hub/infra/openshell/deepseek + property: api_key +{{- end }} diff --git a/charts/openshell-ztm/templates/image-pull-secret.yaml b/charts/openshell-ztm/templates/image-pull-secret.yaml new file mode 100644 index 00000000..066a7b8f --- /dev/null +++ b/charts/openshell-ztm/templates/image-pull-secret.yaml @@ -0,0 +1,12 @@ +{{- if .Values.imagePullSecret.create }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Values.imagePullSecret.name }} + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +type: kubernetes.io/dockerconfigjson +data: + .dockerconfigjson: {{ .Values.imagePullSecret.dockerconfigjson | b64enc | quote }} +{{- end }} diff --git a/charts/openshell-ztm/templates/keycloak-client.yaml b/charts/openshell-ztm/templates/keycloak-client.yaml new file mode 100644 index 00000000..e42a09c8 --- /dev/null +++ b/charts/openshell-ztm/templates/keycloak-client.yaml @@ -0,0 +1,33 @@ +{{- if .Values.keycloak.enabled }} +apiVersion: k8s.keycloak.org/v2alpha1 +kind: KeycloakRealmImport +metadata: + name: openshell-oidc-client + namespace: {{ .Values.keycloak.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +spec: + keycloakCRName: keycloak + realm: + realm: {{ .Values.keycloak.realm }} + enabled: true + clients: + - clientId: {{ .Values.keycloak.clientId }} + name: OpenShell Gateway + enabled: true + publicClient: true + standardFlowEnabled: true + directAccessGrantsEnabled: true + rootUrl: https://{{ include "ztm.routeHostname" . }} + redirectUris: + - https://{{ include "ztm.routeHostname" . }}/* + - http://localhost:*/* + webOrigins: + - https://{{ include "ztm.routeHostname" . }} + - http://localhost:* + protocol: openid-connect + defaultClientScopes: + - openid + - profile + - email +{{- end }} diff --git a/charts/openshell-ztm/templates/maas-secret.yaml b/charts/openshell-ztm/templates/maas-secret.yaml new file mode 100644 index 00000000..372ca40a --- /dev/null +++ b/charts/openshell-ztm/templates/maas-secret.yaml @@ -0,0 +1,12 @@ +{{- if .Values.maas.apiKey }} +apiVersion: v1 +kind: Secret +metadata: + name: maas-api-key + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +type: Opaque +stringData: + api_key: {{ .Values.maas.apiKey | quote }} +{{- end }} diff --git a/charts/openshell-ztm/templates/pi-sandbox-create-job.yaml b/charts/openshell-ztm/templates/pi-sandbox-create-job.yaml new file mode 100644 index 00000000..6fa4d503 --- /dev/null +++ b/charts/openshell-ztm/templates/pi-sandbox-create-job.yaml @@ -0,0 +1,184 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: pi-sandbox-setup-{{ .Release.Revision }} + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} + annotations: + helm.sh/hook: post-install,post-upgrade + helm.sh/hook-weight: "10" + helm.sh/hook-delete-policy: before-hook-creation +spec: + backoffLimit: 3 + activeDeadlineSeconds: 600 + ttlSecondsAfterFinished: 600 + template: + metadata: + labels: + app.kubernetes.io/name: pi-sandbox-setup + spec: + serviceAccountName: openshell-setup + restartPolicy: Never + containers: + - name: setup + image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest + env: + - name: MAAS_API_KEY + valueFrom: + secretKeyRef: + name: maas-api-key + key: api_key + optional: true + {{- if .Values.deepseek.enabled }} + - name: DEEPSEEK_API_KEY + valueFrom: + secretKeyRef: + name: deepseek-api-key + key: api_key + optional: true + {{- end }} + command: ["/bin/bash", "-c"] + args: + - | + set -eo pipefail + + NS="{{ .Values.namespace }}" + SANDBOX="{{ .Values.pi.sandbox.name }}" + IMAGE="{{ .Values.pi.sandbox.image }}" + GW="{{ include "ztm.gatewayEndpoint" . }}" + + # ── Step 1: Install OpenShell CLI ──────────────────────── + echo "==> Step 1: Installing OpenShell CLI..." + CLI_URL="https://github.com/NVIDIA/OpenShell/releases/download/v0.1.6/openshell-x86_64-unknown-linux-musl.tar.gz" + cd /tmp + curl -LsSf -o openshell.tar.gz "${CLI_URL}" + tar xzf openshell.tar.gz + chmod +x openshell + export PATH="/tmp:${PATH}" + openshell --version + + export OPENSHELL_GATEWAY_ENDPOINT="${GW}" + export OPENSHELL_GATEWAY_INSECURE=true + + # ── Step 2: Wait for gateway to accept connections ───────── + echo "==> Step 2: Waiting for OpenShell gateway..." + for i in $(seq 1 60); do + if openshell sandbox list >/dev/null 2>&1; then + echo " Gateway responding" + break + fi + if [ "$i" -eq 60 ]; then + echo " ERROR: Gateway did not respond in 10 min" + exit 1 + fi + echo " Attempt $i/60..." + sleep 10 + done + + # ── Step 3: Import MAAS provider profile ─────────────────── + echo "==> Step 3: Importing MAAS provider profile..." + openshell provider profile import \ + --file /config/maas-profile.yaml 2>&1 || \ + echo " WARN: profile import returned non-zero (may already exist)" + + # ── Step 4: Create MAAS provider (global) ────────────────── + echo "==> Step 4: Creating MAAS provider..." + MAAS_KEY="${MAAS_API_KEY}" + if [ -n "${MAAS_KEY}" ]; then + openshell provider create \ + --name maas \ + --type maas \ + --credential "MAAS_API_KEY=${MAAS_KEY}" 2>&1 || \ + echo " WARN: provider create returned non-zero (may already exist)" + else + echo " SKIP: No MAAS API key — creating provider without credential" + openshell provider create \ + --name maas \ + --type maas 2>&1 || true + fi + + {{- if .Values.deepseek.enabled }} + # ── Step 4b: Import DeepSeek provider profile ────────────── + echo "==> Step 4b: Importing DeepSeek provider profile..." + openshell provider profile import \ + --file /config/deepseek-profile.yaml 2>&1 || \ + echo " WARN: DeepSeek profile import returned non-zero (may already exist)" + + # ── Step 4c: Create DeepSeek provider ────────────────────── + echo "==> Step 4c: Creating DeepSeek provider..." + DS_KEY="${DEEPSEEK_API_KEY}" + if [ -n "${DS_KEY}" ]; then + openshell provider create \ + --name deepseek \ + --type deepseek \ + --credential "DEEPSEEK_API_KEY=${DS_KEY}" 2>&1 || \ + echo " WARN: DeepSeek provider create returned non-zero (may already exist)" + else + echo " SKIP: No DeepSeek API key" + fi + {{- end }} + + # ── Step 5: Clean up any stale sandbox ───────────────────── + echo "==> Step 5: Cleaning up any previous sandbox..." + openshell sandbox delete "${SANDBOX}" 2>&1 || true + sleep 3 + + # ── Step 6: Create sandbox with pre-built image ──────────── + echo "==> Step 6: Creating sandbox: ${SANDBOX} (image: ${IMAGE})..." + openshell sandbox create \ + --name "${SANDBOX}" \ + --from "${IMAGE}" \ + --provider maas \ + {{- if .Values.deepseek.enabled }} + --provider deepseek \ + {{- end }} + --detach 2>&1 + + # ── Step 7: Wait for sandbox Ready ───────────────────────── + echo "==> Step 7: Waiting for sandbox to be Ready..." + for i in $(seq 1 30); do + PHASE=$(openshell sandbox list 2>/dev/null \ + | grep "${SANDBOX}" | awk '{print $NF}' || echo "unknown") + if [ "${PHASE}" = "Ready" ]; then + echo " Sandbox is Ready" + break + fi + if [ "$i" -eq 30 ]; then + echo " WARN: Sandbox did not reach Ready in 5 min" + fi + echo " Phase: ${PHASE} (attempt $i/30)" + sleep 10 + done + + # ── Step 8: Inject Pi models.json into sandbox ────────────── + echo "==> Step 8: Injecting Pi models.json (providers: MAAS{{- if .Values.deepseek.enabled }}, DeepSeek{{- end }})..." + MODELS_B64=$(base64 < /config/models.json | tr -d '\n') + openshell sandbox exec "${SANDBOX}" -- sh -c \ + "mkdir -p /sandbox/.pi/agent && echo ${MODELS_B64} | base64 -d > /sandbox/.pi/agent/models.json" \ + 2>&1 || echo " WARN: models.json injection returned non-zero" + + # ── Step 9: Apply zero-trust policy ──────────────────────── + echo "==> Step 9: Applying zero-trust policy..." + openshell policy set \ + --policy /config/policy.yaml \ + "${SANDBOX}" 2>&1 + + echo "" + echo "============================================" + echo " Setup complete — sandbox '${SANDBOX}' is" + echo " demo-ready with zero-trust policy applied" + {{- if .Values.deepseek.enabled }} + echo " Providers: MAAS ({{ .Values.maas.model }}) + DeepSeek" + {{- else }} + echo " Provider: MAAS ({{ .Values.maas.model }})" + {{- end }} + echo "============================================" + volumeMounts: + - name: config + mountPath: /config + readOnly: true + volumes: + - name: config + configMap: + name: pi-sandbox-policy diff --git a/charts/openshell-ztm/templates/pi-sandbox-policy-cm.yaml b/charts/openshell-ztm/templates/pi-sandbox-policy-cm.yaml new file mode 100644 index 00000000..00652cf0 --- /dev/null +++ b/charts/openshell-ztm/templates/pi-sandbox-policy-cm.yaml @@ -0,0 +1,150 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: pi-sandbox-policy + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +data: + policy.yaml: | + version: 1 + filesystem_policy: + include_workdir: true + read_only: + {{- range .Values.pi.sandbox.policy.filesystemReadOnly }} + - {{ . }} + {{- end }} + read_write: + {{- range .Values.pi.sandbox.policy.filesystemReadWrite }} + - {{ . }} + {{- end }} + landlock: + compatibility: best_effort + network_policies: + {{- range $key, $rule := .Values.pi.sandbox.policy.networkPolicies }} + {{ $key }}: + name: {{ $rule.name }} + endpoints: + {{- range $rule.endpoints }} + - host: {{ .host }} + port: {{ .port }} + {{- if .protocol }} + protocol: {{ .protocol }} + {{- end }} + {{- if .enforcement }} + enforcement: {{ .enforcement }} + {{- end }} + {{- if .access }} + access: {{ .access }} + {{- end }} + {{- end }} + {{- if $rule.binaries }} + binaries: + {{- range $rule.binaries }} + - { path: {{ . }} } + {{- end }} + {{- end }} + {{- end }} + {{- if .Values.deepseek.enabled }} + deepseek_api: + name: "DeepSeek API" + endpoints: + - host: api.deepseek.com + port: 443 + protocol: rest + enforcement: enforce + access: read-write + binaries: + - { path: /usr/bin/curl } + - { path: /usr/bin/node } + {{- end }} + maas-profile.yaml: | + id: maas + display_name: "Red Hat MAAS ({{ .Values.maas.model }})" + description: Red Hat Model-as-a-Service — OpenAI-compatible LLM endpoint + category: inference + inference_capable: true + credentials: + - name: api_key + description: MAAS API key + env_vars: [MAAS_API_KEY] + required: true + auth_style: bearer + header_name: authorization + discovery: + credentials: [api_key] + endpoints: + - host: {{ (urlParse .Values.maas.endpoint).host }} + port: 443 + protocol: rest + access: read-write + enforcement: enforce + binaries: [/usr/bin/curl, /usr/local/bin/curl, /usr/bin/node, /usr/local/bin/node] + {{- if .Values.deepseek.enabled }} + deepseek-profile.yaml: | + id: deepseek + display_name: DeepSeek + description: DeepSeek inference API (OpenAI-compatible) + category: inference + inference_capable: true + credentials: + - name: api_key + description: DeepSeek API key + env_vars: [DEEPSEEK_API_KEY] + required: true + auth_style: bearer + header_name: authorization + discovery: + credentials: [api_key] + endpoints: + - host: api.deepseek.com + port: 443 + protocol: rest + access: read-write + enforcement: enforce + binaries: [/usr/bin/curl, /usr/local/bin/curl, /usr/bin/node, /usr/local/bin/node] + {{- end }} + models.json: | + { + "providers": { + "maas": { + "baseUrl": "{{ .Values.maas.endpoint }}", + "api": "openai-completions", + "apiKey": "$MAAS_API_KEY", + "models": [ + { + "id": "{{ .Values.maas.model }}", + "name": "Red Hat MAAS {{ .Values.maas.model }}", + "contextWindow": 131072, + "maxTokens": 4096, + "input": ["text"], + "reasoning": false, + "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 } + } + ] + } + {{- if .Values.deepseek.enabled }}, + "deepseek": { + "baseUrl": "{{ .Values.deepseek.endpoint }}", + "api": "openai-completions", + "apiKey": "$DEEPSEEK_API_KEY", + "models": [ + { + "id": "deepseek-chat", + "name": "DeepSeek Chat", + "contextWindow": 1048576, + "maxTokens": 393216, + "input": ["text"], + "reasoning": true, + "cost": { "input": 0.14, "output": 0.28, "cacheRead": 0.028, "cacheWrite": 0 }, + "compat": { + "requiresReasoningContentOnAssistantMessages": true, + "thinkingFormat": "deepseek", + "reasoningEffortMap": { "minimal": "high", "low": "high", "medium": "high", "high": "high", "xhigh": "max" } + } + } + ] + } + {{- end }} + } + } diff --git a/charts/openshell-ztm/templates/setup-rbac.yaml b/charts/openshell-ztm/templates/setup-rbac.yaml new file mode 100644 index 00000000..b1f782ab --- /dev/null +++ b/charts/openshell-ztm/templates/setup-rbac.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: openshell-setup + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: openshell-setup + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +rules: + - apiGroups: [""] + resources: ["pods", "pods/log", "services", "configmaps", "secrets"] + verbs: ["get", "list", "watch"] + - apiGroups: ["agents.x-k8s.io"] + resources: ["sandboxes"] + verbs: ["get", "list", "watch", "delete"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: openshell-setup + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: openshell-setup +subjects: + - kind: ServiceAccount + name: openshell-setup + namespace: {{ .Values.namespace }} diff --git a/charts/openshell-ztm/templates/spiffe-registration.yaml b/charts/openshell-ztm/templates/spiffe-registration.yaml new file mode 100644 index 00000000..ad1c511b --- /dev/null +++ b/charts/openshell-ztm/templates/spiffe-registration.yaml @@ -0,0 +1,17 @@ +{{- if .Values.spiffe.enabled }} +apiVersion: spire.spiffe.io/v1alpha1 +kind: ClusterSPIFFEID +metadata: + name: openshell-gateway + labels: + {{- include "ztm.labels" . | nindent 4 }} +spec: + className: openshift + spiffeIDTemplate: "spiffe://{{ include "ztm.trustDomain" . }}/ns/{{ .Values.namespace }}/sa/openshell" + podSelector: + matchLabels: + app.kubernetes.io/name: openshell + namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: {{ .Values.namespace }} +{{- end }} diff --git a/charts/openshell-ztm/templates/vault-secret-job.yaml b/charts/openshell-ztm/templates/vault-secret-job.yaml new file mode 100644 index 00000000..916f4cf7 --- /dev/null +++ b/charts/openshell-ztm/templates/vault-secret-job.yaml @@ -0,0 +1,72 @@ +{{- if and .Values.deepseek.enabled .Values.vault.enabled .Values.deepseek.apiKey }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: deepseek-api-key-ephemeral + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} + annotations: + helm.sh/hook: pre-install,pre-upgrade + helm.sh/hook-weight: "-10" + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +type: Opaque +stringData: + apiKey: {{ .Values.deepseek.apiKey | quote }} +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: vault-seed-deepseek-{{ .Release.Revision }} + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} + annotations: + helm.sh/hook: pre-install,pre-upgrade + helm.sh/hook-weight: "-5" + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +spec: + backoffLimit: 3 + ttlSecondsAfterFinished: 300 + template: + metadata: + labels: + app.kubernetes.io/name: vault-seed-job + spec: + serviceAccountName: vault-seed-job + restartPolicy: Never + containers: + - name: vault-seed + image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest + command: ["/bin/bash", "-c"] + args: + - | + set -e + VAULT_ADDR="{{ include "ztm.vaultInternalUrl" . }}" + SA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) + LOGIN_RESP=$(curl -sk --fail \ + --request POST \ + --data "{\"jwt\":\"${SA_TOKEN}\",\"role\":\"{{ .Values.vault.role }}\"}" \ + "${VAULT_ADDR}/v1/{{ .Values.vault.authPath }}/login" 2>/dev/null || echo "{}") + VAULT_TOKEN=$(echo "${LOGIN_RESP}" | grep -o '"client_token":"[^"]*"' | head -1 | cut -d'"' -f4 || true) + if [ -z "${VAULT_TOKEN}" ]; then + echo "WARN: Vault auth failed; DeepSeek key will be stored as K8s Secret only" + exit 0 + fi + API_KEY=$(cat /secrets/apiKey) + curl -sk --fail \ + --header "X-Vault-Token: ${VAULT_TOKEN}" \ + --request POST \ + --data "{\"data\":{\"api_key\":\"${API_KEY}\"}}" \ + "${VAULT_ADDR}/v1/{{ .Values.vault.secretPath }}" || \ + echo "WARN: Vault write failed; proceeding anyway" + volumeMounts: + - name: api-key + mountPath: /secrets + readOnly: true + volumes: + - name: api-key + secret: + secretName: deepseek-api-key-ephemeral +{{- end }} diff --git a/charts/openshell-ztm/templates/vault-secret-maas-job.yaml b/charts/openshell-ztm/templates/vault-secret-maas-job.yaml new file mode 100644 index 00000000..a2ca5529 --- /dev/null +++ b/charts/openshell-ztm/templates/vault-secret-maas-job.yaml @@ -0,0 +1,72 @@ +{{- if and .Values.vault.enabled .Values.maas.apiKey }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: maas-api-key-ephemeral + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} + annotations: + helm.sh/hook: pre-install,pre-upgrade + helm.sh/hook-weight: "-10" + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +type: Opaque +stringData: + apiKey: {{ .Values.maas.apiKey | quote }} +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: vault-seed-maas-{{ .Release.Revision }} + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} + annotations: + helm.sh/hook: pre-install,pre-upgrade + helm.sh/hook-weight: "-4" + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +spec: + backoffLimit: 3 + ttlSecondsAfterFinished: 300 + template: + metadata: + labels: + app.kubernetes.io/name: vault-seed-maas-job + spec: + serviceAccountName: vault-seed-job + restartPolicy: Never + containers: + - name: vault-seed + image: image-registry.openshift-image-registry.svc:5000/openshift/cli:latest + command: ["/bin/bash", "-c"] + args: + - | + set -e + VAULT_ADDR="{{ include "ztm.vaultInternalUrl" . }}" + SA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) + LOGIN_RESP=$(curl -sk --fail \ + --request POST \ + --data "{\"jwt\":\"${SA_TOKEN}\",\"role\":\"{{ .Values.vault.role }}\"}" \ + "${VAULT_ADDR}/v1/{{ .Values.vault.authPath }}/login" 2>/dev/null || echo "{}") + VAULT_TOKEN=$(echo "${LOGIN_RESP}" | grep -o '"client_token":"[^"]*"' | head -1 | cut -d'"' -f4 || true) + if [ -z "${VAULT_TOKEN}" ]; then + echo "WARN: Vault auth failed; MAAS key will be stored as K8s Secret only" + exit 0 + fi + API_KEY=$(cat /secrets/apiKey) + curl -sk --fail \ + --header "X-Vault-Token: ${VAULT_TOKEN}" \ + --request POST \ + --data "{\"data\":{\"api_key\":\"${API_KEY}\"}}" \ + "${VAULT_ADDR}/v1/secret/data/hub/infra/openshell/maas" || \ + echo "WARN: Vault write failed; proceeding anyway" + volumeMounts: + - name: api-key + mountPath: /secrets + readOnly: true + volumes: + - name: api-key + secret: + secretName: maas-api-key-ephemeral +{{- end }} diff --git a/charts/openshell-ztm/templates/vault-seed-sa.yaml b/charts/openshell-ztm/templates/vault-seed-sa.yaml new file mode 100644 index 00000000..896b6e32 --- /dev/null +++ b/charts/openshell-ztm/templates/vault-seed-sa.yaml @@ -0,0 +1,13 @@ +{{- if and .Values.vault.enabled (or (and .Values.deepseek.enabled .Values.deepseek.apiKey) (and .Values.maas.enabled .Values.maas.apiKey)) }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: vault-seed-job + namespace: {{ .Values.namespace }} + labels: + {{- include "ztm.labels" . | nindent 4 }} + annotations: + helm.sh/hook: pre-install,pre-upgrade + helm.sh/hook-weight: "-9" + helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded +{{- end }} diff --git a/charts/openshell-ztm/values.yaml b/charts/openshell-ztm/values.yaml new file mode 100644 index 00000000..3a2ca03a --- /dev/null +++ b/charts/openshell-ztm/values.yaml @@ -0,0 +1,168 @@ +## ─── Global ───────────────────────────────────────────────────────── +## localClusterDomain is set by the VP framework; used for route/URL derivation. +global: + localClusterDomain: apps.example.com + secretStore: + name: "vault-backend" + kind: "ClusterSecretStore" + +## ─── Namespace ────────────────────────────────────────────────────── +namespace: openshell-system + +## ─── MAAS LLM Provider (Red Hat Model-as-a-Service) ───────────────── +## API key is provided via values-secret.yaml.template → Vault → ESO. +## Only set endpoint/model here; the key flows through Vault automatically. +maas: + enabled: true + endpoint: https://maas-rhdp.apps.maas.redhatworkshops.io/v1 + model: gpt-oss-120b + +## ─── Vault (External Secrets Operator) ────────────────────────────── +## These defaults match the ZTVP validated pattern. +vault: + enabled: true + namespace: vault + internalUrl: "https://vault.vault.svc.cluster.local:8200" + role: openshell-admin + secretPath: secret/data/hub/infra/openshell/maas + authPath: auth/hub + clusterSecretStoreName: vault-backend + +## ─── Keycloak SSO ─────────────────────────────────────────────────── +keycloak: + enabled: true + namespace: keycloak-system + realm: ztvp + clientId: openshell-gateway + +## ─── SPIFFE / SPIRE ───────────────────────────────────────────────── +spiffe: + enabled: true + +## ─── Pi Agent Sandbox ─────────────────────────────────────────────── +pi: + sandbox: + name: pi-agent-demo + image: ghcr.io/avijra/pi-sandbox:v1.0 + policy: + filesystemReadOnly: + - /bin + - /usr + - /lib + - /proc + - /dev/urandom + - /app + - /etc + - /var/log + filesystemReadWrite: + - /sandbox + - /tmp + - /dev/null + networkPolicies: + maas_api: + name: Red Hat MAAS + endpoints: + - host: maas-rhdp.apps.maas.redhatworkshops.io + port: 443 + protocol: rest + enforcement: enforce + access: read-write + binaries: + - /usr/bin/curl + - /usr/bin/node + github: + name: GitHub + endpoints: + - host: github.com + port: 443 + - host: api.github.com + port: 443 + protocol: rest + enforcement: enforce + access: read-only + binaries: + - /usr/bin/git + - /usr/bin/curl + npm_registry: + name: npm Registry + endpoints: + - host: registry.npmjs.org + port: 443 + binaries: + - /usr/bin/npm + - /usr/bin/node + +## ─── Official OpenShell subchart values ───────────────────────────── +openshell: + nameOverride: openshell + replicaCount: 1 + workload: + kind: statefulset + global: + image: + registry: ghcr.io/nvidia + pullPolicy: IfNotPresent + gateway: + image: + repository: openshell/gateway + tag: "0.1.6" + supervisor: + replicas: 1 + podSecurityContext: + runAsNonRoot: true + runAsUser: null + runAsGroup: null + fsGroup: null + seccompProfile: + type: RuntimeDefault + sandbox: + image: + repository: nvcr.io/nvidia/base/ubuntu + tag: "24.04" + podSecurityContext: + fsGroup: null + securityContext: + runAsNonRoot: true + runAsUser: null + allowPrivilegeEscalation: false + capabilities: + drop: [ALL] + seccompProfile: + type: RuntimeDefault + server: + disableTls: false + telemetryEnabled: false + logLevel: info + sandboxNamespace: "" + credentialDrivers: + vault: + enabled: true + address: "https://vault.vault.svc.cluster.local:8200" + mount: secret + kvVersion: "2" + authMethod: kubernetes + role: openshell-admin + kubernetesAuthMount: hub + kubernetesSecrets: + enabled: false + auth: + allowUnauthenticatedUsers: true + oidc: + issuer: "" + audience: "openshell-gateway" + providerTokenGrants: + spiffe: + enabled: false + openshiftRoute: + enabled: true + host: "" + pkiInitJob: + serverDnsNames: [] + credentialDrivers: + vault: + caConfigMapName: vault-ca + networkPolicy: + enabled: true + agentSandbox: + preflight: + enabled: false diff --git a/values-hub.yaml b/values-hub.yaml index 0360ea84..7bf0ba04 100644 --- a/values-hub.yaml +++ b/values-hub.yaml @@ -55,6 +55,8 @@ clusterGroup: vault: qtodo: qtodo-db: + # Layer 2: AI Agent Sandbox (OpenShell) + # openshell-system: external-secrets-operator: operatorGroup: true targetNamespaces: [] @@ -846,6 +848,23 @@ clusterGroup: # - OpenShift # End of Pipeline/DevSecOps configuration + # ── Layer 2: AI Agent Sandbox (OpenShell) ────────────────────────── + # Deploys NVIDIA OpenShell with a Pi coding agent in a zero-trust sandbox. + # Integrates with Vault (secret storage), ESO (secret sync), Keycloak (OIDC), + # SPIFFE/SPIRE (workload identity), and ACS (image scanning). + # Requires: MAAS API key in values-secret.yaml.template + # + # openshell-ztm: + # name: openshell-ztm + # namespace: openshell-system + # argoProject: hub + # path: charts/openshell-ztm + # annotations: + # argocd.argoproj.io/sync-wave: "40" + # overrides: + # - name: openshell.server.oidc.issuer + # value: "https://keycloak.{{ .Values.global.localClusterDomain }}/realms/ztvp" + # exampleRegion: # name: group-one # acmlabels: diff --git a/values-secret.yaml.template b/values-secret.yaml.template index 4d0f6b20..ba557a29 100644 --- a/values-secret.yaml.template +++ b/values-secret.yaml.template @@ -18,6 +18,7 @@ version: "2.0" # hub/infra/rhtpa/ - RHTPA infrastructure secrets # hub/infra/quay/ - Built-in Quay registry credentials (auto-generated) # hub/infra/registry/ - BYO container registry credentials (user-provided) +# hub/infra/openshell/ - OpenShell AI agent LLM API key (MAAS) # hub/infra/users/ - User credentials managed by IdP # # Framework Secrets: @@ -233,6 +234,23 @@ secrets: # path: ~/.config/validated-patterns/registry-token # onMissingValue: error + # =========================================================================== + # OPENSHELL AI AGENT SECRETS (hub/infra/openshell/) + # LLM API key for the Pi coding agent (MAAS / gpt-oss-120b) + # Used by: OpenShell Gateway (credential boundary resolution) + # Policy: hub-infra-openshell-secret (read access to hub/infra/openshell/*) + # + # Store your MAAS API key in a local file: + # echo -n "sk-your-maas-key" > ~/.config/validated-patterns/maas-api-key + # =========================================================================== + #- name: openshell-maas + # vaultPrefixes: + # - hub/infra/openshell + # fields: + # - name: api_key + # path: ~/.config/validated-patterns/maas-api-key + # onMissingValue: error + # =========================================================================== # SUPPLY CHAIN GIT CREDENTIALS (hub/supply-chain/) # Credentials for cloning protected Git repositories in Tekton pipelines