Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.54k stars 2.77k forks source link

DefaultAzureCredential() Ignoring Specified Credentials – We're Stuck! #37200

Closed Simple-And-Modern closed 1 week ago

Simple-And-Modern commented 2 weeks ago

Package Name: azure-identity Package Version: 1.17.1 Operating System: Windows 11 Python Version: 3.11.0

  1. The Problem:

Our team has hit a frustrating roadblock while trying to use DefaultAzureCredential() in an Azure Python Function. Despite specifying valid credentials in local.settings.json, the function is stubbornly using Windows credentials instead.

We've double-checked that AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_CLIENT_SECRET are all correctly set for the service principal. However, when checking the logs on the Azure Portal, the requests are showing as coming from one of our representative’s Windows account instead of the registered app.

  1. File Structure:
[Root Folder]:
|- local.settings.json
|- function_app.py   # This is calling tableStorage.py
|- modules:
   |- tableStorage.py
  1. Relevant Code in tableStorage.py:
from azure.data.tables import TableServiceClient
from azure.identity import DefaultAzureCredential
from os import environ
import logging

account_url = "https://<your-table-service>.table.core.windows.net"

# Checking if Azure Environment is accessible - It's accessible
logging.info(f"Environment Variables:{environ}")

with TableServiceClient(
    endpoint=account_url, credential=DefaultAzureCredential()
) as table_service_client:
    properties = table_service_client.get_service_properties()
    print(f"{properties}")
  1. What We Expected:

We expected DefaultAzureCredential() to use the credentials from the environment variables set in local.settings.json. According to the documentation, this should be the first source of credentials, but it’s just not working as expected.

  1. Additional Context:

We're feeling stuck on this and have even started a discussion on Reddit for help. If anyone has faced this issue or knows a workaround, we’d appreciate any guidance. Here’s the Reddit post for more context.

github-actions[bot] commented 2 weeks ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

xiangyan99 commented 1 week ago

Thanks for reaching out.

Could you share your logs? (Please use sth. like "xxxx" instead of the real value of your secrets)

And could you collect verbose logging by setting the logging level to debug?

github-actions[bot] commented 1 week ago

Hi @Simple-And-Modern. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

Simple-And-Modern commented 1 week ago
Found Python version 3.11.0 (python).
SkipInProcessHost compilation symbol is not defined.
FUNCTIONS_INPROC_NET8_ENABLED app setting is not enabled in local.settings.json

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools
Core Tools Version:       4.0.5907 Commit hash: N/A +807e89766a92b14fd07b9f0bc2bea1d8777ab209 (64-bit)
Function Runtime Version: 4.834.3.22875

