gofr-dev/gofr · error

invalid Azure configuration: account key is required

Error message

invalid Azure configuration: account key is required

What it means

azure.New validation also requires Config.AccountKey; if it is empty the constructor returns errAccountKeyRequired — "invalid Azure configuration: account key is required". The account key (shared-key credential) is what authenticates every request to Azure Files, so without it the SDK client cannot be built and the library fails fast at construction time.

Source

Thrown at pkg/gofr/datasource/file/azure/fs.go:14

package azure

import (
	"context"
	"errors"
	"time"

	"gofr.dev/pkg/gofr/datasource/file"
)

var (
	errInvalidConfig       = errors.New("invalid Azure configuration: share name is required")
	errAccountNameRequired = errors.New("invalid Azure configuration: account name is required")
	errAccountKeyRequired  = errors.New("invalid Azure configuration: account key is required")
)

const defaultTimeout = 10 * time.Second

type azureFileSystem struct {
	*file.CommonFileSystem
}

// Config represents the Azure File Storage configuration.
type Config struct {
	AccountName string // Azure Storage Account name
	AccountKey  string // Azure Storage Account key
	ShareName   string // Azure File Share name
	Endpoint    string // Azure Storage endpoint (optional, defaults to core.windows.net)
}

// New creates and validates a new Azure File Storage file system.
// Returns error if configuration is invalid.

View on GitHub (pinned to 187eb24962)

Solutions

  1. Set Config.AccountKey from the storage account's shared key (Azure Portal > Storage account > Access keys).
  2. Verify the secret mount / env injection in the deployment actually populates the value (check for empty string, not just presence).
  3. Consider Managed Identity or SAS tokens instead of account keys to avoid secret-management pitfalls.
  4. Confirm key rotation didn't leave the app with a blank or revoked key.

Example fix

// before
cfg := &Config{ShareName: "files", AccountName: acc} // AccountKey missing
fs := azure.New(cfg)
// after
key := os.Getenv("AZURE_ACCOUNT_KEY")
if key == "" { log.Fatal("AZURE_ACCOUNT_KEY is required") }
cfg := &Config{ShareName: "files", AccountName: acc, AccountKey: key}
fs := azure.New(cfg)
Defensive patterns

Strategy: validation

Validate before calling

if cfg.AccountKey == "" {
    return errors.New("AZURE_ACCOUNT_KEY is required for azure files")
}

Type guard

func hasAccountKey(cfg *azure.Config) bool {
    return cfg != nil && strings.TrimSpace(cfg.AccountKey) != ""
}

Prevention

When it happens

Trigger: Calling azure.New with a Config whose AccountKey == "": the secret not mounted/injected, an empty env var, or a config built with ShareName and AccountName but no key.

Common situations: Kubernetes secret not created or misnamed in the manifest; CI pipeline lacking secret injection; rotating keys in Azure portal and clearing the old value locally; local development .env missing the key entry.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/1ea86a4f15a10494. Report an issue: GitHub.