-
Notifications
You must be signed in to change notification settings - Fork 838
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
Successfully Authenticate AzureChina with an Azure Public Credential #18508
Comments
Authentication happens in the credential's import "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
// normally you don't need to think about this, because
// Azure SDK clients call GetToken automatically as needed
tokenOptions := policy.TokenRequestOptions{
Scopes: []string{"https://management.core.chinacloudapi.cn//.default",
}
tk, err := cred.GetToken(ctx, tokenOptions)
if err != nil {
// client IDs and secrets are validated by Azure AD.
// If they're incorrect, you'll land here.
} |
Thanks for the quick reply. Yes, after adding the code above, I got the error stating the application cannot be found However, In my original code I could use the new created
|
Clients are similar to credentials in that they don't attempt to authenticate until necessary. You won't get an error about your invalid service principal configuration until you call a method that sends a request to the service (methods that do this have a |
I also try the method that have Context parameter (e.g. `var selectFilter string = "eventTimestamp,operationName,resourceId,resourceType,resourceGroupName,status,level,category"
|
I also try VirualMachinesClient which has method with Context parameter directly (e.g vmClient.Get). The same behavior that Azure public resources returned but not error returned ` if err != nil {
} |
Sounds like you have the credential and client configured for the public cloud (which is the default). Can you share more of the code you're running, showing credential and client construction? |
Hi, here are most of my sample code without credential details. currentSubscription is subscription under an Azure Public tenant `credential_options := &azidentity.ClientSecretCredentialOptions{ClientOptions: policy.ClientOptions{Cloud: cloud.AzureChina}}
|
Like the credential, client configuration defaults to public cloud. They need explicit configuration for Azure China. The API is the same for all clients, so you can reuse cloud options like this: import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
)
+++clientOpts := policy.ClientOptions{Cloud: cloud.AzureChina}
+++credential_options := &azidentity.ClientSecretCredentialOptions{ClientOptions: clientOpts}
cred, err := azidentity.NewClientSecretCredential(
tenant_id_auzre_public,
client_id_auzre_public,
client_secret_auzre_public,
credential_options)
...
+++armOpts := &arm.ClientOptions{ClientOptions: clientOpts}
+++vmClient, err := armcompute.NewVirtualMachinesClient(currentSubscription, cred, armOpts)
...
+++alClient, err := armmonitor.NewActivityLogsClient(currentSubscription, cred, armOpts) As for why authentication succeeds, that's because the credential doesn't simply send requests to Azure China, which would respond with an error because the tenant and client IDs are invalid so far as it's concerned. When a client first requests a token, the credential asks Azure AD where to send token requests for your tenant. The credential then requests tokens from a public cloud endpoint, which works because the client ID and secret are valid for that (public cloud) tenant. The credential can't get a token for Azure China, but that's okay because your clients are configured (by default) for the public cloud. Similarly, your client calls succeed because |
Thanks a lot for your investigation. |
azure-sdk-for-go/sdk/azidentity/client_secret_credential.go
Line 33 in e1d15b6
I try to authenticate Azure_China with an Azure_Public credential. I expect authentication errors returned, but no error returns and authentication succeeded as if the authentication endpoint was Azure_Public
The text was updated successfully, but these errors were encountered: