Set up on AWS

Install DebugLogManager

Before you start

  1. The tools account is a StackSets delegated admin.
  2. A subnet in it with outbound internet.
  3. A certificate for debuglogmanager.<your-domain>, from your company's CA.
  4. A subscription on AWS Marketplace, from the tools account (coming soon: the listing is on its way).

Complete these 4 steps

1EntraYour Entra admin · Azure Cloud Shell
URL for DebugLogManager:https://debuglogmanager.

Give each DebugLogManager role to your Entra groups. Use the groups you have. Any that don't exist are created for you, empty: add people to them in Entra afterwards. People get their role through the group they're in.

Role in DebugLogManagerWhat they can doEntra groups given this role
AdminEverything: allowed sources, OU settings, the certificate
+ add
OperatorTurn logging on and off, search and share
+ add
OperatorElevatedTemporary access in production, for example through PIM
+ add
UserYour engineers or developers: read the logs shared with them
+ add
Paste into Azure Cloud Shell (PowerShell):
It shows which groups it found and which it will create, and asks before creating any. Then it creates the app, gives each group its role, and prints a metadata URL for step 2.
Show the script
<#
.SYNOPSIS
Creates the DebugLogManager SAML app in Microsoft Entra ID and prints the
metadata URL the install stack needs.

.DESCRIPTION
Run in Azure Cloud Shell (PowerShell), or anywhere with PowerShell 7 and the
Azure CLI, signed in (az login) as an Application Administrator, Cloud
Application Administrator or Global Administrator of your tenant.

It creates an enterprise application (non-gallery, SAML) that:
  - uses https://<Hostname>/saml as its Identifier and
    https://<Hostname>/saml/acs as its Reply URL;
  - has four app roles (DebugLogManager's own roles, not Entra directory
    roles): Admin, Operator, OperatorElevated and User, each given to the
    Entra groups you name;
  - requires assignment, so only those groups can sign in;
  - sends the groups assigned to the app in the SAML assertion (display names
    for cloud groups), which DebugLogManager uses for sharing;
  - signs with a new 3-year certificate, and emails NotifyEmail (default: you)
    before it expires.

Use the groups you have, from AD or Entra. Any that don't exist are created
as empty Entra cloud groups, after you confirm (or straight away with -Yes):
add people to them afterwards. If it creates an Admin group it adds you to it;
if your Admin groups already exist and you're in none of them, it says so.
Groups are given the role directly: members of groups nested inside them
don't get in (Entra doesn't pass app access through nesting). Everything is
checked before anything is changed.

The user's UPN is sent as the NameID (Entra's default); DebugLogManager
records it in its audit.

Running it again updates the same app: it adds what is missing and changes
nothing else.

Assigning groups to an app needs Entra ID P1 or P2. For elevation with
Privileged Identity Management (P2), the OperatorElevated group must be a
cloud group.

.EXAMPLE
./New-DlmEntraApp.ps1 -Hostname debuglogmanager.client.com -AdminGroups 'Cloud Admins' `
  -OperatorGroups 'Platform Team' -ElevatedGroups 'Prod Elevated' -UserGroups 'payments-team','data-team'
#>
[CmdletBinding()]
param(
    [Parameter(Mandatory)] [ValidatePattern('^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$')]
    [string] $Hostname,
    [Parameter(Mandatory)] [string[]] $AdminGroups,
    [Parameter(Mandatory)] [string[]] $OperatorGroups,
    [Parameter(Mandatory)] [string[]] $ElevatedGroups,
    [Parameter(Mandatory)] [string[]] $UserGroups,
    [switch] $Yes,
    [string] $NotifyEmail = "",
    [string] $DisplayName = "DebugLogManager"
)

$ErrorActionPreference = "Stop"
$graph = "https://graph.microsoft.com/v1.0"
# Entra's "non-gallery application" template: what the portal uses for "Create
# your own application"
$nonGalleryTemplate = "8adf8e6e-67b2-4cf2-a259-e3dc5476c621"

function Invoke-Graph([string] $Method, [string] $Path, $Body = $null) {
    $azArgs = @("rest", "--method", $Method, "--url", "$graph$Path", "--headers", "Content-Type=application/json", "--output", "json")
    $file = $null
    if ($null -ne $Body) {
        # through a file: no quoting problems in any shell
        $file = New-TemporaryFile
        $Body | ConvertTo-Json -Depth 10 -Compress | Set-Content -Path $file -Encoding utf8NoBOM
        $azArgs += @("--body", "@$file")
    }
    try {
        $out = & az @azArgs
        if ($LASTEXITCODE -ne 0) { throw "Graph $Method $Path failed" }
        if ($out) { return ($out | Out-String | ConvertFrom-Json) }
    } finally {
        if ($file) { Remove-Item $file -ErrorAction SilentlyContinue }
    }
}

# A group by name (or id): $null if there's none. Two with the same name is
# an error: say which.
function Find-Group([string] $Group) {
    if ($Group -match '^[0-9a-fA-F-]{36}$') { return Invoke-Graph GET "/groups/$Group`?`$select=id,displayName,onPremisesSyncEnabled" }
    $f = [uri]::EscapeDataString("displayName eq '$($Group.Replace("'", "''"))'")
    $found = @((Invoke-Graph GET "/groups?`$filter=$f&`$select=id,displayName,onPremisesSyncEnabled").value)
    if ($found.Count -gt 1) { throw "There are $($found.Count) groups called '$Group': use its object id instead." }
    if ($found.Count -eq 1) { return $found[0] }
    return $null
}
function Where-From($g) { if ($g.onPremisesSyncEnabled) { "from AD" } else { "Entra cloud group" } }

$tenant = (az account show --query tenantId --output tsv)
if ($LASTEXITCODE -ne 0 -or -not $tenant) { throw "Not signed in: run az login first" }
$tenant = $tenant.Trim()
$entityId = "https://$Hostname/saml"
$replyUrl = "https://$Hostname/saml/acs"

# Check the signed-in user's Entra role before anything is made. Roles held
# through a group count (transitiveMemberOf); a PIM role counts only while
# active. Signed in as something other than a user (no /me): warn and go on.
$allowedRoles = @{
    "62e90394-69f5-4237-9190-012177145e10" = "Global Administrator"
    "9b895d92-2cd3-44c7-9d02-a6ac2d5ea5c3" = "Application Administrator"
    "158c047a-c907-4556-b7ef-446551a6b5f7" = "Cloud Application Administrator"
}
$myRoles = $null
try {
    $myRoles = (Invoke-Graph GET "/me/transitiveMemberOf/microsoft.graph.directoryRole?`$select=roleTemplateId,displayName").value
} catch {
    Write-Warning "Couldn't read your Entra roles ($($_.Exception.Message)); carrying on. You need Application Administrator, Cloud Application Administrator or Global Administrator."
}
if ($null -ne $myRoles) {
    $held = @($myRoles | Where-Object { $allowedRoles.ContainsKey($_.roleTemplateId) })
    if ($held.Count -eq 0) {
        throw ("You need one of these Entra roles to create the DebugLogManager app: " +
            "Application Administrator, Cloud Application Administrator or Global Administrator. " +
            "If you're eligible through Privileged Identity Management, activate it and run this again; " +
            "otherwise ask your Entra admin to run this same line. Nothing has been changed.")
    }
    Write-Host "Signed in with: $(($held | ForEach-Object { $allowedRoles[$_.roleTemplateId] }) -join ', ')"
}

$me = Invoke-Graph GET "/me?`$select=id,userPrincipalName,mail"
if (-not $NotifyEmail) { $NotifyEmail = if ($me.mail) { $me.mail } else { $me.userPrincipalName } }

# Check every group before anything is changed.
$want = [ordered]@{ Admin = $AdminGroups; Operator = $OperatorGroups; OperatorElevated = $ElevatedGroups; User = $UserGroups }
$plan = @()   # one row per group: role, name, the group (or $null: to create)
Write-Host "Checking groups..."
foreach ($role in $want.Keys) {
    foreach ($name in $want[$role]) {
        $g = Find-Group $name
        $plan += [pscustomobject]@{ Role = $role; Name = $name; Group = $g }
        $state = if ($g) { "found ($(Where-From $g))" } else { "not found: will be created" }
        Write-Host ("  {0,-24} {1,-34} -> {2}" -f $name, $state, $role)
    }
}
$toCreate = @($plan | Where-Object { -not $_.Group })
if ($toCreate) {
    $names = ($toCreate | ForEach-Object { $_.Name } | Select-Object -Unique) -join ", "
    if (-not $Yes) {
        $answer = Read-Host "Create $names as empty Entra groups? [Y/n]"
        if ($answer -and $answer -notmatch '^(y|yes)$') { throw "Nothing has been changed. Check the group names and run it again." }
    }
}

