-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
174 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
use Google\Auth\CredentialSource\ExecutableSource; | ||
use Google\Auth\CredentialSource\FileSource; | ||
use Google\Auth\CredentialSource\UrlSource; | ||
use Google\Auth\ExecutableHandler\ExecutableHandler; | ||
use Google\Auth\ExternalAccountCredentialSourceInterface; | ||
use Google\Auth\FetchAuthTokenInterface; | ||
use Google\Auth\GetQuotaProjectInterface; | ||
|
@@ -33,6 +34,7 @@ | |
use Google\Auth\UpdateMetadataTrait; | ||
use GuzzleHttp\Psr7\Request; | ||
use InvalidArgumentException; | ||
use Symfony\Component\Process\Process; | ||
|
||
class ExternalAccountCredentials implements | ||
FetchAuthTokenInterface, | ||
|
@@ -178,30 +180,32 @@ private static function buildCredentialSource(array $jsonKey): ExternalAccountCr | |
} | ||
|
||
// Build command environment variables | ||
$envVars = [ | ||
$env = [ | ||
'GOOGLE_EXTERNAL_ACCOUNT_AUDIENCE' => $jsonKey['audience'], | ||
'GOOGLE_EXTERNAL_ACCOUNT_TOKEN_TYPE' => $jsonKey['subject_token_type'], | ||
// Always set to 0 because interactive mode is not supported. | ||
'GOOGLE_EXTERNAL_ACCOUNT_INTERACTIVE' => '0', | ||
|
||
]; | ||
if ($outputFile = $credentialSource['executable']['output_file'] ?? null) { | ||
$envVars['GOOGLE_EXTERNAL_ACCOUNT_OUTPUT_FILE'] = $outputFile; | ||
$env['GOOGLE_EXTERNAL_ACCOUNT_OUTPUT_FILE'] = $outputFile; | ||
} | ||
if ($serviceAccountImpersonationUrl = $jsonKey['service_account_impersonation_url'] ?? null) { | ||
// Parse email from URL. The formal looks as follows: | ||
// https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/[email protected]:generateAccessToken | ||
$regex = '/serviceAccounts\/(?<email>[^:]+):generateAccessToken$/'; | ||
if (preg_match($regex, $serviceAccountImpersonationUrl, $matches)) { | ||
$envVars['GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL'] = $matches['email']; | ||
$env['GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL'] = $matches['email']; | ||
} | ||
} | ||
|
||
return new ExecutableSource( | ||
$credentialSource['executable']['command'], | ||
$credentialSource['executable']['timeout_millis'] ?? null, | ||
$outputFile, | ||
$envVars, | ||
new ExecutableHandler( | ||
$credentialSource['executable']['timeout_millis'] ?? null, | ||
$env | ||
) | ||
); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters