{"record":{"id":"126d91fd4e7d31fc","repo":"grafana/k6","slug":"sigv4-config-region-awsaccesskeyid-awssecre","errorCode":null,"errorMessage":"sigV4 config `Region`, `AwsAccessKeyID`, `AwsSecretAccessKey` must all be set","messagePattern":"sigV4 config `Region`, `AwsAccessKeyID`, `AwsSecretAccessKey` must all be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/output/prometheusrw/sigv4/tripper.go","lineNumber":31,"sourceCode":"\tnext   http.RoundTripper\n}\n\n// Config holds aws access configurations\ntype Config struct {\n\tRegion             string\n\tAwsAccessKeyID     string\n\tAwsSecretAccessKey string\n}\n\nfunc (c *Config) validate() error {\n\tif c == nil {\n\t\treturn errors.New(\"config should not be nil\")\n\t}\n\thasRegion := len(strings.TrimSpace(c.Region)) != 0\n\thasAccessID := len(strings.TrimSpace(c.AwsAccessKeyID)) != 0\n\thasSecretAccessKey := len(strings.TrimSpace(c.AwsSecretAccessKey)) != 0\n\tif !hasRegion || !hasAccessID || !hasSecretAccessKey {\n\t\treturn errors.New(\"sigV4 config `Region`, `AwsAccessKeyID`, `AwsSecretAccessKey` must all be set\")\n\t}\n\treturn nil\n}\n\n// NewRoundTripper creates a new sigv4 round tripper\nfunc NewRoundTripper(config *Config, next http.RoundTripper) (*Tripper, error) {\n\tif err := config.validate(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif next == nil {\n\t\tnext = http.DefaultTransport\n\t}\n\n\ttripper := &Tripper{\n\t\tconfig: config,\n\t\tnext:   next,\n\t\tsigner: newDefaultSigner(config),","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/output/prometheusrw/sigv4/tripper.go#L13-L49","documentation":"This is the second, stricter sigv4 check inside the signing round tripper itself (internal/output/prometheusrw/sigv4/tripper.go). Config.validate() requires Region, AwsAccessKeyID and AwsSecretAccessKey to be non-empty after whitespace trimming. It fires when a sigv4.Config reaches NewRoundTripper with a blank or whitespace-only field — including values that passed the earlier env-var presence check in remotewrite/config.go.","triggerScenarios":"All three K6_PROMETHEUS_RW_SIGV4_* variables are exported but one is empty or contains only spaces (e.g. `export K6_PROMETHEUS_RW_SIGV4_REGION=\" \"` or `=\"\"`), so each null.String is Valid and the partial-config check passes, but the trimmed length is zero. Also hits Go code that calls sigv4.NewRoundTripper directly with a hand-built *Config missing a field, or passes a nil config (separate 'config should not be nil' error).","commonSituations":"CI secrets masked to empty strings when the vault lookup fails silently; `.env` files with `KEY=` lines; shell scripts that set variables conditionally and leave one blank; embedding k6 as a library and constructing sigv4.Config without all three fields.","solutions":["Give every one of the three sigv4 settings a non-empty, non-whitespace value","Run `env | grep SIGV4` and re-export any variable that prints empty or padded","Unset all three variables if sigv4 is not actually required","If calling NewRoundTripper from Go, populate Region, AwsAccessKeyID and AwsSecretAccessKey and check the returned error before use"],"exampleFix":"# before\nK6_PROMETHEUS_RW_SIGV4_REGION=\"\"\nK6_PROMETHEUS_RW_SIGV4_ACCESS_KEY=AKIA...\nK6_PROMETHEUS_RW_SIGV4_SECRET_KEY=...\n\n# after\nK6_PROMETHEUS_RW_SIGV4_REGION=us-east-1\nK6_PROMETHEUS_RW_SIGV4_ACCESS_KEY=AKIA...\nK6_PROMETHEUS_RW_SIGV4_SECRET_KEY=...","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\nset -eu\nfor v in K6_PROMETHEUS_RW_SIGV4_REGION K6_PROMETHEUS_RW_SIGV4_ACCESS_KEY K6_PROMETHEUS_RW_SIGV4_SECRET_KEY; do\n  val=\"${!v:-}\"\n  if [ -n \"$val\" ] && [ -z \"$(echo \"$val\" | tr -d '[:space:]')\" ]; then\n    echo \"$v is set but whitespace-only\" >&2; exit 1\n  fi\ndone\n# Go embedders:\n// if strings.TrimSpace(cfg.Region) == \"\" || strings.TrimSpace(cfg.AwsAccessKeyID) == \"\" || strings.TrimSpace(cfg.AwsSecretAccessKey) == \"\" { return fmt.Errorf(\"sigv4 config incomplete\") }\n// if _, err := sigv4.NewRoundTripper(cfg, nil); err != nil { return err }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat empty-string secret values in CI masks as failures, not defaults","In Go code, always check the error returned by sigv4.NewRoundTripper before using the Tripper","Trim and assert non-empty on all three fields before building the round tripper"],"tags":["prometheus","remote-write","aws","sigv4","configuration","whitespace"],"backgroundTag":"incomplete-environment-variables","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}