Connect an Azure tenant
Connect Azure in one click where your deployment offers it, or create your own app registration with a read-only role, in the Azure portal or with the Azure CLI, then check its permissions and run a scan.
Valkan reads your Azure subscriptions through an app that can only read. Connect in one click with Valkan's own app, where your deployment offers it, or with an app registration you create. What Valkan scans lists what is read today; Azure scanning is new and limited.
Connect in one click
Not available on Valkan's hosted service yet. Where your deployment offers it:
- On Sources, choose Connect Azure → Grant access, and sign in to Microsoft Entra as a Global Administrator or Privileged Role Administrator. Accept, then sign in once more as the same administrator. If the role is eligible through Privileged Identity Management, activate it first.
- Back on Sources, choose Deploy to Azure and pick a management group. Paste the principalId Sources shows. Deploying takes Owner or User Access Administrator on that group; at the top-level Tenant Root Group, a Global Administrator first turns on Access management for Azure resources in Entra ID properties.
- Valkan checks on its own. Once it can read a subscription, the source connects and its first scan starts.
The template creates ValkanDiscovery Read-Only plus a six-character code from the management group, so a role left from an earlier setup never blocks it. Azure allows no custom role with data permissions at a management group, so it also assigns Microsoft's built-in Defender CSPM role, which reads Foundry agents (agents/read) and allows assets/read, which Valkan does not use. Microsoft maintains that role. agents/read also allows reading agents' threads and messages; Valkan only lists agents (Two grants that allow more than Valkan reads). One-click covers a whole management group and stores no secret of yours. The consent in step 1 also grants Microsoft Graph Directory.Read.All, so people, groups and apps show by name.
| If Sources says | Do this |
|---|---|
| The consent was declined, or the link expired or was used | Choose Grant access again, in the browser you finish in. A link works once, for 15 minutes. |
| You signed in to a different directory | Sign in, after consent, to the directory that granted it. |
| The account is not an administrator who can grant consent | Use a Global Administrator or Privileged Role Administrator, both times. Application administrators, members and guests are refused. |
| Entra did not say which directory roles you hold | Your Valkan deployment's app is not set up for one-click. Ask its operator, or use your own app registration. |
| The directory is already connected, here or in another workspace | Remove that source first, or use your own app registration. |
| Entra could not be reached to check an older Azure source | Try again in a few minutes. If it keeps failing, disconnect that source, then choose Grant access again. |
Connect with your own app registration
You create the app in your tenant and give it the read-only role. You need to:
- register an app in Entra ID and give it a certificate;
- create a custom role and assign it at a management group: Owner or User Access Administrator on that group (at the Tenant Root Group, a Global Administrator first turns on Access management for Azure resources in Entra ID properties), or on a single subscription (One subscription only);
- grant admin consent for Graph: Global Administrator or Privileged Role Administrator.
Create the app registration
- Register a single-tenant app, and copy its Tenant ID and Application (client) ID.
- Upload a certificate, valid for 3 years.
- Create the ValkanDiscovery Read-Only role at a management group, and assign it and Defender CSPM to the app there.
- Grant Graph Directory.Read.All and admin consent, so principals show names instead of ids.
- Enter the Tenant ID, Client ID and the certificate, choose Test connection, then Connect.
The read-only role
ValkanDiscovery Read-Only lists only read actions and one compliance query that changes nothing. It cannot list keys, connection strings, secrets, app-setting values or deploy credentials, so it cannot read what is stored in your databases, storage accounts or Key Vaults.
Valkan reads at a management group, so it sees every subscription under it, including new ones. Step 3 of each route downloads the role and fills in your management group's ID (the Tenant Root Group's ID is your tenant ID): the portal reads azure-readonly-role-mg.json, and az reads the same role in its own format, azure-readonly-role-mg.cli.json. Azure allows no custom role with data permissions at a management group, so this role has none; the built-in Defender CSPM role, assigned beside it, lets Valkan list Foundry agents (agents/read, and assets/read, which Valkan does not use). Two grants allow more than Valkan reads: Two grants that allow more than Valkan reads.
The role (valkan-role.json)
{
"properties": {
"roleName": "ValkanDiscovery Read-Only",
"description": "Read-only role for Valkan Discovery Azure enumeration (ARM plane). Explicit read actions, one compliance query (Microsoft.PolicyInsights/policyStates/queryResults/action); it carries no data action (Azure refuses one at a management group): the built-in Defender CSPM role, assigned beside it, lists Foundry agents; no write, delete, key, secret, setting-value or credential-listing action.",
"type": "CustomRole",
"isCustom": true,
"permissions": [
{
"actions": [
"Microsoft.Resources/subscriptions/read",
"Microsoft.Resources/subscriptions/resourceGroups/read",
"Microsoft.Management/managementGroups/read",
"Microsoft.Management/managementGroups/descendants/read",
"Microsoft.Management/managementGroups/subscriptions/read",
"Microsoft.ResourceGraph/resources/read",
"Microsoft.Authorization/permissions/read",
"Microsoft.Authorization/roleAssignments/read",
"Microsoft.Authorization/roleDefinitions/read",
"Microsoft.Authorization/roleEligibilitySchedules/read",
"Microsoft.Authorization/roleEligibilityScheduleInstances/read",
"Microsoft.Authorization/roleAssignmentScheduleInstances/read",
"Microsoft.Authorization/denyAssignments/read",
"Microsoft.ManagedIdentity/userAssignedIdentities/read",
"Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/read",
"Microsoft.CognitiveServices/accounts/read",
"Microsoft.CognitiveServices/accounts/deployments/read",
"Microsoft.CognitiveServices/accounts/raiPolicies/read",
"Microsoft.CognitiveServices/accounts/projects/read",
"Microsoft.CognitiveServices/accounts/connections/read",
"Microsoft.CognitiveServices/accounts/projects/connections/read",
"Microsoft.MachineLearningServices/workspaces/read",
"Microsoft.MachineLearningServices/workspaces/connections/read",
"Microsoft.MachineLearningServices/workspaces/computes/read",
"Microsoft.MachineLearningServices/workspaces/onlineEndpoints/read",
"Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments/read",
"Microsoft.MachineLearningServices/workspaces/serverlessEndpoints/read",
"Microsoft.Insights/metricDefinitions/read",
"Microsoft.Insights/metrics/read",
"Microsoft.Insights/eventtypes/values/read",
"Microsoft.Insights/diagnosticSettings/read",
"Microsoft.Insights/logProfiles/read",
"Microsoft.OperationalInsights/workspaces/read",
"Microsoft.OperationalInsights/workspaces/query/read",
"Microsoft.OperationalInsights/workspaces/query/DNSQueryLogs/read",
"Microsoft.OperationalInsights/workspaces/query/AZFWDnsQuery/read",
"Microsoft.OperationalInsights/workspaces/query/AzureDiagnostics/read",
"Microsoft.OperationalInsights/workspaces/query/AGWAccessLogs/read",
"Microsoft.OperationalInsights/workspaces/query/AGWFirewallLogs/read",
"Microsoft.Search/searchServices/read",
"Microsoft.Logic/workflows/read",
"Microsoft.Web/sites/read",
"Microsoft.Web/sites/config/read",
"Microsoft.Web/sites/functions/read",
"Microsoft.Web/serverfarms/read",
"Microsoft.App/containerApps/read",
"Microsoft.App/containerApps/revisions/read",
"Microsoft.App/managedEnvironments/read",
"Microsoft.ContainerInstance/containerGroups/read",
"Microsoft.Batch/batchAccounts/read",
"Microsoft.Batch/batchAccounts/pools/read",
"Microsoft.Automation/automationAccounts/read",
"Microsoft.Automation/automationAccounts/runbooks/read",
"Microsoft.Compute/virtualMachines/read",
"Microsoft.Compute/virtualMachines/extensions/read",
"Microsoft.Compute/virtualMachineScaleSets/read",
"Microsoft.Compute/virtualMachineScaleSets/virtualMachines/read",
"Microsoft.Network/networkInterfaces/read",
"Microsoft.ContainerService/managedClusters/read",
"Microsoft.ContainerService/managedClusters/agentPools/read",
"Microsoft.Sql/servers/read",
"Microsoft.Sql/servers/databases/read",
"Microsoft.Sql/servers/firewallRules/read",
"Microsoft.Sql/servers/administrators/read",
"Microsoft.Sql/servers/azureADOnlyAuthentications/read",
"Microsoft.DBforPostgreSQL/flexibleServers/read",
"Microsoft.DBforPostgreSQL/flexibleServers/firewallRules/read",
"Microsoft.DBforPostgreSQL/flexibleServers/administrators/read",
"Microsoft.DBforMySQL/flexibleServers/read",
"Microsoft.DBforMySQL/flexibleServers/firewallRules/read",
"Microsoft.DBforMySQL/flexibleServers/administrators/read",
"Microsoft.DocumentDB/databaseAccounts/read",
"Microsoft.Storage/storageAccounts/read",
"Microsoft.Storage/storageAccounts/blobServices/read",
"Microsoft.Storage/storageAccounts/blobServices/containers/read",
"Microsoft.KeyVault/vaults/read",
"Microsoft.KeyVault/vaults/keys/read",
"Microsoft.KeyVault/vaults/secrets/read",
"Microsoft.ServiceBus/namespaces/read",
"Microsoft.EventHub/namespaces/read",
"Microsoft.Network/networkSecurityGroups/read",
"Microsoft.Network/networkSecurityGroups/securityRules/read",
"Microsoft.Network/publicIPAddresses/read",
"Microsoft.Network/loadBalancers/read",
"Microsoft.Network/virtualNetworks/read",
"Microsoft.Network/dnszones/read",
"Microsoft.Network/privateDnsZones/read",
"Microsoft.Network/dnsResolvers/read",
"Microsoft.Network/azureFirewalls/read",
"Microsoft.Network/firewallPolicies/read",
"Microsoft.Network/privateDnsZones/virtualNetworkLinks/read",
"Microsoft.Network/dnsResolverPolicies/read",
"Microsoft.Network/dnsResolverPolicies/virtualNetworkLinks/read",
"Microsoft.Network/applicationGateways/read",
"Microsoft.Network/frontdoors/read",
"Microsoft.Cdn/profiles/read",
"Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/read",
"Microsoft.Network/FrontDoorWebApplicationFirewallPolicies/read",
"Microsoft.Authorization/policyAssignments/read",
"Microsoft.Authorization/policyDefinitions/read",
"Microsoft.Authorization/policySetDefinitions/read",
"Microsoft.PolicyInsights/policyStates/queryResults/action",
"Microsoft.Security/pricings/read",
"Microsoft.Security/alerts/read",
"Microsoft.Security/assessments/read",
"Microsoft.Security/locations/alerts/read"
],
"notActions": [],
"dataActions": [],
"notDataActions": []
}
],
"assignableScopes": [
"/providers/Microsoft.Management/managementGroups/<MG_ID>"
]
}
}Two actions to review before you grant them
Microsoft.OperationalInsights/workspaces/query/readruns queries on your Log Analytics workspaces. Valkan uses it only for network and DNS logs and keeps counts, not log lines. Remove it if you do not want that.- A query returns rows only from tables the app may read; others come back empty, with no error. So the role also grants
workspaces/query/<Table>/readforDNSQueryLogs,AZFWDnsQuery,AzureDiagnostics,AGWAccessLogsandAGWFirewallLogs. Front Door's own tables needworkspaces/query/*/read, which reads every table and is not in the role; add it if you want those read. A table Valkan cannot read shows as a permission gap, never as quiet.
Two grants that allow more than Valkan reads
- Foundry agents (
Microsoft.CognitiveServices/accounts/AIServices/agents/read, in the one-subscription role or through Defender CSPM). Microsoft's permission also covers the agents' threads and messages, so the role can read conversations. Valkan only lists agents and never calls the thread or message endpoints. The agent list includes each agent's instructions: Valkan receives them and discards them, and never stores them. AzureDiagnostics(Microsoft.OperationalInsights/workspaces/query/AzureDiagnostics/read). This is a shared table: any resource sending logs in Azure diagnostics mode writes there, including Azure SQL audit and Key Vault audit logs. So the role can query those too. Valkan's queries read only DNS, Application Gateway and Front Door rows, filtered and counted in the workspace. If you remove this action, DNS and gateway logs kept in that table show as not read.
Set up and connect
Pick one route. All three do the same thing.
1. Register the app
- Open Microsoft Entra ID → App registrations → New registration.
- Name it, for example
Valkan Discovery. Choose Single tenant, leave Redirect URI empty, and choose Register. - Copy the Application (client) ID and Directory (tenant) ID from the app's Overview.
2. Add a certificate
The certificate below is valid for 3 years.
Open Cloud Shell (the >_ button at the top of the portal, Bash) and run:
openssl req -x509 -newkey rsa:2048 -nodes -days 1095 -subj "/CN=valkan" -keyout key.pem -out cert.pem
cat key.pem cert.pem > valkan.pem- Download
cert.pemandvalkan.pem(Manage files → Download). - In your app, Certificates & secrets → Certificates → Upload certificate, and upload
cert.pem.
Keep valkan.pem, the private key and certificate, until step 5: you give it to Valkan there, then delete it.
3. Create the role and assign it
- Download azure-readonly-role-mg.json. Open it in a text editor, replace
<MG_ID>with your management group's ID (for the Tenant Root Group, your tenant ID), and save it asvalkan-role.json. - Open Management groups, then that group. Access control (IAM) → Add → Add custom role → Start from JSON, select
valkan-role.json, then Review + create → Create. - Access control (IAM) → Add → Add role assignment: pick ValkanDiscovery Read-Only, then under Members select your app, and choose Review + assign.
- Do the same for the built-in Defender CSPM role.
4. Grant Graph consent
In your app, API permissions → Add a permission → Microsoft Graph → Application permissions → Directory.Read.All → Add permissions → Grant admin consent. It lets Valkan name the people, groups and apps it finds; without it they show by id.
5. Connect in Valkan
Sources → Connect Azure → Use my own app registration. Choose Certificate, enter the Tenant ID and Client ID, and paste or upload valkan.pem. Choose Test connection, then Connect. A new role assignment can take a few minutes to show.
6. Delete the private key
Valkan now holds the only copy it needs, encrypted. The .pem file can sign in as your app, so delete every copy you made: anyone who finds it can read what the role allows until the certificate expires.
In Cloud Shell:
rm key.pem valkan.pemDelete the downloaded valkan.pem from your computer too. Keep cert.pem if you like: it holds no private key.
Run these in Azure Cloud Shell (Bash), or in a bash terminal after az login, in one session. Every step is safe to run again in that session. They need Azure CLI 2.37 or later (az version).
1. Register the app
The app's name ends in a few random characters, so it cannot collide with an app your tenant already has. Note the name it prints: it is how you find the app later. To use an app you already made, set APP_NAME to its exact name first.
APP_NAME=${APP_NAME:-"Valkan Discovery $(openssl rand -hex 3)"}
APP_ID=$(az ad app create --display-name "$APP_NAME" --sign-in-audience AzureADMyOrg --query appId -o tsv)
APP_SP=$([ -n "$APP_ID" ] && az ad sp list --filter "appId eq '$APP_ID'" --query "[0].id" -o tsv)
[ -z "$APP_ID" ] || [ -n "$APP_SP" ] || APP_SP=$(az ad sp create --id "$APP_ID" --query id -o tsv)
if [ -n "$APP_SP" ]; then
echo "App: $APP_NAME Tenant ID: $(az account show --query tenantId -o tsv) Client ID: $APP_ID"
else
echo "Step 1 did not finish: fix the error above, then run it again." >&2
fi2. Add a certificate
az creates a certificate valid for 3 years, adds it to the app, and prints the path of a .pem file holding the private key and the certificate. You give that file to Valkan, then delete it.
az ad app credential reset --id "$APP_ID" --append --create-cert --years 3 --query fileWithCertAndPrivateKey -o tsv3. Create the role and assign it
This moves to your temporary folder, downloads the role there, fills in the management group, and creates the role or, if your tenant already has it, updates it. MG_ID here is the Tenant Root Group; set another management group's ID to use that one. If step 1 did not finish or the role is refused, it stops there and assigns nothing.
MG_ID=$(az account show --query tenantId -o tsv)
SCOPE="/providers/Microsoft.Management/managementGroups/$MG_ID"
cd "${TMPDIR:-/tmp}"
curl -fsSL https://docs.valkan.ai/integration/downloads/azure-readonly-role-mg.cli.json | sed "s|<MG_ID>|$MG_ID|" > valkan-role.json
if [ -z "$APP_SP" ] || [ -z "$MG_ID" ]; then
echo "No role was created or assigned: run step 1 again first, after az login." >&2
else
EXISTING=$(az role definition list --name "ValkanDiscovery Read-Only" --scope "$SCOPE" --query "[0].name" -o tsv)
if [ -n "$EXISTING" ]; then VERB=update; else VERB=create; fi
if az role definition $VERB --role-definition @valkan-role.json; then
for ROLE in "ValkanDiscovery Read-Only" "Defender CSPM"; do
az role assignment create --assignee-object-id "$APP_SP" \
--assignee-principal-type ServicePrincipal --role "$ROLE" --scope "$SCOPE"
done
else
echo "The role was not saved, so nothing was assigned: fix the error above, then run step 3 again." >&2
fi
fi4. Grant Graph consent
Run this as a Global Administrator or Privileged Role Administrator. az warns that az ad app permission grant is needed: ignore it, the second command grants the permission.
az ad app permission add --id "$APP_ID" --api 00000003-0000-0000-c000-000000000000 \
--api-permissions 7ab1d382-f21e-4acd-a863-ba3e13f7da61=Role
az ad app permission admin-consent --id "$APP_ID"The ids are Microsoft Graph and its Directory.Read.All application permission. It lets Valkan name the people, groups and apps it finds; without it they show by id.
5. Connect in Valkan
Sources → Connect Azure → Use my own app registration. Choose Certificate, enter the Tenant ID and Client ID, and upload the .pem file from step 2. Choose Test connection, then Connect. A new role assignment can take a few minutes to show.
6. Delete the private key
Valkan now holds the only copy it needs, encrypted. The .pem file can sign in as your app, so delete every copy you made: anyone who finds it can read what the role allows until the certificate expires.
rm "<path printed in step 2>"Run these in PowerShell after az login, in one session. Every step is safe to run again in that session. They need Azure CLI 2.37 or later (az version).
1. Register the app
The app's name ends in a few random characters, so it cannot collide with an app your tenant already has. Note the name it prints: it is how you find the app later. To use an app you already made, set $APP_NAME to its exact name first.
if (-not $APP_NAME) { $APP_NAME = "Valkan Discovery " + (New-Guid).ToString().Substring(0, 6) }
$APP_ID = az ad app create --display-name $APP_NAME --sign-in-audience AzureADMyOrg --query appId -o tsv
$APP_SP = if ($APP_ID) { az ad sp list --filter "appId eq '$APP_ID'" --query "[0].id" -o tsv }
if ($APP_ID -and -not $APP_SP) { $APP_SP = az ad sp create --id $APP_ID --query id -o tsv }
if ($APP_SP) {
"App: $APP_NAME Tenant ID: $(az account show --query tenantId -o tsv) Client ID: $APP_ID"
} else { Write-Error "Step 1 did not finish: fix the error above, then run it again." }2. Add a certificate
az creates a certificate valid for 3 years, adds it to the app, and prints the path of a .pem file holding the private key and the certificate. You give that file to Valkan, then delete it.
az ad app credential reset --id $APP_ID --append --create-cert --years 3 --query fileWithCertAndPrivateKey -o tsv3. Create the role and assign it
This moves to your temporary folder (an administrator PowerShell starts in C:\Windows\System32, where the download is refused), downloads the role there, fills in the management group, and creates the role or, if your tenant already has it, updates it. $MG_ID here is the Tenant Root Group; set another management group's ID to use that one. In PowerShell the @ needs quotes. If step 1 did not finish or the role is refused, it stops there and assigns nothing.
$MG_ID = az account show --query tenantId -o tsv
$SCOPE = "/providers/Microsoft.Management/managementGroups/$MG_ID"
Set-Location $env:TEMP
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072 # TLS 1.2
Invoke-WebRequest -UseBasicParsing https://docs.valkan.ai/integration/downloads/azure-readonly-role-mg.cli.json -OutFile valkan-role.json
if (-not ($APP_SP -and $MG_ID)) { Write-Error "No role was created or assigned: run step 1 again first, after az login." } else {
(Get-Content valkan-role.json -Raw) -replace '<MG_ID>', $MG_ID | Set-Content -Encoding ascii valkan-role.json
$EXISTING = az role definition list --name "ValkanDiscovery Read-Only" --scope $SCOPE --query "[0].name" -o tsv
$VERB = if ($EXISTING) { "update" } else { "create" }
az role definition $VERB --role-definition "@valkan-role.json"
if ($LASTEXITCODE -ne 0) {
Write-Error "The role was not saved, so nothing was assigned: fix the error above, then run step 3 again."
} else {
foreach ($ROLE in "ValkanDiscovery Read-Only", "Defender CSPM") {
az role assignment create --assignee-object-id $APP_SP --assignee-principal-type ServicePrincipal `
--role $ROLE --scope $SCOPE
}
}
}4. Grant Graph consent
Run this as a Global Administrator or Privileged Role Administrator. az warns that az ad app permission grant is needed: ignore it, the second command grants the permission.
az ad app permission add --id $APP_ID --api 00000003-0000-0000-c000-000000000000 `
--api-permissions 7ab1d382-f21e-4acd-a863-ba3e13f7da61=Role
az ad app permission admin-consent --id $APP_IDThe ids are Microsoft Graph and its Directory.Read.All application permission. It lets Valkan name the people, groups and apps it finds; without it they show by id.
5. Connect in Valkan
Sources → Connect Azure → Use my own app registration. Choose Certificate, enter the Tenant ID and Client ID, and upload the .pem file from step 2. Choose Test connection, then Connect. A new role assignment can take a few minutes to show.
6. Delete the private key
Valkan now holds the only copy it needs, encrypted. The .pem file can sign in as your app, so delete every copy you made: anyone who finds it can read what the role allows until the certificate expires.
Remove-Item "<path printed in step 2>"Valkan stores the certificate encrypted and never shows it again. It scans every subscription under the management group; to skip one, untick it on the source's Subscriptions card.
One subscription only
If you can grant access on one subscription but on no management group, create the role on that subscription instead. Follow your route as written, except step 3: run this in its place, in the same session as step 1, as an Owner or User Access Administrator of the subscription. On a subscription the role keeps its permission to list Foundry agents, so it needs no Defender CSPM beside it.
SUB_ID here is the subscription az is signed in to; set another subscription's ID to use that one. Like step 3, it is safe to run again, and it stops without assigning anything if step 1 did not finish or the role is refused.
SUB_ID=${SUB_ID:-$(az account show --query id -o tsv)}
SCOPE="/subscriptions/$SUB_ID"
cd "${TMPDIR:-/tmp}"
curl -fsSL https://docs.valkan.ai/integration/downloads/azure-readonly-role-sub.cli.json | sed "s|<SUBSCRIPTION_ID>|$SUB_ID|" > valkan-role.json
HAS=$(az role definition list --name "ValkanDiscovery Read-Only" --scope "$SCOPE" --query "[0].assignableScopes[0]" -o tsv)
if [ -z "$APP_SP" ] || [ -z "$SUB_ID" ]; then
echo "No role was created or assigned: run step 1 again first, after az login." >&2
elif [ -n "$HAS" ] && [ "$HAS" != "$SCOPE" ]; then
echo "A role of this name already exists at $HAS, so nothing was changed: see below." >&2
else
if [ -n "$HAS" ]; then VERB=update; else VERB=create; fi
if az role definition $VERB --role-definition @valkan-role.json; then
az role assignment create --assignee-object-id "$APP_SP" --assignee-principal-type ServicePrincipal --role "ValkanDiscovery Read-Only" --scope "$SCOPE"
else
echo "The role was not saved, so nothing was assigned: fix the error above, then run this again." >&2
fi
fiif (-not $SUB_ID) { $SUB_ID = az account show --query id -o tsv }
$SCOPE = "/subscriptions/$SUB_ID"
Set-Location $env:TEMP
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072 # TLS 1.2
Invoke-WebRequest -UseBasicParsing https://docs.valkan.ai/integration/downloads/azure-readonly-role-sub.cli.json -OutFile valkan-role.json
(Get-Content valkan-role.json -Raw) -replace '<SUBSCRIPTION_ID>', $SUB_ID | Set-Content -Encoding ascii valkan-role.json
$HAS = az role definition list --name "ValkanDiscovery Read-Only" --scope $SCOPE --query "[0].assignableScopes[0]" -o tsv
if (-not ($APP_SP -and $SUB_ID)) {
Write-Error "No role was created or assigned: run step 1 again first, after az login."
} elseif ($HAS -and $HAS -ne $SCOPE) {
Write-Error "A role of this name already exists at $HAS, so nothing was changed: see below."
} else {
$VERB = if ($HAS) { "update" } else { "create" }
az role definition $VERB --role-definition "@valkan-role.json"
if ($LASTEXITCODE -ne 0) {
Write-Error "The role was not saved, so nothing was assigned: fix the error above, then run this again."
} else {
az role assignment create --assignee-object-id $APP_SP --assignee-principal-type ServicePrincipal `
--role "ValkanDiscovery Read-Only" --scope $SCOPE
}
}Valkan then reads that subscription only. If a role of that name already exists at another scope (a management group, or another subscription, from an earlier setup), Azure allows no second one and these commands leave it as it is: assign the existing role instead, after adding /subscriptions/<subscription ID> to its assignable scopes.
On a self-hosted install, your operator may offer Workload identity instead of a certificate: pick it in the Connect form, and add the Issuer, Subject and Audience it shows to your app under Certificates & secrets → Federated credentials → Add credential → Other issuer, exactly.
Disconnect
Removing the source in Valkan deletes what Valkan stored for it. It cannot change your tenant: remove Valkan's access there too, after removing the source. Remove role assignments before deleting the role, because Azure refuses to delete an assigned role.
Disconnect one-click
- Remove Valkan's role assignments under Access control (IAM) → Role assignments where you deployed: at a management group there are two, the ValkanDiscovery role and Defender CSPM. Or run
az role assignment list --scope <SCOPE> --assignee <VALKAN_APP_ID> -o table, thenaz role assignment delete --ids <ASSIGNMENT_ID>. - Delete the role: Access control (IAM) → Roles, search ValkanDiscovery, Delete. Or run
az role definition delete --name "<ROLE_NAME>" --scope <SCOPE>. - Delete Valkan's app under Microsoft Entra ID → Enterprise applications → Properties → Delete, or run
az ad sp delete --id <VALKAN_APP_ID>. This withdraws your consent.
Disconnect your own app
- Remove the app's role assignments: two at a management group (ValkanDiscovery and Defender CSPM), or one on a subscription. Then delete the role if nothing else uses it, as above.
- Delete the secret or certificate under Certificates & secrets (or
az ad app credential delete --id <APP_ID> --key-id <KEY_ID>), or the whole app registration if it was only for Valkan. An app made with the CLI steps is namedValkan Discoveryand a few random characters; delete any others of that name left by a setup you did not finish.
Disconnect workload identity
- Remove the role assignment and, if unused, the role.
- Delete the federated credential under Certificates & secrets → Federated credentials (or
az ad app federated-credential delete --id <APP_ID> --federated-credential-id <CREDENTIAL_ID>), then the app if it was only for Valkan.
If a setup command fails
The CLI steps are safe to run again in the same session: fix the cause, then repeat the step that failed.
- The service principal name is already in use: the app already had a service principal. Run step 1 as written here: it reuses one that exists.
- Access to the path is denied on the role download: the terminal is in a folder you cannot write to. Run step 3 as written here: it moves to your temporary folder first.
- A role of that name already exists: an earlier setup created it at another scope. Assign that role instead, after adding your scope to its assignable scopes.
- The role or the principal is not found when assigning: Azure has not finished creating it. Wait a minute and run step 3 again.
- Authorization failed creating the role: you need the access listed under Connect with your own app registration. If you have just turned on Access management for Azure resources, run
az logoutandaz loginbefore step 3. - Insufficient privileges granting consent: step 4 needs a Global Administrator or Privileged Role Administrator. Another administrator can run it, or grant it in the portal under the app's API permissions.
- Sign-in failed in Valkan after a second run of step 1: a certificate belongs to the app it was added to. Enter the Client ID that step 1 printed last, and the
.pemfile from the step 2 you ran after it.
If connecting fails
- Sign-in failed: the Tenant ID, Client ID or secret is wrong, or the secret expired.
- Already connected: the tenant is already a source; use Replace credentials.
- Certificate rejected: the PEM needs the private key and the certificate, and the password if encrypted.
- No subscriptions found: the app has no role yet. Assign it, wait a few minutes, test again.
- Actions missing: the role came from an older file. Apply the current one.
- Principals show as ids: Graph consent is not granted.
- Azure Government and Azure China are not supported.
App-setting names (optional)
Optional, once the source is connected: Valkan can show which App Service and Function apps call an AI service, from their app-setting names. It needs a second app registration, and the source's App-setting detection card takes you through it.
Why it needs a second app, and the steps
An app setting's name shows whether an App Service or Function App calls an AI service (AZURE_OPENAI_ENDPOINT, say). Azure only exposes names through an action that also returns setting values, connection strings and deploy credentials, and deploy credentials can change an app. So the app Valkan scans with never holds it: it is in a second role, ValkanDiscovery App Settings (opt-in), which you assign to a second app registration with its own credential. Valkan uses that app only to list app settings, keeps the names and discards every value on arrival. If the second app's credential leaked, it could read setting values and deploy to your App Service apps, but read nothing else; the scan app's credential cannot deploy.
Without it, the apps are still listed, and each subscription shows a permission gap for app-setting names. To add it, open the Azure source under Sources; the App-setting detection card takes you through it:
- In Microsoft Entra ID → App registrations → New registration, create an app for app-setting names only (any name, single tenant, no redirect URI), and give it a client secret or a certificate under Certificates & secrets. Do not reuse the app Valkan scans with: Valkan refuses it.
- On the card, enter the new app's Application (client) ID and its secret or certificate. Valkan signs in with it to your tenant before storing it, encrypted; it is never shown again.
- Choose Enable app-setting detection: it deploys the opt-in role at a management group. Paste the appSettingsPrincipalId the card shows (the new app's service principal, never the scan app's), then Check again.
The template cannot tell whose principal id you paste. If it is the scan app's, the role lands on the app Valkan scans with, and the permission check (Check again, or Test connection) warns that the scan credential holds Microsoft.Web/sites/config/list/action, which also returns deploy credentials. If you see that warning, delete that role assignment from the scan app's service principal and assign the role to the second app instead. Before deploying, check that the appSettingsPrincipalId is the object id Entra shows for the second app under Enterprise applications.
By hand, create azure-app-settings-role.json at the same management group and assign it to the new app's service principal, as in step 3, or run azure-onboard.sh with --app-settings-app-id <new app id>. To stop, choose Remove on the card and delete the role assignment or the second app.
Replace credentials
Replace the certificate before it expires (it lasts 3 years), at once if its private key may have been seen by anyone else, or to move a source off a client secret. Create a new certificate as in your route's step 2, add it to the app under Certificates & secrets, then choose Replace credentials on the source under Sources. Valkan signs in with it before saving, and the source keeps its scans, findings and history.
What must stay the same, and what to delete afterwards
- The Tenant ID must stay the same; another tenant is a new source.
- Keep the Client ID to keep the same app; a different app in the same tenant needs the same role first.
- You can switch between a secret and a certificate.
- Once the new one is saved, delete the old certificate or secret from the app in Azure, and delete the new private key file from your computer.
A one-click source has no credential of yours, so it has no Replace credentials.