Validate path types (#9967)

* Validate path types

* Fix the year of header

* Update internal/ingress/controller/config/config.go

Co-authored-by: Jintao Zhang <tao12345666333@163.com>

---------

Co-authored-by: Jintao Zhang <tao12345666333@163.com>
This commit is contained in:
Ricardo Katz 2023-05-20 08:58:18 -03:00 committed by GitHub
parent 0dd1cf7460
commit c540b58474
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 296 additions and 0 deletions

View file

@ -17,6 +17,9 @@ limitations under the License.
package inspector
import (
"errors"
"fmt"
corev1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1"
"k8s.io/klog/v2"
@ -36,3 +39,29 @@ func DeepInspect(obj interface{}) error {
return nil
}
}
var (
implSpecific = networking.PathTypeImplementationSpecific
)
func ValidatePathType(ing *networking.Ingress) error {
if ing == nil {
return fmt.Errorf("received null ingress")
}
var err error
for _, rule := range ing.Spec.Rules {
if rule.HTTP != nil {
for _, path := range rule.HTTP.Paths {
if path.Path == "" {
continue
}
if path.PathType == nil || *path.PathType != implSpecific {
if isValid := validPathType.MatchString(path.Path); !isValid {
err = errors.Join(err, fmt.Errorf("path %s cannot be used with pathType %s", path.Path, string(*path.PathType)))
}
}
}
}
}
return err
}