Skip to content

Commit 1f40e09

Browse files
committed
Only default mode to AlwaysAllow when config file is unspecified
1 parent 246d363 commit 1f40e09

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/controlplane/apiserver/options/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ func (o *Options) Complete(alternateDNS []string, alternateIPs []net.IP) (Comple
222222
klog.Infof("external host was not specified, using %v", completed.GenericServerRunOptions.ExternalHost)
223223
}
224224

225+
// put authorization options in final state
226+
completed.Authorization.Complete()
227+
// adjust authentication for completed authorization
225228
completed.Authentication.ApplyAuthorization(completed.Authorization)
226229

227230
// Use (ServiceAccountSigningKeyFile != "") as a proxy to the user enabling

pkg/kubeapiserver/options/authorization.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,22 @@ type BuiltInAuthorizationOptions struct {
8080
// NewBuiltInAuthorizationOptions create a BuiltInAuthorizationOptions with default value
8181
func NewBuiltInAuthorizationOptions() *BuiltInAuthorizationOptions {
8282
return &BuiltInAuthorizationOptions{
83-
Modes: []string{authzmodes.ModeAlwaysAllow},
83+
Modes: []string{},
8484
WebhookVersion: "v1beta1",
8585
WebhookCacheAuthorizedTTL: 5 * time.Minute,
8686
WebhookCacheUnauthorizedTTL: 30 * time.Second,
8787
WebhookRetryBackoff: genericoptions.DefaultAuthWebhookRetryBackoff(),
8888
}
8989
}
9090

91+
// Complete modifies authorization options
92+
func (o *BuiltInAuthorizationOptions) Complete() []error {
93+
if len(o.AuthorizationConfigurationFile) == 0 && len(o.Modes) == 0 {
94+
o.Modes = []string{authzmodes.ModeAlwaysAllow}
95+
}
96+
return nil
97+
}
98+
9199
// Validate checks invalid config combination
92100
func (o *BuiltInAuthorizationOptions) Validate() []error {
93101
if o == nil {
@@ -185,7 +193,7 @@ func (o *BuiltInAuthorizationOptions) AddFlags(fs *pflag.FlagSet) {
185193
}
186194

187195
fs.StringSliceVar(&o.Modes, authorizationModeFlag, o.Modes, ""+
188-
"Ordered list of plug-ins to do authorization on secure port. Comma-delimited list of: "+
196+
"Ordered list of plug-ins to do authorization on secure port. Defaults to AlwaysAllow if --authorization-config is not used. Comma-delimited list of: "+
189197
strings.Join(authzmodes.AuthorizationModeChoices, ",")+".")
190198

191199
fs.StringVar(&o.PolicyFile, authorizationPolicyFileFlag, o.PolicyFile, ""+

0 commit comments

Comments
 (0)