Skip to content

Validate .spec.name and apply its default consistently - #584

Merged
scothis merged 3 commits into
servicebinding:mainfrom
rashedkvm:validate-binding-name
Aug 12, 2026
Merged

Validate .spec.name and apply its default consistently#584
scothis merged 3 commits into
servicebinding:mainfrom
rashedkvm:validate-binding-name

Conversation

@rashedkvm

@rashedkvm rashedkvm commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

.spec.name is projected into workload containers as a volume mount directory at
$SERVICE_BINDING_ROOT/<name>, but nothing validated it. path.Join cleans its result, so a
ServiceBinding with spec.name: "../../etc" produced MountPath: /etc — mounting the bound Secret
over an arbitrary directory in every workload matched by .spec.workload.

The specification already forbids this. From Workload Projection:

Binding names MUST match [a-z0-9\-\.]{1,253}

That rule simply was not implemented. This PR implements it.

.spec.name is projected into workload containers as a volume mount
directory at $SERVICE_BINDING_ROOT/<name>, but was never validated.
path.Join cleans its result, so `spec.name: ../../etc` produced
MountPath: /etc, mounting the bound Secret over an arbitrary directory in
every workload matched by .spec.workload.

The specification already requires binding names to match
[a-z0-9\-\.]{1,253}; the rule simply was not implemented. Enforce it,
anchored, and additionally reject "." and "..". Those are the only values
in that character set whose path.Join result can leave the intended
directory: the set contains no "/", so the name is always one path
element, and Clean gives special meaning to exactly those two.

Name validation is ratcheted on update, so ServiceBindings created before
this rule remain writable and deletable -- deletion clears a finalizer,
which is an UPDATE, and would otherwise be rejected.

Signed-off-by: Rashed Kamal <rashed.kamal@broadcom.com>
@rashedkvm
rashedkvm force-pushed the validate-binding-name branch from db2f29e to a501c69 Compare August 11, 2026 22:30

@scothis scothis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for finding this issue and proposing a fix.

Inline comments are minor. I can polish them up if you don't have capacity.

Comment thread apis/v1/servicebinding_webhook.go Outdated
Comment thread apis/v1/servicebinding_test.go Outdated
Comment thread apis/v1/servicebinding_webhook.go Outdated
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.27%. Comparing base (08152fb) to head (dc8ed84).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #584      +/-   ##
==========================================
+ Coverage   73.01%   73.27%   +0.25%     
==========================================
  Files          28       28              
  Lines        1460     1474      +14     
==========================================
+ Hits         1066     1080      +14     
  Misses        324      324              
  Partials       70       70              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Move the name format check next to the immutable field checks in
ValidateUpdate, so the old object no longer needs to be plumbed through
validate() and ServiceBindingSpec.validate(). ValidateUpdate applies the check
only when the value changes, so that objects predating the rule are not frozen
by it: deleting one clears a finalizer, which is an update.

Signed-off-by: Rashed Kamal <rashed.kamal@broadcom.com>
@rashedkvm
rashedkvm force-pushed the validate-binding-name branch from 4f3fbb2 to edca2ef Compare August 12, 2026 13:53
Comment thread apis/v1/servicebinding_webhook.go
Signed-off-by: Scott Andrews <scott@andrews.me>
@scothis
scothis enabled auto-merge (squash) August 12, 2026 15:53
@scothis
scothis merged commit 12fbd46 into servicebinding:main Aug 12, 2026
20 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants