Add Entra ID Sign-In to Codex CLI Through agentgateway (Part 2) A follow-up post to a two-part series documents adding Microsoft Entra ID sign-in to Codex CLI 0.170.0 through open source agentgateway v1.7.0, closing a hole from Part 1 in which the gateway accepted requests from anyone who could reach its port. The setup requires an Entra app registration that issues tokens carrying the user's group IDs, an agentgateway policy that validates the token's signature, issuer, audience and membership in a `codex` group, and a Codex profile that points users to the Microsoft sign-in page; the gateway returns 401 for requests without a token and 403 for users outside the group. The configuration covers both the `/v1` Bedrock route and the `/mcp` Solo.io docs search server, with full commands in the sebbycorp/agentgateway-oss-k8s repository. In Part 1 https://agentgateway.dev/blog/2026-11-18-deploy-codex-cli-bedrock-agentgateway/ I put Codex CLI behind open source agentgateway so it could use an OpenAI model on Amazon Bedrock without holding a key. That left one obvious hole: the gateway took requests from anyone who could reach the port. This post closes it. When I type codex now, it sends me to the Microsoft sign-in page first. The gateway only accepts my requests if I come back with an Entra ID token and I am in the codex group. What you end up with: codex group, or the gateway answers 403. /v1 Bedrock and /mcp the Solo.io docs search server . All of it is open source agentgateway v1.7.0 and Codex CLI 0.170.0. The full step list with every command is in the repo: sebbycorp/agentgateway-oss-k8s, entra-id/README.md https://github.com/sebbycorp/agentgateway-oss-k8s/blob/main/entra-id/README.md . php flowchart LR U You type codex -- C Codex CLI C -- "1. no sign-in yet: open browser" -- E Microsoft Entra ID E -- "2. token with your group IDs" -- C C -- "3. Authorization: Bearer token" -- G agentgateway proxy G -- "valid token + codex group" -- B Amazon Bedrock G -- "valid token + codex group" -- M search.solo.io MCP G -. "no token: 401, wrong group: 403" .- C Three parts have to agree: | Part | What it does | |---|---| | Entra app registration | Issues tokens for “the gateway”, with the user’s group IDs inside | | agentgateway policy | Checks the token’s signature, issuer, audience and group | | Codex profile | Tells Codex where to send the user to sign in | solo-search MCP route and a Codex profile. az login export TENANT ID=$ az account show --query tenantId -o tsv export CTX=kind-agentgateway-codex export GROUP ID=$ az ad group create --display-name codex --mail-nickname codex \ --description "Access to LLMs and MCP servers through agentgateway" --query id -o tsv az ad group member add --group $GROUP ID \ --member-id $ az ad signed-in-user show --query id -o tsv The app registration stands for the gateway. The gateway accepts only tokens that were issued for this app. export APP ID=$ az ad app create --display-name agentgateway-oss-codex \ --sign-in-audience AzureADMyOrg --query appId -o tsv OBJECT ID=$ az ad app show --id $APP ID --query id -o tsv Application ID URI, and put the user's security groups in the token az ad app update --id $APP ID --identifier-uris "api://$APP ID" \ --set groupMembershipClaims=SecurityGroup Expose one scope "access" and issue v2.0 tokens SCOPE ID=$ uuidgen | tr 'A-Z' 'a-z' az rest --method PATCH --uri "https://graph.microsoft.com/v1.0/applications/$OBJECT ID" \ --headers 'Content-Type=application/json' --body "{ \"api\": { \"requestedAccessTokenVersion\": 2, \"oauth2PermissionScopes\": { \"id\": \"$SCOPE ID\", \"value\": \"access\", \"type\": \"User\", \"isEnabled\": true, \"adminConsentDisplayName\": \"Access agentgateway\", \"adminConsentDescription\": \"Call LLMs and MCP servers through agentgateway\", \"userConsentDisplayName\": \"Access agentgateway\", \"userConsentDescription\": \"Call LLMs and MCP servers through agentgateway\" } } }" Public client no secret with loopback redirect URIs, so Codex can finish the sign-in az rest --method PATCH --uri "https://graph.microsoft.com/v1.0/applications/$OBJECT ID" \ --headers 'Content-Type=application/json' --body '{ "isFallbackPublicClient": true, "publicClient": { "redirectUris": "http://127.0.0.1/callback", "http://localhost/callback" } }' az ad sp create --id $APP ID Four settings matter here, and each one fails in its own way if you skip it: | Setting | If you skip it | |---|---| | Scope api://