Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kuma-cp) user token enabled by default #2941

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -33,6 +33,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_rbac "github.com/kumahq/kuma/pkg/tokens/builtin/rbac"
tokens_server "github.com/kumahq/kuma/pkg/tokens/builtin/server"
Expand Down Expand Up @@ -281,7 +282,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