# ── 0. Create the missing groups (cloud groups, you as owner) ───────────────
$created = @{}
foreach ($row in $toCreate) {
    if ($created.ContainsKey($row.Name)) { $row.Group = $created[$row.Name]; continue }
    $nick = ($row.Name -replace '[^A-Za-z0-9]', '').ToLowerInvariant()
    if (-not $nick) { $nick = "dlmgroup" }
    $body = @{
        displayName = $row.Name; description = "DebugLogManager $($row.Role)"; mailEnabled = $false; mailNickname = $nick; securityEnabled = $true
        "owners@odata.bind" = @("$graph/users/$($me.id)")
    }
    if ($row.Role -eq "Admin") { $body["members@odata.bind"] = @("$graph/users/$($me.id)") }
    $row.Group = Invoke-Graph POST "/groups" $body
    $created[$row.Name] = $row.Group
    if ($row.Role -eq "Admin") { Write-Host "Created $($row.Name) and added you ($($me.userPrincipalName))" }
    else { Write-Host "Created $($row.Name): it's empty, add people to it in Entra (Groups > $($row.Name) > Members)" }
}

# Can you sign in as an admin for the certificate step?
$adminIds = @($plan | Where-Object { $_.Role -eq "Admin" } | ForEach-Object { $_.Group.id })
$mine = @((Invoke-Graph GET "/me/transitiveMemberOf/microsoft.graph.group?`$select=id").value | ForEach-Object { $_.id })
if (-not ($adminIds | Where-Object { $_ -in $mine })) {
    Write-Host "You're not in $($AdminGroups -join ' or '): add yourself, or have someone in it do the certificate step."
}
foreach ($row in $plan | Where-Object { $_.Role -eq "OperatorElevated" -and $_.Group.onPremisesSyncEnabled }) {
    Write-Host "$($row.Name) comes from AD: fine if you add people by hand; elevation with PIM needs a cloud group."
}
$roleGroups = [ordered]@{}
foreach ($role in $want.Keys) { $roleGroups[$role] = @($plan | Where-Object { $_.Role -eq $role } | ForEach-Object { $_.Group.id } | Select-Object -Unique) }

# ── 1. The app and its service principal ─────────────────────────────────────
$filter = [uri]::EscapeDataString("displayName eq '$DisplayName'")
$app = (Invoke-Graph GET "/applications?`$filter=$filter").value | Select-Object -First 1
if (-not $app) {
    Write-Host "Creating enterprise app '$DisplayName'"
    Invoke-Graph POST "/applicationTemplates/$nonGalleryTemplate/instantiate" @{ displayName = $DisplayName } | Out-Null
    for ($i = 0; $i -lt 24 -and -not $app; $i++) {
        Start-Sleep -Seconds 5
        $app = (Invoke-Graph GET "/applications?`$filter=$filter").value | Select-Object -First 1
    }
    if (-not $app) { throw "The new app didn't appear; run the script again in a minute" }
} else {
    Write-Host "Updating existing app '$DisplayName' ($($app.appId))"
}
$spFilter = [uri]::EscapeDataString("appId eq '$($app.appId)'")
$sp = $null
for ($i = 0; $i -lt 24 -and -not $sp; $i++) {
    $sp = (Invoke-Graph GET "/servicePrincipals?`$filter=$spFilter").value | Select-Object -First 1
    if (-not $sp) { Start-Sleep -Seconds 5 }
}
if (-not $sp) { throw "The app's service principal didn't appear; run the script again in a minute" }

# ── 2. SAML URLs, app roles, groups in the assertion ─────────────────────────
$roles = @($app.appRoles)
$descriptions = @{
    Admin            = "Everything: allowed sources, OU settings, turn on and off, share, delete logs early."
    Operator         = "Turn logging on and off, search, download and share, in OUs that don't need elevation."
    OperatorElevated = "As Operator, in every OU including those that need elevation. Make people eligible with PIM where you can."
    User             = "Read the logs shared with them."
}
foreach ($value in @("Admin", "Operator", "OperatorElevated", "User")) {
    if (-not ($roles | Where-Object { $_.value -eq $value })) {
        $roles += [pscustomobject]@{
            id                 = [guid]::NewGuid().ToString()
            allowedMemberTypes = @("User")
            displayName        = "DebugLogManager $value"
            description        = $descriptions[$value]
            value              = $value
            isEnabled          = $true
        }
    }
}
Invoke-Graph PATCH "/applications/$($app.id)" @{
    identifierUris        = @($entityId)
    web                   = @{ redirectUris = @($replyUrl) }
    appRoles              = $roles
    groupMembershipClaims = "ApplicationGroup"
    optionalClaims        = @{
        saml2Token = @(@{ name = "groups"; essential = $false; additionalProperties = @("cloud_displayname") })
    }
} | Out-Null
$app = Invoke-Graph GET "/applications/$($app.id)"

