0

我有一个完全工作的 python 脚本,它连接到一个密钥库,从中检索一些秘密并使用这些秘密来执行一些备份。不用说,这段代码在本地工作得很好:

import datetime
import logging

import azure.functions as func
from typing import Container
from azure.cosmosdb.table.tableservice import TableService,ListGenerator
from azure.storage.blob import BlobClient, BlobServiceClient, ContainerClient
from azure.storage.blob import ResourceTypes, AccountSasPermissions
from azure.storage.blob import generate_account_sas    
from datetime import date, timedelta
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential

def main(mytimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    if mytimer.past_due:
        logging.info('The timer is past due!')

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

    today = str(date.today().strftime("%Y%m%d"))
    print(today)
    keyvault_name = f'url'
    KeyVaultName = "name"
    credential = DefaultAzureCredential()
    client_keyvault = SecretClient(vault_url=keyvault_name, credential=credential)

脚本选择正确的凭据并开始移动容器作为备份。

我面临的问题是在将此逻辑移至 azure 函数后开始的。当代码触发时,我收到以下错误

Result: Failure Exception: ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials. Attempted credentials: EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found. SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. VisualStudioCodeCredential: Failed to get Azure user details from Visual Studio Code. AzureCliCredential: Azure CLI not found on path AzurePowerShellCredential: PowerShell is not installed Stack

我了解 azure 函数正在寻找凭据进行身份验证,但我认为此身份验证(在 azure 函数中)在我通过身份验证时会自动发生。

请帮助解决和理解这个问题?

如果您需要更多信息,请随时询问

4

1 回答 1

0

问题已解决,我必须激活ManageIdentity

于 2021-10-11T12:59:49.727 回答