The Cloud Run application creates a new key for a GCP service account, updates the required secret data, and deletes old versions of a key. The function is triggered by a Pub/Sub message sent by a secret stored in Secret Manager.
- A secret in Secret Manager sends a Pub/Sub message to the
secret-manager-notifications
Pub/Sub topic. - The Cloud Run application checks if the value of the eventType attribute is set to
SECRET_ROTATE
. If not, it stops running. - The Cloud Run application checks if the value of the type label is set to
gardener-service-account
. If not, it stops running. - The Cloud Run application checks if the values of the kubeconfig-secret, gardener-secret, and gardener-secret-namespace labels are set. If not, it stops running.
- The Cloud Run application authenticates to a cluster using the kubeconfig from the latest version of a secret provided in the kubeconfig-secret label.
- The Cloud Run application reads the name of the service account from the latest version of a secret.
- The Cloud Run application generates a new key for the service account.
- The Cloud Run application creates a new secret version containing the newly created service account key in Secret Manger.
- The Cloud Run application updates a secret containing the newly created service account key in the Gardener cluster.
- The Cloud Run application deletes old versions of a key in IAM.
- The Cloud Run application destroys old versions of a secret in Secret Manager.
To deploy the Cloud Run application, follow the following steps:
- Create the
secret-manager-notifications
Pub/Sub topic if it does not exist. - Create the
service-${PROJECT_NUMBER}@gcp-sa-secretmanager.iam.gserviceaccount.com
service account with theroles/pubsub.publisher
role if it does not exist. - Use the following command to deploy the Cloud Run application:
gcloud run deploy rotate-gardener-secrets-service-account \
--region europe-west1 \
--timeout 600 \
--max-instances 1 \
--memory 128Mi \
--service-account [email protected] \
--ingress internal \
--project sap-kyma-prow \
--allow-unauthenticated \
--image eu.gcr.io/kyma-project/test-infra/gardener-sa-rotate:v20221006-6fd98cfd
- Create the push
rotate-gardener-secrets-service-account
Pub/Sub subscription onsecret-manager-notifications
topic pointing to the Cloud Run application URL.
To setup an automatic rotation for a Secret Manager secret, follow these steps:
- Create a new secret in Secret Manager with the existing service account data.
- Add the
type: gardener-service-account
label to the secret. - Add the
kubeconfig-secret
label with the name of the secret containing the Gardener cluster kubeconfig to the secret. - Add the
gardener-secret
label with the name of a Gardener secret containing service account credentials to the secret. - Add the
gardener-secret-namespace
label containing the name of a Gardener secret namespace to the secret. - Set
secret-manager-notifications
as a secret Pub/Sub topic. - Set up a rotation period for the secret.
See the list of labels required for the function:
Name | Required | Description |
---|---|---|
type | Yes | The type of secret. It must be set to gardener-service-account . |
kubeconfig-secret | Yes | The name of the Secret Manager secret containing the kubeconfig. |
gardener-secret | Yes | The name of the Gardener secret containing service account credentials. |
gardener-secret-namespace | Yes | The name of the Gardener secret namespace containing service account credentials. |
See the list of GET arguments for the function:
Name | Required | Description |
---|---|---|
dry_run | No | Enables a dry run without updating secrets (defaults to false). |