Skip to content

Can't use get_managed_token for system assigned MI or user assigned MI within App Service, error 404 #75

@dmuijen

Description

@dmuijen

Hello,

Using a system or user assigned identity in combination with get_managed_token gives a 404 error. Could not get the function working from within an app service running a Shiny app using a managed identity to access a storage account. AzureAuth seems to make the wrong API call at and endpoint /MSI/token/token that does not exist and hence returns 404 since it should be http://{endpoint}/MSI/token. From within a VM for local development obtaining a token using managed identity using AzureAuth works as expected.

Current workaround for the app service is to create the API call manually instead of using AzureAuth for a system assigned MI reading data from a storage account in a Shiny app hosted in App Services.

library(httr)
library(AzureStor)

# Fetch / set variables for API call within app service running Shiny app running on Shiny server
api_version <- "2019-08-01" ## Might work with newer versions as well
mi_endpoint <- Sys.getenv("MSI_ENDPOINT")
mi_secret <- Sys.getenv("MSI_SECRET")
resource <- "https://storage.azure.com"
storage_account <- "https://<storageaccountname>.blob.core.windows.net"
container_name <- "mycontainer"
headers <- c(
`X-IDENTITY-HEADER` = mi_secret
)

## Fetch managed identity token
res <- GET(url = paste0(mi_endpoint, '?resource=', resource, "&api-version=", api_version), add_headers(.headers=headers))
mi_token <- content(res)$access_token

## Connect to storage account using MI
ad = storage_endpoint(storage_account, token = mi_token)
cont = storage_container(ad, container_name) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions