Skip to content

Commit

Permalink
Add TLS support for Trillian server
Browse files Browse the repository at this point in the history
Signed-off-by: Firas Ghanmi <fghanmi@redhat.com>
  • Loading branch information
fghanmi committed Jul 2, 2024
1 parent 5fd1711 commit 9679d43
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/rekor-server/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Memory and file-based signers should only be used for testing.`)
rootCmd.PersistentFlags().String("redis_server.password", "", "Redis server password")
rootCmd.PersistentFlags().Bool("redis_server.enable-tls", false, "Whether to enable TLS verification when connecting to Redis endpoint")
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'")
rootCmd.PersistentFlags().String("tls_ca_cert", "", "Certificate file to use for secure connections with Trillian server")
rootCmd.PersistentFlags().Bool("trillian_log_server.tls", false, "Use TLS when connecting to Trillian")

rootCmd.PersistentFlags().Bool("enable_attestation_storage", false, "enables rich attestation storage")
rootCmd.PersistentFlags().String("attestation_storage_bucket", "", "url for attestation storage bucket")
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ services:
"--rpc_endpoint=0.0.0.0:8090",
"--http_endpoint=0.0.0.0:8091",
"--alsologtostderr",
"--tls_cert_file=/tests/tls/tls.crt",
"--tls_key_file=/tests/tls/tls.key"
]
volumes:
- "./tests/tls:/tests/tls:z"
restart: always # retry while mysql is starting up
ports:
- "8090:8090"
Expand Down Expand Up @@ -102,11 +106,13 @@ services:
"--enable_stable_checkpoint",
"--search_index.storage_provider=mysql",
"--search_index.mysql.dsn=test:zaphod@tcp(mysql:3306)/test",
"--tls_ca_cert=/tests/tls/ca.crt"
# Uncomment this for production logging
# "--log_type=prod",
]
volumes:
- "/var/run/attestations:/var/run/attestations:z"
- "./tests/tls:/tests/tls:z"
restart: always # keep the server running
ports:
- "3000:3000"
Expand Down
31 changes: 30 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import (
"crypto/x509"
"encoding/hex"
"fmt"
"os"
"path/filepath"

"github.com/google/trillian"
"github.com/redis/go-redis/v9"
"github.com/spf13/viper"
"golang.org/x/exp/slices"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"github.com/sigstore/rekor/pkg/indexstorage"
Expand All @@ -47,7 +50,33 @@ import (

func dial(rpcServer string) (*grpc.ClientConn, error) {
// Set up and test connection to rpc server
creds := insecure.NewCredentials()
var creds credentials.TransportCredentials
tlsCACertFile := viper.GetString("tls_ca_cert")
useSystemTrustStore := viper.GetBool("trillian_log_server.tls")

switch {
case useSystemTrustStore:
creds = credentials.NewTLS(&tls.Config{
ServerName: rpcServer,
MinVersion: tls.VersionTLS12,
})
case tlsCACertFile == "":
creds = insecure.NewCredentials()
default:
tlsCaCert, err := os.ReadFile(filepath.Clean(tlsCACertFile))
if err != nil {
log.Logger.Fatalf("Failed to load tls_ca_cert:", err)
}
certPool := x509.NewCertPool()
if !certPool.AppendCertsFromPEM(tlsCaCert) {
return nil, fmt.Errorf("failed to append CA certificate to pool")
}
creds = credentials.NewTLS(&tls.Config{
ServerName: rpcServer,
RootCAs: certPool,
MinVersion: tls.VersionTLS12,
})
}
conn, err := grpc.NewClient(rpcServer, grpc.WithTransportCredentials(creds))
if err != nil {
log.Logger.Fatalf("Failed to connect to RPC server:", err)
Expand Down
19 changes: 19 additions & 0 deletions tests/tls/ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDATCCAemgAwIBAgIUXVkFgPS1jbBHhXk2M3NKTfOkTeIwDQYJKoZIhvcNAQEL
BQAwEDEOMAwGA1UEAwwFTXkgQ0EwHhcNMjQwNzAyMTU0MDQwWhcNMjUwNzAyMTU0
MDQwWjAQMQ4wDAYDVQQDDAVNeSBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBAOM3859H+Kod32SgW2zHN3KN3+r3fXVnkpA+j0CR0Vq1YEcexsQIaXJx
hXUXK4EXsa6lnzqqquCo5OmpTs1ZUWyFdlrFSwes2RFLOJ/QIVGSyVirtYOpgFdo
F/cmfI66UNeH1UpAsf2tTjcDmE5A8aAaoyQllIUZ8QqhDjNy3i6zPAf+cW9+wq8w
nk8M9blcXg0v6gjIA0e6XnkHyNmUep3bUbpQ9JbtD901/hbmM/uYu0VoyaxhTwha
2zRqmkK1EOqTvsoI2g3WSnTLL+H9bWdJg1HSYA/MQCkNOpOWO3SRIxNKDysYRMoW
eJigHE5/Fcs0q7zkIZXfJkFXINQVglMCAwEAAaNTMFEwHQYDVR0OBBYEFJdAxaB8
JkZN9z/fT5Bgn5wnK830MB8GA1UdIwQYMBaAFJdAxaB8JkZN9z/fT5Bgn5wnK830
MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBADbQ7wkSoLyhcbc7
du7bLTFk7xTg0WV6IiV0ZmBxGVvRW6kjUA1diH+Sr1Gy4Z+HmVhT28zFVVKNataE
g53n9wJigH7FwMVqNrZHD6V7JXc2il+lO9ICvGnH4xYUQBjNHu99g10WAeA706M7
IlbGIsFc+tWcplpFW2H/UIIio3fLq1HCRe7WbbQHsbZ5OkoeUhu9YCvslqSa0w/f
t7d8oDZltquH7zkiZoqY6hNZTJYy2+5HSjx3n/QumKuzuhhEjGuG8LX8dNrL4k6y
nqVf3PBWlMeK+jwwa9AXcqcL+5a/npeM5Z7UOA6W/I+zVop6OZK7KohKeDIErC/t
Tn8+2Co=
-----END CERTIFICATE-----
19 changes: 19 additions & 0 deletions tests/tls/tls.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIC/jCCAeagAwIBAgIUXBONalvsgMSSss6Ac9F+Qiy0RoMwDQYJKoZIhvcNAQEL
BQAwEDEOMAwGA1UEAwwFTXkgQ0EwHhcNMjQwNzAyMTU0MDQwWhcNMjUwNzAyMTU0
MDQwWjAeMRwwGgYDVQQDDBN0cmlsbGlhbi1sb2ctc2VydmVyMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuSy6h6wZ4C8HEmeZMnqwYviJiTcjxXArZaPx
ytxrvUOKviyA7oRhepOtSwpuUGh38+yrW6g9fv0c88DLktOwsNGSNZx9Gn8P0cLO
PO1qzXI0zxNwzaTvywHEpUHIynrEILwy5orAcuP004P3Wsx4k2vhe5YdWZBdcw2V
MFbJxOcHVXcrgENsFJkn6M6IuJ3yx+YClaRmYdp8C2jn3uHl4XQt+33kPPiWVj6l
lhW2vkpTzvBLQKwAav6ZCckJGCzUI7deYcZGEkSS0KYfzhH7oODZaLFaKywUHM61
uqZ5N6e/HiNNpQdf5tI1Zqf6Aoa5YQSBvY9oynbCYoMdgUwOnQIDAQABo0IwQDAd
BgNVHQ4EFgQUKR3YSbyQ7sBy5ekiKbOsOKR07CUwHwYDVR0jBBgwFoAUl0DFoHwm
Rk33P99PkGCfnCcrzfQwDQYJKoZIhvcNAQELBQADggEBAEx7hg6YEh9r76afDGg/
Wm/7cru3jyHKrJOogIdvYqmyCXVTez4ZanHKAfjqv8V/WCeW+ZXqjQsKwMy4napx
GGc1JxvLrF5dO0LS0jRT32HD/qAV14HNV7anN0YotbxSenAJlHG7H6uxfHvo1k/R
rte2JKUF0ut3P0cLIdnWGW6fIpB2lnmXFnb6FBtxRZFxFzsV+TBLX+1L0xOrFuvq
lI6Fu4xav5UwJs1ZMf3LhpGVLk5jmvUhnuWXwMYkcWqcCV9R0NKk49xyZ3uU2KYN
crCHIepUbe/efDWBZMexNDqOKMtedoE5gWP4VjYV+AK4e160zig9sJw6q6KCPdie
y3E=
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions tests/tls/tls.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @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