Skip to content

Commit

Permalink
chore: Fix escaping regex special characters (#3840)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed May 1, 2023
1 parent 6a5a705 commit a3ac553
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/apis/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ var (
RestrictedTagPatterns = []*regexp.Regexp{
// Adheres to cluster name pattern matching as specified in the API spec
// https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html
regexp.MustCompile(`^kubernetes.io/cluster/[0-9A-Za-z][A-Za-z0-9\-_]*$`),
regexp.MustCompile(fmt.Sprintf("^%s$", v1alpha5.ProvisionerNameLabelKey)),
regexp.MustCompile(fmt.Sprintf("^%s$", v1alpha5.ManagedByLabelKey)),
regexp.MustCompile(`^kubernetes\.io/cluster/[0-9A-Za-z][A-Za-z0-9\-_]*$`),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(v1alpha5.ProvisionerNameLabelKey))),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(v1alpha5.ManagedByLabelKey))),
}
AMIFamilyBottlerocket = "Bottlerocket"
AMIFamilyAL2 = "AL2"
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/v1alpha1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ var _ = Describe("Validation", func() {
}
Expect(ant.Validate(ctx)).To(Succeed())
})
It("should succeed by validating that regex is properly escaped", func() {
ant.Spec.Tags = map[string]string{
"karpenterzsh/provisioner-name": "value",
}
Expect(ant.Validate(ctx)).To(Succeed())
ant.Spec.Tags = map[string]string{
"kubernetesbio/cluster/test": "value",
}
Expect(ant.Validate(ctx)).To(Succeed())
ant.Spec.Tags = map[string]string{
"karpenterzsh/managed-by": "test",
}
Expect(ant.Validate(ctx)).To(Succeed())
})
It("should fail if tags contain a restricted domain key", func() {
ant.Spec.Tags = map[string]string{
"karpenter.sh/provisioner-name": "value",
Expand Down

0 comments on commit a3ac553

Please sign in to comment.