mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-08 11:38:15 +00:00
Add statusz to kubelet auth.
This commit is contained in:
parent
902dedbb52
commit
7caff55fd9
@ -27,6 +27,7 @@ import (
|
|||||||
"k8s.io/apiserver/pkg/server/healthz"
|
"k8s.io/apiserver/pkg/server/healthz"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
"k8s.io/component-base/configz"
|
"k8s.io/component-base/configz"
|
||||||
|
"k8s.io/component-base/zpages/statusz"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
)
|
)
|
||||||
@ -72,6 +73,7 @@ func isSubpath(subpath, path string) bool {
|
|||||||
// /runningPods/* => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=pods,proxy
|
// /runningPods/* => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=pods,proxy
|
||||||
// /healthz/* => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=healthz,proxy
|
// /healthz/* => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=healthz,proxy
|
||||||
// /configz => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=configz,proxy
|
// /configz => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=configz,proxy
|
||||||
|
// /statusz => verb=<api verb from request>, resource=nodes, name=<node name>, subresource(s)=statusz,proxy
|
||||||
func (n nodeAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *http.Request) []authorizer.Attributes {
|
func (n nodeAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *http.Request) []authorizer.Attributes {
|
||||||
|
|
||||||
apiVerb := ""
|
apiVerb := ""
|
||||||
@ -99,6 +101,8 @@ func (n nodeAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *htt
|
|||||||
subresources = append(subresources, "healthz")
|
subresources = append(subresources, "healthz")
|
||||||
case isSubpath(requestPath, configz.DefaultConfigzPath):
|
case isSubpath(requestPath, configz.DefaultConfigzPath):
|
||||||
subresources = append(subresources, "configz")
|
subresources = append(subresources, "configz")
|
||||||
|
case isSubpath(requestPath, statusz.DefaultStatuszPath):
|
||||||
|
subresources = append(subresources, "statusz")
|
||||||
// We put runningpods last since it will allocate a new string on every
|
// We put runningpods last since it will allocate a new string on every
|
||||||
// check since the handler path has a trailing slash.
|
// check since the handler path has a trailing slash.
|
||||||
case isSubpath(requestPath, runningPodsPath):
|
case isSubpath(requestPath, runningPodsPath):
|
||||||
|
@ -125,6 +125,7 @@ func AuthzTestCases(fineGrained bool) []AuthzTestCase {
|
|||||||
"/attach/{podNamespace}/{podID}/{uid}/{containerName}": {"proxy"},
|
"/attach/{podNamespace}/{podID}/{uid}/{containerName}": {"proxy"},
|
||||||
"/checkpoint/{podNamespace}/{podID}/{containerName}": {"checkpoint"},
|
"/checkpoint/{podNamespace}/{podID}/{containerName}": {"checkpoint"},
|
||||||
"/configz": {"proxy"},
|
"/configz": {"proxy"},
|
||||||
|
"/statusz": {"proxy"},
|
||||||
"/containerLogs/{podNamespace}/{podID}/{containerName}": {"proxy"},
|
"/containerLogs/{podNamespace}/{podID}/{containerName}": {"proxy"},
|
||||||
"/debug/flags/v": {"proxy"},
|
"/debug/flags/v": {"proxy"},
|
||||||
"/debug/pprof/{subpath:*}": {"proxy"},
|
"/debug/pprof/{subpath:*}": {"proxy"},
|
||||||
@ -159,6 +160,7 @@ func AuthzTestCases(fineGrained bool) []AuthzTestCase {
|
|||||||
testPaths["/pods/"] = append([]string{"pods"}, testPaths["/pods/"]...)
|
testPaths["/pods/"] = append([]string{"pods"}, testPaths["/pods/"]...)
|
||||||
testPaths["/runningpods/"] = append([]string{"pods"}, testPaths["/runningpods/"]...)
|
testPaths["/runningpods/"] = append([]string{"pods"}, testPaths["/runningpods/"]...)
|
||||||
testPaths["/configz"] = append([]string{"configz"}, testPaths["/configz"]...)
|
testPaths["/configz"] = append([]string{"configz"}, testPaths["/configz"]...)
|
||||||
|
testPaths["/statusz"] = append([]string{"statusz"}, testPaths["/statusz"]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []AuthzTestCase{}
|
testCases := []AuthzTestCase{}
|
||||||
|
@ -573,6 +573,7 @@ func TestAuthzCoverage(t *testing.T) {
|
|||||||
func TestAuthFilters(t *testing.T) {
|
func TestAuthFilters(t *testing.T) {
|
||||||
// Enable features.ContainerCheckpoint during test
|
// Enable features.ContainerCheckpoint during test
|
||||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ContainerCheckpoint, true)
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ContainerCheckpoint, true)
|
||||||
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, zpagesfeatures.ComponentStatusz, true)
|
||||||
|
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
defer fw.testHTTPServer.Close()
|
defer fw.testHTTPServer.Close()
|
||||||
|
@ -35,6 +35,8 @@ var (
|
|||||||
errUnsupportedMediaType = fmt.Errorf("media type not acceptable, must be: text/plain")
|
errUnsupportedMediaType = fmt.Errorf("media type not acceptable, must be: text/plain")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DefaultStatuszPath = "/statusz"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
headerFmt = `
|
headerFmt = `
|
||||||
%s statusz
|
%s statusz
|
||||||
@ -73,7 +75,7 @@ func Install(m mux, componentName string, reg statuszRegistry) {
|
|||||||
klog.Errorf("error while parsing gotemplates: %v", err)
|
klog.Errorf("error while parsing gotemplates: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Handle("/statusz", handleStatusz(componentName, dataTmpl, reg))
|
m.Handle(DefaultStatuszPath, handleStatusz(componentName, dataTmpl, reg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeTemplates() (*template.Template, error) {
|
func initializeTemplates() (*template.Template, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user