Skip to content

Commit

Permalink
feat(kuma-cp) user token enabled by default
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz committed Oct 11, 2021
1 parent 5f76b57 commit e3533b5
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/api-server/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

config "github.com/kumahq/kuma/pkg/config/api-server"
"github.com/kumahq/kuma/pkg/metrics"
"github.com/kumahq/kuma/pkg/plugins/authn/api-server/certs"
"github.com/kumahq/kuma/pkg/plugins/resources/memory"
"github.com/kumahq/kuma/pkg/tls"
http2 "github.com/kumahq/kuma/pkg/util/http"
Expand All @@ -38,6 +39,7 @@ var _ = Describe("Auth test", func() {
cfg := config.DefaultApiServerConfig()
cfg.HTTPS.TlsCertFile = certPath
cfg.HTTPS.TlsKeyFile = keyPath
cfg.Authn.Type = certs.PluginName
cfg.Auth.ClientCertsDir = filepath.Join("..", "..", "test", "certs", "client")
apiServer := createTestApiServer(resourceStore, cfg, true, metrics)
httpsPort = cfg.HTTPS.Port
Expand Down
2 changes: 1 addition & 1 deletion pkg/api-server/config_ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("Config WS", func() {
},
"authn": {
"localhostIsAdmin": true,
"type": "clientCerts",
"type": "tokens",
"tokens": {
"bootstrapAdminToken": true
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/api-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kumahq/kuma/pkg/core/resources/registry"
"github.com/kumahq/kuma/pkg/core/runtime"
"github.com/kumahq/kuma/pkg/metrics"
"github.com/kumahq/kuma/pkg/plugins/authn/api-server/certs"
"github.com/kumahq/kuma/pkg/tokens/builtin"
tokens_server "github.com/kumahq/kuma/pkg/tokens/builtin/server"
util_prometheus "github.com/kumahq/kuma/pkg/util/prometheus"
Expand Down Expand Up @@ -285,7 +286,7 @@ func (a *ApiServer) startHttpServer(errChan chan error) *http.Server {

func (a *ApiServer) startHttpsServer(errChan chan error) *http.Server {
var tlsConfig *tls.Config
if a.config.Authn.Type == "clientCerts" {
if a.config.Authn.Type == certs.PluginName {
tlsC, err := configureMTLS(a.config.Auth.ClientCertsDir)
if err != nil {
errChan <- err
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/api-server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func DefaultApiServerConfig() *ApiServerConfig {
ClientCertsDir: "",
},
Authn: ApiServerAuthn{
Type: "clientCerts",
Type: "tokens",
LocalhostIsAdmin: true,
Tokens: ApiServerAuthnTokens{
BootstrapAdminToken: true,
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ apiServer:
clientCertsDir: "" # ENV: KUMA_API_SERVER_AUTH_CLIENT_CERTS_DIR
# Api Server Authentication configuration
authn:
# Type of authentication mechanism (available values: "clientCerts")
type: clientCerts # ENV: KUMA_API_SERVER_AUTHN_TYPE
# Type of authentication mechanism (available values: "adminClientCerts", "tokens")
type: tokens # ENV: KUMA_API_SERVER_AUTHN_TYPE
# Localhost is authenticated as a user admin of group admin
localhostIsAdmin: true # ENV: KUMA_API_SERVER_AUTHN_LOCALHOST_IS_ADMIN
# Configuration for tokens authentication
Expand Down
1 change: 1 addition & 0 deletions pkg/plugins/authn/api-server/certs/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/kumahq/kuma/pkg/core/user"
)

// backwards compatibility with Kuma 1.3.x
func ClientCertAuthenticator(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
if user.FromCtx(request.Request.Context()) == nil && // do not overwrite existing user
request.Request.TLS != nil &&
Expand Down
6 changes: 5 additions & 1 deletion pkg/plugins/authn/api-server/certs/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package certs

import (
"github.com/kumahq/kuma/pkg/api-server/authn"
"github.com/kumahq/kuma/pkg/core"
"github.com/kumahq/kuma/pkg/core/plugins"
)

const PluginName = "clientCerts"
const PluginName = "adminClientCerts"

var log = core.Log.WithName("plugins").WithName("authn").WithName("api-server").WithName("certs")

type plugin struct {
}
Expand All @@ -17,5 +20,6 @@ func init() {
var _ plugins.AuthnAPIServerPlugin = plugin{}

func (c plugin) NewAuthenticator(_ plugins.PluginContext) (authn.Authenticator, error) {
log.Info("WARNING: admin client certificates are deprecated. Please migrate to user token as API Server authentication mechanism.")
return ClientCertAuthenticator, nil
}
1 change: 1 addition & 0 deletions tools/e2e/examples/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
# DNS name of the Kuma xDS server
- KUMA_GENERAL_TLS_CERT_FILE=/certs/server/cert.pem
- KUMA_GENERAL_TLS_KEY_FILE=/certs/server/key.pem
- KUMA_API_SERVER_AUTHN_TYPE=adminClientCerts
- KUMA_API_SERVER_AUTH_CLIENT_CERTS_DIR=/certs/client
expose:
- "5678"
Expand Down

0 comments on commit e3533b5

Please sign in to comment.