Authenticate ingress
When you add an Ingress port for incoming traffic to the sandbox, you can set-up a Microsoft Entra ID authentication for the sandbox port. Only authenticated and authorized users will be able to access the app running in your sandbox. The ingress proxy outside the sandbox handles authentication and authorization.
Ingress authentication is a per-port access policy and you can configure it in the sandboxes portal or via SDK.
How it works
The Azure Container Apps sandboxes ingress proxy checks the access policy outside the sandbox, so code in the sandbox can't bypass it. There are three fields you can set. The first one is required:
| Setting | Allows |
|---|---|
| Tenant ID | Directory ID for your Entra tenant. Required. |
| Allowed object IDs | User UDs permittend to access. |
| Allowed emails | Users with a listed email or UPN. |
A caller must match the tenant and at least one of the object IDs or emails to be allowed. If both lists are empty, every user in the tenant has access. The ingress proxy removes the sign-in cookie or token before it forwards the request to the sandbox.
Group object IDs don't grant access to group members. List user object IDs.
Set ingress authentication in the portal
- Open the Sandboxes portal.
- Open the sandbox from Sandbox groups > your group > Sandboxes.
- Select Add Ingress Port.
- Enter the port number.
- In Authentication, select Microsoft Entra ID.
- Enter the Tenant ID.
- In Allowed object IDs or Allowed emails, enter a value and press Enter. To allow yourself, select Add next to Your object ID.
- Click Add Ingress Port button.
Set ingress authentication using the SDK
The SDK sets allowed emails. Set Tenant ID and Allowed object IDs in the portal.
import os
from azure.identity import DefaultAzureCredential
from azure.containerapps.sandbox import (
AddPortRequest,
PortAuthConfig,
PortAuthEntraId,
SandboxGroupClient,
endpoint_for_region,
)
client = SandboxGroupClient(
endpoint_for_region(os.environ["ACA_SANDBOXGROUP_REGION"]),
DefaultAzureCredential(),
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"],
resource_group=os.environ["ACA_RESOURCE_GROUP"],
sandbox_group=os.environ["ACA_SANDBOX_GROUP"],
)
sandbox = client.get_sandbox_client(os.environ["SANDBOX_ID"])
# One user
port = sandbox.add_port(8080, email="alice@contoso.com")
print(port.url)
# Several users. The update_ports replaces every port on the sandbox.
sandbox.update_ports([
AddPortRequest(
port=8080,
auth=PortAuthConfig(
entra_id=PortAuthEntraId(
enabled=True,
emails=["alice@contoso.com", "bob@contoso.com"],
),
),
),
])
Call the port
In a browser, open the port URL and sign in.
From a script, send a Microsoft Entra token. Scripted requests require a Tenant ID on the port.
For the following examples, install Azure CLI and sign in with an allowed user. Set the URL environment variable to the port's HTTPS URL; Bash also requires curl. The scripts keep the token in memory and don't print it.
- Bash
- PowerShell
set +x
: "${URL:?Set URL to the sandbox port HTTPS URL}"
TOKEN=$(az account get-access-token --resource https://auth.adcproxy.io --query accessToken -o tsv)
test -n "$TOKEN" || { echo "Azure CLI returned an empty token." >&2; exit 1; }
curl --fail --silent --show-error --max-time 30 -H "Authorization: Bearer $TOKEN" "$URL"
if (-not $env:URL) { throw 'Set URL to the sandbox port HTTPS URL' }
$Token = az account get-access-token --resource https://auth.adcproxy.io --query accessToken -o tsv
if ($LASTEXITCODE -ne 0 -or -not $Token) { throw 'Azure CLI did not return a token.' }
Invoke-RestMethod -Uri $env:URL -Headers @{ Authorization = "Bearer $Token" } -TimeoutSec 30