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

add HTTP and GRPC health check endpoints #1258

Merged
merged 6 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions cmd/app/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
health "google.golang.org/grpc/health/grpc_health_v1"
)

const (
Expand Down Expand Up @@ -105,6 +106,8 @@ func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, ba
myServer := grpc.NewServer(serverOpts...)

grpcCAServer := server.NewGRPCCAServer(ctClient, baseca, ip)

health.RegisterHealthServer(myServer, grpcCAServer)
// Register your gRPC service implementations.
gw.RegisterCAServer(myServer, grpcCAServer)

Expand Down Expand Up @@ -161,6 +164,10 @@ func (g *grpcServer) startUnixListener() {
}()
}

func (g *grpcServer) ExposesGRPCTLS() bool {
return viper.IsSet("grpc-tls-certificate") && viper.IsSet("grpc-tls-key")
}

func createLegacyGRPCServer(cfg *config.FulcioConfig, v2Server gw.CAServer) (*grpcServer, error) {
logger, opts := log.SetupGRPCLogging()

Expand Down
18 changes: 16 additions & 2 deletions cmd/app/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import (
"context"
"crypto/tls"
"errors"
"fmt"
"net/http"
Expand All @@ -32,7 +33,9 @@
"github.com/sigstore/fulcio/pkg/log"
"github.com/sigstore/fulcio/pkg/server"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
health "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
)
Expand All @@ -48,10 +51,21 @@
}

func createHTTPServer(ctx context.Context, serverEndpoint string, grpcServer, legacyGRPCServer *grpcServer) httpServer {
opts := []grpc.DialOption{}
if grpcServer.ExposesGRPCTLS() {
opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: true})))

Check failure on line 56 in cmd/app/http.go

View workflow job for this annotation

GitHub Actions / golangci-lint

G402: TLS InsecureSkipVerify set true. (gosec)
Dismissed Show dismissed Hide dismissed
} else {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
cc, err := grpc.Dial(grpcServer.grpcServerEndpoint, opts...)
if err != nil {
log.Logger.Fatal(err)
}

mux := runtime.NewServeMux(runtime.WithMetadata(extractOIDCTokenFromAuthHeader),
runtime.WithForwardResponseOption(setResponseCodeModifier))
runtime.WithForwardResponseOption(setResponseCodeModifier),
runtime.WithHealthzEndpoint(health.NewHealthClient(cc)))

opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
if err := gw.RegisterCAHandlerFromEndpoint(ctx, mux, grpcServer.grpcServerEndpoint, opts); err != nil {
log.Logger.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions config/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ spec:
readOnly: true
- name: oidc-info
mountPath: /var/run/fulcio
livenessProbe:
httpGet:
path: /healthz
port: 5555
initialDelaySeconds: 5
resources:
requests:
memory: "1G"
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
- ~/.config/gcloud:/root/.config/gcloud/:z # for GCP authentication
- ./config/config.jsn:/etc/fulcio-config/config.json:z
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5555/ping"]
test: ["CMD", "curl", "-f", "http://localhost:5555/healthz"]
interval: 10s
timeout: 3s
retries: 3
Expand All @@ -62,7 +62,7 @@ services:
volumes:
- ./config/dex:/etc/config/:ro
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8888/auth/healthz"]
test: ["CMD", "wget", "-O", "/dev/null", "http://localhost:8888/auth/healthz"]
interval: 10s
timeout: 3s
retries: 3
Expand Down
13 changes: 12 additions & 1 deletion pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@
"github.com/sigstore/fulcio/pkg/log"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"google.golang.org/grpc/codes"
health "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)

type grpcCAServer struct {
fulciogrpc.UnimplementedCAServer
health.HealthServer
ct *ctclient.LogClient
ca certauth.CertificateAuthority
identity.IssuerPool
}

func NewGRPCCAServer(ct *ctclient.LogClient, ca certauth.CertificateAuthority, ip identity.IssuerPool) fulciogrpc.CAServer {
func NewGRPCCAServer(ct *ctclient.LogClient, ca certauth.CertificateAuthority, ip identity.IssuerPool) *grpcCAServer {

Check warning on line 48 in pkg/server/grpc_server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unexported-return: exported func NewGRPCCAServer returns unexported type *server.grpcCAServer, which can be annoying to use (revive)
return &grpcCAServer{
ct: ct,
ca: ca,
Expand Down Expand Up @@ -263,3 +266,11 @@
Issuers: cfg.ToIssuers(),
}, nil
}

func (g *grpcCAServer) Check(_ context.Context, _ *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
return &health.HealthCheckResponse{Status: health.HealthCheckResponse_SERVING}, nil
}

func (g *grpcCAServer) Watch(_ *health.HealthCheckRequest, _ health.Health_WatchServer) error {
return status.Error(codes.Unimplemented, "unimplemented")
}
Loading