mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
kubeadm: update token separator to '.'
This commit is contained in:
parent
fcb234e580
commit
96fb797abc
@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TokenExpectedRegex = "^\\S{6}\\:\\S{16}\n$"
|
TokenExpectedRegex = "^\\S{6}\\.\\S{16}\n$"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunGenerateToken(t *testing.T) {
|
func TestRunGenerateToken(t *testing.T) {
|
||||||
|
@ -34,7 +34,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
tokenIDRegexpString = "^([a-z0-9]{6})$"
|
tokenIDRegexpString = "^([a-z0-9]{6})$"
|
||||||
tokenIDRegexp = regexp.MustCompile(tokenIDRegexpString)
|
tokenIDRegexp = regexp.MustCompile(tokenIDRegexpString)
|
||||||
tokenRegexpString = "^([a-z0-9]{6})\\:([a-z0-9]{16})$"
|
tokenRegexpString = "^([a-z0-9]{6})\\.([a-z0-9]{16})$"
|
||||||
tokenRegexp = regexp.MustCompile(tokenRegexpString)
|
tokenRegexp = regexp.MustCompile(tokenRegexpString)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -87,13 +87,13 @@ func ParseToken(s string) (string, string, error) {
|
|||||||
|
|
||||||
// BearerToken returns a string representation of the passed token.
|
// BearerToken returns a string representation of the passed token.
|
||||||
func BearerToken(d *kubeadmapi.TokenDiscovery) string {
|
func BearerToken(d *kubeadmapi.TokenDiscovery) string {
|
||||||
return fmt.Sprintf("%s:%s", d.ID, d.Secret)
|
return fmt.Sprintf("%s.%s", d.ID, d.Secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateToken validates whether a token is well-formed.
|
// ValidateToken validates whether a token is well-formed.
|
||||||
// In case it's not, the corresponding error is returned as well.
|
// In case it's not, the corresponding error is returned as well.
|
||||||
func ValidateToken(d *kubeadmapi.TokenDiscovery) (bool, error) {
|
func ValidateToken(d *kubeadmapi.TokenDiscovery) (bool, error) {
|
||||||
if _, _, err := ParseToken(d.ID + ":" + d.Secret); err != nil {
|
if _, _, err := ParseToken(d.ID + "." + d.Secret); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -28,14 +28,14 @@ func TestTokenParse(t *testing.T) {
|
|||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{token: "1234567890123456789012", expected: false}, // invalid parcel size
|
{token: "1234567890123456789012", expected: false}, // invalid parcel size
|
||||||
{token: "12345:1234567890123456", expected: false}, // invalid parcel size
|
{token: "12345.1234567890123456", expected: false}, // invalid parcel size
|
||||||
{token: ".1234567890123456", expected: false}, // invalid parcel size
|
{token: ".1234567890123456", expected: false}, // invalid parcel size
|
||||||
{token: "123456:1234567890.123456", expected: false}, // invalid separation
|
{token: "123456:1234567890.123456", expected: false}, // invalid separation
|
||||||
{token: "abcdef.1234567890123456", expected: false}, // invalid separation
|
{token: "abcdef:1234567890123456", expected: false}, // invalid separation
|
||||||
{token: "Abcdef:1234567890123456", expected: false}, // invalid token id
|
{token: "Abcdef.1234567890123456", expected: false}, // invalid token id
|
||||||
{token: "123456:AABBCCDDEEFFGGHH", expected: false}, // invalid token secret
|
{token: "123456.AABBCCDDEEFFGGHH", expected: false}, // invalid token secret
|
||||||
{token: "abcdef:1234567890123456", expected: true},
|
{token: "abcdef.1234567890123456", expected: true},
|
||||||
{token: "123456:aabbccddeeffgghh", expected: true},
|
{token: "123456.aabbccddeeffgghh", expected: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
@ -154,7 +154,7 @@ func TestBearerToken(t *testing.T) {
|
|||||||
token *kubeadmapi.TokenDiscovery
|
token *kubeadmapi.TokenDiscovery
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{token: &kubeadmapi.TokenDiscovery{ID: "foo", Secret: "bar"}, expected: "foo:bar"}, // should use default
|
{token: &kubeadmapi.TokenDiscovery{ID: "foo", Secret: "bar"}, expected: "foo.bar"}, // should use default
|
||||||
}
|
}
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
actual := BearerToken(rt.token)
|
actual := BearerToken(rt.token)
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TokenExpectedRegex = "^\\S{6}\\:\\S{16}\n$"
|
TokenExpectedRegex = "^\\S{6}\\.\\S{16}\n$"
|
||||||
)
|
)
|
||||||
|
|
||||||
var kubeadmPath = flag.String("kubeadm-path", filepath.Join(os.Getenv("KUBE_ROOT"), "cluster/kubeadm.sh"), "Location of kubeadm")
|
var kubeadmPath = flag.String("kubeadm-path", filepath.Join(os.Getenv("KUBE_ROOT"), "cluster/kubeadm.sh"), "Location of kubeadm")
|
||||||
|
Loading…
Reference in New Issue
Block a user