Skip to content

Commit 3b19a5b

Browse files
committed
Better support for multitenant
1 parent 9073b65 commit 3b19a5b

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

app/backend/app.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
SpeechSynthesizer,
1717
)
1818
from azure.core.exceptions import ResourceNotFoundError
19-
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider
19+
from azure.identity.aio import (
20+
AzureDeveloperCliCredential,
21+
ManagedIdentityCredential,
22+
get_bearer_token_provider,
23+
)
2024
from azure.monitor.opentelemetry import configure_azure_monitor
2125
from azure.search.documents.aio import SearchClient
2226
from azure.search.documents.indexes.aio import SearchIndexClient
@@ -436,11 +440,13 @@ async def setup_clients():
436440
USE_SPEECH_OUTPUT_BROWSER = os.getenv("USE_SPEECH_OUTPUT_BROWSER", "").lower() == "true"
437441
USE_SPEECH_OUTPUT_AZURE = os.getenv("USE_SPEECH_OUTPUT_AZURE", "").lower() == "true"
438442

439-
# Use the current user identity to authenticate with Azure OpenAI, AI Search and Blob Storage (no secrets needed,
440-
# just use 'az login' locally, and managed identity when deployed on Azure). If you need to use keys, use separate AzureKeyCredential instances with the
441-
# keys for each service
442-
# If you encounter a blocking error during a DefaultAzureCredential resolution, you can exclude the problematic credential by using a parameter (ex. exclude_shared_token_cache_credential=True)
443-
azure_credential = DefaultAzureCredential(exclude_shared_token_cache_credential=True)
443+
# Use the current user identity for keyless authentication to Azure services.
444+
# This assumes you use 'azd auth login' locally, and managed identity when deployed on Azure.
445+
# The managed identity is setup in the infra/ folder.
446+
if os.getenv("WEBSITE_HOSTNAME"):
447+
azure_credential = ManagedIdentityCredential()
448+
else:
449+
azure_credential = AzureDeveloperCliCredential(tenant_id=AZURE_TENANT_ID)
444450

445451
# Set up clients for AI Search and Storage
446452
search_client = SearchClient(

app/backend/prepdocs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,12 @@ async def main(strategy: Strategy, setup_index: bool = True):
381381
use_int_vectorization = args.useintvectorization and args.useintvectorization.lower() == "true"
382382

383383
# Use the current user identity to connect to Azure services unless a key is explicitly set for any of them
384-
azd_credential = (
385-
AzureDeveloperCliCredential()
386-
if args.tenantid is None
387-
else AzureDeveloperCliCredential(tenant_id=args.tenantid, process_timeout=60)
388-
)
384+
if args.tenantid:
385+
logger.info("Connecting to Azure services using the azd credential for tenant %s", args.tenantid)
386+
azd_credential = AzureDeveloperCliCredential(tenant_id=args.tenantid, process_timeout=60)
387+
else:
388+
logger.info("Connecting to Azure services using the azd credential for home tenant")
389+
azd_credential = AzureDeveloperCliCredential()
389390

390391
if args.removeall:
391392
document_action = DocumentAction.RemoveAll

infra/main.parameters.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@
191191
"enableUnauthenticatedAccess": {
192192
"value": "${AZURE_ENABLE_UNAUTHENTICATED_ACCESS=false}"
193193
},
194-
"tenantId": {
195-
"value": "${AZURE_TENANT_ID}"
196-
},
197194
"authTenantId": {
198195
"value": "${AZURE_AUTH_TENANT_ID}"
199196
},

0 commit comments

Comments
 (0)