Rotate managed service credentials
As a Project administrator or developer, rotate a published credential role manually or on a schedule.
This guide covers platform-managed roles on services whose plans allow RotateCredentials.
For PostgreSQL SQL logins and superuser access, see PostgreSQL credentials.
Before you begin
Check these requirements:
- The service is ready, and you know its name and UID.
- You have the Project
adminordeveloperrole. - The family supports rotation for the selected role, and the plan allows it.
- Your applications can reload credentials and reconnect after rotation.
Role names differ between families. Examples include PostgreSQL, MySQL, and MariaDB owner, and Valkey default.
Use the family guide to check supported roles and any credential overlap period.
Do not assume that the previous password remains usable after rotation.
Read the service UID before you create an operation or policy:
kubectl get managedservice <service> -n <project> \
-o jsonpath='{.metadata.uid}{"\n"}'
Replace <service> with the service name and <project> with its Project namespace.
Rotate a role manually
-
Submit the
RotateCredentialsexample in Request an operation. -
Wait for the operation to reach
Succeeded. -
Check the affected bindings:
kubectl get servicebindings -n <project>Confirm that bindings for the role report
Ready=Trueand the replacement credential version. -
Reload the credential in your applications.
-
Verify that each application can reconnect.
All bindings of the same role receive the replacement credential. An operation's success does not prove that applications have loaded it.
Schedule rotation
-
Save this manifest as
app-credential-rotation.yaml:apiVersion: services.kube-dc.com/v1alpha1kind: ServiceCredentialPolicymetadata:name: app-credential-rotationnamespace: <project>spec:serviceRef:name: <service>serviceUID: <service-uid>role: <role>rotationIntervalSeconds: 2592000paused: falseReplace
<service-uid>with the UID you read and<role>with a supported credential role. Use the same<service>and<project>as the lookup command. The interval is 30 days. Allowed values range from 60 to 31536000 seconds. -
Create the policy:
kubectl apply -f app-credential-rotation.yaml -
Check its schedule:
kubectl get servicecredentialpolicy app-credential-rotation -n <project> -o yamlA scheduled policy reports
Ready=Truewith reasonScheduledand astatus.nextRotationAtvalue. After a successful rotation, the reason can beRotated.
Only one policy can manage a credential target. A duplicate reports CredentialPolicyConflict.
The first declared-role rotation is due one interval after policy creation.
Later intervals start after the previous attempt finishes, including a failed attempt.
Missed intervals produce one attempt, not a series of catch-up rotations.
A policy submits rotation only while the service is ready.
If the plan requires approval, its operations wait for the provider in AwaitingApproval.
Project identities cannot modify or cancel policy-created operations.
Pause or retire a policy
-
Pause new submissions:
kubectl patch servicecredentialpolicy app-credential-rotation -n <project> \--type merge -p '{"spec":{"paused":true}}' -
Check the policy until
status.activeOperationis empty. -
Read the result of
status.lastOperation, if present. -
Confirm that applications connect with the current credential.
To resume the schedule, set paused: false in the policy manifest and apply it.
The interval and paused state can change; the service identity and credential target cannot.
To remove a declared-role schedule after these checks, delete its policy:
kubectl delete servicecredentialpolicy app-credential-rotation -n <project>
Deleting a declared-role policy stops future rotations. Its role, bindings, and credentials remain. Existing PostgreSQL login policies have additional cleanup behavior; see Retire a PostgreSQL policy.