Azure App Secret Rotation
Automatically rotate the secret of an Azure app using Keeper Secrets Manager rotations
Overview
This documentation explains how to rotate Azure application secrets using KeeperPAM's rotation option called "Run PAM scripts only". This is a setting in the PAM User rotation settings which tells the Gateway to skip the primary rotation method and directly execute the post-rotation script attached to the PAM User record in the vault.
This guide includes prerequisites, step-by-step instructions, and a Python script example. The script ensures secure application secrets rotation, including deletion of previous application secrets, and stores the new application secret in Keeper. This new secret is automatically available to all already allowed KSM applications and users.
See the Azure Overview for a high level overview and getting started with Azure
Prerequisites
This guide assumes the following tasks have already taken place:
Rotation enforcements are configured for your role
A Keeper Secrets Manager application has been created
Your Azure environment is configured per our documentation
The gateway host will need to have a supported Python version installed with the 2 dependencies below:
Rotation Script Logic Flow
1. Admin Credentials Retrieval
The script retrieve admin credentials in three ways:
Record directly attached to the post rotation script.
The access key provided to the Azure PAM config selected for the rotation. This will be used if no access key is found in the record(s) attached (method 1 above) to the post rotation script.
2. Secret Rotation Logic
The script will:
Retrieve an admin application secret either from an attached record to the PAM Script or from the PAM Config.
Get a Microsoft Graph access token using the admin application secret found at the step above.
Create a new client secret on the Azure application defined in the PAM User record.
Delete all other existing secrets for the defined Azure application. Only the one generated at the step above will be kept.
Update the Keeper PAM User record with the new secret, and secret ID.
PAM User Record - Fields Requirements
You need to create a PAM User record where the rotation will be configured later on. The fields below need to be created.
Fields required:
Login
This mandatory field is not used in this script. You can use the field to store any useful information, like the name of the Azure app that will be rotated.
Password
It will be a dummy value in this case. The password field gets automatically rotated, but it is not used anywhere. This is still required field.
Custom fields required:
Text
This field is used to specify which application in Azure you want to rotate. You need to retrieve the application object ID of the application to rotate from the Azure portal > App Registration > Overview tab of your app > Application (client) ID.
Text
This field will receive the new client secret ID after the rotation.
Hidden Field
This field will receive the new client secret after the rotation.
Text
This field will receive the expiration date of the new secret after the rotation.
Text
Second field to enable NOOP.
The value has to be:

Setting Up the Rotation in the Keeper Vault
The script require an admin application secret to authenticate against Azure and rotate another application's secret. Here we will be using the admin app secret provided in the Azure PAM Configuration.
Configuration From the Keeper Vault:
Create a shared folder in the vault
Create a PAM User record in the shared folder with the fields and custom fields described above.

In the Secret Manager tab of the Keeper vault, create a new application for the gateway if there is no gateway yet.
Make sure the Application has edit permissions on the shared folder created above.
Provision the gateway (gateway tab after selecting the application) on a Linux box. Simply run the install command provided by the Keeper vault and make sure Python and the dependencies listed above are installed.
In the Secret Manager tab of the Keeper vault, go to the PAM Configurations tab. Create a new PAM configuration if needed.
Under Environment, please select “Azure”, select the Gateway, select the shared folder, provide the “Entra ID” name (arbitrary name of your Entra ID environment), the admin application “Client ID” (Overview tab of the admin application in the Azure portal), “Client Secret” (Certificates & secrets tab of the admin application in the Azure portal), "Subscription ID" and "Tenant ID".

Edit the PAM User record previously described in this documentation:
Password Rotation Settings: select your desired schedule and the PAM configuration created above.
Select "Run PAM Scripts only" as the Rotation method.
Add PAM Script to the record: select the provided file below and make sure to specify the script command:

Python Script
Last updated
Was this helpful?