Automatically rotate the secret of an Azure app using Keeper Secrets Manager rotations
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
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:
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.
Attaching another record containing the admin application secret to the PAM Script will allow to easily rotate this admin application secrets in that other record using the same process described in this documentation.
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.
You need to create a PAM User record where the rotation will be configured later on. The fields below need to be created.
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.
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:
Instead of creating the PAM User record manually using the details above, you could also import the csv file below. It will create a template record you can amend and duplicate as needed.
Importing the file will generate a Login record type: make sure to convert it to PAM User.
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.
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:
It is possible to also rotate the application secret of the admin Azure application. To do this, you will need to store you admin Azure app secret in another Keeper PAM User record.
The PAM user record will need all fields as described in the documentation above, along with the additional fields below:
Text
Enter your Azure Tenant ID.
Text
Enter your admin application client ID. This is available in the Overview tab of the admin application in the Azure portal > App registrations.
Instead of creating the PAM User record manually using the documentation above and the extra fields above, you could also import the csv file below. It will create a template record you can amend and duplicate as needed.
Importing the file will generate a Login record type: make sure to convert it to PAM User.
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 “Local Network”, select the Gateway and the shared folder.
Edit the target app PAM User record:
Password Rotation Settings: select your desired schedule and the PAM configuration created above.
Add PAM Script to the record:
Select the provided Python file below.
Rotation Credential: select the admin app PAM User record.
Specify the script command: