Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for deploying to non-home tenant #1964

Merged
merged 7 commits into from
Sep 13, 2024

Conversation

pamelafox
Copy link
Collaborator

@pamelafox pamelafox commented Sep 11, 2024

Purpose

I've been deploying to my non-home tenant this week, and it's been tricky since DefaultAzureCredential doesn't necessarily know which tenant to use. Its chain is:

  1. AzureCliCredential - which can have a default tenant override, if explicitly set
  2. AzureDeveloperCliCredential - doesn't have a default tenant override, but will obey tenant_id or AZURE_TENANT_ID in global env

So sometimes my DAC will work, if I've got my az or env setup right, but often it will break.
This change makes our code more explicitly pass in the tenant_id for local use, which should be set by the azd up process.
However, its slightly backward incompatible as we were bringing tenantId into main.parameters.json, which was overriding what would otherwise be a correctly output tenantId and setting it to an empty string. So some developers may need to re-run azd provision, or go into their .env and set AZURE_TENANT_ID="" there, to get local dev working again.

Does this introduce a breaking change?

When developers merge from main and run the server, azd up, or azd deploy, will this produce an error?
If you're not sure, try it out on an old environment.

[X] Yes - See above
[ ] No

Does this require changes to learn.microsoft.com docs?

This repository is referenced by this tutorial
which includes deployment, settings and usage instructions. If text or screenshot need to change in the tutorial,
check the box below and notify the tutorial author. A Microsoft employee can do this for you if you're an external contributor.

[ ] Yes
[X] No

Type of change

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

Code quality checklist

See CONTRIBUTING.md for more details.

  • The current tests all pass (python -m pytest).
  • I added tests that prove my fix is effective or that my feature works
  • I ran python -m pytest --cov to verify 100% coverage of added lines
  • I ran python -m mypy to check for type errors
  • I either used the pre-commit hooks or ran ruff and black manually on my code.

@pamelafox
Copy link
Collaborator Author

CCing everyone who I've discussed DefaultAzureCredential woes with :)

app/backend/app.py Outdated Show resolved Hide resolved
azd_credential = AzureDeveloperCliCredential(tenant_id=args.tenantid, process_timeout=60)
else:
logger.info("Connecting to Azure services using the azd credential for home tenant")
azd_credential = AzureDeveloperCliCredential()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this one not have the same timeout?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know! I thought about removing it for consistency but then thought I shouldnt change things I dont know the origin for. Maybe @mattgotteiner recalls a reason?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should put the timeout in both, just to give the credential more time to come back locally.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think adding the timeout will have much issue. Sure, we can add it to both

@@ -22,7 +22,9 @@ jobs:
- name: Build Bicep for linting
uses: azure/CLI@v2
with:
inlineScript: az config set bicep.use_binary_from_path=false && az bicep build -f infra/main.bicep --stdout
inlineScript: |
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for AZ CLI regression-
Azure/azure-cli#29828

Copy link
Collaborator

@mattgotteiner mattgotteiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate DefaultAzureCredential didn't work here

@pamelafox
Copy link
Collaborator Author

@mattgotteiner It works only if you're also logged into Azure CLI and have explicitly set your tenant's subscription to the one that was used in the app. So I think it's safer to go with the more explicit credential. We'll see if we get more/less issues with this sort of approach.

@pamelafox pamelafox merged commit 2333426 into Azure-Samples:main Sep 13, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants