Skip to main content
Guide

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:

SettingAllows
Tenant IDDirectory ID for your Entra tenant. Required.
Allowed object IDsUser UDs permittend to access.
Allowed emailsUsers 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.

note

Group object IDs don't grant access to group members. List user object IDs.

Set ingress authentication in the portal​

  1. Open the Sandboxes portal.
  2. Open the sandbox from Sandbox groups > your group > Sandboxes.
  3. Select Add Ingress Port.
  4. Enter the port number.
  5. In Authentication, select Microsoft Entra ID.
  6. Enter the Tenant ID.
  7. In Allowed object IDs or Allowed emails, enter a value and press Enter. To allow yourself, select Add next to Your object ID.
  8. 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.

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"