Skip to content

[cherrypick][6.11] Validate token endpoints of user-supplied external_account credentials - #1639

Merged
akkaur merged 1 commit into
release/0.24from
cherry-pick-validate-external-account-endpoints-0.24
Nov 19, 2026
Merged

akkaur merged 1 commit into
release/0.24from
cherry-pick-validate-external-account-endpoints-0.24

Conversation

@akkaur

@akkaur akkaur commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick of #1628 (commit de27cae1acefe95902eb449d4287eba6395b0c77, merge commit 14eab53585aefd829df36f860d58d80bf23be651) into release/0.24 for CDAP 6.11.


Issue

The GCP plugins accept a service account credential as inline JSON or a file path and load it with GoogleCredentials.fromStream, which accepts any credential type the auth library supports, including external_account (workload identity federation).

An external_account configuration tells the auth library where to obtain a subject token (credential_source) and where to send it: the subject token is sent to token_url and the resulting access token to service_account_impersonation_url. When such a configuration comes from user input, these endpoints must be validated; otherwise the configuration could direct tokens to an arbitrary endpoint. See Google's guidance on validating credential configurations from external sources: https://cloud.google.com/docs/authentication/client-libraries#validate_other_credential_configurations

Fix

This change adds that validation in GCPUtils.loadServiceAccountCredentials, the single method all plugin credential paths (validation, connection test, deploy and runtime) go through. For configurations of type external_account, both endpoints must be Google-owned:

  • token_url must match ^https://sts(\.[a-z0-9-]+\.rep)?(\.mtls)?\.googleapis\.com/v1/token$ — i.e. https://sts.googleapis.com/v1/token, or the locational (sts.<location>.rep.googleapis.com) and mTLS (sts.mtls.googleapis.com) variants generated by gcloud iam workload-identity-pools create-cred-config --sts-location / --enable-mtls.
  • service_account_impersonation_url, if present, must match ^https://iamcredentials(\.mtls)?\.googleapis\.com/v1/projects/-/serviceAccounts/<email>:generateAccessToken$

With both endpoints pinned to googleapis.com, whatever the configuration reads can only be sent to Google. Non-conforming configurations are rejected with a validation error naming the field. Configurations of any other type are passed to the library unchanged.

The JSON is parsed with the same parser GoogleCredentials.fromStream uses, so the validation sees exactly the document the library will act on (including lenient handling of trailing content).

Tests

GCPUtilsTest covers:

  • service_account JSON and external_account configurations with the global, locational and mTLS endpoints load successfully.
  • The reported token-theft payload (credential_source.url → metadata server, token_url → attacker) is rejected before any endpoint is contacted, verified with local stand-in HTTP servers.
  • Exfiltration via service_account_impersonation_url, host-suffix/userinfo/scheme/case/query/trailing-slash tricks, and trailing content after the JSON object are all rejected.
  • Non-external_account content (including unparseable or null input) yields the same exception as the library alone.

A credential configuration of type external_account tells the auth
library where to read a subject token from (credential_source) and
where to send it: the subject token is POSTed to token_url and the
resulting access token to service_account_impersonation_url. When such
a configuration is supplied through the service account JSON field of a
plugin, these endpoints must be validated so that tokens are only sent
to Google.

Following
https://cloud.google.com/docs/authentication/client-libraries#validate_other_credential_configurations
GCPUtils.loadServiceAccountCredentials now requires, for
external_account configurations, that
 - token_url is https://sts.googleapis.com/v1/token or one of the
   Google locational (sts.<location>.rep.googleapis.com) or mTLS
   (sts.mtls.googleapis.com) variants generated by
   'gcloud iam workload-identity-pools create-cred-config'
 - service_account_impersonation_url, if present, is
   https://iamcredentials[.mtls].googleapis.com/v1/projects/-/serviceAccounts/<email>:generateAccessToken

The configuration is parsed with the same parser that
GoogleCredentials.fromStream uses, so validation and the library see
exactly the same document and unparseable content fails with the
library's own error. The external_account credential generated by CDAP
for GKE Workload Identity and gcloud-generated configurations continue
to load; service_account JSON and all other content are handled by the
library exactly as before.

(cherry picked from commit de27cae)
@akkaur akkaur added the build Trigger unit test build label Nov 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces validation for Google Cloud external account (workload identity federation) credential configurations in GCPUtils. It ensures that the token_url and service_account_impersonation_url point to trusted Google endpoints before the credentials are used, preventing potential token leakage to unauthorized endpoints. Comprehensive unit tests have been added in GCPUtilsTest to verify these validations. A review comment suggests adding null checks in the test teardown method to prevent masking initialization errors with a NullPointerException.

Comment on lines +85 to +88
public void tearDown() {
metadataServer.stop(0);
tokenExchangeServer.stop(0);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In tearDown(), calling stop(0) on metadataServer or tokenExchangeServer without a null check can result in a NullPointerException if the test setup (setUp()) fails before both servers are fully initialized. This NullPointerException in tearDown will mask the actual initialization exception, making test failures harder to debug. Consider adding null checks before stopping the servers.

  public void tearDown() {
    if (metadataServer != null) {
      metadataServer.stop(0);
    }
    if (tokenExchangeServer != null) {
      tokenExchangeServer.stop(0);
    }
  }

@akkaur
akkaur merged commit c42d5b9 into release/0.24 Nov 19, 2026
18 checks passed
@akkaur
akkaur deleted the cherry-pick-validate-external-account-endpoints-0.24 branch November 19, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Trigger unit test build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants