Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to rotate your service account keys using gkectl for
Cloud Audit Logs, Usage Metering, and Stackdriver components on Google Distributed Cloud.
To rotate your service account keys:
Create a directory to store a backup of your current secrets:
mkdir backup
Note the following information for the relevant component:
Cloud Audit Logs
Cluster
Secret
Namespace
Admin
create-config
kube-system
Admin
create-config
CLUSTER_NAME
Admin
audit-logging-config
kube-system
Admin
kube-apiserver
CLUSTER_NAME
Usage Metering
Cluster
Secret
Namespace
Admin
create-config
CLUSTER_NAME
User
usage-metering-bigquery-service-account-key
kube-system
Stackdriver
Cluster
Secret
Namespace
Admin
create-config
kube-system
Admin
create-config
CLUSTER_NAME
User
google-cloud-credentials
kube-system
User
stackdriver-service-account-key
knative-serving
Create a backup of each secret using the following command:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[[["\u003cp\u003eThis page details the process of rotating service account keys for Cloud Audit Logs, Usage Metering, and Stackdriver components on Google Distributed Cloud using \u003ccode\u003egkectl\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eBefore rotating keys, you should create a backup of existing secrets for each relevant component, including Cloud Audit Logs, Usage Metering, and Stackdriver, using the \u003ccode\u003ekubectl get secret\u003c/code\u003e command.\u003c/p\u003e\n"],["\u003cp\u003eGenerate a new service account key file using the \u003ccode\u003egcloud iam service-accounts keys create\u003c/code\u003e command, specifying the new key file name and the service account email.\u003c/p\u003e\n"],["\u003cp\u003eUpdate the configuration files for both the admin and user clusters to reflect the new key file by replacing the \u003ccode\u003eserviceAccountKeyPath\u003c/code\u003e with the path to the new key file, then applying changes with \u003ccode\u003egkectl update credentials\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIn case a rollback is necessary, the backup of the secrets can be restored by executing the command \u003ccode\u003ekubectl apply -f backup/\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Rotating service account keys\n\nThis page describes how to rotate your service account keys using `gkectl` for\nCloud Audit Logs, Usage Metering, and Stackdriver components on Google Distributed Cloud.\n\nTo rotate your service account keys:\n\n1. Create a directory to store a backup of your current secrets:\n\n ```\n mkdir backup\n ```\n2. Note the following information for the relevant component:\n\n **Cloud Audit Logs**\n\n **Usage Metering**\n\n **Stackdriver**\n\n3. Create a backup of each secret using the following command:\n\n ```\n kubectl get secret SECRET --namespace NAMESPACE \\\n --kubeconfig KUBECONFIG -o json \u003e backup/SECRET-NAMESPACE.json\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e is the namespace where the secret is located. For example, `kube-system`.\n - \u003cvar translate=\"no\"\u003eKUBECONFIG\u003c/var\u003e is the path to the kubeconfig file for the admin or user cluster.\n - \u003cvar translate=\"no\"\u003eSECRET\u003c/var\u003e is the name of the secret. For example, `create-config`.\n\n For example, run the following commands for the Cloud Audit Logs component: \n\n ```\n kubectl get secret create-config --namespace kube-system \\\n --kubeconfig KUBECONFIG -o json \u003e backup/admin-create-config-kube-system.json\n\n kubectl get secret create-config --namespace NAMESPACE \\\n --kubeconfig KUBECONFIG -o json \u003e backup/admin-create-config-NAMESPACE.json\n\n kubectl get secret audit-logging-config --namespace kube-system \\\n --kubeconfig KUBECONFIG -o json \u003e backup/audit-logging-config-kube-system.json\n\n kubectl get secret kube-apiserver --namespace NAMESPACE \\\n --kubeconfig KUBECONFIG -o json \u003e backup/kube-apiserver-NAMESPACE.json\n ```\n4. To create a new service account key file, run the following command:\n\n ```\n gcloud iam service-accounts keys create NEW_KEY_FILE --iam-account IAM_ACCOUNT\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eNEW_KEY_FILE\u003c/var\u003e is the name for your new service account key file\n - \u003cvar translate=\"no\"\u003eIAM_ACCOUNT\u003c/var\u003e is your service account email address for either [Cloud Audit Logs](/anthos/clusters/docs/on-prem/1.7/how-to/service-accounts#audit_logging_service_account), [Usage Metering](/anthos/clusters/docs/on-prem/1.7/how-to/service-accounts#usage_metering_service_account), or Stackdriver.\n5. In the config yaml file for both the admin and user cluster, find the `cloudauditlogging`, `usagemetering`, or `stackdriver` section.\n\n6. Replace the `serviceAccountKeyPath` field with the \u003cvar translate=\"no\"\u003eNEW_KEY_FILE\u003c/var\u003e you created earlier.\n\n7. Save the changes you made using the following commands:\n\n ```\n gkectl update credentials COMPONENT --admin-cluster --kubeconfig \\\n KUBECONFIG --config ADMIN_CONFIG\n\n gkectl update credentials COMPONENT --kubeconfig \\\n KUBECONFIG --config USER_CONFIG\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eKUBECONFIG\u003c/var\u003e is the path to the kubeconfig file for the admin cluster.\n - \u003cvar translate=\"no\"\u003eADMIN_CONFIG\u003c/var\u003e is the path to the config file for the admin cluster.\n - \u003cvar translate=\"no\"\u003eUSER_CONFIG\u003c/var\u003e is the path to the config file for the user cluster.\n - \u003cvar translate=\"no\"\u003eCOMPONENT\u003c/var\u003e is `cloudauditlogging`, `usagemetering`, or `stackdriver`.\n\n| **Note:** If you need to restore the backup of the secret you made earlier, run the following command: \n|\n| ```\n| kubectl apply -f backup/\n| ```"]]