Skip to content

Fix workload identity pool ID validation to strip the literal .svc.id.goog suffix - #18470

Open
nikolauspschuetz wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
nikolauspschuetz:fix-workload-identity-pool-id-trimsuffix
Open

Fix workload identity pool ID validation to strip the literal .svc.id.goog suffix#18470
nikolauspschuetz wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
nikolauspschuetz:fix-workload-identity-pool-id-trimsuffix

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

Bug

ValidateWorkloadIdentityPoolId (used by google_iam_workload_identity_pool) strips the optional .svc.id.goog suffix before its regex/length checks, but uses strings.TrimRight:

if strings.HasSuffix(value, defaultWorkloadIdentityPoolIdSuffix) {
    value = strings.TrimRight(value, defaultWorkloadIdentityPoolIdSuffix)
}

strings.TrimRight(s, cutset) treats its second argument as a set of characters ({'.','s','v','c','i','d','g','o'}), not a literal suffix. It greedily removes every trailing character in that set, not the 12-char .svc.id.goog suffix.

Concrete effects (base name = the ID before the suffix):

Input after TrimRight result today correct
goods.svc.id.goog "" rejected (regex + too short) accepted (goods)
foods.svc.id.goog "f" rejected (too short) accepted (foods)
33-char id + .svc.id.goog trailing g also eaten accepted should be rejected (too long)

So valid pool IDs whose base name ends in any of s v c i d g o are wrongly rejected, and an over-length ID can slip through. The existing foo-bar.svc.id.goog test passes only by luck (foo-bar ends in r, outside the cutset), which is why this went unnoticed.

Fix

Use strings.TrimSuffix, which removes exactly the literal .svc.id.goog suffix (and is a no-op when absent, so the HasSuffix guard is no longer needed). No behavior change for valid inputs; the buggy rejections/acceptance are corrected.

Test

Added a case to TestValidateIAMBetaWorkloadIdentityPoolId: goods.svc.id.goog (a valid ID whose base name ends in a cutset character) is expected to pass. It fails under the old TrimRight code and passes with TrimSuffix; all existing cases still pass.

iam: fixed validation of `google_iam_workload_identity_pool` IDs ending in `.svc.id.goog` where the base name ends in one of the suffix's characters

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Jul 30, 2026
@google-cla

google-cla Bot commented Jul 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

These cases fail under the current strings.TrimRight suffix stripping:
a valid ID whose base name ends in a suffix character
('goods.svc.id.goog') is wrongly rejected, and an over-length ID whose
base ends in a suffix character ('a'*32+'g'+suffix) is wrongly accepted
because TrimRight eats the trailing 'g' too.
strings.TrimRight treats its argument as a cutset of characters, not a
literal suffix, so it removed every trailing character in
{. s v c i d g o} rather than the '.svc.id.goog' suffix. Use
strings.TrimSuffix so exactly that suffix is removed; the HasSuffix
guard is then redundant and dropped. Makes the tests added in the
previous commit pass.
@nikolauspschuetz
nikolauspschuetz force-pushed the fix-workload-identity-pool-id-trimsuffix branch from b24b757 to 0fb0bd9 Compare July 30, 2026 15:09
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review July 30, 2026 15:18
@github-actions

Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@rileykarson, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@github-actions
github-actions Bot requested a review from rileykarson July 30, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-approval Pull requests that need reviewer's approval to run presubmit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants