JuliusBrussee/caveman · error
kms: auth token is required
Error message
kms: auth token is required
What it means
New validates the Scaleway KMS client configuration and requires a non-trivial auth token. strings.TrimSpace(cfg.AuthToken) must be at least 20 characters; anything shorter (including empty or whitespace) yields this error before any network activity.
Solutions
- Set the auth token in Config.AuthToken (or the corresponding environment variable) to the full Scaleway secret key
- Verify the secret key is complete (Scaleway keys are longer than 20 chars); re-copy from the Scaleway console
- Check that your env loading (dotenv, CI secrets) actually populates the variable before kms.New runs
Example fix
// before
client, err := kms.New(ctx, kms.Config{AuthToken: os.Getenv("TOKEN")}) // TOKEN empty
// after
if os.Getenv("TOKEN") == "" { return errors.New("TOKEN not set") }
client, err := kms.New(ctx, kms.Config{AuthToken: os.Getenv("TOKEN")}) Defensive patterns
Strategy: validation
Validate before calling
token := strings.TrimSpace(os.Getenv("SCALEWAY_SECRET_KEY"))
if len(token) < 20 {
return fmt.Errorf("SCALEWAY_SECRET_KEY missing or truncated (len=%d)", len(token))
} Prevention
- Fail fast at startup with an explicit env-var presence check
- Never trim or truncate secret keys when copying them
- Load .env / CI secrets before client construction and log which vars are set (not their values)
When it happens
Trigger: Constructing kms.New with Config.AuthToken empty, unset, whitespace-only, or a placeholder/short value — typically from fromEnvironment when SCALEWAY_SECRET_KEY (or equivalent env var) is missing or truncated.
Common situations: Missing KMS auth env var in CI or production, a .env file not loaded, an expired/rotated secret replaced with a truncated string, or copying a key with only part of it pasted.
Related errors
- bedrock: invalid API key
- kms: create request
- kms: invalid API base URL
- kms: invalid Scaleway key ID
- kms: invalid Scaleway region
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/799a52bdd7e1bb19.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/kms/kms.go:94
provider := strings.ToLower(strings.TrimSpace(cfg.Provider))
if provider != ProviderScaleway {
return nil, fmt.Errorf("kms: unsupported provider %q", provider)
}
region, keyID := strings.TrimSpace(cfg.Region), strings.TrimSpace(cfg.KeyID)
if err := validateLocation(region, keyID); err != nil {
return nil, err
}
decryptKeyIDs := map[string]struct{}{keyID: {}}
for _, allowedKeyID := range cfg.AllowedDecryptKeyIDs {
allowedKeyID = strings.TrimSpace(allowedKeyID)
if err := validateLocation(region, allowedKeyID); err != nil {
return nil, err
}
decryptKeyIDs[allowedKeyID] = struct{}{}
}
token := strings.TrimSpace(cfg.AuthToken)
if len(token) < 20 {
return nil, errors.New("kms: auth token is required")
}
baseURL := strings.TrimRight(strings.TrimSpace(cfg.APIBaseURL), "/")
if baseURL == "" {
baseURL = scalewayAPI
}
parsed, err := url.Parse(baseURL)
if err != nil || parsed.Scheme == "" || parsed.Host == "" || parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" {
return nil, errors.New("kms: invalid API base URL")
}
client := cfg.HTTPClient
if client == nil {
client = &http.Client{
Timeout: 8 * time.Second,
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
}
}View on GitHub (pinned to 3ee70a1026)