Rivergate

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
  1. You declare a RivergateStore (which Rivergate cluster identity to use) and a RivergateSecret (which secret to sync, and where to put it).
  2. The Operator exchanges its projected ServiceAccount JWT for a five-minute Rivergate token.
  3. It reads only the exact secret named, which Rivergate authorizes and audits.
  4. It writes the value into the target Kubernetes Secret and records the source version and sync time in status.
  5. 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

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
FieldDescription
spec.clusterIDThe 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
FieldDescription
spec.storeRefName of the RivergateStore in the same namespace.
spec.organization, project, environment, secretThe exact secret to deliver.
spec.refreshIntervalHow often to refresh. Default 5m; allowed range 30 seconds to 24 hours.
spec.deletionPolicyRetain (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.nameName of the Kubernetes Secret to write (up to 253 characters).
spec.target.keyKey inside that Secret that receives the value (up to 253 characters).

Status

Status never contains values, tokens, response bodies or secret-derived hashes.

FieldMeaning
observedGenerationThe spec generation last reconciled.
lastSyncTimeWhen the value was last delivered successfully.
secretVersionThe Rivergate secret version currently delivered.
conditionsSanitized conditions describing sync health.
kubectl -n rivergate-sync get rivergatesecret database-credentials -o yaml

Delivery behavior

Kubernetes Secrets hold plaintext

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

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

  1. Export your existing RivergateStore and RivergateSecret manifests.
  2. Apply reviewed CRD changes from config/crd/bases/ before helm upgrade. Helm does not upgrade CRDs installed from a chart’s crds/ directory.
  3. Run helm upgrade with the new image.
  4. 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

  1. Apply a store and a secret in the Operator’s namespace.
  2. Confirm the target Secret exists and the resource reports the expected secretVersion — without printing the value.
  3. To compare payloads safely, pipe the decoded key to cmp -s against a protected fixture instead of displaying it.
  4. Change the secret in Rivergate and confirm the target updates on the next interval.
  5. Disable the mapping or remove the policy, and confirm refresh stops while the last value is kept.