Skip to content

keyvault: Providing a subscription generates a tenant, conflicts with CLI authentication method #25758

@lbordowitz

Description

@lbordowitz

Bug Report

Using the following packages (from go.mod):

go 1.25.0

require (
	github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1
	github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.4.0
)

I run the following code:

package main

import (
	"context"
	"fmt"

	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys"
)

func main() {
	ctx := context.Background()

	vaultURL := "https://my-vault.vault.azure.net/"
	vaultKey := "my-key"

	credential, _ := azidentity.NewAzureCLICredential(&azidentity.AzureCLICredentialOptions{
		Subscription: "xxxxxxxxxxx",
		TenantID:     "",
	})
	client, _ := azkeys.NewClient(vaultURL, credential, nil)

	keyInfo, err := client.GetKey(ctx, vaultKey, "", nil)
	if err != nil {
		fmt.Printf("get key err: %+v", err)
		return
	}
	fmt.Printf("key info: %+v\n", *keyInfo.Key.KID)
}

I've provided a SubscriptionID but no tenant. In fact, I've explicitly excluded a tenant. However, when I run this, I get the following error message:

get key err: AzureCLICredential: ERROR: Please specify only one of subscription and tenant, not both

What appears to be going on is that deep inside the internal keyvault code, the client helpfully parses and includes the tenant from the request as part of the TokenRequestOptions. Those are passed through as opts.TenantId which subsequently sets both tenant and subscription in the CLI command

For reference, I am an OpenTofu developer working on an issue (opentofu/opentofu#3520) which deals with how key encryption specifically does not handle this appropriately, especially in conjunction with azurerm provider. That provider uses Hashicorp's go-azure-sdk, which has logic to prevent setting both tenant and subscription simultaneously. The ideal solution would be incorporating similar logic in azure_cli_credential.go.

Metadata

Metadata

Assignees

Labels

Azure.IdentitybugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

Type

Projects

Status

Untriaged

Status

Untriaged

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions