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
973774b0
Commit
973774b0
authored
May 23, 2016
by
AdoHe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix kubelet tls overwrite issue
parent
1e97583f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
26 deletions
+29
-26
server.go
cmd/kubelet/app/server.go
+5
-3
genericapiserver.go
pkg/genericapiserver/genericapiserver.go
+1
-23
crypto.go
pkg/util/crypto/crypto.go
+23
-0
No files found.
cmd/kubelet/app/server.go
View file @
973774b0
...
@@ -406,10 +406,12 @@ func InitializeTLS(s *options.KubeletServer) (*server.TLSOptions, error) {
...
@@ -406,10 +406,12 @@ func InitializeTLS(s *options.KubeletServer) (*server.TLSOptions, error) {
if
s
.
TLSCertFile
==
""
&&
s
.
TLSPrivateKeyFile
==
""
{
if
s
.
TLSCertFile
==
""
&&
s
.
TLSPrivateKeyFile
==
""
{
s
.
TLSCertFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.crt"
)
s
.
TLSCertFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.crt"
)
s
.
TLSPrivateKeyFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.key"
)
s
.
TLSPrivateKeyFile
=
path
.
Join
(
s
.
CertDirectory
,
"kubelet.key"
)
if
err
:=
crypto
.
GenerateSelfSignedCert
(
nodeutil
.
GetHostname
(
s
.
HostnameOverride
),
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
,
nil
,
nil
);
err
!=
nil
{
if
crypto
.
ShouldGenSelfSignedCerts
(
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
)
{
return
nil
,
fmt
.
Errorf
(
"unable to generate self signed cert: %v"
,
err
)
if
err
:=
crypto
.
GenerateSelfSignedCert
(
nodeutil
.
GetHostname
(
s
.
HostnameOverride
),
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
,
nil
,
nil
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to generate self signed cert: %v"
,
err
)
}
glog
.
V
(
4
)
.
Infof
(
"Using self-signed cert (%s, %s)"
,
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
)
}
}
glog
.
V
(
4
)
.
Infof
(
"Using self-signed cert (%s, %s)"
,
s
.
TLSCertFile
,
s
.
TLSPrivateKeyFile
)
}
}
tlsOptions
:=
&
server
.
TLSOptions
{
tlsOptions
:=
&
server
.
TLSOptions
{
Config
:
&
tls
.
Config
{
Config
:
&
tls
.
Config
{
...
...
pkg/genericapiserver/genericapiserver.go
View file @
973774b0
...
@@ -692,7 +692,7 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) {
...
@@ -692,7 +692,7 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) {
alternateDNS
:=
[]
string
{
"kubernetes.default.svc"
,
"kubernetes.default"
,
"kubernetes"
}
alternateDNS
:=
[]
string
{
"kubernetes.default.svc"
,
"kubernetes.default"
,
"kubernetes"
}
// It would be nice to set a fqdn subject alt name, but only the kubelets know, the apiserver is clueless
// It would be nice to set a fqdn subject alt name, but only the kubelets know, the apiserver is clueless
// alternateDNS = append(alternateDNS, "kubernetes.default.svc.CLUSTER.DNS.NAME")
// alternateDNS = append(alternateDNS, "kubernetes.default.svc.CLUSTER.DNS.NAME")
if
s
houldGenSelfSignedCerts
(
options
.
TLSCertFile
,
options
.
TLSPrivateKeyFile
)
{
if
crypto
.
S
houldGenSelfSignedCerts
(
options
.
TLSCertFile
,
options
.
TLSPrivateKeyFile
)
{
if
err
:=
crypto
.
GenerateSelfSignedCert
(
s
.
ClusterIP
.
String
(),
options
.
TLSCertFile
,
options
.
TLSPrivateKeyFile
,
alternateIPs
,
alternateDNS
);
err
!=
nil
{
if
err
:=
crypto
.
GenerateSelfSignedCert
(
s
.
ClusterIP
.
String
(),
options
.
TLSCertFile
,
options
.
TLSPrivateKeyFile
,
alternateIPs
,
alternateDNS
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to generate self signed cert: %v"
,
err
)
glog
.
Errorf
(
"Unable to generate self signed cert: %v"
,
err
)
}
else
{
}
else
{
...
@@ -731,28 +731,6 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) {
...
@@ -731,28 +731,6 @@ func (s *GenericAPIServer) Run(options *options.ServerRunOptions) {
glog
.
Fatal
(
http
.
ListenAndServe
())
glog
.
Fatal
(
http
.
ListenAndServe
())
}
}
// If the file represented by path exists and
// readable, return true otherwise return false.
func
canReadFile
(
path
string
)
bool
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
false
}
defer
f
.
Close
()
return
true
}
func
shouldGenSelfSignedCerts
(
certPath
,
keyPath
string
)
bool
{
if
canReadFile
(
certPath
)
||
canReadFile
(
keyPath
)
{
glog
.
Infof
(
"using existing apiserver.crt and apiserver.key files"
)
return
false
}
return
true
}
// Exposes the given group version in API.
// Exposes the given group version in API.
func
(
s
*
GenericAPIServer
)
InstallAPIGroup
(
apiGroupInfo
*
APIGroupInfo
)
error
{
func
(
s
*
GenericAPIServer
)
InstallAPIGroup
(
apiGroupInfo
*
APIGroupInfo
)
error
{
apiPrefix
:=
s
.
APIGroupPrefix
apiPrefix
:=
s
.
APIGroupPrefix
...
...
pkg/util/crypto/crypto.go
View file @
973774b0
...
@@ -33,6 +33,29 @@ import (
...
@@ -33,6 +33,29 @@ import (
"time"
"time"
)
)
// ShouldGenSelfSignedCerts returns false if the certificate or key files already exists,
// otherwise returns true.
func
ShouldGenSelfSignedCerts
(
certPath
,
keyPath
string
)
bool
{
if
canReadFile
(
certPath
)
||
canReadFile
(
keyPath
)
{
return
false
}
return
true
}
// If the file represented by path exists and
// readable, returns true otherwise returns false.
func
canReadFile
(
path
string
)
bool
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
false
}
defer
f
.
Close
()
return
true
}
// GenerateSelfSignedCert creates a self-signed certificate and key for the given host.
// GenerateSelfSignedCert creates a self-signed certificate and key for the given host.
// Host may be an IP or a DNS name
// Host may be an IP or a DNS name
// You may also specify additional subject alt names (either ip or dns names) for the certificate
// You may also specify additional subject alt names (either ip or dns names) for the certificate
...
...
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