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

App service support for MI #537

Open
wants to merge 20 commits into
base: andyohart/managed-identity
Choose a base branch
from

Conversation

4gust
Copy link
Collaborator

@4gust 4gust commented Nov 28, 2024

Added support for App service
Added support for logging in Managed Identity

@4gust 4gust marked this pull request as ready for review November 28, 2024 14:38
@4gust 4gust requested review from chlowell and bgavrilMS and removed request for rayluo and bgavrilMS November 28, 2024 14:38
Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comments.

Copy link
Collaborator

@chlowell chlowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blockers are:

  • query parameter names (docs)
  • returned token expiration time is always 0
  • fake token responses in tests don't resemble actual responses

Expiration time is always 0 because App Service responses include only expires_on (docs) and MSAL unmarshals only expires_in, using a custom UnmarshalJSON to convert that duration to an instant. Unit tests pass despite this because their fake responses always include expires_in

apps/managedidentity/managedidentity.go Outdated Show resolved Hide resolved
@@ -377,8 +394,7 @@ func (c Client) retry(maxRetries int, req *http.Request) (*http.Response, error)
var resp *http.Response
var err error
for attempt := 0; attempt < maxRetries; attempt++ {
tryCtx, tryCancel := context.WithTimeout(req.Context(), time.Second*15)
defer tryCancel()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the problem with deferring this?

case UserAssignedResourceID:
q.Set(miQueryParameterResourceId, string(t))
case UserAssignedObjectID:
q.Set(miQueryParameterObjectId, string(t))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
q.Set(miQueryParameterObjectId, string(t))
q.Set("principal_id", string(t))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this in .net or other msal's
Is this changed for App service only?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it appears I'm out of date on this point, as the docs now state the API will accept object_id as an alias for principal_id. 🤷 I'd still make this change because Azure SDK uses, and tests, principal_id, and these docs have been incorrect before (i.e. if you want to keep using object_id, make sure you test it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with object_id and it worked, would you recommend that I also test with principal_id?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should run live tests before merging in any case

apps/managedidentity/managedidentity.go Outdated Show resolved Hide resolved
apps/managedidentity/managedidentity.go Outdated Show resolved Hide resolved
apps/managedidentity/managedidentity_test.go Outdated Show resolved Hide resolved
Updated the resource Id parameter for every source except IMDS
apps/managedidentity/managedidentity_test.go Show resolved Hide resolved
apps/internal/oauth/ops/accesstokens/tokens.go Outdated Show resolved Hide resolved
apps/internal/oauth/ops/accesstokens/tokens.go Outdated Show resolved Hide resolved
apps/internal/oauth/ops/accesstokens/tokens.go Outdated Show resolved Hide resolved
4gust added 2 commits January 3, 2025 10:01
Added support for expires_in
different time formats for expire_in
support for principle_id for app service in managed identity
apps/internal/json/types/time/time.go Outdated Show resolved Hide resolved
apps/internal/oauth/ops/accesstokens/tokens.go Outdated Show resolved Hide resolved
}

// Function to parse different date formats
parseExpiresOn := func(expiresOn string) (time.Time, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add a comment pointing at AzureAD/microsoft-authentication-library-for-dotnet#4963 to explain when this can occur.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm overlooking it, but that issue doesn't mention the platform returning the unsupported format

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CX who reported this didn't make it very clear, it seems to be container + App Service.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to know what the linked PR added support for so that support is easier to maintain. Setting that aside, the linked PR added ISO 8601 parsing. Why does this PR have two additional formats?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We asked, the CX didn't answer. Ultimately, Azure SDK for .NET did not have this problem so it was clearly a regression.

Not objecting to supporting only ISO 8601. The .NET code uses a general-purpose DateTime parser btw https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/pull/4964/files#diff-a7d2338916806e48fb637fd9caad6095fec8537a96d157bc2ea47ab64903fef9R93

I assume Azure.SDK for .NET did the same.

@AndyOHart AndyOHart self-requested a review January 9, 2025 15:44
Copy link
Collaborator

@AndyOHart AndyOHart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants