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
6ea1d5d5
Commit
6ea1d5d5
authored
Dec 05, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
join client CA bundles into the accept path for genericapiserver
parent
fbb35b72
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
22 deletions
+46
-22
server.go
cmd/kube-apiserver/app/server.go
+3
-1
apiserver.go
examples/apiserver/apiserver.go
+3
-1
server.go
federation/cmd/federation-apiserver/app/server.go
+3
-1
local-up-cluster.sh
hack/local-up-cluster.sh
+1
-3
config.go
pkg/genericapiserver/config.go
+31
-6
serve.go
pkg/genericapiserver/serve.go
+2
-7
io.go
pkg/util/cert/io.go
+3
-3
No files found.
cmd/kube-apiserver/app/server.go
View file @
6ea1d5d5
...
@@ -103,7 +103,9 @@ func Run(s *options.ServerRunOptions) error {
...
@@ -103,7 +103,9 @@ func Run(s *options.ServerRunOptions) error {
if
_
,
err
:=
genericConfig
.
ApplySecureServingOptions
(
s
.
SecureServing
);
err
!=
nil
{
if
_
,
err
:=
genericConfig
.
ApplySecureServingOptions
(
s
.
SecureServing
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to configure https: %s"
,
err
)
return
fmt
.
Errorf
(
"failed to configure https: %s"
,
err
)
}
}
genericConfig
.
ApplyAuthenticationOptions
(
s
.
Authentication
)
if
_
,
err
=
genericConfig
.
ApplyAuthenticationOptions
(
s
.
Authentication
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to configure authentication: %s"
,
err
)
}
capabilities
.
Initialize
(
capabilities
.
Capabilities
{
capabilities
.
Initialize
(
capabilities
.
Capabilities
{
AllowPrivileged
:
s
.
AllowPrivileged
,
AllowPrivileged
:
s
.
AllowPrivileged
,
...
...
examples/apiserver/apiserver.go
View file @
6ea1d5d5
...
@@ -106,7 +106,9 @@ func (serverOptions *ServerRunOptions) Run(stopCh <-chan struct{}) error {
...
@@ -106,7 +106,9 @@ func (serverOptions *ServerRunOptions) Run(stopCh <-chan struct{}) error {
if
_
,
err
:=
config
.
ApplySecureServingOptions
(
serverOptions
.
SecureServing
);
err
!=
nil
{
if
_
,
err
:=
config
.
ApplySecureServingOptions
(
serverOptions
.
SecureServing
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to configure https: %s"
,
err
)
return
fmt
.
Errorf
(
"failed to configure https: %s"
,
err
)
}
}
config
.
ApplyAuthenticationOptions
(
serverOptions
.
Authentication
)
if
_
,
err
:=
config
.
ApplyAuthenticationOptions
(
serverOptions
.
Authentication
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to configure authentication: %s"
,
err
)
}
config
.
Authorizer
=
authorizer
.
NewAlwaysAllowAuthorizer
()
config
.
Authorizer
=
authorizer
.
NewAlwaysAllowAuthorizer
()
s
,
err
:=
config
.
Complete
()
.
New
()
s
,
err
:=
config
.
Complete
()
.
New
()
...
...
federation/cmd/federation-apiserver/app/server.go
View file @
6ea1d5d5
...
@@ -85,7 +85,9 @@ func Run(s *options.ServerRunOptions) error {
...
@@ -85,7 +85,9 @@ func Run(s *options.ServerRunOptions) error {
if
_
,
err
:=
genericConfig
.
ApplySecureServingOptions
(
s
.
SecureServing
);
err
!=
nil
{
if
_
,
err
:=
genericConfig
.
ApplySecureServingOptions
(
s
.
SecureServing
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to configure https: %s"
,
err
)
return
fmt
.
Errorf
(
"failed to configure https: %s"
,
err
)
}
}
genericConfig
.
ApplyAuthenticationOptions
(
s
.
Authentication
)
if
_
,
err
:=
genericConfig
.
ApplyAuthenticationOptions
(
s
.
Authentication
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to configure authentication: %s"
,
err
)
}
// TODO: register cluster federation resources here.
// TODO: register cluster federation resources here.
resourceConfig
:=
genericapiserver
.
NewResourceConfig
()
resourceConfig
:=
genericapiserver
.
NewResourceConfig
()
...
...
hack/local-up-cluster.sh
View file @
6ea1d5d5
...
@@ -455,14 +455,12 @@ EOF
...
@@ -455,14 +455,12 @@ EOF
EOF
EOF
create_client_certkey auth-proxy-client-ca auth-proxy system:auth-proxy
create_client_certkey auth-proxy-client-ca auth-proxy system:auth-proxy
sudo
bash
-c
"cat '
${
CERT_DIR
}
/client-ca.crt' '
${
CERT_DIR
}
/auth-proxy-client-ca.crt' > '
${
CERT_DIR
}
/client-ca-bundle.crt'"
APISERVER_LOG
=
/tmp/kube-apiserver.log
APISERVER_LOG
=
/tmp/kube-apiserver.log
${
CONTROLPLANE_SUDO
}
"
${
GO_OUT
}
/hyperkube"
apiserver
${
anytoken_arg
}
${
auth_proxy_arg
}
${
authorizer_arg
}
${
priv_arg
}
${
runtime_config
}
\
${
CONTROLPLANE_SUDO
}
"
${
GO_OUT
}
/hyperkube"
apiserver
${
anytoken_arg
}
${
auth_proxy_arg
}
${
authorizer_arg
}
${
priv_arg
}
${
runtime_config
}
\
${
advertise_address
}
\
${
advertise_address
}
\
--v
=
${
LOG_LEVEL
}
\
--v
=
${
LOG_LEVEL
}
\
--cert-dir
=
"
${
CERT_DIR
}
"
\
--cert-dir
=
"
${
CERT_DIR
}
"
\
--client-ca-file
=
"
${
CERT_DIR
}
/client-ca
-bundle
.crt"
\
--client-ca-file
=
"
${
CERT_DIR
}
/client-ca.crt"
\
--service-account-key-file
=
"
${
SERVICE_ACCOUNT_KEY
}
"
\
--service-account-key-file
=
"
${
SERVICE_ACCOUNT_KEY
}
"
\
--service-account-lookup
=
"
${
SERVICE_ACCOUNT_LOOKUP
}
"
\
--service-account-lookup
=
"
${
SERVICE_ACCOUNT_LOOKUP
}
"
\
--admission-control
=
"
${
ADMISSION_CONTROL
}
"
\
--admission-control
=
"
${
ADMISSION_CONTROL
}
"
\
...
...
pkg/genericapiserver/config.go
View file @
6ea1d5d5
...
@@ -18,6 +18,7 @@ package genericapiserver
...
@@ -18,6 +18,7 @@ package genericapiserver
import
(
import
(
"crypto/tls"
"crypto/tls"
"crypto/x509"
"encoding/pem"
"encoding/pem"
"fmt"
"fmt"
"io"
"io"
...
@@ -60,6 +61,7 @@ import (
...
@@ -60,6 +61,7 @@ import (
"k8s.io/kubernetes/pkg/genericapiserver/routes"
"k8s.io/kubernetes/pkg/genericapiserver/routes"
genericvalidation
"k8s.io/kubernetes/pkg/genericapiserver/validation"
genericvalidation
"k8s.io/kubernetes/pkg/genericapiserver/validation"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
certutil
"k8s.io/kubernetes/pkg/util/cert"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/version"
"k8s.io/kubernetes/pkg/version"
authenticatorunion
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
authenticatorunion
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/request/union"
...
@@ -180,7 +182,7 @@ type SecureServingInfo struct {
...
@@ -180,7 +182,7 @@ type SecureServingInfo struct {
SNICerts
map
[
string
]
*
tls
.
Certificate
SNICerts
map
[
string
]
*
tls
.
Certificate
// ClientCA is the certificate bundle for all the signers that you'll recognize for incoming client certificates
// ClientCA is the certificate bundle for all the signers that you'll recognize for incoming client certificates
ClientCA
string
ClientCA
*
x509
.
CertPool
}
}
// NewConfig returns a Config struct with the default values
// NewConfig returns a Config struct with the default values
...
@@ -299,17 +301,40 @@ func (c *Config) ApplyInsecureServingOptions(insecureServing *options.ServingOpt
...
@@ -299,17 +301,40 @@ func (c *Config) ApplyInsecureServingOptions(insecureServing *options.ServingOpt
return
c
return
c
}
}
func
(
c
*
Config
)
ApplyAuthenticationOptions
(
o
*
options
.
BuiltInAuthenticationOptions
)
*
Config
{
func
(
c
*
Config
)
ApplyAuthenticationOptions
(
o
*
options
.
BuiltInAuthenticationOptions
)
(
*
Config
,
error
)
{
if
o
==
nil
||
o
.
PasswordFile
==
nil
{
if
o
==
nil
||
o
.
PasswordFile
==
nil
{
return
c
return
c
,
nil
}
}
if
o
.
ClientCert
!=
nil
&&
c
.
SecureServingInfo
!=
nil
{
if
c
.
SecureServingInfo
!=
nil
{
c
.
SecureServingInfo
.
ClientCA
=
o
.
ClientCert
.
ClientCA
if
o
.
ClientCert
!=
nil
&&
len
(
o
.
ClientCert
.
ClientCA
)
>
0
{
clientCAs
,
err
:=
certutil
.
CertsFromFile
(
o
.
ClientCert
.
ClientCA
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to load client CA file: %v"
,
err
)
}
if
c
.
SecureServingInfo
.
ClientCA
==
nil
{
c
.
SecureServingInfo
.
ClientCA
=
x509
.
NewCertPool
()
}
for
_
,
cert
:=
range
clientCAs
{
c
.
SecureServingInfo
.
ClientCA
.
AddCert
(
cert
)
}
}
if
o
.
RequestHeader
!=
nil
&&
len
(
o
.
RequestHeader
.
ClientCAFile
)
>
0
{
clientCAs
,
err
:=
certutil
.
CertsFromFile
(
o
.
RequestHeader
.
ClientCAFile
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"unable to load requestheader client CA file: %v"
,
err
)
}
if
c
.
SecureServingInfo
.
ClientCA
==
nil
{
c
.
SecureServingInfo
.
ClientCA
=
x509
.
NewCertPool
()
}
for
_
,
cert
:=
range
clientCAs
{
c
.
SecureServingInfo
.
ClientCA
.
AddCert
(
cert
)
}
}
}
}
c
.
SupportsBasicAuth
=
len
(
o
.
PasswordFile
.
BasicAuthFile
)
>
0
c
.
SupportsBasicAuth
=
len
(
o
.
PasswordFile
.
BasicAuthFile
)
>
0
return
c
return
c
,
nil
}
}
// ApplyOptions applies the run options to the method receiver and returns self
// ApplyOptions applies the run options to the method receiver and returns self
...
...
pkg/genericapiserver/serve.go
View file @
6ea1d5d5
...
@@ -26,7 +26,6 @@ import (
...
@@ -26,7 +26,6 @@ import (
"sync"
"sync"
"time"
"time"
certutil
"k8s.io/kubernetes/pkg/util/cert"
utilruntime
"k8s.io/kubernetes/pkg/util/runtime"
utilruntime
"k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/validation"
"k8s.io/kubernetes/pkg/util/validation"
...
@@ -69,16 +68,12 @@ func (s *GenericAPIServer) serveSecurely(stopCh <-chan struct{}) error {
...
@@ -69,16 +68,12 @@ func (s *GenericAPIServer) serveSecurely(stopCh <-chan struct{}) error {
secureServer
.
TLSConfig
.
Certificates
=
append
(
secureServer
.
TLSConfig
.
Certificates
,
*
c
)
secureServer
.
TLSConfig
.
Certificates
=
append
(
secureServer
.
TLSConfig
.
Certificates
,
*
c
)
}
}
if
len
(
s
.
SecureServingInfo
.
ClientCA
)
>
0
{
if
s
.
SecureServingInfo
.
ClientCA
!=
nil
{
clientCAs
,
err
:=
certutil
.
NewPool
(
s
.
SecureServingInfo
.
ClientCA
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to load client CA file: %v"
,
err
)
}
// Populate PeerCertificates in requests, but don't reject connections without certificates
// Populate PeerCertificates in requests, but don't reject connections without certificates
// This allows certificates to be validated by authenticators, while still allowing other auth types
// This allows certificates to be validated by authenticators, while still allowing other auth types
secureServer
.
TLSConfig
.
ClientAuth
=
tls
.
RequestClientCert
secureServer
.
TLSConfig
.
ClientAuth
=
tls
.
RequestClientCert
// Specify allowed CAs for client certificates
// Specify allowed CAs for client certificates
secureServer
.
TLSConfig
.
ClientCAs
=
clientCAs
secureServer
.
TLSConfig
.
ClientCAs
=
s
.
SecureServingInfo
.
ClientCA
}
}
glog
.
Infof
(
"Serving securely on %s"
,
s
.
SecureServingInfo
.
BindAddress
)
glog
.
Infof
(
"Serving securely on %s"
,
s
.
SecureServingInfo
.
BindAddress
)
...
...
pkg/util/cert/io.go
View file @
6ea1d5d5
...
@@ -90,7 +90,7 @@ func WriteKey(keyPath string, data []byte) error {
...
@@ -90,7 +90,7 @@ func WriteKey(keyPath string, data []byte) error {
// NewPool returns an x509.CertPool containing the certificates in the given PEM-encoded file.
// NewPool returns an x509.CertPool containing the certificates in the given PEM-encoded file.
// Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates
// Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates
func
NewPool
(
filename
string
)
(
*
x509
.
CertPool
,
error
)
{
func
NewPool
(
filename
string
)
(
*
x509
.
CertPool
,
error
)
{
certs
,
err
:=
c
ertsFromFile
(
filename
)
certs
,
err
:=
C
ertsFromFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -101,9 +101,9 @@ func NewPool(filename string) (*x509.CertPool, error) {
...
@@ -101,9 +101,9 @@ func NewPool(filename string) (*x509.CertPool, error) {
return
pool
,
nil
return
pool
,
nil
}
}
//
c
ertsFromFile returns the x509.Certificates contained in the given PEM-encoded file.
//
C
ertsFromFile returns the x509.Certificates contained in the given PEM-encoded file.
// Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates
// Returns an error if the file could not be read, a certificate could not be parsed, or if the file does not contain any certificates
func
c
ertsFromFile
(
file
string
)
([]
*
x509
.
Certificate
,
error
)
{
func
C
ertsFromFile
(
file
string
)
([]
*
x509
.
Certificate
,
error
)
{
if
len
(
file
)
==
0
{
if
len
(
file
)
==
0
{
return
nil
,
errors
.
New
(
"error reading certificates from an empty filename"
)
return
nil
,
errors
.
New
(
"error reading certificates from an empty filename"
)
}
}
...
...
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