Skip to content

[fixes #56772] Fix WasmPlugin .spec.url validation #3531

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion extensions/v1alpha1/wasm.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extensions/v1alpha1/wasm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ message WasmPlugin {
// within the proxy container, and `http[s]://` for `.wasm` module files
// hosted remotely.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:XValidation:message="url must have schema one of [http, https, file, oci]",rule="isURL(self) ? (url(self).getScheme() in ['', 'http', 'https', 'oci', 'file']) : (isURL('http://' + self) && url('http://' +self).getScheme() in ['', 'http', 'https', 'oci', 'file'])"
// +kubebuilder:validation:XValidation:message="url must have schema one of [http, https, file, oci] or be a valid OCI image reference",rule="(isURL(self) && url(self).getScheme() in ['http','https','file','oci']) || matches(self,'^([A-Za-z0-9.-]+(?::[0-9]+)?)?(/[A-Za-z0-9][A-Za-z0-9._-]*)*(?::[\\w][\\w.-]{0,127})?$')"
string url = 2 [(google.api.field_behavior) = REQUIRED];

// SHA256 checksum that will be used to verify Wasm module or OCI container.
Expand Down
8 changes: 4 additions & 4 deletions kubernetes/customresourcedefinitions.gen.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 71 additions & 8 deletions tests/testdata/wasm-valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ spec:
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: url-without-schema
spec:
url: "test"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: env
spec:
Expand All @@ -41,4 +34,74 @@ spec:
valueFrom: INLINE
value: "test"
- name: "test3"
value: "test"
value: "test"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: noprefix-image-default-lib-and-tag
spec:
url: "bar"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: noprefix-image-default-lib-with-tag
spec:
url: "bar:latest"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: noprefix-image-explicit-lib-default-tag
spec:
url: "library/bar"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: noprefix-image-explicit-lib-and-tag
spec:
url: "library/bar:latest"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: noprefix-image-with-explicit-repo-and-tag
spec:
url: "foo.bar/foo/bar:1.21.4"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: noprefix-image-with-explicit-repo-and-tag-and-port
spec:
url: "foo.bar:5000/client_id_matches_cert:latest"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: oci-image-explicit-lib-default-tag
spec:
url: "oci://library/bar"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: oci-image-explicit-lib-and-tag
spec:
url: "oci://library/bar:latest"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: oci-image-with-explicit-repo-and-tag
spec:
url: "oci://foo.bar/foo/bar:1.21.4"
---
apiVersion: extensions.istio.io/v1alpha1
kind: WasmPlugin
metadata:
name: oci-image-with-explicit-repo-and-tag-and-port
spec:
url: "oci://foo.bar:5000/client_id_matches_cert:latest"