> ## Documentation Index
> Fetch the complete documentation index at: https://sariva.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes Secret

> The verified credential path — and the only option for self-hosted mTLS.

> [!NOTE]
>
> Kubernetes/EKS only. On a VM, skip this page.

Use this when you don't have AWS SM/SSM standardized, you're running Sariva off-AWS (GKE, AKS, on-prem), or you need self-hosted **mTLS** (currently K8s-Secret-only). This is the path verified in the onboarding rehearsal.

**Prerequisites:** a namespace you control for the Secret — the release namespace, a dedicated `team-secrets`, or any namespace where you keep credentials.

## Customer-managed Kubernetes Secret

### 1. Create the Secret

```bash theme={null}
kubectl create secret generic payments-dev-creds \
  --namespace team-secrets \
  --from-literal=api_key='ABCD1234' \
  --from-literal=api_secret='xyzABC...'
```

Self-hosted **mTLS (PEM)**:

```bash theme={null}
kubectl create secret generic onprem-kafka-creds --namespace team-secrets \
  --from-file=client.cert.pem=./client.cert.pem \
  --from-file=client.key.pem=./client.key.pem \
  --from-file=ca.cert.pem=./ca.cert.pem
# optional: --from-literal=client.key.password='<password>'
```

Self-hosted **mTLS (JKS)**:

```bash theme={null}
kubectl create secret generic onprem-kafka-creds --namespace team-secrets \
  --from-file=keystore.jks=./keystore.jks \
  --from-file=truststore.jks=./truststore.jks \
  --from-literal=keystore.password='<keystore-password>' \
  --from-literal=truststore.password='<truststore-password>'
```

### 2. Grant Sariva read access (the secrets-read Role) — before you attach

> [!WARNING]
>
> Apply this RBAC **before** the attach step, or Gate 7 fails `credentials_resolve_failed` / `Forbidden`. The chart does **not** provision it — it's customer-authored on purpose, so least-privilege scoping is auditable in your repo.

```yaml theme={null}
# sariva-read-payments-dev-creds.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: sariva-read-payments-dev-creds
  namespace: team-secrets
rules:
- apiGroups: [""]
  resources: ["secrets"]
  resourceNames: ["payments-dev-creds"]   # scoped to the specific Secret
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: sariva-read-payments-dev-creds
  namespace: team-secrets
subjects:
- kind: ServiceAccount
  name: sariva-platform        # Sariva's ServiceAccount (chart default)
  namespace: sariva-platform   # Sariva's release namespace
roleRef:
  kind: Role
  name: sariva-read-payments-dev-creds
  apiGroup: rbac.authorization.k8s.io
```

```bash theme={null}
kubectl apply -f sariva-read-payments-dev-creds.yaml
```

For multiple clusters, use one Role per Secret (cleanest to audit) or one Role with `resourceNames: ["secret-A","secret-B",…]`.

### 3. Attach the credential (from your laptop, no exec)

```bash theme={null}
sariva cluster patch --alias payments-dev \
  --credentials-ref k8s://team-secrets/payments-dev-creds \
  --api-url <platform-url> --api-key <bearer>
```

Gate 7 calls `get secret payments-dev-creds -n team-secrets` under the pod's ServiceAccount and validates the payload shape. On pass → `credential_lifecycle=resolved`. Use `auth_type: api_key` for a CC key.

## Terraform-managed Kubernetes Secret

Use this only if your CI runner can reach the Kubernetes API and has RBAC to create/update Secrets in the target namespace. For the AWS EKS + GitHub Actions path, AWS Secrets Manager or SSM is usually the cleaner automated store because GitHub Actions can write it through AWS OIDC without needing direct network access to the EKS API.

If you use this path, Sariva opens a GitOps PR that creates the observability credential and writes the Kubernetes Secret. The resulting `credentials_ref` uses the explicit form:

```text theme={null}
k8s://<namespace>/<secret-name>
```

## Gate failures

| Reason code | Cause | Fix |
| - | - | - |
| `credentials_resolve_failed: Forbidden` | RoleBinding missing / wrong ServiceAccount | Verify `subjects[0].name` + `namespace` match Sariva's SA |
| `credentials_resolve_failed: NotFound` | Secret or namespace doesn't exist | `kubectl get secret <name> -n <namespace>` |
| `credentials_payload_shape_mismatch` | Secret missing the keys for the `auth_type` | See the payload-shape table on the overview |
| `credentials_payload_shape_mismatch` (mTLS) | Both JKS and PEM keys present | One format per Secret — remove the unused keys |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.