Kubernetes Operator
The Operator authenticates your cluster’s workloads to Rivergate with short-lived identity and keeps ordinary Kubernetes Secrets in sync with the values they are allowed to read.
How it works
The Operator is a standalone API client built on controller-runtime. It never touches PostgreSQL, never evaluates policy locally, and never places source values or credentials in custom resources, status or logs.
Operator Pod ── projected ServiceAccount JWT ──▶ Rivergate (token exchange, audited)
◀── 5-minute opaque token ─────────
── GET secret value (policy-checked, audited) ─▶
──▶ writes a Kubernetes Secret in its own namespace
- You declare a
RivergateStore(which Rivergate cluster identity to use) and aRivergateSecret(which secret to sync, and where to put it). - The Operator exchanges its projected ServiceAccount JWT for a five-minute Rivergate token.
- It reads only the exact secret named, which Rivergate authorizes and audits.
- It writes the value into the target Kubernetes Secret and records the source version and sync time in status.
- It refreshes on your interval and skips writes when the version has not changed.
Workload identity
Trust is established explicitly, in Rivergate, by a system administrator. Nothing in a custom resource can grant or widen access.
1. Trust the cluster
Register the cluster’s exact ServiceAccount issuer, an HTTPS JWKS URL and the audience the chart uses. Updating trust revokes tokens previously issued for that cluster.
PUT /auth/workload/clusters/production-cluster
{
"issuer": "https://oidc.kube.example.com",
"jwks_url": "https://oidc.kube.example.com/keys.json",
"audience": "rivergate"
}
Rivergate fetches the JWKS only over HTTPS, does not follow redirects, caps the response size, caches signing keys for five minutes, and fails closed on any invalid, expired or wrongly scoped token. It validates the JWT itself and does not use Kubernetes TokenReview.
2. Map the Operator’s ServiceAccount
Read the ServiceAccount’s UID from the cluster, then map the exact namespace, name and UID to a machine principal.
kubectl -n rivergate-sync get serviceaccount rivergate-operator -o jsonpath='{.metadata.uid}'
POST /auth/workload/clusters/production-cluster/mappings
{
"namespace": "rivergate-sync",
"service_account_name": "rivergate-operator",
"service_account_uid": "UID_FROM_KUBECTL"
}
The response includes a machine principal_id. Keep it for the next step.
3. Grant the least access needed
Add the machine to the organization with the membership-only machine role, which grants no actions, then bind secret_reader to the exact secret.
POST /api/v1/organizations/ORG_ID/members
{ "principal_id": "MACHINE_PRINCIPAL_ID", "role": "machine" }
POST /api/v1/organizations/ORG_ID/policies
{ "principal_id": "MACHINE_PRINCIPAL_ID", "scope_type": "secret", "scope_id": "SECRET_ID", "role": "secret_reader" }
Machine identities cannot receive organization-wide bindings, cannot become system administrators, and their tokens can only read metadata and values their scoped policies allow. Disabling a mapping or a cluster revokes active tokens.
Install the Operator
Install the chart from rivergate-helm into a dedicated namespace. The Rivergate API origin is pinned in the Deployment — it is never read from a custom resource, so a user cannot redirect the workload token to an endpoint they control.
helm upgrade --install rivergate-operator ./charts/rivergate-operator \
--namespace rivergate-sync --create-namespace \
--set rivergate.serverURL=https://rivergate.example.com \
--set workloadIdentity.audience=rivergate \
--set image.repository=registry.example.com/rivergate-operator \
--set image.tag=0.1.0
- The chart creates a ServiceAccount named
rivergate-operator, its RBAC and the CRDs. - It mounts the normal ServiceAccount token for Kubernetes API access, and separately projects a short-lived token with the Rivergate audience.
- The Operator watches only its release namespace. Create stores, secrets and target workloads in that same namespace.
Custom resource reference
API group and version: rivergate.dev/v1alpha1. Both kinds are namespaced.
RivergateStore
apiVersion: rivergate.dev/v1alpha1
kind: RivergateStore
metadata:
name: rivergate
namespace: rivergate-sync
spec:
clusterID: production-cluster
| Field | Description |
|---|---|
spec.clusterID | The cluster identity configured in Rivergate (up to 128 characters). A store holds no URL, token or credential. |
RivergateSecret
apiVersion: rivergate.dev/v1alpha1
kind: RivergateSecret
metadata:
name: database-credentials
namespace: rivergate-sync
spec:
storeRef: rivergate
organization: ORG_ID
project: payments
environment: production
secret: database-password
refreshInterval: 5m
deletionPolicy: Retain
target:
name: database-credentials
key: password
| Field | Description |
|---|---|
spec.storeRef | Name of the RivergateStore in the same namespace. |
spec.organization, project, environment, secret | The exact secret to deliver. |
spec.refreshInterval | How often to refresh. Default 5m; allowed range 30 seconds to 24 hours. |
spec.deletionPolicy | Retain (default) leaves the target in place on delete. Delete removes it, but only if it still carries this resource’s source-UID marker. |
spec.target.name | Name of the Kubernetes Secret to write (up to 253 characters). |
spec.target.key | Key inside that Secret that receives the value (up to 253 characters). |
Status
Status never contains values, tokens, response bodies or secret-derived hashes.
| Field | Meaning |
|---|---|
observedGeneration | The spec generation last reconciled. |
lastSyncTime | When the value was last delivered successfully. |
secretVersion | The Rivergate secret version currently delivered. |
conditions | Sanitized conditions describing sync health. |
kubectl -n rivergate-sync get rivergatesecret database-credentials -o yaml
Delivery behavior
- Refresh. The value is re-read on your interval. Unchanged versions cause no write and no rollout.
- Ownership. The Operator refuses to overwrite an existing Secret that does not carry its own source-UID marker.
- Outages. If Rivergate is unreachable or access is revoked, the last successfully delivered value stays in place. The condition is updated with a sanitized message, and retries use bounded exponential backoff that honors rate limits.
- Revocation does not erase. Disabling a mapping or removing a policy stops future reads. A value already delivered remains in the Kubernetes Secret until you delete it. To remove it, delete the
RivergateSecretwithdeletionPolicy: Delete, or delete the target Secret as part of your incident procedure. - Audit. Every delivered value is a policy-checked, audited read, and every token exchange is audited before a token is returned.
Once delivered, a value is visible to sufficiently privileged Kubernetes API, node and etcd principals. Enable encryption at rest for etcd, restrict namespace RBAC, and dedicate a namespace to the Operator and the workloads that need its Secrets. No design can hide a delivered value from a cluster administrator.
Permissions and isolation
- The Operator’s Role is namespaced. It can read and write the Secrets it manages, but it cannot list Secrets, cannot read ServiceAccount objects, and cannot touch other namespaces.
- Anyone who can create or edit
RivergateSecretresources in the namespace can request delivery within the machine principal’s policy scope. Restrict that permission accordingly. - Cross-namespace delivery and cluster-scoped stores are not supported.
After installing, verify the boundaries. You need permission to impersonate the ServiceAccount.
kubectl auth can-i get secrets -n rivergate-sync --as=system:serviceaccount:rivergate-sync:rivergate-operator # yes
kubectl auth can-i list secrets -n rivergate-sync --as=system:serviceaccount:rivergate-sync:rivergate-operator # no
kubectl auth can-i get secrets -n default --as=system:serviceaccount:rivergate-sync:rivergate-operator # no
Upgrading
- Export your existing
RivergateStoreandRivergateSecretmanifests. - Apply reviewed CRD changes from
config/crd/bases/beforehelm upgrade. Helm does not upgrade CRDs installed from a chart’scrds/directory. - Run
helm upgradewith the new image. - Confirm existing resources keep their status and target values and that reconciliation resumes.
Changing the API group is a breaking Kubernetes change: custom resources are not migrated by Helm. Update apiVersion to rivergate.dev/v1alpha1, install the new CRDs, reapply, and verify before removing old CRDs.
Checking it works
- Apply a store and a secret in the Operator’s namespace.
- Confirm the target Secret exists and the resource reports the expected
secretVersion— without printing the value. - To compare payloads safely, pipe the decoded key to
cmp -sagainst a protected fixture instead of displaying it. - Change the secret in Rivergate and confirm the target updates on the next interval.
- Disable the mapping or remove the policy, and confirm refresh stops while the last value is kept.