-
Notifications
You must be signed in to change notification settings - Fork 40.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50933 from mattmoyer/bootstrap-token-groups
Automatic merge from submit-queue (batch tested with PRs 49861, 50933, 51380, 50688, 51305) Add configurable groups to bootstrap tokens. **What this PR does / why we need it**: This change adds support for authenticating bootstrap tokens into a configurable set of extra groups in addition to `system:bootstrappers`. Previously, bootstrap tokens could only ever authenticate to the `system:bootstrappers` group. Groups are specified as a comma-separated list in the `auth-extra-groups` key of the `bootstrap.kubernetes.io/token` Secret, and must begin with the prefix `system:bootstrapper:` (and match a validation regex that checks against our normal convention). Whether or not any extra groups are configured, `system:bootstrappers` will still be added. This also adds a `--groups` flag for `kubeadm token create`, which sets the `auth-extra-groups` key on the resulting Secret. The default is to not set the key. `kubeadm token list` is also updated to include a `EXTRA GROUPS` output column. **Which issue this PR fixes**: fixes #49306 **Special notes for your reviewer**: The use case for this is in #49306. Comments on the feature itself are probably better over there. It will be part of how HA/self-hosting kubeadm bootstraps new master nodes (post 1.8). **Release note**: ```release-note Add support for configurable groups for bootstrap token authentication. ``` cc @luxas @kubernetes/sig-cluster-lifecycle-api-reviews @kubernetes/sig-auth-api-reviews /kind feature
- Loading branch information
Showing
12 changed files
with
298 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
var bootstrapGroupRegexp = regexp.MustCompile(`\A` + BootstrapGroupPattern + `\z`) | ||
|
||
// ValidateBootstrapGroupName checks if the provided group name is a valid | ||
// bootstrap group name. Returns nil if valid or a validation error if invalid. | ||
// TODO(mattmoyer): this validation should migrate out to client-go (see https://github.com/kubernetes/client-go/issues/114) | ||
func ValidateBootstrapGroupName(name string) error { | ||
if bootstrapGroupRegexp.Match([]byte(name)) { | ||
return nil | ||
} | ||
return fmt.Errorf("bootstrap group %q is invalid (must match %s)", name, BootstrapGroupPattern) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestValidateBootstrapGroupName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
valid bool | ||
}{ | ||
{"valid", "system:bootstrappers:foo", true}, | ||
{"valid nested", "system:bootstrappers:foo:bar:baz", true}, | ||
{"valid with dashes and number", "system:bootstrappers:foo-bar-42", true}, | ||
{"invalid uppercase", "system:bootstrappers:Foo", false}, | ||
{"missing prefix", "foo", false}, | ||
{"prefix with no body", "system:bootstrappers:", false}, | ||
{"invalid spaces", "system:bootstrappers: ", false}, | ||
{"invalid asterisk", "system:bootstrappers:*", false}, | ||
{"trailing colon", "system:bootstrappers:foo:", false}, | ||
{"trailing dash", "system:bootstrappers:foo-", false}, | ||
{"script tags", "system:bootstrappers:<script> alert(\"scary?!\") </script>", false}, | ||
{"too long", "system:bootstrappers:" + strings.Repeat("x", 300), false}, | ||
} | ||
for _, test := range tests { | ||
err := ValidateBootstrapGroupName(test.input) | ||
if err != nil && test.valid { | ||
t.Errorf("test %q: ValidateBootstrapGroupName(%q) returned unexpected error: %v", test.name, test.input, err) | ||
} | ||
if err == nil && !test.valid { | ||
t.Errorf("test %q: ValidateBootstrapGroupName(%q) was supposed to return an error but didn't", test.name, test.input) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.