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: add config option for skipping cert verify when connecting to cloud/enterprise #4763

Merged
merged 6 commits into from
Dec 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func main() {
mode = common.ModeAgent
}
if mode == common.ModeAgent {
grpcConn, err = agent.NewGRPCConnection(ctx, cfg.TestkubeProTLSInsecure, cfg.TestkubeProURL, log.DefaultLogger)
grpcConn, err = agent.NewGRPCConnection(ctx, cfg.TestkubeProTLSInsecure, cfg.TestkubeProSkipVerify, cfg.TestkubeProURL, log.DefaultLogger)
ui.ExitOnError("error creating gRPC connection", err)
defer grpcConn.Close()

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type Config struct {
TestkubeProTLSInsecure bool `envconfig:"TESTKUBE_PRO_TLS_INSECURE" default:"false"`
TestkubeProWorkerCount int `envconfig:"TESTKUBE_PRO_WORKER_COUNT" default:"50"`
TestkubeProLogStreamWorkerCount int `envconfig:"TESTKUBE_PRO_LOG_STREAM_WORKER_COUNT" default:"25"`
TestkubeProSkipVerify bool `envconfig:"TESTKUBE_PRO_SKIP_VERIFY" default:"false"`
TestkubeWatcherNamespaces string `envconfig:"TESTKUBE_WATCHER_NAMESPACES" default:""`
GraphqlPort string `envconfig:"TESTKUBE_GRAPHQL_PORT" default:"8070"`
TestkubeRegistry string `envconfig:"TESTKUBE_REGISTRY" default:""`
Expand Down
9 changes: 7 additions & 2 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"context"
"crypto/tls"
"fmt"
"math"
"os"
Expand Down Expand Up @@ -41,8 +42,12 @@ const (
// buffer up to five messages per worker
const bufferSizePerWorker = 5

func NewGRPCConnection(ctx context.Context, isInsecure bool, server string, logger *zap.SugaredLogger) (*grpc.ClientConn, error) {
creds := credentials.NewTLS(nil)
func NewGRPCConnection(ctx context.Context, isInsecure bool, skipVerify bool, server string, logger *zap.SugaredLogger) (*grpc.ClientConn, error) {
var tlsConfig *tls.Config
if skipVerify {
tlsConfig = &tls.Config{InsecureSkipVerify: true}
}
creds := credentials.NewTLS(tlsConfig)
if isInsecure {
creds = insecure.NewCredentials()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestCommandExecution(t *testing.T) {
atomic.AddInt32(&msgCnt, 1)
}

grpcConn, err := agent.NewGRPCConnection(context.Background(), true, url, log.DefaultLogger)
grpcConn, err := agent.NewGRPCConnection(context.Background(), true, false, url, log.DefaultLogger)
ui.ExitOnError("error creating gRPC connection", err)
defer grpcConn.Close()

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestEventLoop(t *testing.T) {

logger, _ := zap.NewDevelopment()

grpcConn, err := agent.NewGRPCConnection(context.Background(), true, url, log.DefaultLogger)
grpcConn, err := agent.NewGRPCConnection(context.Background(), true, false, url, log.DefaultLogger)
ui.ExitOnError("error creating gRPC connection", err)
defer grpcConn.Close()

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestLogStream(t *testing.T) {
fmt.Fprintf(ctx, "Hi there! RequestURI is %q", ctx.RequestURI())
}

grpcConn, err := agent.NewGRPCConnection(context.Background(), true, url, log.DefaultLogger)
grpcConn, err := agent.NewGRPCConnection(context.Background(), true, false, url, log.DefaultLogger)
ui.ExitOnError("error creating gRPC connection", err)
defer grpcConn.Close()

Expand Down
2 changes: 2 additions & 0 deletions pkg/envs/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Params struct {
CloudAPITLSInsecure bool `envconfig:"RUNNER_CLOUD_API_TLS_INSECURE"` // RUNNER_CLOUD_API_TLS_INSECURE
CloudAPIURL string `envconfig:"RUNNER_CLOUD_API_URL"` // RUNNER_CLOUD_API_URL
CloudConnectionTimeoutSec int `envconfig:"RUNNER_CLOUD_CONNECTION_TIMEOUT" default:"10"` // RUNNER_CLOUD_CONNECTION_TIMEOUT
CloudAPISkipVerify bool `envconfig:"RUNNER_CLOUD_API_SKIP_VERIFY" default:"false"` // RUNNER_CLOUD_API_SKIP_VERIFY
SlavesConfigs string `envconfig:"RUNNER_SLAVES_CONFIGS"` // RUNNER_SLAVES_CONFIGS
}

Expand Down Expand Up @@ -85,6 +86,7 @@ func PrintParams(params Params) {
output.PrintLogf("RUNNER_CLOUD_API_URL=\"%s\"", params.CloudAPIURL)
printSensitiveParam("RUNNER_CLOUD_API_KEY", params.CloudAPIKey)
output.PrintLogf("RUNNER_CLOUD_CONNECTION_TIMEOUT=%d", params.CloudConnectionTimeoutSec)
output.PrintLogf("RUNNER_CLOUD_API_SKIP_VERIFY=\"%t\"", params.CloudAPISkipVerify)
}

// printSensitiveParam shows in logs if a parameter is set or not
Expand Down
4 changes: 4 additions & 0 deletions pkg/executor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ var RunnerEnvVars = []corev1.EnvVar{
Name: "RUNNER_CLOUD_API_URL",
Value: os.Getenv("TESTKUBE_CLOUD_URL"),
},
{
Name: "RUNNER_CLOUD_API_SKIP_VERIFY",
Value: getOr("TESTKUBE_PRO_SKIP_VERIFY", "false"),
},
{
Name: "RUNNER_DASHBOARD_URI",
Value: os.Getenv("TESTKUBE_DASHBOARD_URI"),
Expand Down
1 change: 1 addition & 0 deletions pkg/executor/containerexecutor/containerexecutor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func TestNewExecutorJobSpecWithArgs(t *testing.T) {
{Name: "RUNNER_CLOUD_API_KEY", Value: ""},
{Name: "RUNNER_CLOUD_API_URL", Value: ""},
{Name: "RUNNER_CLOUD_API_TLS_INSECURE", Value: "false"},
{Name: "RUNNER_CLOUD_API_SKIP_VERIFY", Value: "false"},
{Name: "RUNNER_CLUSTERID", Value: ""},
{Name: "CI", Value: "1"},
{Name: "key", Value: "value"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/scraper/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func getCloudLoader(ctx context.Context, params envs.Params) (uploader *cloudscr
defer cancel()

output.PrintLogf("%s Uploading artifacts using Cloud Uploader (timeout:%ds)", ui.IconCheckMark, params.CloudConnectionTimeoutSec)
grpcConn, err := agent.NewGRPCConnection(ctxTimeout, params.CloudAPITLSInsecure, params.CloudAPIURL, log.DefaultLogger)
grpcConn, err := agent.NewGRPCConnection(ctxTimeout, params.CloudAPITLSInsecure, params.SkipVerify, params.CloudAPIURL, log.DefaultLogger)
if err != nil {
return nil, err
}
Expand Down
Loading