Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a13b48de
Commit
a13b48de
authored
Oct 26, 2018
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
default api audiences to service account token issuer if available
This is a sane default that users can choose to migrate away from later.
parent
a8934ff6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
6 deletions
+20
-6
BUILD
pkg/kubeapiserver/options/BUILD
+2
-0
authentication.go
pkg/kubeapiserver/options/authentication.go
+13
-3
authentication_test.go
pkg/kubeapiserver/options/authentication_test.go
+5
-3
No files found.
pkg/kubeapiserver/options/BUILD
View file @
a13b48de
...
...
@@ -61,6 +61,7 @@ go_library(
"//staging/src/k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/mutating:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/authentication/authenticator:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/server:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
...
...
@@ -99,6 +100,7 @@ go_test(
"//pkg/kubeapiserver/authorizer/modes:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/authentication/authenticator:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/authentication/authenticatorfactory:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/server/options:go_default_library",
],
...
...
pkg/kubeapiserver/options/authentication.go
View file @
a13b48de
...
...
@@ -26,6 +26,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apiserver/pkg/authentication/authenticator"
genericapiserver
"k8s.io/apiserver/pkg/server"
genericoptions
"k8s.io/apiserver/pkg/server/options"
"k8s.io/apiserver/pkg/util/flag"
...
...
@@ -176,7 +177,9 @@ func (s *BuiltInAuthenticationOptions) Validate() []error {
func
(
s
*
BuiltInAuthenticationOptions
)
AddFlags
(
fs
*
pflag
.
FlagSet
)
{
fs
.
StringSliceVar
(
&
s
.
APIAudiences
,
"api-audiences"
,
s
.
APIAudiences
,
""
+
"Identifiers of the API. The service account token authenticator will validate that "
+
"tokens used against the API are bound to at least one of these audiences."
)
"tokens used against the API are bound to at least one of these audiences. If the "
+
"--service-account-issuer flag is configured and this flag is not, this field "
+
"defaults to a single element list containing the issuer URL ."
)
if
s
.
Anonymous
!=
nil
{
fs
.
BoolVar
(
&
s
.
Anonymous
.
Allow
,
"anonymous-auth"
,
s
.
Anonymous
.
Allow
,
""
+
...
...
@@ -327,11 +330,14 @@ func (s *BuiltInAuthenticationOptions) ToAuthenticationConfig() kubeauthenticato
ret
.
RequestHeaderConfig
=
s
.
RequestHeader
.
ToAuthenticationRequestHeaderConfig
()
}
ret
.
APIAudiences
=
s
.
APIAudiences
if
s
.
ServiceAccounts
!=
nil
{
if
s
.
ServiceAccounts
.
Issuer
!=
""
&&
len
(
s
.
APIAudiences
)
==
0
{
ret
.
APIAudiences
=
authenticator
.
Audiences
{
s
.
ServiceAccounts
.
Issuer
}
}
ret
.
ServiceAccountKeyFiles
=
s
.
ServiceAccounts
.
KeyFiles
ret
.
ServiceAccountLookup
=
s
.
ServiceAccounts
.
Lookup
ret
.
ServiceAccountIssuer
=
s
.
ServiceAccounts
.
Issuer
ret
.
APIAudiences
=
s
.
APIAudiences
ret
.
ServiceAccountLookup
=
s
.
ServiceAccounts
.
Lookup
}
if
s
.
TokenFile
!=
nil
{
...
...
@@ -373,7 +379,11 @@ func (o *BuiltInAuthenticationOptions) ApplyTo(c *genericapiserver.Config) error
}
c
.
Authentication
.
SupportsBasicAuth
=
o
.
PasswordFile
!=
nil
&&
len
(
o
.
PasswordFile
.
BasicAuthFile
)
>
0
c
.
Authentication
.
APIAudiences
=
o
.
APIAudiences
if
o
.
ServiceAccounts
!=
nil
&&
o
.
ServiceAccounts
.
Issuer
!=
""
&&
len
(
o
.
APIAudiences
)
==
0
{
c
.
Authentication
.
APIAudiences
=
authenticator
.
Audiences
{
o
.
ServiceAccounts
.
Issuer
}
}
return
nil
}
...
...
pkg/kubeapiserver/options/authentication_test.go
View file @
a13b48de
...
...
@@ -23,9 +23,10 @@ import (
"time"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apiserver/pkg/authentication/authenticator"
"k8s.io/apiserver/pkg/authentication/authenticatorfactory"
apiserveroptions
"k8s.io/apiserver/pkg/server/options"
"k8s.io/kubernetes/pkg/kubeapiserver/authenticator"
kubeauthenticator
"k8s.io/kubernetes/pkg/kubeapiserver/authenticator"
)
func
TestAuthenticationValidate
(
t
*
testing
.
T
)
{
...
...
@@ -137,7 +138,8 @@ func TestToAuthenticationConfig(t *testing.T) {
TokenFailureCacheTTL
:
0
,
}
expectConfig
:=
authenticator
.
AuthenticatorConfig
{
expectConfig
:=
kubeauthenticator
.
AuthenticatorConfig
{
APIAudiences
:
authenticator
.
Audiences
{
"http://foo.bar.com"
},
Anonymous
:
false
,
BasicAuthFile
:
"/testBasicAuthFile"
,
BootstrapToken
:
false
,
...
...
@@ -167,6 +169,6 @@ func TestToAuthenticationConfig(t *testing.T) {
resultConfig
:=
testOptions
.
ToAuthenticationConfig
()
if
!
reflect
.
DeepEqual
(
resultConfig
,
expectConfig
)
{
t
.
Errorf
(
"Got AuthenticationConfig:
%v, Expected AuthenticationConfig:
%v"
,
resultConfig
,
expectConfig
)
t
.
Errorf
(
"Got AuthenticationConfig:
\n\t
%v
\n
Expected AuthenticationConfig:
\n\t
%v"
,
resultConfig
,
expectConfig
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment