feat(azure-foundry): add Microsoft Entra ID auth#27509
Conversation
Use azure-identity DefaultAzureCredential for keyless Foundry auth. Preserve refreshable callable credentials through OpenAI and Anthropic client paths. Add setup, doctor, auth status, docs, and tests for Entra auth. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Merged via PR #28101. Your commit was cherry-picked onto current main with your authorship preserved in git log (commit 9df9816 — "feat(azure-foundry): add Microsoft Entra ID auth"). Two small things on top:
On your design question ("api_key as Thanks for the contribution — keyless Foundry was a real gap. Will ship in the next release. Closes #25162. |
Use azure-identity DefaultAzureCredential for keyless Foundry auth.
Preserve refreshable callable credentials through OpenAI and Anthropic client paths. Add setup, doctor, auth status, docs, and tests for Entra auth.
One design question: I tried to not impact Hermes as much as I could, but it does introduces the idea that api_key could be a string or callable depending on your provider. We should perhaps make it only a callable everywhere and have the paths that use an api_key return the str from that callable. I didn't do it because it wasn't completely obvious that was better, or that there wasn't a more minimal approach we could take. Looking for feedback on that.
What does this PR do?
Implements foundry bearer auth using DefaultAzureCredential, which is a chained credential that looks at many locations but most importantly for this use case looks at your local
az logincreds for local use and the agent id that is assigned to an agent when it is running on foundry itself. It takes into account token refresh, token caching, and attempts to do this changing as little of the rest of Hermes as it can.Token auth is preferred over API keys because it uses short-lived bearer tokens derived from the local or managed identity environment, reducing the risk and impact of leaked long-lived API keys. Many corporate environments do not allow api key to be enabled on Foundry when creating projects meaning without this they cannot use Hermes with Foundry models at all.
Related Issue
Fixes #25162
Type of Change
Changes Made
agent/azure_identity_adapter.py.auth_mode: entra_idinhermes_cli/runtime_provider.py,agent/agent_init.py, and related agent runtime paths.hermes_cli/auth.py,hermes_cli/auth_commands.py,hermes_cli/azure_detect.py,hermes_cli/doctor.py, andhermes_cli/main.py.azure-identityinpyproject.toml,uv.lock, andtools/lazy_deps.py.plugins/model-providers/azure-foundry/.How to Test
hermes model
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/AScreenshots / Logs
as a follow up PR we can probably improve this model list selection when logged in with az, as the user could call apis that you cannot with just an api key and fetch actually deployed models in the project rather than all possible models.