Fix workload identity pool ID validation to strip the literal .svc.id.goog suffix - #18470
Open
nikolauspschuetz wants to merge 2 commits into
Open
Conversation
|
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
force-pushed
the
fix-workload-identity-pool-id-trimsuffix
branch
from
July 30, 2026 15:09
b24b757 to
0fb0bd9
Compare
nikolauspschuetz
marked this pull request as ready for review
July 30, 2026 15:18
|
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. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
ValidateWorkloadIdentityPoolId(used bygoogle_iam_workload_identity_pool) strips the optional.svc.id.googsuffix before its regex/length checks, but usesstrings.TrimRight: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.googsuffix.Concrete effects (base name = the ID before the suffix):
TrimRightgoods.svc.id.goog""goods)foods.svc.id.goog"f"foods).svc.id.googgalso eatenSo valid pool IDs whose base name ends in any of
s v c i d g oare wrongly rejected, and an over-length ID can slip through. The existingfoo-bar.svc.id.googtest passes only by luck (foo-barends inr, outside the cutset), which is why this went unnoticed.Fix
Use
strings.TrimSuffix, which removes exactly the literal.svc.id.googsuffix (and is a no-op when absent, so theHasSuffixguard 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 oldTrimRightcode and passes withTrimSuffix; all existing cases still pass.