mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
apiextensions: 404 if request scope does not match crd scope
This commit is contained in:
parent
8670a4bceb
commit
df75700efe
@ -197,6 +197,10 @@ func NewCustomResourceDefinitionHandler(
|
|||||||
// and on the client side (by restarting the watch)
|
// and on the client side (by restarting the watch)
|
||||||
var longRunningFilter = genericfilters.BasicLongRunningRequestCheck(sets.NewString("watch"), sets.NewString())
|
var longRunningFilter = genericfilters.BasicLongRunningRequestCheck(sets.NewString("watch"), sets.NewString())
|
||||||
|
|
||||||
|
// possiblyAcrossAllNamespacesVerbs contains those verbs which can be per-namespace and across all
|
||||||
|
// namespaces for namespaces resources. I.e. for these an empty namespace in the requestInfo is fine.
|
||||||
|
var possiblyAcrossAllNamespacesVerbs = sets.NewString("list", "watch")
|
||||||
|
|
||||||
func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
ctx := req.Context()
|
ctx := req.Context()
|
||||||
requestInfo, ok := apirequest.RequestInfoFrom(ctx)
|
requestInfo, ok := apirequest.RequestInfoFrom(ctx)
|
||||||
@ -232,10 +236,24 @@ func (r *crdHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the scope in the CRD and the scope in request differ (with exception of the verbs in possiblyAcrossAllNamespacesVerbs
|
||||||
|
// for namespaced resources), pass request to the delegate, which is supposed to lead to a 404.
|
||||||
|
namespacedCRD, namespacedReq := crd.Spec.Scope == apiextensions.NamespaceScoped, len(requestInfo.Namespace) > 0
|
||||||
|
if !namespacedCRD && namespacedReq {
|
||||||
|
r.delegate.ServeHTTP(w, req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if namespacedCRD && !namespacedReq && !possiblyAcrossAllNamespacesVerbs.Has(requestInfo.Verb) {
|
||||||
|
r.delegate.ServeHTTP(w, req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if !apiextensions.HasServedCRDVersion(crd, requestInfo.APIVersion) {
|
if !apiextensions.HasServedCRDVersion(crd, requestInfo.APIVersion) {
|
||||||
r.delegate.ServeHTTP(w, req)
|
r.delegate.ServeHTTP(w, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is a small chance that a CRD is being served because NamesAccepted condition is true,
|
// There is a small chance that a CRD is being served because NamesAccepted condition is true,
|
||||||
// but it becomes "unserved" because another names update leads to a conflict
|
// but it becomes "unserved" because another names update leads to a conflict
|
||||||
// and EstablishingController wasn't fast enough to put the CRD into the Established condition.
|
// and EstablishingController wasn't fast enough to put the CRD into the Established condition.
|
||||||
|
Loading…
Reference in New Issue
Block a user