Reducing Credential Exposure with IBM Cloud Secrets Manager Automatic Rotation in Containerized Apps
Learn how IBM Cloud Secrets Manager automatic rotation limits the exposure window of leaked credentials in containerized workloads, with a step‑by‑step example using Code Engine and IBM Cloud Functions.
05 Feb 2026, 23:59 UTC

Problem: Static credentials linger in containers
When a containerized workload uses an IAM API key or database credential that is injected once at build time, the secret remains valid for the lifetime of the key. If the key is leaked, an attacker can use it until it is manually revoked, which may be hours or days. In environments where secrets are stored in image layers or environment variables, the exposure window can be long enough to cause significant damage.
How automatic rotation limits exposure
IBM Cloud Secrets Manager can rotate a secret on a schedule (for example, every 24 hours) without requiring the application to be redeployed. The rotation is performed by a user‑provided IBM Cloud Function that generates a new credential value and writes it back to the same secret. Applications that retrieve the secret at startup or periodically (e.g., via a sidecar or the Secrets Manager SDK) automatically see the updated value, so the window during which a compromised key can be abused is bounded by the rotation interval.
Worked example: Rotating an IAM API key for a Code Engine job
- Create the secret
ibmcloud secrets-manager secret-create \ --instance-id \ --name \ --secret-type arbitrary \ --payload '{"api_key":""}' \ --resource-groupRequired permission:
secretsmanager.secrets.createon the target instance. - Write a rotation function
The function receives the current secret payload, generates a new IAM API key (or calls an external identity provider), and returns the updated payload. A minimal Node.js example:
const iam = require('@ibm-cloud/iam-auth'); exports.main = async (params) => { const newKey = await iam.createApiKey({ name: `rotated-${Date.now()}` }); return { payload: JSON.stringify({ api_key: newKey }) }; };Deploy the function with:
ibmcloud fn action update rotation.js \ --kind nodejs:20 \ --web trueRequired permission:
functions.action.createandfunctions.action.update. - Configure rotation
ibmcloud secrets-manager rotation-policy-create \ --instance-id \ --secret-id \ --target-action \ --interval 86400 \ --enabled trueThe interval is in seconds; 86400 s = 24 hours.
- Deploy a Code Engine job that reads the secret
Use the Secrets Manager integration to inject the secret as an environment variable:
ibmcloud ce job create --name \ --image /: \ --env-from-secret \The job’s container can read
process.env.api_keyat startup. If the job runs longer than the rotation interval, it will need to refresh the environment variable (e.g., by restarting or by using the SDK to fetch the latest value). - Verify rotation
Check audit logs for rotation events:
ibmcloud at log search \ --type activity \ --target-crns \ --query 'secrets-manager.rotation'Each successful rotation creates a log entry with a timestamp and the initiator (the IBM Cloud Function ID).
Trade‑off and limitation
Automatic rotation adds operational complexity: you must maintain a reliable, idempotent rotation function and monitor its execution. If the function fails, the secret may stay unchanged until manual intervention, which could lead to stale credentials if the application expects frequent updates. Additionally, applications that cache the credential for longer than the rotation interval will see outdated values until the cache is refreshed, potentially causing authentication failures. To mitigate this, design the workload to fetch the secret on each use or to restart periodically.
Actionable closing
Start with a test secret and a short rotation interval (e.g., 5 minutes) to validate the end‑to‑end flow in a non‑production Code Engine job. Observe the secret value change in the job’s logs and confirm that each rotation generates an audit entry. Once the process is stable, adjust the interval to match your security policy and deploy the pattern to production workloads.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.