# ── 3. SAML single sign-on, assignment required, expiry notices ──────────────
Invoke-Graph PATCH "/servicePrincipals/$($sp.id)" @{
    preferredSingleSignOnMode  = "saml"
    appRoleAssignmentRequired  = $true
    notificationEmailAddresses = @($NotifyEmail)
} | Out-Null

# ── 4. Signing certificate (only if it has none) ─────────────────────────────
$sp = Invoke-Graph GET "/servicePrincipals/$($sp.id)"
if (-not $sp.preferredTokenSigningKeyThumbprint) {
    $end = (Get-Date).ToUniversalTime().AddYears(3).ToString("yyyy-MM-ddT00:00:00Z")
    $cert = Invoke-Graph POST "/servicePrincipals/$($sp.id)/addTokenSigningCertificate" @{
        displayName = "CN=$DisplayName"; endDateTime = $end
    }
    Invoke-Graph PATCH "/servicePrincipals/$($sp.id)" @{ preferredTokenSigningKeyThumbprint = $cert.thumbprint } | Out-Null
    Write-Host "Signing certificate created, expires $end"
}

# ── 5. Groups to roles ───────────────────────────────────────────────────────
$existing = (Invoke-Graph GET "/servicePrincipals/$($sp.id)/appRoleAssignedTo").value
foreach ($value in $roleGroups.Keys) {
    $roleId = ($app.appRoles | Where-Object { $_.value -eq $value }).id
    foreach ($groupId in $roleGroups[$value]) {
        if ($existing | Where-Object { $_.principalId -eq $groupId -and $_.appRoleId -eq $roleId }) { continue }
        Invoke-Graph POST "/servicePrincipals/$($sp.id)/appRoleAssignedTo" @{
            principalId = $groupId; resourceId = $sp.id; appRoleId = $roleId
        } | Out-Null
        Write-Host "Assigned $value to group $groupId"
    }
}

# ── 6. What the install stack needs ──────────────────────────────────────────
$metadata = "https://login.microsoftonline.com/$tenant/federationmetadata/2007-06/federationmetadata.xml?appid=$($app.appId)"
Write-Host ""
Write-Host "Done. For the DebugLogManager install stack:"
Write-Host "  Hostname        $Hostname"
Write-Host "  IdpMetadataUrl  $metadata"
Write-Host ""
Write-Host "Check: Entra admin center > Enterprise applications > $DisplayName > Single sign-on"
Write-Host "shows Identifier $entityId and Reply URL $replyUrl."
2CloudFormationCloud team · tools account
Who can reach DebugLogManager (port 443)
+ add a range
By default, anything on your private networks: offices, VPN and other VPCs. People still sign in with Microsoft. Narrow it if you like.
Where it may debug: your workload OUs (or the root ID, r-…, for the whole organization)
+ add an OU
Accounts added to these OUs later are covered automatically.
Find your OUs
In the tools account, open AWS CloudShell and paste this. It prints every OU with its ID:
Regions it offers, where your workloads run:
Not sure? Find the regions you use
In the management account: last month's spend by region (ignore global and NoRegion).
More options
Launch stack Opens CloudFormation with these filled in. Tick the IAM box, press Create stack. About 6 minutes.
Prefer the AWS CLI?
When it's done, its Outputs give the IP and the DNS line for step 3.
3DNSDNS admin
The stack's Outputs show the DNS line, ready to paste. Or paste the IP here:
Your DNS:
On your DNS server (PowerShell):
Check from any company machine: should return the IP. It never changes, so this is done once.
4CertificateA DebugLogManager admin
You need a certificate for from your company's CA: a PFX with its password, or PEM files (certificate, key, and chain if you have one).
  1. Open . The first time the browser warns: DebugLogManager still uses its own temporary certificate.
  2. Check its fingerprint matches the stack's FirstVisitFingerprint output, then continue.
    How to check the fingerprint
    On your machine, in a terminal with OpenSSL (macOS, Linux, Git Bash):
    Or PowerShell 7:
    Or in the browser: click Not secure, then the certificate, and read its SHA-256 fingerprint.
  3. Sign in with Microsoft as an admin. Until a certificate is loaded, DebugLogManager opens only its Install page, for admins; everyone else is told it's still being set up.
  4. Upload a certificate to complete the installation: choose PFX or PEM, Browse… to your file, type the password, and press OK (it turns on once both are there). DebugLogManager checks it covers the URL, the key matches and it hasn't expired, then uses it straight away. Reload: the browser trusts it.
Rather have no warning at all? Load the certificate from AWS CloudShell first
Your certificate is:
DebugLogManager picks it up within a minute; the first visit then has no warning.
Done. Next, in DebugLogManager: Allowed sources, to choose what may log.