Skip to content

Commit 597c42c

Browse files
committed
ING-1340: Support client certs not signed by the cluster CA
1 parent c1dde88 commit 597c42c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cmd/gateway/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func init() {
8585
configFlags.Bool("self-sign", false, "specifies to allow a self-signed certificate")
8686
configFlags.String("cert", "", "path to default tls cert")
8787
configFlags.String("cluster-cert", "", "path to cluster tls ca cert")
88+
configFlags.String("client-ca-cert", "", "path to tls ca cert for client certs for mtls")
8889
configFlags.String("key", "", "path to default private tls key")
8990
configFlags.String("grpc-cert", "", "path to grpc tls cert for GRPC")
9091
configFlags.String("grpc-key", "", "path to grpc private tls key for GRPC")
@@ -261,6 +262,7 @@ type config struct {
261262
dapiCertPath string
262263
dapiKeyPath string
263264
clusterCaCertPath string
265+
clientCaCertPath string
264266
rateLimit int
265267
otlpEndpoint string
266268
disableTraces bool
@@ -300,6 +302,7 @@ func readConfig(logger *zap.Logger) *config {
300302
dapiCertPath: viper.GetString("dapi-cert"),
301303
dapiKeyPath: viper.GetString("dapi-key"),
302304
clusterCaCertPath: viper.GetString("cluster-cert"),
305+
clientCaCertPath: viper.GetString("client-ca-cert"),
303306
rateLimit: viper.GetInt("rate-limit"),
304307
otlpEndpoint: viper.GetString("otlp-endpoint"),
305308
disableTraces: viper.GetBool("disable-traces"),
@@ -332,6 +335,7 @@ func readConfig(logger *zap.Logger) *config {
332335
zap.Int("dapiPort", config.dapiPort),
333336
zap.Bool("selfSign", config.selfSign),
334337
zap.String("certPath", config.certPath),
338+
zap.String("clientCaCertPath", config.clientCaCertPath),
335339
zap.String("keyPath", config.keyPath),
336340
zap.String("grpcCertPath", config.grpcCertPath),
337341
zap.String("grpcKeyPath", config.grpcKeyPath),
@@ -524,6 +528,17 @@ func startGateway() {
524528
caCertPool.AppendCertsFromPEM(caCert)
525529
}
526530

531+
var clientCaCertPool *x509.CertPool
532+
if config.clientCaCertPath != "" {
533+
clientCaCertPool = x509.NewCertPool()
534+
clientCaCert, err := os.ReadFile(config.clientCaCertPath)
535+
if err != nil {
536+
logger.Error("failed to load client tls ca certificate", zap.Error(err))
537+
}
538+
539+
clientCaCertPool.AppendCertsFromPEM(clientCaCert)
540+
}
541+
527542
if config.cbCredsAwsId != "" {
528543
if config.cbUser != "Administrator" || config.cbPass != "password" {
529544
logger.Error("cannot use cb-pass or cb-user when fetching creds from cloud provider")
@@ -601,6 +616,7 @@ func startGateway() {
601616
GrpcCertificate: grpcCertificate,
602617
DapiCertificate: dapiCertificate,
603618
ClusterCaCert: caCertPool,
619+
ClientCaCert: clientCaCertPool,
604620
NumInstances: 1,
605621
StartupCallback: func(m *gateway.StartupInfo) {
606622
webapi.MarkSystemHealthy()

gateway/gateway.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type Config struct {
6969
GrpcCertificate tls.Certificate
7070
DapiCertificate tls.Certificate
7171
ClusterCaCert *x509.CertPool
72+
ClientCaCert *x509.CertPool
7273

7374
NumInstances uint
7475
StartupCallback func(*StartupInfo)
@@ -410,7 +411,7 @@ func (g *Gateway) Run(ctx context.Context) error {
410411
Metrics: metrics.GetSnMetrics(),
411412
RateLimiter: rateLimiter,
412413
GrpcTlsConfig: &tls.Config{
413-
ClientCAs: config.ClusterCaCert,
414+
ClientCAs: config.ClientCaCert,
414415
ClientAuth: tls.VerifyClientCertIfGiven,
415416
GetCertificate: func(chi *tls.ClientHelloInfo) (*tls.Certificate, error) {
416417
return g.atomicGrpcCert.Load(), nil

0 commit comments

Comments
 (0)