CredHub in Cloud Foundry Usage | Generated by AI

Home 2026.01

Question: How to use CredHub in Cloud Foundry?

Answer:

CredHub is the centralized secrets management component in many Cloud Foundry deployments (especially Tanzu Application Service / VMware Tanzu Platform, PAS, PCF). It stores and manages credentials such as passwords, certificates, keys, JSON blobs, and more securely.

There are two main ways developers interact with CredHub:

  1. Indirectly (recommended for most apps) — via a CredHub Service Broker (creates/binds service instances that deliver secrets to your app via VCAP_SERVICES without exposing them in cf env).
  2. Directly — using the CredHub CLI or API (for admins, automation, or advanced use cases).

1. Using CredHub via Service Broker (Most Common for Applications)

In environments where the CredHub Service Broker is installed (common in Tanzu Application Service), follow these steps:

2. Using the CredHub CLI (Direct Access – Admin / Debugging / Scripting)

Install the CredHub CLI:

# macOS (Homebrew)
brew install cloudfoundry/tap/credhub-cli

# Or download binary from https://github.com/cloudfoundry-incubator/credhub-cli/releases

Authenticate (target your CredHub instance):

# Usually provided by your platform team (often same UAA as cf login)
credhub login --client-id <uaa-client-id> --client-secret <uaa-client-secret>
# OR use cf oauth-token as bearer
credhub api https://credhub.service.cf.internal:8844   # internal URL (from inside CF)
credhub login --token "$(cf oauth-token | cut -d' ' -f2)"

Common commands:

# Set a simple value
credhub set -n /my-org/my-app/api-key -t value -v "sk_live_xyz123"

# Generate a random password
credhub generate -n /my-org/my-app/db-pass -t password -l 32

# Generate a certificate
credhub generate -n /my-org/my-app/cert -t certificate \
  --common-name myapp.example.com --alternative-names "*.example.com"

# Get a credential
credhub get -n /my-org/my-app/api-key

# Find credentials
credhub find -p /my-org/my-app/

# Delete
credhub delete -n /my-org/my-app/old-key

Quick Comparison: User-Provided vs CredHub

Feature User-Provided Service (cf cups) CredHub (via Broker or Direct)
Visibility in cf env Redacted (mostly) Reference only or interpolated
Rotation support Manual Built-in regeneration
Central auditing No Yes
Generation (passwords, certs) No Yes
Best for Simple, non-enterprise setups Enterprise, compliance

Ask your platform operators:

References:


Back

x-ai/grok-4.1-fast

Donate