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: allow to configure TLS for gRPC servers #303

Merged
merged 1 commit into from
Aug 31, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/artifact-cas/configs/samples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ server:
grpc:
addr: 0.0.0.0:9001
timeout: 1s
tls_config:
certificate: "./configs/tls/server.crt"
private_key: "./configs/tls/server.key"
http_metrics:
addr: 0.0.0.0:5001

Expand Down
167 changes: 126 additions & 41 deletions app/artifact-cas/internal/conf/conf.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/artifact-cas/internal/conf/conf.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ message Server {
string addr = 2;
google.protobuf.Duration timeout = 3;
}
message TLS {
// path to certificate and private key
string certificate = 1;
string private_key = 2;
}
message GRPC {
string network = 1;
string addr = 2;
google.protobuf.Duration timeout = 3;
TLS tls_config = 4;
}
// Regular HTTP endpoint
HTTP http = 1;
Expand Down
16 changes: 16 additions & 0 deletions app/artifact-cas/internal/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package server

import (
"context"
"crypto/tls"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -99,6 +100,21 @@ func NewGRPCServer(c *conf.Server, authConf *conf.Auth, byteService *service.Byt
if c.Grpc.Timeout != nil {
opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration()))
}
if tlsConf := c.Grpc.GetTlsConfig(); tlsConf != nil {
migmartri marked this conversation as resolved.
Show resolved Hide resolved
cert := tlsConf.GetCertificate()
privKey := tlsConf.GetPrivateKey()
if cert != "" && privKey != "" {
cert, err := tls.LoadX509KeyPair(cert, privKey)
if err != nil {
return nil, fmt.Errorf("loading gRPC server TLS certificate: %w", err)
}
opts = append(opts, grpc.TLSConfig(&tls.Config{
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS12, // gosec complains about insecure minimum version we use default value
}))
}
}

srv := grpc.NewServer(opts...)

bytestream.RegisterByteStreamServer(srv.Server, byteService)
Expand Down
3 changes: 2 additions & 1 deletion app/cli/api/attestation/v1/crafting_state.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/controlplane/cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/controlplane/configs/samples/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
server:
grpc:
tls_config:
certificate: "./configs/tls/server.crt"
private_key: "./configs/tls/server.key"

auth:
# Development credentials for the SSO authentication roundtrip
oauth:
Expand Down