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.
Solutions
- Set Config.AccountKey from the storage account's shared key (Azure Portal > Storage account > Access keys).
- Verify the secret mount / env injection in the deployment actually populates the value (check for empty string, not just presence).
- Consider Managed Identity or SAS tokens instead of account keys to avoid secret-management pitfalls.
- 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
- Verify secret mounts actually populate the env var (log length, never the value).
- Prefer Managed Identity or SAS tokens to reduce key-management failures.
- Track key rotation and update deployed secrets atomically.
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
- azure config is nil
- invalid Azure configuration: account name is required
- invalid Azure configuration: share name is required
- both username and password must be provided
- burst must be positive
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/1ea86a4f15a10494.
Report an issue: GitHub.
Appendix: 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)