Skip to content

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:

client_secret = $__file{/etc/grafana/secrets/azuread_client_secret.txt}

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

  1. In the Azure portal, go to Microsoft Entra ID → App registrations and open the Grafana app (client ID 1b01a4d3-2375-4595-a742-648ed5bcc28f).
  2. Open Certificates & secrets → Client secrets → New client secret.
  3. Enter a description that includes the date, for example grafana-2026-10, and choose an expiry (12 or 24 months).
  4. 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:

printf '%s' 'PASTE-NEW-SECRET-VALUE-HERE' > /root/grafana/secrets/azuread_client_secret.txt

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):

cd /root
docker compose up -d --force-recreate grafana

Confirm the container sees the new file. The command prints the number of characters, so it doesn't show the secret itself:

docker exec grafana sh -c 'wc -c < /etc/grafana/secrets/azuread_client_secret.txt'

The number should match the length of the new secret (Entra secrets are usually 40 characters).

Step 4: Verify sign-in

  1. Open a private or incognito browser window.
  2. Go to https://hostmonitor.iohub.cloud and click Sign in with Microsoft.
  3. 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:

rm /root/grafana/secrets/azuread_client_secret.txt.old

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