-
Notifications
You must be signed in to change notification settings - Fork 13
fix(templates): validate feature gates, track branches, and endpoint host #647
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -128,3 +128,120 @@ func TestValidateTemplateInputs_Injection(t *testing.T) { | |||||||||||||||||||||||||||||||
| t.Error("expected error for injection attempt, got nil") | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func TestFeatureGatePattern(t *testing.T) { | ||||||||||||||||||||||||||||||||
| accept := []string{"FeatureName=true", "MyGate=false", "A=true"} | ||||||||||||||||||||||||||||||||
| reject := []string{ | ||||||||||||||||||||||||||||||||
| "bad;rm -rf /", | ||||||||||||||||||||||||||||||||
| "NoValue", | ||||||||||||||||||||||||||||||||
| "=true", | ||||||||||||||||||||||||||||||||
| "Feature=maybe", | ||||||||||||||||||||||||||||||||
| "Feature=true; echo pwned", | ||||||||||||||||||||||||||||||||
| "$(curl evil)=true", | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for _, v := range accept { | ||||||||||||||||||||||||||||||||
| if !featureGatePattern.MatchString(v) { | ||||||||||||||||||||||||||||||||
| t.Errorf("featureGatePattern should accept %q", v) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| for _, v := range reject { | ||||||||||||||||||||||||||||||||
| if featureGatePattern.MatchString(v) { | ||||||||||||||||||||||||||||||||
| t.Errorf("featureGatePattern should reject %q", v) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func TestHostnamePattern(t *testing.T) { | ||||||||||||||||||||||||||||||||
| accept := []string{"host.example.com", "192.168.1.1", "k8s-api:6443", "my-host"} | ||||||||||||||||||||||||||||||||
| reject := []string{ | ||||||||||||||||||||||||||||||||
| "host.com; rm -rf /", | ||||||||||||||||||||||||||||||||
| "$(curl evil)", | ||||||||||||||||||||||||||||||||
| "host && bad", | ||||||||||||||||||||||||||||||||
| "host`id`", | ||||||||||||||||||||||||||||||||
| "; echo pwned", | ||||||||||||||||||||||||||||||||
|
Comment on lines
+156
to
+162
|
||||||||||||||||||||||||||||||||
| accept := []string{"host.example.com", "192.168.1.1", "k8s-api:6443", "my-host"} | |
| reject := []string{ | |
| "host.com; rm -rf /", | |
| "$(curl evil)", | |
| "host && bad", | |
| "host`id`", | |
| "; echo pwned", | |
| accept := []string{"host.example.com", "192.168.1.1", "my-host"} | |
| reject := []string{ | |
| "host.com; rm -rf /", | |
| "$(curl evil)", | |
| "host && bad", | |
| "host`id`", | |
| "; echo pwned", | |
| "k8s-api:6443", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hostnamePatterncurrently allows:and the hostname tests accept values likek8s-api:6443, but the Kubernetes templates append:6443when usingK8sEndpointHost(e.g.,--control-plane-endpoint="${K8S_ENDPOINT_HOST}:6443"andcontrolPlaneEndpoint: "{{.ControlPlaneEndpoint}}:6443"). This combination can produce invalid endpoints likek8s-api:6443:6443if a user includes a port. Consider either tightening validation to reject host:port (no:allowed), or updating the templates/templating data model to treat this field ashost[:port]and only append the default port when none is provided.