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

Cannot use azure.PublicCloud.KeyVaultEndpoint as an OAuth resource #697

Closed
chessman opened this issue Jul 26, 2017 · 8 comments
Closed

Cannot use azure.PublicCloud.KeyVaultEndpoint as an OAuth resource #697

chessman opened this issue Jul 26, 2017 · 8 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved.

Comments

@chessman
Copy link

azure.PublicCloud.KeyVaultEndpoint has a trailing slash. If I get authorizer with this resource, key vault client fails. But it works with https://vault.azure.net.

I think, it should be tolerant to trailing slashes.

Reproduction is here: https://github.com/chessman/azure-kv-slash-bug.

@salameer
Copy link
Member

Thanks again @chessman, @jhendrixMSFT will be looking into this

@salameer salameer added Sprint-104 bug This issue requires a change to an existing behavior in the product in order to be resolved. labels Jul 27, 2017
@marstr
Copy link
Member

marstr commented Jul 28, 2017

Some additional context from a conversation I had with @devigned last night:

The formatting of this string is getting in the way because we are needing to authenticate against a Resource ID, which happens to look like the KeyVault endpoint, but could be any arbitrary string. For that reason, whether or not the slash is included is important information to send over the wire. As per this bug, we seem to be choosing poorly for KeyVault. To make matters somewhat more confusing, other resource IDs seem to match their endpoints.

One thing that should help out this situation is that the 401 that is returned should tell us exactly how to respond.

Now that still leaves us a couple of action items we could pursue here:

  • Expose Resource IDs in addition to Endpoints.
  • Update our Retry logic to respond to 401s in a manner that corrects for these sorts of mistakes.

@jhendrixMSFT
Copy link
Member

This has been resolved in PR Azure/go-autorest#156, with this new functionality you can write the following authenticator.

	kv := keyvault.New()

	auth := autorest.NewBearerAuthorizerCallback(kv.Sender, func(tenantID, resource string) (*autorest.BearerAuthorizer, error) {
		oauthConfig, err := adal.NewOAuthConfig(azure.PublicCloud.ActiveDirectoryEndpoint, tenantID)
		if err != nil {
			return nil, err
		}

		spt, err := adal.NewServicePrincipalToken(*oauthConfig, clientID, "secret", resource)
		if err != nil {
			return nil, err
		}

		return autorest.NewBearerAuthorizer(spt), nil
	})

	kv.Authorizer = auth

@yangl900
Copy link

yangl900 commented Mar 7, 2019

I see this issue has been closed and it will work. However I think the fix rely on client sending a request and get 401 response, then correct the resource string. Why don't we just fix the KV resource string?

KeyVaultEndpoint: "https://vault.azure.net/",

https://github.com/Azure/go-autorest/blob/1f7cd6cfe0adea687ad44a512dfe76140f804318/autorest/azure/environments.go#L70

@jhendrixMSFT
Copy link
Member

@yangl900 KeyVaultEndpoint is the URL endpoint, not the resource ID. Sadly they are almost identical which is what made this confusing (and even more confusing, for some RPs the endpoint and resource ID are identical). Removing the trailing '/' would likely break a lot of other code so we can't do that.

@yangl900
Copy link

yangl900 commented Mar 7, 2019

Possible we define separate KeyVaultResourceUri in the SDK? I would be good if we can avoid making 401s. I understand each service may have different authentication logic, some cares about the trailing slash and some doesn't. But I'm hoping for the core Azure services, we just make it right for user.

@jhendrixMSFT
Copy link
Member

We could do that, please open an issue in this repo to track that (and of course we accept PRs too :)).

@karataliu
Copy link

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved.
Projects
None yet
Development

No branches or pull requests

6 participants