Merge pull request #123972 from deads2k/remove-insecure-serving
Remove k8s.io/apiserver ability to bind insecure ports Kubernetes-commit: daa3356e72a4586a2676b90ec3b664687b6bc2a0
This commit is contained in:
commit
4b2cb3c960
4
go.mod
4
go.mod
|
|
@ -45,8 +45,8 @@ require (
|
||||||
gopkg.in/square/go-jose.v2 v2.6.0
|
gopkg.in/square/go-jose.v2 v2.6.0
|
||||||
k8s.io/api v0.0.0-20240418013359-a819b1d9bd16
|
k8s.io/api v0.0.0-20240418013359-a819b1d9bd16
|
||||||
k8s.io/apimachinery v0.0.0-20240418093209-8c36da9e60f7
|
k8s.io/apimachinery v0.0.0-20240418093209-8c36da9e60f7
|
||||||
k8s.io/client-go v0.0.0-20240418093650-a82df61b8434
|
k8s.io/client-go v0.0.0-20240418093651-9990b0b122c9
|
||||||
k8s.io/component-base v0.0.0-20240404040301-d0106a887d7d
|
k8s.io/component-base v0.0.0-20240418094434-57ba0489bfa6
|
||||||
k8s.io/klog/v2 v2.120.1
|
k8s.io/klog/v2 v2.120.1
|
||||||
k8s.io/kms v0.0.0-20240404040452-6ba2c57b192f
|
k8s.io/kms v0.0.0-20240404040452-6ba2c57b192f
|
||||||
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
|
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
|
||||||
|
|
|
||||||
8
go.sum
8
go.sum
|
|
@ -385,10 +385,10 @@ k8s.io/api v0.0.0-20240418013359-a819b1d9bd16 h1:DXJla1ulezom5N0QIRlZetozcxtRPdS
|
||||||
k8s.io/api v0.0.0-20240418013359-a819b1d9bd16/go.mod h1:a1YU16kjsAapUzg1LYaOqTnbMlo87NXy9bSeWjRmfoo=
|
k8s.io/api v0.0.0-20240418013359-a819b1d9bd16/go.mod h1:a1YU16kjsAapUzg1LYaOqTnbMlo87NXy9bSeWjRmfoo=
|
||||||
k8s.io/apimachinery v0.0.0-20240418093209-8c36da9e60f7 h1:SydhMcp6AJkjqqVcd0o0uz7ntTcs/QyIgIHAFYfIm7E=
|
k8s.io/apimachinery v0.0.0-20240418093209-8c36da9e60f7 h1:SydhMcp6AJkjqqVcd0o0uz7ntTcs/QyIgIHAFYfIm7E=
|
||||||
k8s.io/apimachinery v0.0.0-20240418093209-8c36da9e60f7/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
|
k8s.io/apimachinery v0.0.0-20240418093209-8c36da9e60f7/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
|
||||||
k8s.io/client-go v0.0.0-20240418093650-a82df61b8434 h1:jCA1zO9GS3huFRwtvsMO5YrHG3tDplgb+aeMSZRyCQA=
|
k8s.io/client-go v0.0.0-20240418093651-9990b0b122c9 h1:eC8SD8kFISw8xhx2kTsXpIuB4qOGtCUdnK+ciXaJeEA=
|
||||||
k8s.io/client-go v0.0.0-20240418093650-a82df61b8434/go.mod h1:qmgPSZQ21ke/aLcgydRX8fK48pjHfF4anbvDcixuBqM=
|
k8s.io/client-go v0.0.0-20240418093651-9990b0b122c9/go.mod h1:qmgPSZQ21ke/aLcgydRX8fK48pjHfF4anbvDcixuBqM=
|
||||||
k8s.io/component-base v0.0.0-20240404040301-d0106a887d7d h1:GXlcnFrgrTHaNzWsti6jrwVYgX5w4XvzcEHksFDFvjw=
|
k8s.io/component-base v0.0.0-20240418094434-57ba0489bfa6 h1:ZdeuYrtChorFLu6yEbUE48mY6xXc/gkTqd5BFenIAyk=
|
||||||
k8s.io/component-base v0.0.0-20240404040301-d0106a887d7d/go.mod h1:bofvVDXaxRQVifEgl/jRWjjGgRx3X8v/hpD3SI9C1sk=
|
k8s.io/component-base v0.0.0-20240418094434-57ba0489bfa6/go.mod h1:sJI0btwpLHRQW24fjrxPwCC8dPfDnLT5Zjjvo1E3BeA=
|
||||||
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
|
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
|
||||||
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
||||||
k8s.io/kms v0.0.0-20240404040452-6ba2c57b192f h1:ZaAOI0By9kSY59JaeZn90KWp4MAnCQbzHqNDA9VvHsc=
|
k8s.io/kms v0.0.0-20240404040452-6ba2c57b192f h1:ZaAOI0By9kSY59JaeZn90KWp4MAnCQbzHqNDA9VvHsc=
|
||||||
|
|
|
||||||
|
|
@ -1,126 +0,0 @@
|
||||||
/*
|
|
||||||
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 options
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
|
|
||||||
"k8s.io/apiserver/pkg/server"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeprecatedInsecureServingOptions are for creating an unauthenticated, unauthorized, insecure port.
|
|
||||||
// No one should be using these anymore.
|
|
||||||
// DEPRECATED: all insecure serving options are removed in a future version
|
|
||||||
type DeprecatedInsecureServingOptions struct {
|
|
||||||
BindAddress net.IP
|
|
||||||
BindPort int
|
|
||||||
// BindNetwork is the type of network to bind to - defaults to "tcp", accepts "tcp",
|
|
||||||
// "tcp4", and "tcp6".
|
|
||||||
BindNetwork string
|
|
||||||
|
|
||||||
// Listener is the secure server network listener.
|
|
||||||
// either Listener or BindAddress/BindPort/BindNetwork is set,
|
|
||||||
// if Listener is set, use it and omit BindAddress/BindPort/BindNetwork.
|
|
||||||
Listener net.Listener
|
|
||||||
|
|
||||||
// ListenFunc can be overridden to create a custom listener, e.g. for mocking in tests.
|
|
||||||
// It defaults to options.CreateListener.
|
|
||||||
ListenFunc func(network, addr string, config net.ListenConfig) (net.Listener, int, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate ensures that the insecure port values within the range of the port.
|
|
||||||
func (s *DeprecatedInsecureServingOptions) Validate() []error {
|
|
||||||
if s == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
errors := []error{}
|
|
||||||
|
|
||||||
if s.BindPort < 0 || s.BindPort > 65535 {
|
|
||||||
errors = append(errors, fmt.Errorf("insecure port %v must be between 0 and 65535, inclusive. 0 for turning off insecure (HTTP) port", s.BindPort))
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddFlags adds flags related to insecure serving to the specified FlagSet.
|
|
||||||
func (s *DeprecatedInsecureServingOptions) AddFlags(fs *pflag.FlagSet) {
|
|
||||||
if s == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.IPVar(&s.BindAddress, "insecure-bind-address", s.BindAddress, ""+
|
|
||||||
"The IP address on which to serve the --insecure-port (set to 0.0.0.0 or :: for listening on all interfaces and IP address families).")
|
|
||||||
// Though this flag is deprecated, we discovered security concerns over how to do health checks without it e.g. #43784
|
|
||||||
fs.MarkDeprecated("insecure-bind-address", "This flag will be removed in a future version.")
|
|
||||||
fs.Lookup("insecure-bind-address").Hidden = false
|
|
||||||
|
|
||||||
fs.IntVar(&s.BindPort, "insecure-port", s.BindPort, ""+
|
|
||||||
"The port on which to serve unsecured, unauthenticated access.")
|
|
||||||
// Though this flag is deprecated, we discovered security concerns over how to do health checks without it e.g. #43784
|
|
||||||
fs.MarkDeprecated("insecure-port", "This flag will be removed in a future version.")
|
|
||||||
fs.Lookup("insecure-port").Hidden = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUnqualifiedFlags adds flags related to insecure serving without the --insecure prefix to the specified FlagSet.
|
|
||||||
func (s *DeprecatedInsecureServingOptions) AddUnqualifiedFlags(fs *pflag.FlagSet) {
|
|
||||||
if s == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.IPVar(&s.BindAddress, "address", s.BindAddress,
|
|
||||||
"The IP address on which to serve the insecure --port (set to '0.0.0.0' or '::' for listening on all interfaces and IP address families).")
|
|
||||||
fs.MarkDeprecated("address", "see --bind-address instead.")
|
|
||||||
fs.Lookup("address").Hidden = false
|
|
||||||
|
|
||||||
fs.IntVar(&s.BindPort, "port", s.BindPort, "The port on which to serve unsecured, unauthenticated access. Set to 0 to disable.")
|
|
||||||
fs.MarkDeprecated("port", "see --secure-port instead.")
|
|
||||||
fs.Lookup("port").Hidden = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyTo adds DeprecatedInsecureServingOptions to the insecureserverinfo and kube-controller manager configuration.
|
|
||||||
// Note: the double pointer allows to set the *DeprecatedInsecureServingInfo to nil without referencing the struct hosting this pointer.
|
|
||||||
func (s *DeprecatedInsecureServingOptions) ApplyTo(c **server.DeprecatedInsecureServingInfo) error {
|
|
||||||
if s == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if s.BindPort <= 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.Listener == nil {
|
|
||||||
var err error
|
|
||||||
listen := CreateListener
|
|
||||||
if s.ListenFunc != nil {
|
|
||||||
listen = s.ListenFunc
|
|
||||||
}
|
|
||||||
addr := net.JoinHostPort(s.BindAddress.String(), fmt.Sprintf("%d", s.BindPort))
|
|
||||||
s.Listener, s.BindPort, err = listen(s.BindNetwork, addr, net.ListenConfig{})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create listener: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*c = &server.DeprecatedInsecureServingInfo{
|
|
||||||
Listener: s.Listener,
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue