{"record":{"id":"a8fa8c222c4f2f1c","repo":"JuliusBrussee/caveman","slug":"awssig-incomplete-aws-credentials","errorCode":null,"errorMessage":"awssig: incomplete AWS credentials","messagePattern":"awssig: incomplete AWS credentials","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/awssig/awssig.go","lineNumber":71,"sourceCode":"}\n\n// Sign computes the SigV4 signature for req against the given payload and sets\n// the Authorization, X-Amz-Date, X-Amz-Content-Sha256 (and, when present,\n// X-Amz-Security-Token) headers on req. The Host header is derived from req.URL.\n//\n// payloadHash is the lowercase hex SHA-256 of the request body; pass\n// HashPayload(body) for the common case, or UnsignedPayload() for streaming\n// bodies that must not be buffered. now fixes the signing instant (use\n// time.Now().UTC()); it is a parameter so tests are deterministic.\n//\n// Sign returns an error only for malformed inputs (no region/service, missing\n// credentials, unparseable URL). It never returns the secret in the error.\nfunc (s Signer) Sign(req *http.Request, creds Credentials, payloadHash string, now time.Time) error {\n\tif s.Region == \"\" || s.Service == \"\" {\n\t\treturn fmt.Errorf(\"awssig: signer requires region and service\")\n\t}\n\tif !creds.Valid() {\n\t\treturn fmt.Errorf(\"awssig: incomplete AWS credentials\")\n\t}\n\tif req.URL == nil {\n\t\treturn fmt.Errorf(\"awssig: request has no URL\")\n\t}\n\tnow = now.UTC()\n\tamzDate := now.Format(\"20060102T150405Z\")\n\tdateStamp := now.Format(\"20060102\")\n\n\thost := req.URL.Host\n\tif req.Host != \"\" {\n\t\thost = req.Host\n\t}\n\treq.Header.Set(\"Host\", host)\n\treq.Header.Set(\"X-Amz-Date\", amzDate)\n\treq.Header.Set(\"X-Amz-Content-Sha256\", payloadHash)\n\tif creds.SessionToken != \"\" {\n\t\treq.Header.Set(\"X-Amz-Security-Token\", creds.SessionToken)\n\t}","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/awssig/awssig.go#L53-L89","documentation":"Signer.Sign calls creds.Valid() and rejects signing when the Credentials are incomplete (empty access key ID, secret, or other required fields per Valid()). This prevents producing signatures with zero-valued material. Per the library docs, the error never includes the secret.","triggerScenarios":"Calling Sign with awssig.Credentials{} or one where AccessKeyID/SecretAccessKey (or SessionToken when required by Valid) is empty; credentials loaded from awscreds failed silently upstream and zero values were passed through.","commonSituations":"Environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY unset; a failed metadata credential fetch whose empty result was used anyway; struct literal initialization missing fields.","solutions":["Call creds.Valid() yourself before Sign to get an earlier, clearer failure point and log which field is missing (without printing secrets).","Ensure the credentials were actually loaded: check AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (and session token) are populated.","Check the awscreds Provider error path: if Credentials(ctx) returned an error, don't proceed with its zero-value result.","Fix struct construction so all credential fields are assigned."],"exampleFix":"// before\nerr := signer.Sign(req, creds, payloadHash, now) // creds partially populated\n// after\nif !creds.Valid() {\n    return errors.New(\"refusing to sign: credentials not loaded\")\n}\nerr := signer.Sign(req, creds, payloadHash, now)","handlingStrategy":"validation","validationCode":"if !creds.Valid() {\n    return errors.New(\"cannot sign: AWS credentials not loaded (check AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY or metadata provider)\")\n}","typeGuard":null,"tryCatchPattern":"if err := signer.Sign(req, creds, hash, now); err != nil {\n    if strings.Contains(err.Error(), \"incomplete AWS credentials\") {\n        return fmt.Errorf(\"credential load failed upstream: %w\", err)\n    }\n    return err\n}","preventionTips":["Never use the zero-value Credentials struct; load credentials through the awscreds Provider and propagate its errors.","Call creds.Valid() before every Sign call in wrappers.","Never log credentials when diagnosing; check only presence/non-empty."],"tags":["aws","sigv4","credentials","validation"],"backgroundTag":"missing-credentials","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}