Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Managed Service Identity does not work from Azure Container Apps #2395

Closed
jirikopecky opened this issue Apr 21, 2023 · 7 comments
Closed

Managed Service Identity does not work from Azure Container Apps #2395

jirikopecky opened this issue Apr 21, 2023 · 7 comments
Labels
impact/usability Something that impacts users' ability to use the product easily and intuitively kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed

Comments

@jirikopecky
Copy link

jirikopecky commented Apr 21, 2023

What happened?

We have an application that manages Azure resources using Pulumi Automation API. This application is written in .NET and deployed as Azure Container App with Pulumi CLI installed in the container. We wanted to migrate away from using Service Principal to use MSI for authentication agains Azure. This was attempted by setting ARM_USE_MSI to true in the container environment (and of course creating user-assigned MSI with relevant permissions assigned and associating it with the container app).

While attempting to run Up on the stack we received following error:

Provider[azure-native, 0xc000ba4690].Configure() failed: err=please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.

Expected Behavior

Pulumi uses configured managed identity to manage Azure resources

Steps to reproduce

  1. Create app that uses Pulumi Automation API to manage Azure resources with azure-native (we used version 1.100.1)
  2. Create container image with this app and Pulumi CLI installed
  3. Deploy to Azure as Container App with MSI configured and ARM_USE_MSI environment variable set to true
  4. Invoke the app and see it fail

Output of pulumi about

CLI
Version      3.64.0
Go Version   go1.20.3
Go Compiler  gc

Host
OS       debian
Version  11.6
Arch     x86_64

Pulumi locates its logs in /tmp by default
warning: Failed to read project: no Pulumi.yaml project file found (searching upwards from /). If you have not created a project yet, use `pulumi new` to do so: no project file found

There is no project since the app uses Automation API to create workspaces on-the-fly.

Additional context

I was able to capture following log from the provider:

I0421 09:14:33.372403     304 log.go:75] 2023/04/21 09:14:33 Testing if Service Principal / Client Certificate is applicable for Authentication..
I0421 09:14:33.372409     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Testing if Service Principal / Client Certificate is applicable for Authentication..<{%reset%}>)
I0421 09:14:33.372620     304 log.go:75] 2023/04/21 09:14:33 Testing if Multi Tenant Service Principal / Client Secret is applicable for Authentication..
I0421 09:14:33.372626     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Testing if Multi Tenant Service Principal / Client Secret is applicable for Authentication..<{%reset%}>)
I0421 09:14:33.372867     304 log.go:75] 2023/04/21 09:14:33 Testing if Service Principal / Client Secret is applicable for Authentication..
I0421 09:14:33.372875     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Testing if Service Principal / Client Secret is applicable for Authentication..<{%reset%}>)
I0421 09:14:33.373091     304 log.go:75] 2023/04/21 09:14:33 Testing if OIDC is applicable for Authentication..
I0421 09:14:33.373094     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Testing if OIDC is applicable for Authentication..<{%reset%}>)
I0421 09:14:33.373352     304 log.go:75] 2023/04/21 09:14:33 Testing if Managed Service Identity is applicable for Authentication..
I0421 09:14:33.373358     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Testing if Managed Service Identity is applicable for Authentication..<{%reset%}>)
I0421 09:14:33.373544     304 log.go:75] 2023/04/21 09:14:33 Testing if Obtaining a Multi-tenant token from the Azure CLI is applicable for Authentication..
I0421 09:14:33.373553     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Testing if Obtaining a Multi-tenant token from the Azure CLI is applicable for Authentication..<{%reset%}>)
I0421 09:14:33.373704     304 log.go:75] 2023/04/21 09:14:33 Testing if Obtaining a token from the Azure CLI is applicable for Authentication..
I0421 09:14:33.373710     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Testing if Obtaining a token from the Azure CLI is applicable for Authentication..<{%reset%}>)
I0421 09:14:33.373968     304 log.go:75] 2023/04/21 09:14:33 Using Obtaining a token from the Azure CLI for Authentication
I0421 09:14:33.373973     304 log.go:75] eventSink::Debug(<{%reset%}>2023/04/21 09:14:33 Using Obtaining a token from the Azure CLI for Authentication<{%reset%}>)
I0421 09:14:33.374217     304 log.go:75] Provider[azure-native, 0xc000ba4690].Configure() failed: err=please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH.

Looking at hashicorp/go-azure-helpers source I found following snippet. Mentioned environment variables are set within the Container App environment.

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@jirikopecky jirikopecky added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Apr 21, 2023
@rquitales
Copy link
Member

@jirikopecky Thanks for the detailed issue description and logs and I apologize for this issue that you're running into. Looking into hashicorp/go-azure-helpers and the code snippet you provided, it appears that in order for MSI to be used as an authentication method, MSI_ENDPOINT and MSI_SECRET must be unset/empty as they specifically mention:
if the Endpoint and Sender are present this is App Service/Function Apps which we intentionally don't support at this time .

Having these 2 env variables set would result in the MSI authentication mode to be marked as not applicable, and skipped as an auth method.

Could you try to unset these 2 variables in your container and see if it resolves your issue?

@rquitales rquitales added impact/usability Something that impacts users' ability to use the product easily and intuitively awaiting-feedback Blocked on input from the author and removed needs-triage Needs attention from the triage team labels Apr 24, 2023
@jirikopecky
Copy link
Author

These environment variables are set automatically by Azure Container Apps runtime and as such are out of our control, so we cannot unset them.

@michal-bajer1
Copy link

Has there been any progress on this? Unsetting these variables also doesn't work, because then the library can't find the correct MSI endpoint.
I also tried creating workaround using az login --identity, but that is also blocked, because CLI login can only be used by User, not service principal.

@sureshgarre
Copy link

Is there any progress on this please? We are currently facing this issue when trying to run pulumi code within an Azure container app which authenticates to Azure using managed identity (MSI).

@mikhailshilkov mikhailshilkov removed the awaiting-feedback Blocked on input from the author label Aug 26, 2023
@JontyMC
Copy link

JontyMC commented Oct 25, 2023

+1

@thomas11
Copy link
Contributor

thomas11 commented Nov 7, 2024

The new v2.70 release should fix this as it introduces a new authentication backend with support for various variants of MSI such as Service Fabric, App Service, Arc, Azure ML, and Cloud Shell. You can see all the details in the package source.

The new authentication backend is behind a feature toggle for the time being. Set environment variable PULUMI_ENABLE_AZCORE_BACKEND to "true" to use it. Please report back any issues you may be encountering.

As I don't have a working repro for this issue, I couldn't verify that the new backend fixes it, but I think it will.

@thomas11 thomas11 added the resolution/fixed This issue was fixed label Nov 7, 2024
@thomas11
Copy link
Contributor

thomas11 commented Nov 7, 2024

I'll optimistically close this issue but feel free to re-open if you still face issues.

@thomas11 thomas11 closed this as completed Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/usability Something that impacts users' ability to use the product easily and intuitively kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

No branches or pull requests

7 participants