Skip to content

Commit 875796c

Browse files
authored
feat: Support External Account Authorized User as a Source Credential for impersonated credentials in ADC (#1608)
* feat: Support External Account Authorized User as a Source Credential for impersonated credentials in ADC * formatting
1 parent 484c8db commit 875796c

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

google/auth/_default.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ def _get_impersonated_service_account_credentials(filename, info, scopes):
472472
source_credentials, _ = _get_service_account_credentials(
473473
filename, source_credentials_info
474474
)
475+
elif source_credentials_type == _EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE:
476+
source_credentials, _ = _get_external_account_authorized_user_credentials(
477+
filename, source_credentials_info
478+
)
475479
else:
476480
raise exceptions.InvalidType(
477481
"source credential of type {} is not supported.".format(

system_tests/secrets.tar.enc

0 Bytes
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"delegates": [
3+
"service-account-delegate@example.com"
4+
],
5+
"service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/service-account-target@example.com:generateAccessToken",
6+
"source_credentials": {
7+
"type": "external_account_authorized_user",
8+
"audience": "//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID",
9+
"refresh_token": "refreshToken",
10+
"token_url": "https://sts.googleapis.com/v1/oauth/token",
11+
"token_info_url": "https://sts.googleapis.com/v1/instrospect",
12+
"client_id": "clientId",
13+
"client_secret": "clientSecret"
14+
},
15+
"type": "impersonated_service_account"
16+
}

tests/test__default.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@
153153
DATA_DIR, "impersonated_service_account_service_account_source.json"
154154
)
155155

156+
IMPERSONATED_SERVICE_ACCOUNT_EXTERNAL_ACCOUNT_AUTHORIZED_USER_SOURCE_FILE = os.path.join(
157+
DATA_DIR,
158+
"impersonated_service_account_external_account_authorized_user_source.json",
159+
)
160+
156161
EXTERNAL_ACCOUNT_AUTHORIZED_USER_FILE = os.path.join(
157162
DATA_DIR, "external_account_authorized_user.json"
158163
)
@@ -365,6 +370,17 @@ def test_load_credentials_from_file_impersonated_with_service_account_source():
365370
assert not credentials._quota_project_id
366371

367372

373+
def test_load_credentials_from_file_impersonated_with_external_account_authorized_user_source():
374+
credentials, _ = _default.load_credentials_from_file(
375+
IMPERSONATED_SERVICE_ACCOUNT_EXTERNAL_ACCOUNT_AUTHORIZED_USER_SOURCE_FILE
376+
)
377+
assert isinstance(credentials, impersonated_credentials.Credentials)
378+
assert isinstance(
379+
credentials._source_credentials, external_account_authorized_user.Credentials
380+
)
381+
assert not credentials._quota_project_id
382+
383+
368384
def test_load_credentials_from_file_impersonated_passing_quota_project():
369385
credentials, _ = _default.load_credentials_from_file(
370386
IMPERSONATED_SERVICE_ACCOUNT_SERVICE_ACCOUNT_SOURCE_FILE,

0 commit comments

Comments
 (0)