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
394f93b9
Unverified
Commit
394f93b9
authored
Jan 16, 2017
by
Paulo Pires
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: replaced period as token separator in favor of colon.
parent
c707cbf1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
17 deletions
+21
-17
token.go
cmd/kubeadm/app/cmd/token.go
+1
-1
token_test.go
cmd/kubeadm/app/cmd/token_test.go
+1
-1
tokens.go
cmd/kubeadm/app/util/tokens.go
+8
-7
tokens_test.go
cmd/kubeadm/app/util/tokens_test.go
+10
-7
token_test.go
cmd/kubeadm/test/token_test.go
+1
-1
No files found.
cmd/kubeadm/app/cmd/token.go
View file @
394f93b9
...
...
@@ -108,7 +108,7 @@ func NewCmdTokenGenerate(out io.Writer) *cobra.Command {
the "init" and "join" commands.
You don't have to use this command in order to generate a token, you can do so
yourself as long as it's in the format "<6 characters>
.
<16 characters>". This
yourself as long as it's in the format "<6 characters>
:
<16 characters>". This
command is provided for convenience to generate tokens in that format.
You can also use "kubeadm init" without specifying a token, and it will
...
...
cmd/kubeadm/app/cmd/token_test.go
View file @
394f93b9
...
...
@@ -23,7 +23,7 @@ import (
)
const
(
TokenExpectedRegex
=
"^
\\
S{6}
\\
.
\\
S{16}
\n
$"
TokenExpectedRegex
=
"^
\\
S{6}
\\
:
\\
S{16}
\n
$"
)
func
TestRunGenerateToken
(
t
*
testing
.
T
)
{
...
...
cmd/kubeadm/app/util/tokens.go
View file @
394f93b9
...
...
@@ -36,13 +36,13 @@ import (
const
(
TokenIDBytes
=
3
Token
Bytes
=
8
Token
SecretBytes
=
8
BootstrapTokenSecretPrefix
=
"bootstrap-token-"
DefaultTokenDuration
=
time
.
Duration
(
8
)
*
time
.
Hour
tokenCreateRetries
=
5
)
func
R
andBytes
(
length
int
)
(
string
,
error
)
{
func
r
andBytes
(
length
int
)
(
string
,
error
)
{
b
:=
make
([]
byte
,
length
)
_
,
err
:=
rand
.
Read
(
b
)
if
err
!=
nil
{
...
...
@@ -52,12 +52,12 @@ func RandBytes(length int) (string, error) {
}
func
GenerateToken
(
d
*
kubeadmapi
.
TokenDiscovery
)
error
{
tokenID
,
err
:=
R
andBytes
(
TokenIDBytes
)
tokenID
,
err
:=
r
andBytes
(
TokenIDBytes
)
if
err
!=
nil
{
return
err
}
token
,
err
:=
RandBytes
(
Token
Bytes
)
token
,
err
:=
randBytes
(
TokenSecret
Bytes
)
if
err
!=
nil
{
return
err
}
...
...
@@ -68,7 +68,7 @@ func GenerateToken(d *kubeadmapi.TokenDiscovery) error {
}
var
(
tokenRegexpString
=
"^([a-zA-Z0-9]{6})
\\
.
([a-zA-Z0-9]{16})$"
tokenRegexpString
=
"^([a-zA-Z0-9]{6})
\\
:
([a-zA-Z0-9]{16})$"
tokenRegexp
=
regexp
.
MustCompile
(
tokenRegexpString
)
)
...
...
@@ -96,15 +96,16 @@ func ParseToken(s string) (string, string, error) {
}
// BearerToken returns a string representation of the passed token.
func
BearerToken
(
d
*
kubeadmapi
.
TokenDiscovery
)
string
{
return
fmt
.
Sprintf
(
"%s
.
%s"
,
d
.
ID
,
d
.
Secret
)
return
fmt
.
Sprintf
(
"%s
:
%s"
,
d
.
ID
,
d
.
Secret
)
}
func
IsTokenValid
(
d
*
kubeadmapi
.
TokenDiscovery
)
(
bool
,
error
)
{
if
len
(
d
.
ID
)
+
len
(
d
.
Secret
)
==
0
{
return
false
,
nil
}
if
_
,
_
,
err
:=
ParseToken
(
d
.
ID
+
"
.
"
+
d
.
Secret
);
err
!=
nil
{
if
_
,
_
,
err
:=
ParseToken
(
d
.
ID
+
"
:
"
+
d
.
Secret
);
err
!=
nil
{
return
false
,
err
}
return
true
,
nil
...
...
cmd/kubeadm/app/util/tokens_test.go
View file @
394f93b9
...
...
@@ -22,17 +22,20 @@ import (
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
)
func
TestTokenParse
Errors
(
t
*
testing
.
T
)
{
func
TestTokenParse
(
t
*
testing
.
T
)
{
invalidTokens
:=
[]
string
{
// invalid parcel size
"1234567890123456789012"
,
"12345
.
1234567890123456"
,
"12345
:
1234567890123456"
,
".1234567890123456"
,
"123456.1234567890.123456"
,
// invalid separation
"123456:1234567890.123456"
,
"abcdef.1234567890123456"
,
}
for
_
,
token
:=
range
invalidTokens
{
if
_
,
_
,
err
:=
ParseToken
(
token
);
err
==
nil
{
t
.
Errorf
(
"
generateTokenIfNeeded
did not return an error for this invalid token: [%s]"
,
token
)
t
.
Errorf
(
"
ParseToken
did not return an error for this invalid token: [%s]"
,
token
)
}
}
}
...
...
@@ -59,12 +62,12 @@ func TestRandBytes(t *testing.T) {
}
for
_
,
rt
:=
range
randTest
{
actual
,
err
:=
R
andBytes
(
rt
)
actual
,
err
:=
r
andBytes
(
rt
)
if
err
!=
nil
{
t
.
Errorf
(
"failed
R
andBytes: %v"
,
err
)
t
.
Errorf
(
"failed
r
andBytes: %v"
,
err
)
}
if
len
(
actual
)
!=
rt
*
2
{
t
.
Errorf
(
"failed
R
andBytes:
\n\t
expected: %d
\n\t
actual: %d
\n
"
,
rt
*
2
,
len
(
actual
))
t
.
Errorf
(
"failed
r
andBytes:
\n\t
expected: %d
\n\t
actual: %d
\n
"
,
rt
*
2
,
len
(
actual
))
}
}
}
cmd/kubeadm/test/token_test.go
View file @
394f93b9
...
...
@@ -25,7 +25,7 @@ import (
)
const
(
TokenExpectedRegex
=
"^
\\
S{6}
\\
.
\\
S{16}
\n
$"
TokenExpectedRegex
=
"^
\\
S{6}
\\
:
\\
S{16}
\n
$"
)
var
kubeadmPath
string
...
...
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