0

I have a fully working python script that connects to a key vault, retrieve some secrets from them and use those secrets to perform some backup. Goes without saying that locally this code works just fine:

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)

The scripts picks up the correct credentials and start moving the containers as backup.

The problem I am facing started after moving this logic to azure function. When the code triggers, I am getting the following error

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

I understand that the azure function is looking for credentials to authenticate, but I though that this authentication( in azure function) happens automatically as I am authenticated.

Any help to solve and understand this issue please?

And if you need more info, please don't hesitate to ask

Nayden Van
  • 1,133
  • 1
  • 23
  • 70

1 Answers1

0

Issue solved, I had to activate the ManageIdentity

Nayden Van
  • 1,133
  • 1
  • 23
  • 70