mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-23 22:40:39 +02:00
* azure: authenticate the blob sink with Entra ID Shared account keys have to be distributed and rotated everywhere a sink runs. Leaving account_key empty now falls back to the identity chain, so a workload identity or managed identity carries the authorization instead. * azure: authenticate remote storage with Entra ID The remote storage client demanded an account key and refused to start without one. Fall back to the identity chain when it is absent, and let azure.client_id pin a user-assigned identity. * azure: reject a malformed storage account name The account name is interpolated into the service URL, so a name carrying a "/", "?" or "@" moves the authority elsewhere and an authenticated request follows it. Hold callers to Azure's own naming rule instead. * azure: keep a leftover environment key off the identity path A configured client id asks for Entra ID, but AZURE_STORAGE_ACCESS_KEY still filled in the account key behind it. An old mounted secret would go on authenticating until it rotated, and the failure then blamed the key. * azure: say what the identity path reads from the environment A pinned client id alone is not enough for workload identity: the tenant and the projected token come from the environment, and missing them only surfaces later, when a token is first requested.
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package azure
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewAzBlobClientRequiresAccountName(t *testing.T) {
|
|
if _, err := NewAzBlobClient("", "aW52YWxpZGtleQ==", ""); err == nil {
|
|
t.Error("expected an error without an account name")
|
|
}
|
|
}
|
|
|
|
func TestNewAzBlobClientRejectsMalformedAccountName(t *testing.T) {
|
|
for _, accountName := range []string{"ab", "TestAccount", "test-account", "evil.com/x", "evil@host.com", "account?x=1"} {
|
|
if _, err := NewAzBlobClient(accountName, "", ""); err == nil {
|
|
t.Errorf("expected an error for account name %q", accountName)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNewAzBlobClientSharedKey(t *testing.T) {
|
|
client, err := NewAzBlobClient("testaccount", "aW52YWxpZGtleQ==", "")
|
|
if err != nil {
|
|
t.Fatalf("failed to create a shared key client: %v", err)
|
|
}
|
|
if client == nil {
|
|
t.Error("expected a client")
|
|
}
|
|
}
|
|
|
|
func TestNewAzBlobClientSharedKeyRejectsMalformedKey(t *testing.T) {
|
|
if _, err := NewAzBlobClient("testaccount", "not base64", ""); err == nil {
|
|
t.Error("expected an error with a malformed account key")
|
|
}
|
|
}
|
|
|
|
// no account key: authenticate through the Entra ID chain instead
|
|
func TestNewAzBlobClientEntraID(t *testing.T) {
|
|
client, err := NewAzBlobClient("testaccount", "", "")
|
|
if err != nil {
|
|
t.Fatalf("failed to create an Entra ID client: %v", err)
|
|
}
|
|
if client == nil {
|
|
t.Error("expected a client")
|
|
}
|
|
}
|
|
|
|
func TestNewAzBlobClientWorkloadIdentity(t *testing.T) {
|
|
t.Setenv("AZURE_FEDERATED_TOKEN_FILE", filepath.Join(t.TempDir(), "token"))
|
|
t.Setenv("AZURE_TENANT_ID", "00000000-0000-0000-0000-000000000000")
|
|
|
|
client, err := NewAzBlobClient("testaccount", "", "11111111-1111-1111-1111-111111111111")
|
|
if err != nil {
|
|
t.Fatalf("failed to create a workload identity client: %v", err)
|
|
}
|
|
if client == nil {
|
|
t.Error("expected a client")
|
|
}
|
|
}
|
|
|
|
// a pinned client id without a projected token file is a plain managed identity
|
|
func TestNewAzureTokenCredentialManagedIdentity(t *testing.T) {
|
|
t.Setenv("AZURE_FEDERATED_TOKEN_FILE", "")
|
|
|
|
credential, err := newAzureTokenCredential("11111111-1111-1111-1111-111111111111")
|
|
if err != nil {
|
|
t.Fatalf("failed to create a managed identity credential: %v", err)
|
|
}
|
|
if credential == nil {
|
|
t.Error("expected a credential")
|
|
}
|
|
}
|