moodle/moodle · error · CredentialsException

Uri ' ' contains an unsupported host.

Error message

Uri '{$uri}' contains an unsupported host.

What it means

The container credential provider rejects any AWS_CONTAINER_CREDENTIALS_FULL_URI whose host is not a link-local trusted address. isCompatibleUri() allows only https schemes, the ECS endpoint 169.254.170.2, the EKS pod identity agent 169.254.170.23 / fd00:ec2::23, or hosts resolving (via gethostbyname) to a loopback address; anything else throws this CredentialsException from __invoke before any request is made.

Solutions

  1. Ensure the FULL_URI host is loopback (127.0.0.1/::1) — run your local credential server on 127.0.0.1 and use http://127.0.0.1:PORT/... .
  2. Or use https:// with any host, which bypasses the host allowlist entirely.
  3. Or use the standard link-local endpoints: http://169.254.170.2 (ECS) or 169.254.170.23 / fd00:ec2::23 (EKS pod identity).
  4. Verify AWS_CONTAINER_CREDENTIALS_RELATIVE_URI (not FULL_URI) is the right variable when you intend to use the default ECS endpoint.
  5. Print and parse the URI (parse_url) to confirm scheme/host are as expected.

Example fix

// before
export AWS_CONTAINER_CREDENTIALS_FULL_URI="http://172.17.0.5:9000/creds"

// after (loopback or https)
export AWS_CONTAINER_CREDENTIALS_FULL_URI="http://127.0.0.1:9000/creds"
# or
export AWS_CONTAINER_CREDENTIALS_FULL_URI="https://creds.internal.local/creds"
Defensive patterns

Strategy: validation

Validate before calling

<?php
$uri = getenv('AWS_CONTAINER_CREDENTIALS_FULL_URI');
if ($uri !== false && $uri !== '') {
    $p = parse_url($uri);
    $ok = isset($p['scheme'], $p['host'])
        && ($p['scheme'] === 'https'
            || in_array(trim($p['host'], '[]'), ['169.254.170.2', '169.254.170.23', 'fd00:ec2::23'], true)
            || str_starts_with(trim($p['host'], '[]'), '127.'));
    if (!$ok) throw new RuntimeException("FULL_URI host not allowed: {$uri}");
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Setting AWS_CONTAINER_CREDENTIALS_FULL_URI to a URL whose host is a public IP, an arbitrary external hostname resolving to a non-loopback IP, a malformed URL (parse_url fails to yield 'host'), or an http:// URL to a non-allowlisted host. The check runs before the HTTP request, so the error is thrown synchronously.

Common situations: Pointing FULL_URI at a custom local credentials server that is not on loopback (e.g. bound to a docker bridge IP or LAN address); forgetting the scheme so parse_url misparses the host; using http:// with a public endpoint in a self-managed container environment; typos like an extra path/space breaking the URL.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/09e7a90f1ceb9d3e. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/aws-sdk/src/Credentials/EcsCredentialProvider.php:127

                        $isRetryable = $reason instanceof ConnectException;
                        if ($isRetryable && ($this->attempts < $this->retries)) {
                            sleep((int)pow(1.2, $this->attempts));
                        } else {
                            $msg = $reason->getMessage();
                            throw new CredentialsException(
                                sprintf('Error retrieving credentials from container metadata after attempt %d/%d (%s)', $this->attempts, $this->retries, $msg)
                            );
                        }
                    }));
                    $this->attempts++;
                }

                yield $credentials;
            });
        }

        throw new CredentialsException("Uri '{$uri}' contains an unsupported host.");
    }

    /**
     * Returns the number of attempts that have been done.
     *
     * @return int
     */
    public function getAttempts(): int
    {
        return $this->attempts;
    }

    /**
     * Retrieves authorization token.
     *
     * @return array|false|string
     */
    private function getEcsAuthToken()

View on GitHub (pinned to 48ea8c3322)