Rotating the Entra ID Client Secret for Grafana
This runbook explains how to replace the Microsoft Entra ID client secret that Grafana on hostmonitor uses for "Sign in with Microsoft". Entra client secrets expire (maximum 24 months), and when the secret expires, Microsoft sign-in stops working until it is replaced.
Rotation causes no downtime if done before expiry, because Entra allows the old and new secrets to be valid at the same time.
Reference details
| Item | Value |
|---|---|
| Grafana URL | https://hostmonitor.iohub.cloud |
| Entra app (client) ID | 1b01a4d3-2375-4595-a742-648ed5bcc28f |
| Tenant ID | f8bceab8-4a5d-4fe2-b458-49f88c19fb16 |
| Docker Compose directory | /root |
| Grafana container name | grafana |
| Secret file on host | /root/grafana/secrets/azuread_client_secret.txt |
| Secret file in container | /etc/grafana/secrets/azuread_client_secret.txt |
| Grafana config | /root/grafana/grafana.ini (section [auth.azuread]) |
Grafana reads the secret from the file through this line in grafana.ini, which does not need to change during rotation:
When to do this
Rotate the secret about 30 days before it expires. To check the expiry date, open the Azure portal and go to Microsoft Entra ID → App registrations → (Grafana app) → Certificates & secrets. The Expires column shows the date for each secret.
If the secret has already expired, users will see an error such as AADSTS7000222: The provided client secret keys are expired when signing in with Microsoft. Local Grafana accounts, including the local admin, keep working, so follow the same steps below to restore Microsoft sign-in.
Step 1: Create a new secret in Entra
- In the Azure portal, go to Microsoft Entra ID → App registrations and open the Grafana app (client ID
1b01a4d3-2375-4595-a742-648ed5bcc28f). - Open Certificates & secrets → Client secrets → New client secret.
- Enter a description that includes the date, for example
grafana-2026-10, and choose an expiry (12 or 24 months). - Click Add, then immediately copy the Value column.
The value is shown only once. Copy the Value, not the Secret ID; using the Secret ID is the most common mistake and results in error AADSTS7000215: Invalid client secret provided.
Do not delete the old secret yet.
Step 2: Update the secret file on hostmonitor
Log in to hostmonitor as root and back up the current secret:
cp /root/grafana/secrets/azuread_client_secret.txt /root/grafana/secrets/azuread_client_secret.txt.old
Write the new value to the file. Use printf so that no trailing newline is added:
To keep the secret out of your shell history, either start the command with a space (if your shell ignores such commands) or paste the value into the file with an editor such as nano and make sure there is no empty line at the end.
Set ownership and permissions so the Grafana container (which runs as UID 472) can read the file:
chown 472:472 /root/grafana/secrets/azuread_client_secret.txt
chmod 400 /root/grafana/secrets/azuread_client_secret.txt
Step 3: Recreate the Grafana container
Grafana reads the secret only at startup. Recreate the container (a plain restart may not pick up file changes in bind mounts):
Confirm the container sees the new file. The command prints the number of characters, so it doesn't show the secret itself:
The number should match the length of the new secret (Entra secrets are usually 40 characters).
Step 4: Verify sign-in
- Open a private or incognito browser window.
- Go to
https://hostmonitor.iohub.cloudand click Sign in with Microsoft. - Confirm you land on the Grafana home page, logged in with your Microsoft account.
If sign-in fails, check the logs:
docker compose logs --since 5m grafana 2>&1 | grep -iE "azuread|oauth|authn" | grep -iE "error|fail"
Step 5: Remove the old secret in Entra
Once sign-in works with the new secret, go back to Certificates & secrets in the Entra app and delete the old secret. This ensures only the current secret can be used.
Then remove the backup file on hostmonitor:
Step 6: Set a reminder
Add a calendar reminder for about 30 days before the new secret's expiry date, so the next rotation happens before sign-in breaks.
Rollback
If the new secret does not work and the old secret has not expired or been deleted, restore the old one:
cp /root/grafana/secrets/azuread_client_secret.txt.old /root/grafana/secrets/azuread_client_secret.txt
chown 472:472 /root/grafana/secrets/azuread_client_secret.txt
chmod 400 /root/grafana/secrets/azuread_client_secret.txt
cd /root && docker compose up -d --force-recreate grafana
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
AADSTS7000215: Invalid client secret provided |
The Secret ID was copied instead of the Value, or the value was pasted incorrectly | Create a new secret in Entra and copy the Value column |
AADSTS7000222: The provided client secret keys are expired |
Grafana is still using the old, expired secret | Check the file content length (Step 3) and recreate the container |
permission denied reading the secret file in the logs |
File is not readable by UID 472 | Run the chown and chmod commands from Step 2 |
| Secret file is correct, but Grafana still uses the old secret | Azure AD settings were saved in the Grafana UI, which override grafana.ini |
Check Administration → Authentication → Azure AD in Grafana and update the secret there, or reset the UI settings to defaults |
| Microsoft sign-in completely unavailable | Any of the above | Log in with the local Grafana admin account (keep its password in the team password vault) and work through the fixes |