Operating kbridge

This guide covers what a cluster operator and an application team need once kbridge runs: connecting a provider account, writing managed resources, reading their status, and handling drift, adoption and deletion. Installation is in the README.

ProviderConfig

A ProviderConfig (cluster-scoped, kbridge.io/v1alpha1) connects one provider account. Managed resources name it in spec.providerConfigRef.

FieldRequiredDescription
spec.provideryesName of the Provider descriptor, for example aws or cloudflare. A resource of another provider cannot use it.
spec.allowedNamespacesyesNamespaces whose resources may use it. "*" allows every namespace.
spec.credentials.sourceyesSecret, WebIdentity or PodIdentity. Only awsSigV4 providers accept the last two.
spec.credentials.secretRef.namewith SecretSecret in the controller namespace.
spec.credentials.assumeRoleARNnoAWS role assumed with the base credentials, for cross-account access.
spec.credentials.stsRegionwith WebIdentity or assumeRoleARNRegion of the STS endpoint. kbridge never guesses it.
spec.valuesnoString values exposed to descriptor expressions as config, for example the Cloudflare accountId.

Secret keys by provider authentication type:

Auth typeKeys
bearertoken
headervalue
basicusername, password
awsSigV4accessKeyId, secretAccessKey, optional sessionToken

WebIdentity uses the token that IRSA mounts (AWS_ROLE_ARN, AWS_WEB_IDENTITY_TOKEN_FILE). PodIdentity uses the EKS Pod Identity agent (AWS_CONTAINER_CREDENTIALS_FULL_URI, AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE). kbridge does not fall back to the default AWS credential chain.

kbridge reads Secrets directly from the API server and reuses them for 5 minutes. A rotated Secret applies within 5 minutes, or at once when the ProviderConfig changes.

Examples: providerconfig-aws.yaml, providerconfig-aws-irsa.yaml, providerconfig-cloudflare.yaml, providerconfig-proxmox.yaml.

Self-hosted APIs

The Proxmox VE provider talks to your own cluster, so its address is not known in advance. Before you build the image, set spec.endpoint and spec.allowedHosts in providers/proxmox/provider.yaml, for example:

endpoint: https://pve.lab.example.com:8006/api2/json
allowedHosts:
  - '^pve\.lab\.example\.com:8006$'

kbridge trusts the system certificate authorities only and never skips TLS verification, so it refuses the self-signed certificate Proxmox VE installs by default. Either:

  • issue a trusted certificate with the ACME support built into Proxmox VE, or
  • mount the cluster CA, /etc/pve/pve-root-ca.pem on any node, in a directory of the controller pod, and set SSL_CERT_DIR to that directory. The system authorities stay trusted.

Create a dedicated user and its token on a node. The role covers storage management only; Datastore.Audit lets kbridge see every storage, without it every storage looks absent and creates fail:

pveum user add kbridge@pve --comment "kbridge controller"
pveum role add KbridgeStorage --privs "Datastore.Allocate,Datastore.Audit"
pveum acl modify /storage --users kbridge@pve --roles KbridgeStorage
pveum user token add kbridge@pve kbridge --privsep 0

Store the whole header in the Secret, with the token secret that the last command prints:

kubectl -n kbridge create secret generic proxmox-token \
  --from-literal=value='PVEAPIToken=kbridge@pve!kbridge=<secret>'

Managed resources

Every generated CRD has the same top-level shape. Only forProvider depends on the descriptor.

FieldRequiredDefaultDescription
spec.providerConfigRefyesName of the ProviderConfig.
spec.forProvideryesDesired state of the external object, validated by the descriptor schema. Fields listed as immutable cannot change after creation; the API server rejects the update.
spec.driftPolicynodescriptor’s policy, Reapply for the shipped onesReapply, Alert or Ignore. See Drift.
spec.deletionPolicynoDeleteDelete removes the external object with the resource; Orphan keeps it.

Examples: s3-bucket.yaml, r2-bucket.yaml, proxmox-storage.yaml.

kubectl -n web get buckets.s3.aws.kbridge.io
kubectl -n web describe buckets.s3.aws.kbridge.io media

Status

FieldDescription
status.conditionsReady and Synced, see below.
status.atProviderExternal object state as the descriptor’s observe expression projects it.
status.observedGenerationLast spec generation applied to the external object.
status.lastSyncTimeEnd of the last sync.

Ready is True (reason Available) once the external object exists and has been read. It turns False with ExternallyDeleted when the object disappears and the policy does not recreate it.

Synced tells whether the last sync succeeded and the external object matches the spec:

StatusReasonMeaning and action
TrueSyncedThe external object matches the spec.
TrueDriftIgnoredFields differ and the policy is Ignore.
FalseDriftedFields differ and the policy is Alert. Fix the external object, or switch to Reapply.
FalseImmutableDriftAn immutable field differs. kbridge never changes immutable fields: recreate the object, or align the spec through a new resource.
True or FalseExternallyDeletedThe external object was deleted outside kbridge and the policy is Ignore (True) or Alert (False). Remove the kbridge.io/external-name annotation, or switch to Reapply, to create it again.
FalseAlreadyExistsAn object matching the spec exists, but kbridge did not create it. See Adoption.
FalseCreatePendingA previous create may have succeeded, and the object cannot be found without its identifier. See Interrupted creates.
FalseProviderConfigErrorThe ProviderConfig is missing, belongs to another provider, or does not allow the namespace.
FalseCredentialsErrorThe Secret is missing or lacks a key, or the credential source does not fit the provider.
FalseUpdateIneffectiveThe update calls succeeded but the fields still differ: the descriptor’s update or observe expression is wrong.
FalseAPIErrorThe provider API refused a request. The message holds the status and the provider’s error.
FalseReconcileErrorAny other failure, such as a network error.

Sync cycle

A resource syncs when it is created, when its spec or annotations change, and then every drift interval of its descriptor, 10 minutes by default, plus up to 10 % jitter. Each sync reads the resource from the API server rather than from the informer cache, so a stale copy is never mistaken for a spec change.

Retries:

  • Statuses listed as retryable in the provider descriptor and network errors retry with exponential backoff, from 1 second to 15 minutes. A Retry-After header sets the delay.
  • Other API errors and configuration errors wait for the next drift interval or for a change to the resource.

Requests of one ProviderConfig share the rate limit of the provider descriptor. Separate accounts therefore get separate budgets.

Drift

A spec change is intent: kbridge applies it, with no drift report. A difference found without a spec change is drift.

kbridge compares only the top-level fields present both in spec.forProvider and in the observed state. A field left out of forProvider is not managed. Values must match exactly; numbers compare by value. A map compares as a whole, so a tag added on the provider side is drift.

PolicyMutable field driftExternal deletion
ReapplyReported, then reverted.Reported, then recreated.
AlertReported. Synced=False, reason Drifted.Reported. Ready=False, not recreated.
IgnoreNot reported. Synced=True, reason DriftIgnored.Not reported. Ready=False, not recreated.

Immutable field drift is never reverted. It sets Synced=False with reason ImmutableDrift under every policy, and is reported unless the policy is Ignore.

A drift report consists of:

  • a Warning event on the resource, with reason DriftDetected, ImmutableDrift or ExternallyDeleted;
  • a JSON log line drift detected with group, kind, namespace, name, reason, fields and policy;
  • an increment of kbridge_drift_detected_total.

Events and logs name the fields that differ, never their values.

Adoption

kbridge never takes over an object it did not create. When the read finds an object matching a new resource, the resource gets Synced=False with reason AlreadyExists, and kbridge leaves the object alone.

To adopt the object, set its identifier as the external name. For S3 and R2 buckets, the identifier is the bucket name:

kubectl -n web annotate buckets.s3.aws.kbridge.io media kbridge.io/external-name=acme-web-media

kbridge then converges the object to the spec. With deletionPolicy: Delete, it also deletes the object when the resource is deleted.

Interrupted creates

kbridge sets the kbridge.io/external-create-pending annotation (a timestamp) before it creates an object. It removes the annotation once it has recorded the identifier in kbridge.io/external-name. When a sync finds the annotation, kbridge knows that this resource started a create:

  • If the descriptor can read the object from spec fields, as for S3 and R2, kbridge finds the object and records its identifier.
  • If the read needs the identifier assigned by the provider, kbridge cannot tell whether the create succeeded. It stops with reason CreatePending rather than risk a duplicate. Check the provider. Then either set kbridge.io/external-name to the created object and remove the pending annotation, or remove only the pending annotation to create the object again.

A create that the provider rejects also leaves the pending annotation, so for such descriptors the same manual step follows a rejected create.

Deletion

kbridge adds the kbridge.io/finalizer finalizer to every resource. When the resource is deleted:

  • with deletionPolicy: Delete, kbridge runs the delete operation, treats “not found” as done, then removes the finalizer;
  • with deletionPolicy: Orphan, or when nothing was ever created, it removes the finalizer and leaves the external object.

kbridge never deletes data inside an object. Deleting a non-empty S3 bucket fails with BucketNotEmpty; the resource stays with Synced=False and reason APIError until the bucket is emptied. To release the resource and keep the external object, set spec.deletionPolicy: Orphan.

Metrics

The metrics endpoint (--metrics-addr, port 8080, service kbridge-metrics) exposes the controller-runtime metrics and:

MetricTypeLabelsDescription
kbridge_drift_detected_totalcountergroup, kind, policyDrift reports.
kbridge_resources_driftedgaugegroup, kindResources whose external object currently differs from the spec and is left so: Alert drift, immutable drift, external deletion under Alert.
kbridge_api_requests_totalcounterprovider, method, codeProvider API requests; code is the HTTP status, or error when no response arrived.
kbridge_api_request_duration_secondshistogramproviderProvider API latency.

Alert on kbridge_resources_drifted > 0 and on increase(kbridge_drift_detected_total[1h]) > 0.

Security model

  • Credentials live only in Secrets of the controller namespace. The controller can get Secrets there, and only there.
  • allowedNamespaces decides which application namespaces may spend a ProviderConfig’s credentials.
  • Requests go over HTTPS, only to hosts that the provider’s allowedHosts patterns match. Redirects are never followed, and responses are capped at 4 MiB.
  • Logs, events and conditions never contain secret values or field values.
  • The container runs as a non-root user with a read-only root filesystem and no capabilities.

Edit this page