Skip to content

Commit 6cdb8d3

Browse files
committed
Add TLS support for Trillian server
Signed-off-by: Firas Ghanmi <[email protected]>
1 parent 5fd1711 commit 6cdb8d3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cmd/rekor-server/app/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Memory and file-based signers should only be used for testing.`)
117117
rootCmd.PersistentFlags().String("redis_server.password", "", "Redis server password")
118118
rootCmd.PersistentFlags().Bool("redis_server.enable-tls", false, "Whether to enable TLS verification when connecting to Redis endpoint")
119119
rootCmd.PersistentFlags().Bool("redis_server.insecure-skip-verify", false, "Whether to skip TLS verification when connecting to Redis endpoint, only applicable when 'redis_server.enable-tls' is set to 'true'")
120+
rootCmd.PersistentFlags().String("tls-ca-cert", "", "Certificate file to use for secure connections with Trillian server")
120121

121122
rootCmd.PersistentFlags().Bool("enable_attestation_storage", false, "enables rich attestation storage")
122123
rootCmd.PersistentFlags().String("attestation_storage_bucket", "", "url for attestation storage bucket")

pkg/api/api.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ import (
2222
"crypto/x509"
2323
"encoding/hex"
2424
"fmt"
25+
"os"
26+
"path/filepath"
2527

2628
"github.com/google/trillian"
2729
"github.com/redis/go-redis/v9"
2830
"github.com/spf13/viper"
2931
"golang.org/x/exp/slices"
3032
"google.golang.org/grpc"
33+
"google.golang.org/grpc/credentials"
3134
"google.golang.org/grpc/credentials/insecure"
3235

3336
"github.com/sigstore/rekor/pkg/indexstorage"
@@ -47,7 +50,24 @@ import (
4750

4851
func dial(rpcServer string) (*grpc.ClientConn, error) {
4952
// Set up and test connection to rpc server
50-
creds := insecure.NewCredentials()
53+
var creds credentials.TransportCredentials
54+
tlsCACertFile := viper.GetString("tls-ca-cert")
55+
if tlsCACertFile == "" {
56+
creds = insecure.NewCredentials()
57+
} else {
58+
tlsCaCert, err := os.ReadFile(filepath.Clean(tlsCACertFile))
59+
if err != nil {
60+
log.Logger.Fatalf("Failed to load tls-ca-cert:", err)
61+
}
62+
certPool := x509.NewCertPool()
63+
if !certPool.AppendCertsFromPEM(tlsCaCert) {
64+
return nil, fmt.Errorf("failed to append CA certificate to pool")
65+
}
66+
creds = credentials.NewTLS(&tls.Config{
67+
ServerName: rpcServer,
68+
RootCAs: certPool,
69+
})
70+
}
5171
conn, err := grpc.NewClient(rpcServer, grpc.WithTransportCredentials(creds))
5272
if err != nil {
5373
log.Logger.Fatalf("Failed to connect to RPC server:", err)

0 commit comments

Comments
 (0)