{"record":{"id":"a0fceaaafdd8df9e","repo":"moodle/moodle","slug":"unexpected-container-metadata-credentials-value","errorCode":null,"errorMessage":"Unexpected container metadata credentials value","messagePattern":"Unexpected container metadata credentials value","errorType":"exception","errorClass":"CredentialsException","httpStatus":null,"severity":"error","filePath":"public/lib/aws-sdk/src/Credentials/EcsCredentialProvider.php","lineNumber":229,"sourceCode":"        if (empty($credsUri)){\n            $credFullUri = getenv(self::ENV_FULL_URI);\n            if ($credFullUri === false){\n                $credFullUri = $_SERVER[self::ENV_FULL_URI] ?? '';\n            }\n\n            if (!empty($credFullUri))\n                return $credFullUri;\n        }\n\n        return self::SERVER_URI . $credsUri;\n    }\n\n    private function decodeResult($response)\n    {\n        $result = json_decode($response, true);\n\n        if (!isset($result['AccessKeyId'])) {\n            throw new CredentialsException('Unexpected container metadata credentials value');\n        }\n        return $result;\n    }\n\n    /**\n     * Determines whether or not a given request URI is a valid\n     * container credential request URI.\n     *\n     * @param $uri\n     *\n     * @return bool\n     */\n    private function isCompatibleUri($uri)\n    {\n        $parsed = parse_url($uri);\n\n        if ($parsed['scheme'] !== 'https') {\n            $host = trim($parsed['host'], '[]');","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/aws-sdk/src/Credentials/EcsCredentialProvider.php#L211-L247","documentation":"The metadata endpoint responded, but its body did not decode to a JSON object containing an AccessKeyId. decodeResult() json_decodes the response body and throws this CredentialsException when 'AccessKeyId' is absent — meaning the response is not valid ECS container-credentials JSON.","triggerScenarios":"__invoke receives an HTTP 200 response whose body is not the expected {AccessKeyId, SecretAccessKey, Token, Expiration} payload: an error/HTML page from a proxy, an empty body, a JSON error document (e.g. {\"message\":\"...\"} from a 4xx that still resolved), or a non-JSON body from a custom FULL_URI server.","commonSituations":"A corporate proxy or load balancer intercepting 169.254.170.2 traffic and returning an error page; custom credential servers returning a different JSON schema; the endpoint returning 404/403 JSON without AccessKeyId; truncated or gzip-encoded bodies the client did not decode.","solutions":["Dump the raw response (e.g. curl the metadata URI from inside the container) to see what body is actually returned.","Confirm the URI points at the real ECS credentials endpoint (http://169.254.170.2/v2/credentials/...) and the task has an IAM role attached.","If using a custom FULL_URI server, make it return exactly {\"AccessKeyId\":..., \"SecretAccessKey\":..., \"Token\":..., \"Expiration\":...} JSON with HTTP 200.","Check that no proxy env vars (HTTP_PROXY etc.) are intercepting the link-local request — the provider sets proxy: '' for its client but environment-level interception may still apply.","Ensure the task role is attached in ECS task definition (\"role\" field) so the endpoint returns credentials rather than an error."],"exampleFix":"// before: custom server returns wrong shape\n{\"error\":\"not found\"}\n\n// after: required shape\n{\"AccessKeyId\":\"ASIA...\",\"SecretAccessKey\":\"...\",\"Token\":\"...\",\"Expiration\":\"2026-09-14T12:00:00Z\"}","handlingStrategy":"try-catch","validationCode":"<?php\n$uri = getenv('AWS_CONTAINER_CREDENTIALS_RELATIVE_URI')\n    ? 'http://169.254.170.2' . getenv('AWS_CONTAINER_CREDENTIALS_RELATIVE_URI')\n    : getenv('AWS_CONTAINER_CREDENTIALS_FULL_URI');\nif ($uri) {\n    $body = @file_get_contents($uri);\n    $json = json_decode((string)$body, true);\n    if (!isset($json['AccessKeyId'])) {\n        error_log('Metadata endpoint returned unexpected body: ' . substr((string)$body, 0, 200));\n    }\n}","typeGuard":"null","tryCatchPattern":"<?php\nuse Aws\\Exception\\CredentialsException;\ntry {\n    $creds = $provider()->wait();\n} catch (CredentialsException $e) {\n    if ($e->getMessage() === 'Unexpected container metadata credentials value') {\n        error_log('Metadata endpoint returned a non-credentials body; check proxy/task role/endpoint');\n    }\n    throw $e;\n}","preventionTips":["Curl the metadata endpoint inside the container to inspect the raw body during incidents","Ensure no HTTP proxy env vars intercept link-local metadata traffic","Attach an IAM role to the ECS task so the endpoint returns credentials, not an error document","Custom FULL_URI servers must return the exact {AccessKeyId, SecretAccessKey, Token, Expiration} JSON shape with HTTP 200"],"tags":["aws-sdk","credentials","ecs","json","unexpected-response"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}