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
91cacb3a
Commit
91cacb3a
authored
Nov 08, 2019
by
Darren Shepherd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix server join issues
parent
c29a3193
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
10 deletions
+27
-10
server.go
pkg/daemons/control/server.go
+25
-8
server.go
pkg/server/server.go
+2
-2
No files found.
pkg/daemons/control/server.go
View file @
91cacb3a
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
_
"github.com/rancher/k3s/pkg/cloudprovider"
_
"github.com/rancher/k3s/pkg/cloudprovider"
certutil
"github.com/rancher/dynamiclistener/cert"
certutil
"github.com/rancher/dynamiclistener/cert"
"github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/cluster"
"github.com/rancher/k3s/pkg/cluster"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/passwd"
"github.com/rancher/k3s/pkg/passwd"
...
@@ -364,7 +365,7 @@ func readTokens(runtime *config.ControlRuntime) error {
...
@@ -364,7 +365,7 @@ func readTokens(runtime *config.ControlRuntime) error {
runtime
.
AgentToken
=
"node:"
+
nodeToken
runtime
.
AgentToken
=
"node:"
+
nodeToken
}
}
if
serverToken
,
ok
:=
tokens
.
Pass
(
"server"
);
ok
{
if
serverToken
,
ok
:=
tokens
.
Pass
(
"server"
);
ok
{
runtime
.
Agent
Token
=
"server:"
+
serverToken
runtime
.
Server
Token
=
"server:"
+
serverToken
}
}
if
clientToken
,
ok
:=
tokens
.
Pass
(
"admin"
);
ok
{
if
clientToken
,
ok
:=
tokens
.
Pass
(
"admin"
);
ok
{
runtime
.
ClientToken
=
"admin:"
+
clientToken
runtime
.
ClientToken
=
"admin:"
+
clientToken
...
@@ -426,6 +427,9 @@ func getServerPass(passwd *passwd.Passwd, config *config.Control) (string, error
...
@@ -426,6 +427,9 @@ func getServerPass(passwd *passwd.Passwd, config *config.Control) (string, error
func
getNodePass
(
config
*
config
.
Control
,
serverPass
string
)
string
{
func
getNodePass
(
config
*
config
.
Control
,
serverPass
string
)
string
{
if
config
.
AgentToken
==
""
{
if
config
.
AgentToken
==
""
{
if
_
,
passwd
,
ok
:=
clientaccess
.
ParseUsernamePassword
(
serverPass
);
ok
{
return
passwd
}
return
serverPass
return
serverPass
}
}
return
config
.
AgentToken
return
config
.
AgentToken
...
@@ -621,9 +625,17 @@ func genRequestHeaderCerts(config *config.Control, runtime *config.ControlRuntim
...
@@ -621,9 +625,17 @@ func genRequestHeaderCerts(config *config.Control, runtime *config.ControlRuntim
}
}
func
createClientCertKey
(
regen
bool
,
commonName
string
,
organization
[]
string
,
altNames
*
certutil
.
AltNames
,
extKeyUsage
[]
x509
.
ExtKeyUsage
,
caCertFile
,
caKeyFile
,
certFile
,
keyFile
string
)
(
bool
,
error
)
{
func
createClientCertKey
(
regen
bool
,
commonName
string
,
organization
[]
string
,
altNames
*
certutil
.
AltNames
,
extKeyUsage
[]
x509
.
ExtKeyUsage
,
caCertFile
,
caKeyFile
,
certFile
,
keyFile
string
)
(
bool
,
error
)
{
caBytes
,
err
:=
ioutil
.
ReadFile
(
caCertFile
)
if
err
!=
nil
{
return
false
,
err
}
pool
:=
x509
.
NewCertPool
()
pool
.
AppendCertsFromPEM
(
caBytes
)
// check for certificate expiration
// check for certificate expiration
if
!
regen
{
if
!
regen
{
regen
=
expired
(
certFile
)
regen
=
expired
(
certFile
,
pool
)
}
}
if
!
regen
{
if
!
regen
{
...
@@ -642,15 +654,11 @@ func createClientCertKey(regen bool, commonName string, organization []string, a
...
@@ -642,15 +654,11 @@ func createClientCertKey(regen bool, commonName string, organization []string, a
return
false
,
err
return
false
,
err
}
}
caBytes
,
err
:=
ioutil
.
ReadFile
(
caCertFile
)
if
err
!=
nil
{
return
false
,
err
}
caCert
,
err
:=
certutil
.
ParseCertsPEM
(
caBytes
)
caCert
,
err
:=
certutil
.
ParseCertsPEM
(
caBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
keyBytes
,
_
,
err
:=
certutil
.
LoadOrGenerateKeyFile
(
keyFile
,
regen
)
keyBytes
,
_
,
err
:=
certutil
.
LoadOrGenerateKeyFile
(
keyFile
,
regen
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
...
@@ -770,7 +778,7 @@ func setupStorageBackend(argsMap map[string]string, cfg *config.Control) {
...
@@ -770,7 +778,7 @@ func setupStorageBackend(argsMap map[string]string, cfg *config.Control) {
}
}
}
}
func
expired
(
certFile
string
)
bool
{
func
expired
(
certFile
string
,
pool
*
x509
.
CertPool
)
bool
{
certBytes
,
err
:=
ioutil
.
ReadFile
(
certFile
)
certBytes
,
err
:=
ioutil
.
ReadFile
(
certFile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
...
@@ -779,6 +787,15 @@ func expired(certFile string) bool {
...
@@ -779,6 +787,15 @@ func expired(certFile string) bool {
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
}
}
_
,
err
=
certificates
[
0
]
.
Verify
(
x509
.
VerifyOptions
{
Roots
:
pool
,
KeyUsages
:
[]
x509
.
ExtKeyUsage
{
x509
.
ExtKeyUsageAny
,
},
})
if
err
!=
nil
{
return
true
}
return
certutil
.
IsCertExpired
(
certificates
[
0
])
return
certutil
.
IsCertExpired
(
certificates
[
0
])
}
}
...
...
pkg/server/server.go
View file @
91cacb3a
...
@@ -200,9 +200,9 @@ func printTokens(advertiseIP string, config *config.Control) error {
...
@@ -200,9 +200,9 @@ func printTokens(advertiseIP string, config *config.Control) error {
advertiseIP
=
"127.0.0.1"
advertiseIP
=
"127.0.0.1"
}
}
if
len
(
config
.
Runtime
.
Agent
Token
)
>
0
{
if
len
(
config
.
Runtime
.
Server
Token
)
>
0
{
p
:=
filepath
.
Join
(
config
.
DataDir
,
"token"
)
p
:=
filepath
.
Join
(
config
.
DataDir
,
"token"
)
if
err
:=
writeToken
(
config
.
Runtime
.
Agent
Token
,
p
,
config
.
Runtime
.
ServerCA
);
err
==
nil
{
if
err
:=
writeToken
(
config
.
Runtime
.
Server
Token
,
p
,
config
.
Runtime
.
ServerCA
);
err
==
nil
{
logrus
.
Infof
(
"Node token is available at %s"
,
p
)
logrus
.
Infof
(
"Node token is available at %s"
,
p
)
nodeFile
=
p
nodeFile
=
p
}
}
...
...
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