Skip to content

Commit 57f326b

Browse files
committed
c/k/a/opts: add --allow-legacy-serviceaccount-tokens flag and validation
Signed-off-by: kramaranya <[email protected]>
1 parent 670377f commit 57f326b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cmd/kube-rbac-proxy/app/options/proxyoptions.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ type ProxyOptions struct {
5858

5959
TokenAudiences []string
6060

61+
AllowLegacyServiceAccountTokens bool
62+
6163
DisableHTTP2Serving bool
6264
}
6365

@@ -79,7 +81,10 @@ func (o *ProxyOptions) AddFlags(flagset *pflag.FlagSet) {
7981
flagset.StringVar(&o.UpstreamHeader.GroupsFieldName, "auth-header-groups-field-name", "x-remote-groups", "The name of the field inside a http(2) request header to tell the upstream server about the user's groups")
8082
flagset.StringVar(&o.UpstreamHeader.GroupSeparator, "auth-header-groups-field-separator", "|", "The separator string used for concatenating multiple group names in a groups header field's value")
8183

82-
flagset.StringSliceVar(&o.TokenAudiences, "auth-token-audiences", []string{}, "Comma-separated list of token audiences to accept. By default a token does not have to have any specific audience. It is recommended to set a specific audience.")
84+
flagset.StringSliceVar(&o.TokenAudiences, "auth-token-audiences", []string{}, "Comma-separated list of token audiences to accept. Tokens must have at least one audience from this list. If omitted, the token is considered legacy.")
85+
86+
// legacy tokens are disabled by default.
87+
flagset.BoolVar(&o.AllowLegacyServiceAccountTokens, "allow-legacy-serviceaccount-tokens", false, "If true, allow legacy service account tokens (without an audience). Legacy tokens are less secure and are disabled by default.")
8388

8489
// proxy endpoints flag
8590
flagset.IntVar(&o.ProxyEndpointsPort, "proxy-endpoints-port", 0, "The port to securely serve proxy-specific endpoints (such as '/healthz'). Uses the host from the '--secure-listen-address'.")
@@ -91,8 +96,10 @@ func (o *ProxyOptions) AddFlags(flagset *pflag.FlagSet) {
9196
func (o *ProxyOptions) Validate() []error {
9297
var errs []error
9398

94-
if len(o.UpstreamHeader.GroupSeparator) > 0 && len(o.UpstreamHeader.GroupsFieldName) == 0 {
95-
errs = append(errs, fmt.Errorf("--auth-header-groups-field-name must be set along with --auth-header-groups-field-separator"))
99+
if o.UpstreamHeader != nil {
100+
if len(o.UpstreamHeader.GroupSeparator) > 0 && len(o.UpstreamHeader.GroupsFieldName) == 0 {
101+
errs = append(errs, fmt.Errorf("--auth-header-groups-field-name must be set along with --auth-header-groups-field-separator"))
102+
}
96103
}
97104

98105
if len(o.AllowPaths) > 0 && len(o.IgnorePaths) > 0 {
@@ -118,6 +125,13 @@ func (o *ProxyOptions) Validate() []error {
118125
errs = append(errs, err)
119126
}
120127

128+
// If no token audiences are provided, then tokens will be legacy.
129+
// By default, we do not allow legacy tokens unless the user explicitly opts in.
130+
if len(o.TokenAudiences) == 0 && !o.AllowLegacyServiceAccountTokens {
131+
errs = append(errs, fmt.Errorf("legacy service account tokens (tokens without audience) are disabled "+
132+
"by default. Use --allow-legacy-serviceaccount-tokens to opt in"))
133+
}
134+
121135
return errs
122136
}
123137

0 commit comments

Comments
 (0)