[2024-09-04T17:02:31.293Z] Building host: version spec: , startup suppressed: 'False', configuration suppressed: 'False', startup operation id: 'a58c37ad-7428-417e-9ba5-d605fe2b2d61'
[2024-09-04T17:02:31.299Z] Reading host configuration file 'D:\otp-verification-1\host.json'
[2024-09-04T17:02:31.301Z] Host configuration file read:
[2024-09-04T17:02:31.302Z] {
[2024-09-04T17:02:31.302Z]   "version": "2.0",
[2024-09-04T17:02:31.302Z]   "logging": {
[2024-09-04T17:02:31.303Z]     "applicationInsights": {
[2024-09-04T17:02:31.303Z]       "samplingSettings": {
[2024-09-04T17:02:31.303Z]         "isEnabled": true,
[2024-09-04T17:02:31.304Z]         "excludedTypes": "Request"
[2024-09-04T17:02:31.304Z]       }
[2024-09-04T17:02:31.304Z]     }
[2024-09-04T17:02:31.305Z]   },
[2024-09-04T17:02:31.305Z]   "extensionBundle": {
[2024-09-04T17:02:31.305Z]     "id": "Microsoft.Azure.Functions.ExtensionBundle",
[2024-09-04T17:02:31.306Z]     "version": "[4.*, 5.0.0)"
[2024-09-04T17:02:31.306Z]   }
[2024-09-04T17:02:31.306Z] }
[2024-09-04T17:02:31.343Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language: java
[2024-09-04T17:02:31.346Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language: node
[2024-09-04T17:02:31.348Z] File 'C:\Program Files\dotnet\dotnet.exe' is not found, 'dotnet' invocation will rely on the PATH environment variable.
[2024-09-04T17:02:31.350Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language: powershell
[2024-09-04T17:02:31.354Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at C:\Users\<User>\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle
[2024-09-04T17:02:31.355Z] Found a matching extension bundle at C:\Users\<User>\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\4.17.0
[2024-09-04T17:02:31.373Z] Loading functions metadata
[2024-09-04T17:02:31.377Z] Worker indexing is enabled
[2024-09-04T17:02:31.382Z] Fetching metadata for workerRuntime: python
[2024-09-04T17:02:31.384Z] Reading functions metadata (Worker)
[2024-09-04T17:02:31.670Z]  INFO: Starting Azure Functions Python Worker.
[2024-09-04T17:02:31.672Z]  INFO: Worker ID: 80d5fbfc-bc5b-4f36-a7d6-b4741629acae, Request ID: c29b8192-7272-4556-818c-4ac062f5c428, Host Address: 127.0.0.1:55110
[2024-09-04T17:02:31.777Z]  INFO: Successfully opened gRPC channel to 127.0.0.1:55110 
[2024-09-04T17:02:31.779Z]  INFO: Detaching console logging.
[2024-09-04T17:02:31.844Z] Switched to gRPC logging.
[2024-09-04T17:02:31.862Z] Received WorkerInitRequest, python version 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)], worker version 4.28.1, request ID c29b8192-7272-4556-818c-4ac062f5c428. App Settings state: PYTHON_THREADPOOL_THREAD_COUNT: 1000 | PYTHON_ENABLE_WORKER_EXTENSIONS: False. To enable debug level logging, please refer to https://aka.ms/python-enable-debug-logging
[2024-09-04T17:02:31.904Z] Successfully loaded OpenTelemetry modules. OpenTelemetry is now enabled.
[2024-09-04T17:02:32.097Z] Received WorkerMetadataRequest, request ID c29b8192-7272-4556-818c-4ac062f5c428, function_path: D:\otp-verification-1\function_app.py
[2024-09-04T17:02:32.099Z] Indexed function app and found 1 functions
[2024-09-04T17:02:32.099Z] Successfully processed FunctionMetadataRequest for functions: Function Name: <functionName>, Function Binding: [('httpTrigger', 'req', ''), ('http', '$return', '')]. Deferred bindings enabled: False.
[2024-09-04T17:02:32.116Z] 1 functions found (Worker)
[2024-09-04T17:02:32.123Z] 1 functions loaded
[2024-09-04T17:02:32.126Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at C:\Users\<User>\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle
[2024-09-04T17:02:32.126Z] Found a matching extension bundle at C:\Users\<User>\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\4.17.0
[2024-09-04T17:02:32.127Z] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[2024-09-04T17:02:32.289Z] Skipping bundle download since it already exists at path C:\Users\<User>\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\4.17.0
[2024-09-04T17:02:32.293Z] Loading extension bundle from C:\Users\<User>\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\4.17.0\bin
[2024-09-04T17:02:32.294Z] Script Startup resetting load context with base path: 'C:\Users\<User>\.azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\4.17.0\bin'.
[2024-09-04T17:02:32.300Z] Reading host configuration file 'D:\otp-verification-1\host.json'
[2024-09-04T17:02:32.302Z] Host configuration file read:
[2024-09-04T17:02:32.302Z] {
[2024-09-04T17:02:32.302Z]   "version": "2.0",
[2024-09-04T17:02:32.303Z]   "logging": {
[2024-09-04T17:02:32.303Z]     "applicationInsights": {
[2024-09-04T17:02:32.304Z]       "samplingSettings": {
[2024-09-04T17:02:32.304Z]         "isEnabled": true,
[2024-09-04T17:02:32.305Z]         "excludedTypes": "Request"
[2024-09-04T17:02:32.305Z]       }
[2024-09-04T17:02:32.305Z]     }
[2024-09-04T17:02:32.306Z]   },
[2024-09-04T17:02:32.306Z]   "extensionBundle": {
[2024-09-04T17:02:32.306Z]     "id": "Microsoft.Azure.Functions.ExtensionBundle",
[2024-09-04T17:02:32.307Z]     "version": "[4.*, 5.0.0)"
[2024-09-04T17:02:32.307Z]   }
[2024-09-04T17:02:32.308Z] }
[2024-09-04T17:02:32.589Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language: java
[2024-09-04T17:02:32.591Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language: node
[2024-09-04T17:02:32.592Z] File 'C:\Program Files\dotnet\dotnet.exe' is not found, 'dotnet' invocation will rely on the PATH environment variable.
[2024-09-04T17:02:32.592Z] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language: powershell
[2024-09-04T17:02:32.699Z] Initializing Warmup Extension.
[2024-09-04T17:02:32.747Z] Initializing Host. OperationId: 'a58c37ad-7428-417e-9ba5-d605fe2b2d61'.
[2024-09-04T17:02:32.757Z] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=a58c37ad-7428-417e-9ba5-d605fe2b2d61
[2024-09-04T17:02:32.808Z] LoggerFilterOptions
[2024-09-04T17:02:32.810Z] {
[2024-09-04T17:02:32.810Z]   "MinLevel": "None",
[2024-09-04T17:02:32.811Z]   "Rules": [
[2024-09-04T17:02:32.811Z]     {
[2024-09-04T17:02:32.811Z]       "ProviderName": null,
[2024-09-04T17:02:32.812Z]       "CategoryName": null,
[2024-09-04T17:02:32.812Z]       "LogLevel": null,
[2024-09-04T17:02:32.812Z]       "Filter": "<AddFilter>b__0"
[2024-09-04T17:02:32.813Z]     },
[2024-09-04T17:02:32.813Z]     {
[2024-09-04T17:02:32.813Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2024-09-04T17:02:32.814Z]       "CategoryName": null,
[2024-09-04T17:02:32.814Z]       "LogLevel": "None",
[2024-09-04T17:02:32.815Z]       "Filter": null
[2024-09-04T17:02:32.815Z]     },
[2024-09-04T17:02:32.816Z]     {
[2024-09-04T17:02:32.816Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2024-09-04T17:02:32.816Z]       "CategoryName": null,
[2024-09-04T17:02:32.817Z]       "LogLevel": null,
[2024-09-04T17:02:32.818Z]       "Filter": "<AddFilter>b__0"
[2024-09-04T17:02:32.819Z]     },
[2024-09-04T17:02:32.819Z]     {
[2024-09-04T17:02:32.820Z]       "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2024-09-04T17:02:32.820Z]       "CategoryName": null,
[2024-09-04T17:02:32.821Z]       "LogLevel": null,
[2024-09-04T17:02:32.821Z]       "Filter": "<AddFilter>b__0"
[2024-09-04T17:02:32.821Z]     }
[2024-09-04T17:02:32.822Z]   ]
[2024-09-04T17:02:32.822Z] }
[2024-09-04T17:02:32.822Z] LoggerFilterOptions
[2024-09-04T17:02:32.823Z] {
[2024-09-04T17:02:32.823Z]   "MinLevel": "None",
[2024-09-04T17:02:32.823Z]   "Rules": [
[2024-09-04T17:02:32.824Z]     {
[2024-09-04T17:02:32.824Z]       "ProviderName": null,
[2024-09-04T17:02:32.824Z]       "CategoryName": null,
[2024-09-04T17:02:32.824Z]       "LogLevel": null,
[2024-09-04T17:02:32.825Z]       "Filter": "<AddFilter>b__0"
[2024-09-04T17:02:32.825Z]     },
[2024-09-04T17:02:32.826Z]     {
[2024-09-04T17:02:32.826Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2024-09-04T17:02:32.827Z]       "CategoryName": null,
[2024-09-04T17:02:32.827Z]       "LogLevel": "None",
[2024-09-04T17:02:32.827Z]       "Filter": null
[2024-09-04T17:02:32.828Z]     },
[2024-09-04T17:02:32.828Z]     {
[2024-09-04T17:02:32.829Z]       "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[2024-09-04T17:02:32.829Z]       "CategoryName": null,
[2024-09-04T17:02:32.829Z]       "LogLevel": null,
[2024-09-04T17:02:32.830Z]       "Filter": "<AddFilter>b__0"
[2024-09-04T17:02:32.830Z]     },
[2024-09-04T17:02:32.830Z]     {
[2024-09-04T17:02:32.831Z]       "ProviderName": "Azure.Functions.Cli.Diagnostics.ColoredConsoleLoggerProvider",
[2024-09-04T17:02:32.831Z]       "CategoryName": null,
[2024-09-04T17:02:32.831Z]       "LogLevel": null,
[2024-09-04T17:02:32.832Z]       "Filter": "<AddFilter>b__0"
[2024-09-04T17:02:32.832Z]     }
[2024-09-04T17:02:32.832Z]   ]
[2024-09-04T17:02:32.833Z] }
[2024-09-04T17:02:32.833Z] LanguageWorkerOptions
[2024-09-04T17:02:32.834Z] {
[2024-09-04T17:02:32.834Z]   "WorkerConfigs": [
[2024-09-04T17:02:32.834Z]     {
[2024-09-04T17:02:32.835Z]       "Description": {
[2024-09-04T17:02:32.835Z]         "Language": "python",
[2024-09-04T17:02:32.835Z]         "DefaultRuntimeName": null,
[2024-09-04T17:02:32.836Z]         "DefaultRuntimeVersion": "3.11",
[2024-09-04T17:02:32.836Z]         "SupportedArchitectures": [
[2024-09-04T17:02:32.836Z]           "X64",
[2024-09-04T17:02:32.837Z]           "X86",
[2024-09-04T17:02:32.837Z]           "Arm64"
[2024-09-04T17:02:32.837Z]         ],
[2024-09-04T17:02:32.838Z]         "SupportedOperatingSystems": [
[2024-09-04T17:02:32.838Z]           "LINUX",
[2024-09-04T17:02:32.838Z]           "OSX",
[2024-09-04T17:02:32.839Z]           "WINDOWS"
[2024-09-04T17:02:32.839Z]         ],
[2024-09-04T17:02:32.839Z]         "SupportedRuntimeVersions": [
[2024-09-04T17:02:32.840Z]           "3.7",
[2024-09-04T17:02:32.840Z]           "3.8",
[2024-09-04T17:02:32.840Z]           "3.9",
[2024-09-04T17:02:32.840Z]           "3.10",
[2024-09-04T17:02:32.841Z]           "3.11"
[2024-09-04T17:02:32.841Z]         ],
[2024-09-04T17:02:32.842Z]         "SanitizeRuntimeVersionRegex": null,
[2024-09-04T17:02:32.843Z]         "WorkerIndexing": "true",
[2024-09-04T17:02:32.843Z]         "Extensions": [
[2024-09-04T17:02:32.843Z]           ".py"
[2024-09-04T17:02:32.844Z]         ],
[2024-09-04T17:02:32.844Z]         "UseStdErrorStreamForErrorsOnly": false,
[2024-09-04T17:02:32.844Z]         "DefaultExecutablePath": "python",
[2024-09-04T17:02:32.845Z]         "DefaultWorkerPath": "C:\\Users\\<User>\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin\\workers\\python\\3.11/WINDOWS/X64/worker.py",
[2024-09-04T17:02:32.845Z]         "WorkerDirectory": "C:\\Users\\<User>\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin\\workers\\python",
[2024-09-04T17:02:32.845Z]         "Arguments": [],
[2024-09-04T17:02:32.846Z]         "WorkerArguments": null
[2024-09-04T17:02:32.846Z]       },
[2024-09-04T17:02:32.846Z]       "Arguments": {
[2024-09-04T17:02:32.847Z]         "ExecutablePath": "python",
[2024-09-04T17:02:32.848Z]         "ExecutableArguments": [],
[2024-09-04T17:02:32.848Z]         "WorkerPath": "C:\\Users\\<User>\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin\\workers\\python\\3.11/WINDOWS/X64/worker.py",
[2024-09-04T17:02:32.849Z]         "WorkerArguments": []
[2024-09-04T17:02:32.850Z]       },
[2024-09-04T17:02:32.850Z]       "CountOptions": {
[2024-09-04T17:02:32.851Z]         "SetProcessCountToNumberOfCpuCores": false,
[2024-09-04T17:02:32.851Z]         "ProcessCount": 1,
[2024-09-04T17:02:32.852Z]         "MaxProcessCount": 10,
[2024-09-04T17:02:32.852Z]         "ProcessStartupInterval": "00:00:10",
[2024-09-04T17:02:32.853Z]         "ProcessStartupTimeout": "00:01:00",
[2024-09-04T17:02:32.853Z]         "InitializationTimeout": "00:00:10",
[2024-09-04T17:02:32.853Z]         "EnvironmentReloadTimeout": "00:00:30",
[2024-09-04T17:02:32.854Z]         "ProcessRestartInterval": "00:00:10",
[2024-09-04T17:02:32.854Z]         "ProcessShutdownTimeout": "00:00:10"
[2024-09-04T17:02:32.854Z]       }
[2024-09-04T17:02:32.855Z]     }
[2024-09-04T17:02:32.855Z]   ]
[2024-09-04T17:02:32.856Z] }
[2024-09-04T17:02:32.856Z] ConcurrencyOptions
[2024-09-04T17:02:32.857Z] {
[2024-09-04T17:02:32.857Z]   "DynamicConcurrencyEnabled": false,
[2024-09-04T17:02:32.857Z]   "MaximumFunctionConcurrency": 500,
[2024-09-04T17:02:32.858Z]   "CPUThreshold": 0.8,
[2024-09-04T17:02:32.858Z]   "SnapshotPersistenceEnabled": true
[2024-09-04T17:02:32.858Z] }
[2024-09-04T17:02:32.859Z] FunctionResultAggregatorOptions
[2024-09-04T17:02:32.859Z] {
[2024-09-04T17:02:32.860Z]   "BatchSize": 1000,
[2024-09-04T17:02:32.860Z]   "FlushTimeout": "00:00:30",
[2024-09-04T17:02:32.860Z]   "IsEnabled": true
[2024-09-04T17:02:32.861Z] }
[2024-09-04T17:02:32.861Z] SingletonOptions
[2024-09-04T17:02:32.861Z] {
[2024-09-04T17:02:32.862Z]   "LockPeriod": "00:00:15",
[2024-09-04T17:02:32.862Z]   "ListenerLockPeriod": "00:00:15",
[2024-09-04T17:02:32.862Z]   "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[2024-09-04T17:02:32.863Z]   "LockAcquisitionPollingInterval": "00:00:05",
[2024-09-04T17:02:32.863Z]   "ListenerLockRecoveryPollingInterval": "00:01:00"
[2024-09-04T17:02:32.863Z] }
[2024-09-04T17:02:32.864Z] ScaleOptions
[2024-09-04T17:02:32.864Z] {
[2024-09-04T17:02:32.864Z]   "ScaleMetricsMaxAge": "00:02:00",
[2024-09-04T17:02:32.865Z]   "ScaleMetricsSampleInterval": "00:00:10",
[2024-09-04T17:02:32.865Z]   "MetricsPurgeEnabled": true,
[2024-09-04T17:02:32.866Z]   "IsTargetScalingEnabled": true,
[2024-09-04T17:02:32.866Z]   "IsRuntimeScalingEnabled": false
[2024-09-04T17:02:32.866Z] }
[2024-09-04T17:02:32.868Z] Starting JobHost
[2024-09-04T17:02:32.871Z] Starting Host (HostId=laptopdo6r8con-208678576, InstanceId=c24bda79-4fd8-4b45-9cf3-53c97b31b502, Version=4.834.3.22875, ProcessId=19404, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=(null))
[2024-09-04T17:02:32.885Z] Loading functions metadata
[2024-09-04T17:02:32.887Z] Worker indexing is enabled
[2024-09-04T17:02:32.887Z] Fetching metadata for workerRuntime: python
[2024-09-04T17:02:32.887Z] Reading functions metadata (Worker)
[2024-09-04T17:02:32.899Z] Reading functions metadata (Custom)
[2024-09-04T17:02:32.912Z] 1 functions found (Custom)
[2024-09-04T17:02:32.922Z] 1 functions loaded
[2024-09-04T17:02:32.961Z] Generating 1 job function(s)[2024-09-04T17:02:32.962Z] Worker process started and initialized.
[2024-09-04T17:02:32.962Z] Received WorkerLoadRequest, request ID c29b8192-7272-4556-818c-4ac062f5c428, function_id: 19d7815d-c828-55bb-8cc3-8569e48dc676,function_name: <functionName>, function_app_directory : D:\otp-verification-1
[2024-09-04T17:02:32.962Z] Successfully processed FunctionLoadRequest, request ID: c29b8192-7272-4556-818c-4ac062f5c428, function ID: 19d7815d-c828-55bb-8cc3-8569e48dc676,function Name: <functionName>,programming model: V2

[2024-09-04T17:02:33.009Z] Found the following functions:
[2024-09-04T17:02:33.010Z] Host.Functions.<functionName>
[2024-09-04T17:02:33.011Z] 
[2024-09-04T17:02:33.019Z] HttpOptions
[2024-09-04T17:02:33.021Z] {
[2024-09-04T17:02:33.022Z]   "DynamicThrottlesEnabled": false,
[2024-09-04T17:02:33.020Z] Initializing function HTTP routes
[2024-09-04T17:02:33.022Z]   "EnableChunkedRequestBinding": false,
[2024-09-04T17:02:33.022Z] Mapped function route 'api/<function>' [all] to '<functionName>'
[2024-09-04T17:02:33.023Z] 
[2024-09-04T17:02:33.023Z]   "MaxConcurrentRequests": -1,
[2024-09-04T17:02:33.024Z]   "MaxOutstandingRequests": -1,
[2024-09-04T17:02:33.024Z]   "RoutePrefix": "api"
[2024-09-04T17:02:33.025Z] }
[2024-09-04T17:02:33.032Z] Host initialized (150ms)
[2024-09-04T17:02:33.036Z] Host started (163ms)
[2024-09-04T17:02:33.037Z] Job host started

Functions:

    <functionName>:  http://localhost:7071/api/<function>

[2024-09-04T17:02:37.819Z] Host lock lease acquired by instance ID '000000000000000000000000FEF8E4ED'.
[2024-09-04T17:03:11.325Z] Executing HTTP request: {
[2024-09-04T17:03:11.326Z]   "requestId": "2a8a4eb8-ca3a-4b4b-90b7-76bb6aef0554",
[2024-09-04T17:03:11.327Z]   "method": "POST",
[2024-09-04T17:03:11.327Z]   "userAgent": "PostmanRuntime/7.41.2",
[2024-09-04T17:03:11.327Z]   "uri": "/api/<function>"
[2024-09-04T17:03:11.328Z] }
[2024-09-04T17:03:11.454Z] Executing 'Functions.<functionName>' (Reason='This function was programmatically called via the host APIs.', Id=99fec7c5-9c45-4734-b7ee-6c46d4cff24f)
[2024-09-04T17:03:11.502Z] Received FunctionInvocationRequest, request ID: c29b8192-7272-4556-818c-4ac062f5c428, function ID: 19d7815d-c828-55bb-8cc3-8569e48dc676, function name: <functionName>, invocation ID: 99fec7c5-9c45-4734-b7ee-6c46d4cff24f, function type: sync, timestamp (UTC): 2024-09-04 17:03:11.500534, sync threadpool max workers: 1000
[2024-09-04T17:03:11.509Z] Python HTTP trigger function processed a request.
[2024-09-04T17:03:11.750Z] Environment Variables:environ({'ALLUSERSPROFILE': 'C:\\ProgramData', 'APPDATA': 'C:\\Users\\<User>\\AppData\\Roaming', 'ASPNETCORE_SUPPRESSSTATUSMESSAGES': 'true', 'AZUREFUNCTIONSJOBHOST__EXTENSIONBUNDLE__DOWNLOADPATH': 'C:\\Users\\<User>\\.azure-functions-core-tools\\Functions\\ExtensionBundles\\Microsoft.Azure.Functions.ExtensionBundle', 'AZUREFUNCTIONSJOBHOST__EXTENSIONBUNDLE__ENSURELATEST': 'true', 'AZUREFUNCTIONSJOBHOST__SEQUENTIALRESTART': 'true', 'AZUREWEBJOBSSCRIPTROOT': 'D:\\otp-verification-1', 'AZUREWEBJOBSSTORAGE': '', 'AZURE_CLIENT_ID': '<AZURE_CLIENT_ID>', 'AZURE_CLIENT_SECRET': '<AZURE_CLIENT_SECRET>', 'AZURE_FUNCTIONS_ENVIRONMENT': 'Development', 'AZURE_TENANT_ID': '<AZURE_TENANT_ID>', 'CHROME_CRASHPAD_PIPE_NAME': '\\\\.\\pipe\\crashpad_17368_XVYQXMRIUQECXSJN', 'COLORTERM': 'truecolor', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'LAPTOP-DO6R8CON', 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe', 'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData', 'EFC_14056': '1', 'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer', 'FPS_BROWSER_USER_PROFILE_STRING': 'Default', 'FUNCTIONSHOSTINGCONFIG__WORKER_INDEXING_ENABLED': '1', 'FUNCTIONS_APPLICATION_DIRECTORY': 'D:\\otp-verification-1', 'FUNCTIONS_CORETOOLS_ENVIRONMENT': 'true', 'FUNCTIONS_WORKER_DIRECTORY': 'C:\\Users\\<User>\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin\\workers\\python', 'FUNCTIONS_WORKER_RUNTIME': 'python', 'FUNCTIONS_WORKER_RUNTIME_VERSION': '3.11', 'GIT_ASKPASS': 'c:\\Users\\<User>\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\extensions\\git\\dist\\askpass.sh', 'HOMEDRIVE': 'C:', 'HOMEPATH': '\\Users\\<User>', 'LANG': 'en_US.UTF-8', 'LANGUAGEWORKERS:PYTHON:DEFAULTEXECUTABLEPATH': 'python', 'LOCALAPPDATA': 'C:\\Users\\<User>\\AppData\\Local', 'LOGGING__LOGLEVEL__MICROSOFT.HOSTING.LIFETIME': 'None', 'LOGONSERVER': '\\\\LAPTOP-DO6R8CON', 'NUMBER_OF_PROCESSORS': '12', 'ONEDRIVE': 'C:\\Users\\<User>\\OneDrive - Simple & Modern Solutions Private Limited', 'ONEDRIVECOMMERCIAL': 'C:\\Users\\<User>\\OneDrive - Simple & Modern Solutions Private Limited', 'ORIGINAL_XDG_CURRENT_DESKTOP': 'undefined', 'OS': 'Windows_NT', 'PATH': 'c:\\Users\\<User>\\.vscode\\extensions\\ms-python.python-2024.12.3-win32-x64\\python_files\\deactivate\\powershell;D:\\otp-verification-1\\.venv\\Scripts;D:\\Python\\Python311\\Scripts\\;D:\\Python\\Python311\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;D:\\Git\\cmd;D:\\nodejs\\;D:\\platform-tools;D:\\Amazon\\AWSSAMCLI\\bin\\;C:\\Program Files\\Docker\\Docker\\resources\\bin;D:\\Google\\Cloud SDK\\google-cloud-sdk\\bin;C:\\Users\\<User>\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\<User>\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\<User>\\AppData\\Roaming\\npm', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW;.CPL', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 158 Stepping 13, GenuineIntel', 'PROCESSOR_LEVEL': '6', 'PROCESSOR_REVISION': '9e0d', 'PROGRAMDATA': 'C:\\ProgramData', 'PROGRAMFILES': 'C:\\Program Files', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'PROGRAMW6432': 'C:\\Program Files', 'PSEXECUTIONPOLICYPREFERENCE': 'Bypass', 'PSMODULEPATH': 'C:\\Users\\<User>\\OneDrive - Simple & Modern Solutions Private Limited\\Documents\\WindowsPowerShell\\Modules;C:\\Program Files (x86)\\WindowsPowerShell\\Modules;C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules;D:\\Google\\Cloud SDK\\google-cloud-sdk\\platform\\PowerShell', 'PUBLIC': 'C:\\Users\\Public', 'PYTHON_THREADPOOL_THREAD_COUNT': '1000', 'SESSIONNAME': 'Console', 'SYSTEMDRIVE': 'C:', 'SYSTEMROOT': 'C:\\Windows', 'TEMP': 'C:\\Users\\<User>\\AppData\\Local\\Temp', 'TERM_PROGRAM': 'vscode', 'TERM_PROGRAM_VERSION': '1.92.2', 'TMP': 'C:\\Users\\<User>\\AppData\\Local\\Temp', 'USERDOMAIN': 'LAPTOP-DO6R8CON', 'USERDOMAIN_ROAMINGPROFILE': 'LAPTOP-DO6R8CON', 'USERNAME': '<User>', 'USERPROFILE': 'C:\\Users\\<User>', 'VIRTUAL_ENV': 'D:\\otp-verification-1\\.venv', 'VIRTUAL_ENV_PROMPT': '.venv', 'VSCODE_ENV_PREPEND': 'PATH=c\\x3a\\Users\\<User>\\.vscode\\extensions\\ms-python.python-2024.12.3-win32-x64\\python_files\\deactivate\\powershell;D\\x3a\\otp-verification-1\\.venv\\Scripts;', 'VSCODE_ENV_REPLACE': 'VIRTUAL_ENV=D\\x3a\\otp-verification-1\\.venv:VIRTUAL_ENV_PROMPT=.venv', 'VSCODE_GIT_ASKPASS_EXTRA_ARGS': '', 'VSCODE_GIT_ASKPASS_MAIN': 'c:\\Users\\<User>\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\extensions\\git\\dist\\askpass-main.js', 'VSCODE_GIT_ASKPASS_NODE': 'C:\\Users\\<User>\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe', 'VSCODE_GIT_IPC_HANDLE': '\\\\.\\pipe\\vscode-git-000bd07306-sock', 'WEBSITE_HOSTNAME': 'localhost:7071', 'WINDIR': 'C:\\Windows', 'WORKER_INDEXING_ENABLED': '1', 'PYTHONPATH': '/home/site/wwwroot/.python_packages\\lib/site-packages:C:\\Users\\<User>\\AppData\\Roaming\\npm\\node_modules\\azure-functions-core-tools\\bin\\workers\\python\\3.11\\WINDOWS\\X64'})
[2024-09-04T17:03:11.837Z] Environment is configured for ClientSecretCredential
[2024-09-04T17:03:11.838Z] ManagedIdentityCredential will use IMDS
[2024-09-04T17:03:11.842Z] Request URL: 'https://login.microsoftonline.com/<AZURE_TENANT_ID>/v2.0/.well-known/openid-configuration'
Request method: 'GET'
Request headers:
    'User-Agent': 'azsdk-python-identity/1.17.1 Python/3.11.0 (Windows-10-10.0.22631-SP0)'
No body was attached to the request
[2024-09-04T17:03:12.129Z] Response status: 200
Response headers:
    'Cache-Control': 'max-age=86400, private'
    'Content-Type': 'application/json; charset=utf-8'
    'Strict-Transport-Security': 'REDACTED'
    'X-Content-Type-Options': 'REDACTED'
    'Access-Control-Allow-Origin': 'REDACTED'
    'Access-Control-Allow-Methods': 'REDACTED'
    'P3P': 'REDACTED'
    'x-ms-request-id': '5e6f351c-1947-42b3-8b51-0224d41bc800'
    'x-ms-ests-server': 'REDACTED'
    'x-ms-srs': 'REDACTED'
    'X-XSS-Protection': 'REDACTED'
    'Set-Cookie': 'REDACTED'
    'Date': 'Wed, 04 Sep 2024 17:03:13 GMT'
    'Content-Length': '1753'
[2024-09-04T17:03:12.132Z] Request URL: 'https://login.microsoftonline.com/<AZURE_TENANT_ID>/oauth2/v2.0/token'
Request method: 'POST'
Request headers:
    'Accept': 'application/json'
    'x-client-sku': 'REDACTED'
    'x-client-ver': 'REDACTED'
    'x-client-os': 'REDACTED'
    'x-ms-lib-capability': 'REDACTED'
    'client-request-id': 'REDACTED'
    'x-client-current-telemetry': 'REDACTED'
    'x-client-last-telemetry': 'REDACTED'
    'User-Agent': 'azsdk-python-identity/1.17.1 Python/3.11.0 (Windows-10-10.0.22631-SP0)'
A body is sent with the request
[2024-09-04T17:03:12.424Z] Response status: 200
Response headers:
    'Cache-Control': 'no-store, no-cache'
    'Pragma': 'no-cache'
    'Content-Type': 'application/json; charset=utf-8'
    'Expires': '-1'
    'Strict-Transport-Security': 'REDACTED'
    'X-Content-Type-Options': 'REDACTED'
    'P3P': 'REDACTED'
    'client-request-id': 'REDACTED'
    'x-ms-request-id': '3bf54542-501c-4aad-b62b-10200956aa00'
    'x-ms-ests-server': 'REDACTED'
    'x-ms-clitelem': 'REDACTED'
    'x-ms-srs': 'REDACTED'
    'X-XSS-Protection': 'REDACTED'
    'Set-Cookie': 'REDACTED'
    'Date': 'Wed, 04 Sep 2024 17:03:13 GMT'
    'Content-Length': '1360'[2024-09-04T17:03:12.426Z] DefaultAzureCredential acquired a token from EnvironmentCredential

[2024-09-04T17:03:12.431Z] Request URL: 'https://<your-table-service>.table.core.windows.net/?restype=REDACTED&comp=REDACTED'
Request method: 'GET'
Request headers:
    'x-ms-version': 'REDACTED'
    'Accept': 'application/xml'
    'x-ms-client-request-id': '9137fc30-6adf-11ef-b606-1c9957add571'
    'x-ms-date': 'REDACTED'
    'Date': 'Wed, 04 Sep 2024 17:03:11 GMT'
    'User-Agent': 'azsdk-python-data-tables/12.5.0 Python/3.11.0 (Windows-10-10.0.22631-SP0)'
    'Authorization': 'REDACTED'
No body was attached to the request
[2024-09-04T17:03:12.683Z] Response status: 403
Response headers:
    'Content-Length': '378'
    'Content-Type': 'application/xml'
    'Server': 'Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0'
    'x-ms-request-id': '6dea622e-c002-0050-55ec-fe7944000000'
    'x-ms-client-request-id': '9137fc30-6adf-11ef-b606-1c9957add571'
    'x-ms-version': 'REDACTED'
    'x-ms-error-code': 'AuthorizationPermissionMismatch'
    'Date': 'Wed, 04 Sep 2024 17:03:13 GMT'
[2024-09-04T17:03:12.711Z] Executed 'Functions.<functionName>' (Failed, Id=99fec7c5-9c45-4734-b7ee-6c46d4cff24f, Duration=1280ms)
[2024-09-04T17:03:12.713Z] System.Private.CoreLib: Exception while executing function: Functions.<functionName>. System.Private.CoreLib: Result: Failure
Exception: HttpResponseError: This request is not authorized to perform this operation using this permission.
RequestId:6dea622e-c002-0050-55ec-fe7944000000
Time:2024-09-04T17:03:14.1971306Z
ErrorCode:AuthorizationPermissionMismatch
{http://schemas.microsoft.com/ado/2007/08/dataservices/metadata}error:None
Content: <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>AuthorizationPermissionMismatch</m:code><m:message xml:lang="en-US">This request is not authorized to perform this operation using this permission.
RequestId:6dea622e-c002-0050-55ec-fe7944000000
Time:2024-09-04T17:03:14.1971306Z</m:message></m:error>
Stack:   File "C:\Users\<User>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 604, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<User>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 933, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<User>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.11\WINDOWS\X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
    result = function(**args)
             ^^^^^^^^^^^^^^^^
  File "D:\otp-verification-1\function_app.py", line 12, in <functionName>
    import modules.tableStorage
  File "D:\otp-verification-1\modules\tableStorage.py", line 14, in <module>
    properties = table_service_client.get_service_properties()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\otp-verification-1\.venv\Lib\site-packages\azure\core\tracing\decorator.py", line 94, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "D:\otp-verification-1\.venv\Lib\site-packages\azure\data\tables\_table_service_client.py", line 124, in get_service_properties
    _process_table_error(error)
  File "D:\otp-verification-1\.venv\Lib\site-packages\azure\data\tables\_error.py", line 210, in _process_table_error
    raise decoded_error from storage_error
.
[2024-09-04T17:03:12.734Z] Executed HTTP request: {
[2024-09-04T17:03:12.736Z]   "requestId": "2a8a4eb8-ca3a-4b4b-90b7-76bb6aef0554",
[2024-09-04T17:03:12.736Z]   "identities": "",
[2024-09-04T17:03:12.736Z]   "status": "500",
[2024-09-04T17:03:12.737Z]   "duration": "1409"
[2024-09-04T17:03:12.737Z] }
Simple-And-Modern commented 1 week ago

Does this work?

xiangyan99 commented 1 week ago

Thanks for the information.

Per the log:

'Content-Length': '1360'[2024-09-04T17:03:12.426Z] DefaultAzureCredential acquired a token from EnvironmentCredential

Seems like you did get the token successfully using the environment credential?

github-actions[bot] commented 1 week ago

Hi @Simple-And-Modern. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

Simple-And-Modern commented 1 week ago

It's acquiring the token, but it's acquiring on behalf of the user logged in Windows OS, and not on behalf of the service prinicipal, whose credentials are stored in the environment variable(local.settings.json)

My question is why isn't it acquiring the token for service principal?

xiangyan99 commented 1 week ago

EnvironmentCredential only has the ability to get token using the service principal. :)

To narrow down the issue, instead of using DefaultAzureCredential, can you try to use EnvironmentCredential and see if you get same result?

github-actions[bot] commented 1 week ago

Hi @Simple-And-Modern. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

Simple-And-Modern commented 1 week ago

Even after switching to EnvironmentCredential(), the request remains unchanged.

It seems this might not be an SDK issue. We truly appreciate everyone’s help and support so far.

Does anyone know the exact requirements for using the get_service_properties() function in TableServiceClient? Are there specific roles that need to be assigned?

We've already granted:

  1. The Storage Table Data Contributor role to the service principal.
  2. Network access to the storage account from our network.

Any guidance would mean the world to us.

xiangyan99 commented 1 week ago

Thanks for the confirmation.

Please refer https://learn.microsoft.com/en-us/azure/storage/tables/authorize-access-azure-active-directory for the role assignment.

If it does not work, please open ticket at https://azure.microsoft.com/support/create-ticket for service help.