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:
parent
0dd1cf7460
commit
c540b58474
7 changed files with 296 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue