Skip to content

feat: Support External Account Authorized User as a Source Credential for impersonated credentials in ADC #1608

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

Merged
merged 2 commits into from
Oct 17, 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
4 changes: 4 additions & 0 deletions google/auth/_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ def _get_impersonated_service_account_credentials(filename, info, scopes):
source_credentials, _ = _get_service_account_credentials(
filename, source_credentials_info
)
elif source_credentials_type == _EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE:
source_credentials, _ = _get_external_account_authorized_user_credentials(
filename, source_credentials_info
)
else:
raise exceptions.InvalidType(
"source credential of type {} is not supported.".format(
Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"delegates": [
"service-account-delegate@example.com"
],
"service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/service-account-target@example.com:generateAccessToken",
"source_credentials": {
"type": "external_account_authorized_user",
"audience": "//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID",
"refresh_token": "refreshToken",
"token_url": "https://sts.googleapis.com/v1/oauth/token",
"token_info_url": "https://sts.googleapis.com/v1/instrospect",
"client_id": "clientId",
"client_secret": "clientSecret"
},
"type": "impersonated_service_account"
}
Copy link
Contributor

@lsirac lsirac Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line

Suggested change
}
}

16 changes: 16 additions & 0 deletions tests/test__default.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
DATA_DIR, "impersonated_service_account_service_account_source.json"
)

IMPERSONATED_SERVICE_ACCOUNT_EXTERNAL_ACCOUNT_AUTHORIZED_USER_SOURCE_FILE = os.path.join(
DATA_DIR,
"impersonated_service_account_external_account_authorized_user_source.json",
)

EXTERNAL_ACCOUNT_AUTHORIZED_USER_FILE = os.path.join(
DATA_DIR, "external_account_authorized_user.json"
)
Expand Down Expand Up @@ -365,6 +370,17 @@ def test_load_credentials_from_file_impersonated_with_service_account_source():
assert not credentials._quota_project_id


def test_load_credentials_from_file_impersonated_with_external_account_authorized_user_source():
credentials, _ = _default.load_credentials_from_file(
IMPERSONATED_SERVICE_ACCOUNT_EXTERNAL_ACCOUNT_AUTHORIZED_USER_SOURCE_FILE
)
assert isinstance(credentials, impersonated_credentials.Credentials)
assert isinstance(
credentials._source_credentials, external_account_authorized_user.Credentials
)
assert not credentials._quota_project_id


def test_load_credentials_from_file_impersonated_passing_quota_project():
credentials, _ = _default.load_credentials_from_file(
IMPERSONATED_SERVICE_ACCOUNT_SERVICE_ACCOUNT_SOURCE_FILE,
Expand Down