2018-10-12 19:48:10 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package http2pushpreload
|
|
|
|
|
|
|
|
import (
|
2021-08-21 20:42:00 +00:00
|
|
|
networking "k8s.io/api/networking/v1"
|
2018-10-12 19:48:10 +00:00
|
|
|
|
|
|
|
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
|
|
|
"k8s.io/ingress-nginx/internal/ingress/resolver"
|
|
|
|
)
|
|
|
|
|
2023-07-22 03:32:07 +00:00
|
|
|
const (
|
|
|
|
http2PushPreloadAnnotation = "http2-push-preload"
|
|
|
|
)
|
|
|
|
|
|
|
|
var http2PushPreloadAnnotations = parser.Annotation{
|
|
|
|
Group: "http2",
|
|
|
|
Annotations: parser.AnnotationFields{
|
|
|
|
http2PushPreloadAnnotation: {
|
|
|
|
Validator: parser.ValidateBool,
|
|
|
|
Scope: parser.AnnotationScopeLocation,
|
|
|
|
Risk: parser.AnnotationRiskLow,
|
|
|
|
Documentation: `Enables automatic conversion of preload links specified in the “Link” response header fields into push requests`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-10-12 19:48:10 +00:00
|
|
|
type http2PushPreload struct {
|
2023-07-22 03:32:07 +00:00
|
|
|
r resolver.Resolver
|
|
|
|
annotationConfig parser.Annotation
|
2018-10-12 19:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewParser creates a new http2PushPreload annotation parser
|
|
|
|
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
2023-07-22 03:32:07 +00:00
|
|
|
return http2PushPreload{
|
|
|
|
r: r,
|
|
|
|
annotationConfig: http2PushPreloadAnnotations,
|
|
|
|
}
|
2018-10-12 19:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse parses the annotations contained in the ingress rule
|
|
|
|
// used to add http2 push preload to the server
|
2019-06-09 22:49:59 +00:00
|
|
|
func (h2pp http2PushPreload) Parse(ing *networking.Ingress) (interface{}, error) {
|
2023-07-22 03:32:07 +00:00
|
|
|
return parser.GetBoolAnnotation(http2PushPreloadAnnotation, ing, h2pp.annotationConfig.Annotations)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h2pp http2PushPreload) GetDocumentation() parser.AnnotationFields {
|
|
|
|
return h2pp.annotationConfig.Annotations
|
|
|
|
}
|
|
|
|
|
2023-08-31 07:36:48 +00:00
|
|
|
func (h2pp http2PushPreload) Validate(anns map[string]string) error {
|
|
|
|
maxrisk := parser.StringRiskToRisk(h2pp.r.GetSecurityConfiguration().AnnotationsRiskLevel)
|
2023-07-22 03:32:07 +00:00
|
|
|
return parser.CheckAnnotationRisk(anns, maxrisk, http2PushPreloadAnnotations.Annotations)
|
2018-10-12 19:48:10 +00:00
|
|
|
}
|