mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	add request header options for groups
This commit is contained in:
		@@ -484,6 +484,8 @@ report-dir
 | 
				
			|||||||
report-prefix
 | 
					report-prefix
 | 
				
			||||||
requestheader-allowed-names
 | 
					requestheader-allowed-names
 | 
				
			||||||
requestheader-client-ca-file
 | 
					requestheader-client-ca-file
 | 
				
			||||||
 | 
					requestheader-extra-headers-prefix
 | 
				
			||||||
 | 
					requestheader-group-headers
 | 
				
			||||||
requestheader-username-headers
 | 
					requestheader-username-headers
 | 
				
			||||||
require-kubeconfig
 | 
					require-kubeconfig
 | 
				
			||||||
required-contexts
 | 
					required-contexts
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,6 +43,11 @@ import (
 | 
				
			|||||||
type RequestHeaderConfig struct {
 | 
					type RequestHeaderConfig struct {
 | 
				
			||||||
	// UsernameHeaders are the headers to check (in order, case-insensitively) for an identity. The first header with a value wins.
 | 
						// UsernameHeaders are the headers to check (in order, case-insensitively) for an identity. The first header with a value wins.
 | 
				
			||||||
	UsernameHeaders []string
 | 
						UsernameHeaders []string
 | 
				
			||||||
 | 
						// GroupHeaders are the headers to check (case-insensitively) for a group names.  All values will be used.
 | 
				
			||||||
 | 
						GroupHeaders []string
 | 
				
			||||||
 | 
						// ExtraHeaderPrefixes are the head prefixes to check (case-insentively) for filling in
 | 
				
			||||||
 | 
						// the user.Info.Extra.  All values of all matching headers will be added.
 | 
				
			||||||
 | 
						ExtraHeaderPrefixes []string
 | 
				
			||||||
	// ClientCA points to CA bundle file which is used verify the identity of the front proxy
 | 
						// ClientCA points to CA bundle file which is used verify the identity of the front proxy
 | 
				
			||||||
	ClientCA string
 | 
						ClientCA string
 | 
				
			||||||
	// AllowedClientNames is a list of common names that may be presented by the authenticating front proxy.  Empty means: accept any.
 | 
						// AllowedClientNames is a list of common names that may be presented by the authenticating front proxy.  Empty means: accept any.
 | 
				
			||||||
@@ -88,9 +93,8 @@ func New(config AuthenticatorConfig) (authenticator.Request, *spec.SecurityDefin
 | 
				
			|||||||
			config.RequestHeaderConfig.ClientCA,
 | 
								config.RequestHeaderConfig.ClientCA,
 | 
				
			||||||
			config.RequestHeaderConfig.AllowedClientNames,
 | 
								config.RequestHeaderConfig.AllowedClientNames,
 | 
				
			||||||
			config.RequestHeaderConfig.UsernameHeaders,
 | 
								config.RequestHeaderConfig.UsernameHeaders,
 | 
				
			||||||
			// TODO add wiring after options are refactored in 1.6
 | 
								config.RequestHeaderConfig.GroupHeaders,
 | 
				
			||||||
			[]string{},
 | 
								config.RequestHeaderConfig.ExtraHeaderPrefixes,
 | 
				
			||||||
			[]string{},
 | 
					 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, nil, err
 | 
								return nil, nil, err
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,12 +63,6 @@ type PasswordFileAuthenticationOptions struct {
 | 
				
			|||||||
	BasicAuthFile string
 | 
						BasicAuthFile string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type RequestHeaderAuthenticationOptions struct {
 | 
					 | 
				
			||||||
	UsernameHeaders []string
 | 
					 | 
				
			||||||
	ClientCAFile    string
 | 
					 | 
				
			||||||
	AllowedNames    []string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ServiceAccountAuthenticationOptions struct {
 | 
					type ServiceAccountAuthenticationOptions struct {
 | 
				
			||||||
	KeyFiles []string
 | 
						KeyFiles []string
 | 
				
			||||||
	Lookup   bool
 | 
						Lookup   bool
 | 
				
			||||||
@@ -206,17 +200,7 @@ func (s *BuiltInAuthenticationOptions) AddFlags(fs *pflag.FlagSet) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if s.RequestHeader != nil {
 | 
						if s.RequestHeader != nil {
 | 
				
			||||||
		fs.StringSliceVar(&s.RequestHeader.UsernameHeaders, "requestheader-username-headers", s.RequestHeader.UsernameHeaders, ""+
 | 
							s.RequestHeader.AddFlags(fs)
 | 
				
			||||||
			"List of request headers to inspect for usernames. X-Remote-User is common.")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		fs.StringVar(&s.RequestHeader.ClientCAFile, "requestheader-client-ca-file", s.RequestHeader.ClientCAFile, ""+
 | 
					 | 
				
			||||||
			"Root certificate bundle to use to verify client certificates on incoming requests "+
 | 
					 | 
				
			||||||
			"before trusting usernames in headers specified by --requestheader-username-headers")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		fs.StringSliceVar(&s.RequestHeader.AllowedNames, "requestheader-allowed-names", s.RequestHeader.AllowedNames, ""+
 | 
					 | 
				
			||||||
			"List of client certificate common names to allow to provide usernames in headers "+
 | 
					 | 
				
			||||||
			"specified by --requestheader-username-headers. If empty, any client certificate validated "+
 | 
					 | 
				
			||||||
			"by the authorities in --requestheader-client-ca-file is allowed.")
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if s.ServiceAccounts != nil {
 | 
						if s.ServiceAccounts != nil {
 | 
				
			||||||
@@ -275,7 +259,7 @@ func (s *BuiltInAuthenticationOptions) ToAuthenticationConfig(clientCAFile strin
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if s.RequestHeader != nil {
 | 
						if s.RequestHeader != nil {
 | 
				
			||||||
		ret.RequestHeaderConfig = s.RequestHeader.AuthenticationRequestHeaderConfig()
 | 
							ret.RequestHeaderConfig = s.RequestHeader.ToAuthenticationRequestHeaderConfig()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if s.ServiceAccounts != nil {
 | 
						if s.ServiceAccounts != nil {
 | 
				
			||||||
@@ -295,15 +279,45 @@ func (s *BuiltInAuthenticationOptions) ToAuthenticationConfig(clientCAFile strin
 | 
				
			|||||||
	return ret
 | 
						return ret
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// AuthenticationRequestHeaderConfig returns an authenticator config object for these options
 | 
					type RequestHeaderAuthenticationOptions struct {
 | 
				
			||||||
// if necessary.  nil otherwise.
 | 
						UsernameHeaders     []string
 | 
				
			||||||
func (s *RequestHeaderAuthenticationOptions) AuthenticationRequestHeaderConfig() *authenticator.RequestHeaderConfig {
 | 
						GroupHeaders        []string
 | 
				
			||||||
 | 
						ExtraHeaderPrefixes []string
 | 
				
			||||||
 | 
						ClientCAFile        string
 | 
				
			||||||
 | 
						AllowedNames        []string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *RequestHeaderAuthenticationOptions) AddFlags(fs *pflag.FlagSet) {
 | 
				
			||||||
 | 
						fs.StringSliceVar(&s.UsernameHeaders, "requestheader-username-headers", s.UsernameHeaders, ""+
 | 
				
			||||||
 | 
							"List of request headers to inspect for usernames. X-Remote-User is common.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs.StringSliceVar(&s.GroupHeaders, "requestheader-group-headers", s.GroupHeaders, ""+
 | 
				
			||||||
 | 
							"List of request headers to inspect for groups. X-Remote-Group is suggested.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs.StringSliceVar(&s.ExtraHeaderPrefixes, "requestheader-extra-headers-prefix", s.ExtraHeaderPrefixes, ""+
 | 
				
			||||||
 | 
							"List of request header prefixes to inspect. X-Remote-Extra- is suggested.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs.StringVar(&s.ClientCAFile, "requestheader-client-ca-file", s.ClientCAFile, ""+
 | 
				
			||||||
 | 
							"Root certificate bundle to use to verify client certificates on incoming requests "+
 | 
				
			||||||
 | 
							"before trusting usernames in headers specified by --requestheader-username-headers")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs.StringSliceVar(&s.AllowedNames, "requestheader-allowed-names", s.AllowedNames, ""+
 | 
				
			||||||
 | 
							"List of client certificate common names to allow to provide usernames in headers "+
 | 
				
			||||||
 | 
							"specified by --requestheader-username-headers. If empty, any client certificate validated "+
 | 
				
			||||||
 | 
							"by the authorities in --requestheader-client-ca-file is allowed.")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ToAuthenticationRequestHeaderConfig returns a RequestHeaderConfig config object for these options
 | 
				
			||||||
 | 
					// if necessary, nil otherwise.
 | 
				
			||||||
 | 
					func (s *RequestHeaderAuthenticationOptions) ToAuthenticationRequestHeaderConfig() *authenticator.RequestHeaderConfig {
 | 
				
			||||||
	if len(s.UsernameHeaders) == 0 {
 | 
						if len(s.UsernameHeaders) == 0 {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &authenticator.RequestHeaderConfig{
 | 
						return &authenticator.RequestHeaderConfig{
 | 
				
			||||||
		UsernameHeaders:     s.UsernameHeaders,
 | 
							UsernameHeaders:     s.UsernameHeaders,
 | 
				
			||||||
 | 
							GroupHeaders:        s.GroupHeaders,
 | 
				
			||||||
 | 
							ExtraHeaderPrefixes: s.ExtraHeaderPrefixes,
 | 
				
			||||||
		ClientCA:            s.ClientCAFile,
 | 
							ClientCA:            s.ClientCAFile,
 | 
				
			||||||
		AllowedClientNames:  s.AllowedNames,
 | 
							AllowedClientNames:  s.AllowedNames,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user