-
Notifications
You must be signed in to change notification settings - Fork 39.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scheduler: enable secure port and authn/z #69663
Changes from all commits
cb95eda
d91feb6
98d8e87
0ba6613
1588af4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ import ( | |
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config" | ||
"k8s.io/kubernetes/pkg/api/legacyscheme" | ||
"k8s.io/kubernetes/pkg/client/leaderelectionconfig" | ||
"k8s.io/kubernetes/pkg/master/ports" | ||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" | ||
kubeschedulerscheme "k8s.io/kubernetes/pkg/scheduler/apis/config/scheme" | ||
"k8s.io/kubernetes/pkg/scheduler/apis/config/validation" | ||
|
@@ -56,7 +57,7 @@ type Options struct { | |
// The default values. These are overridden if ConfigFile is set or by values in InsecureServing. | ||
ComponentConfig kubeschedulerconfig.KubeSchedulerConfiguration | ||
|
||
SecureServing *apiserveroptions.SecureServingOptions | ||
SecureServing *apiserveroptions.SecureServingOptionsWithLoopback | ||
CombinedInsecureServing *CombinedInsecureServingOptions | ||
Authentication *apiserveroptions.DelegatingAuthenticationOptions | ||
Authorization *apiserveroptions.DelegatingAuthorizationOptions | ||
|
@@ -85,25 +86,34 @@ func NewOptions() (*Options, error) { | |
|
||
o := &Options{ | ||
ComponentConfig: *cfg, | ||
SecureServing: nil, // TODO: enable with apiserveroptions.NewSecureServingOptions() | ||
SecureServing: apiserveroptions.NewSecureServingOptions().WithLoopback(), | ||
CombinedInsecureServing: &CombinedInsecureServingOptions{ | ||
Healthz: &apiserveroptions.DeprecatedInsecureServingOptions{ | ||
Healthz: (&apiserveroptions.DeprecatedInsecureServingOptions{ | ||
BindNetwork: "tcp", | ||
}, | ||
Metrics: &apiserveroptions.DeprecatedInsecureServingOptions{ | ||
}).WithLoopback(), | ||
Metrics: (&apiserveroptions.DeprecatedInsecureServingOptions{ | ||
BindNetwork: "tcp", | ||
}, | ||
}).WithLoopback(), | ||
BindPort: hport, | ||
BindAddress: hhost, | ||
}, | ||
Authentication: nil, // TODO: enable with apiserveroptions.NewDelegatingAuthenticationOptions() | ||
Authorization: nil, // TODO: enable with apiserveroptions.NewDelegatingAuthorizationOptions() | ||
Authentication: apiserveroptions.NewDelegatingAuthenticationOptions(), | ||
Authorization: apiserveroptions.NewDelegatingAuthorizationOptions(), | ||
Deprecated: &DeprecatedOptions{ | ||
UseLegacyPolicyConfig: false, | ||
PolicyConfigMapNamespace: metav1.NamespaceSystem, | ||
}, | ||
} | ||
|
||
o.Authentication.RemoteKubeConfigFileOptional = true | ||
o.Authorization.RemoteKubeConfigFileOptional = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in addition to tolerating missing kubeconfig, this needed to tolerate forbidden failures in xref #71743 |
||
o.Authorization.AlwaysAllowPaths = []string{"/healthz"} | ||
|
||
// Set the PairName but leave certificate directory blank to generate in-memory by default | ||
o.SecureServing.ServerCert.CertDirectory = "" | ||
o.SecureServing.ServerCert.PairName = "kube-scheduler" | ||
o.SecureServing.BindPort = ports.KubeSchedulerPort | ||
|
||
return o, nil | ||
} | ||
|
||
|
@@ -173,13 +183,19 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error { | |
} | ||
} | ||
|
||
if err := o.SecureServing.ApplyTo(&c.SecureServing); err != nil { | ||
if err := o.SecureServing.ApplyTo(&c.SecureServing, &c.LoopbackClientConfig); err != nil { | ||
return err | ||
} | ||
if err := o.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil { | ||
return err | ||
if o.SecureServing != nil && (o.SecureServing.BindPort != 0 || o.SecureServing.Listener != nil) { | ||
if err := o.Authentication.ApplyTo(&c.Authentication, c.SecureServing, nil); err != nil { | ||
return err | ||
} | ||
if err := o.Authorization.ApplyTo(&c.Authorization); err != nil { | ||
return err | ||
} | ||
} | ||
return o.Authorization.ApplyTo(&c.Authorization) | ||
|
||
return nil | ||
} | ||
|
||
// Validate validates all the required options. | ||
|
@@ -200,6 +216,12 @@ func (o *Options) Validate() []error { | |
|
||
// Config return a scheduler config object | ||
func (o *Options) Config() (*schedulerappconfig.Config, error) { | ||
if o.SecureServing != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no nil check needed here, MaybeDefaultWithSelfSignedCerts no-ops if SecureServing is nil There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I appear to have led you astray... sorry:
|
||
if err := o.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil { | ||
return nil, fmt.Errorf("error creating self-signed certificates: %v", err) | ||
} | ||
} | ||
|
||
c := &schedulerappconfig.Config{} | ||
if err := o.ApplyTo(c); err != nil { | ||
return nil, err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to understand why is it replacing one deprecated option with another deprecated one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that is it extending it to loopback? though still not sure why to extend a deprecated option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not extending it in the code sense. We have support for insecure ports using these two option structs (not new for scheduler). The whole insecure port code is deprecated, to be removed when all components switched over to secure ports. The difference of
DeprecatedInsecureServingOptionsWithLoopback
is just that it add the loopback authenticator which helps testing. Otherwise it is the same.