Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: disable universe domain check for MDS #575

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/CredentialsWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Google\Auth\FetchAuthTokenInterface;
use Google\Auth\GetQuotaProjectInterface;
use Google\Auth\GetUniverseDomainInterface;
use Google\Auth\Credentials\GCECredentials;
use Google\Auth\HttpHandler\Guzzle6HttpHandler;
use Google\Auth\HttpHandler\Guzzle7HttpHandler;
use Google\Auth\HttpHandler\HttpHandlerFactory;
Expand Down Expand Up @@ -273,7 +274,7 @@ public function getAuthorizationHeaderCallback($audience = null)
*/
public function checkUniverseDomain()
{
if (false === $this->hasCheckedUniverse) {
if (false === $this->hasCheckedUniverse && $this->shouldCheckUniverseDomain()) {
$credentialsUniverse = $this->credentialsFetcher instanceof GetUniverseDomainInterface
? $this->credentialsFetcher->getUniverseDomain()
: GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN;
Expand All @@ -288,6 +289,24 @@ public function checkUniverseDomain()
}
}

/**
* Skip universe domain check for Metadata server (e.g. GCE) credentials.
*
* @return bool
*/
private function shouldCheckUniverseDomain(): bool
{
$fetcher = $this->credentialsFetcher instanceof FetchAuthTokenCache
? $this->credentialsFetcher->getFetcher()
: $this->credentialsFetcher;

if ($fetcher instanceof GCECredentials) {
return false;
}

return true;
}

/**
* @param array $scopes
* @param callable $authHttpHandler
Expand Down
13 changes: 13 additions & 0 deletions tests/Tests/Unit/CredentialsWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ public function provideCheckUniverseDomainPasses()
];
}

public function testCheckUniverseDomainOnGceCredentialsDoesNotCheck()
{
$fetcher = $this->prophesize(GCECredentials::class);
$fetcher->getUniverseDomain()->shouldNotBeCalled();
$credentialsWrapper = new CredentialsWrapper(
$fetcher->reveal(),
null,
'some-random-universe-domain'
);

$credentialsWrapper->checkUniverseDomain();
}

/**
* @dataProvider getBearerStringData
*/
Expand Down