Skip to content

Commit

Permalink
feat(agent): allow connections to controlplane and api with self sign…
Browse files Browse the repository at this point in the history
…ed ssl cert on demand (#3935)

feat(agent): allow insecure controlplane on demand
  • Loading branch information
schoren authored Jul 15, 2024
1 parent 351d5e3 commit 9a86b59
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
15 changes: 10 additions & 5 deletions agent/client/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"net"
"os"
"time"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
Expand Down Expand Up @@ -96,13 +97,17 @@ func getTransportCredentialsForEndpoint(endpoint string) (credentials.TransportC
return nil, fmt.Errorf("cannot parse endpoint: %w", err)
}

tlsCreds := credentials.NewTLS(&tls.Config{
InsecureSkipVerify: true,
})

if os.Getenv("TRACETEST_DEV_FORCE_URL") == "true" {
return tlsCreds, nil
}

switch port {
case "443":
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
transportCredentials := credentials.NewTLS(tlsConfig)
return transportCredentials, nil
return tlsCreds, nil

default:
return insecure.NewCredentials(), nil
Expand Down
19 changes: 19 additions & 0 deletions cli/config/api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package config

import (
"crypto/tls"
"fmt"
"net/http"
"os"
"strings"

"github.com/kubeshop/tracetest/cli/analytics"
Expand All @@ -23,6 +26,22 @@ func GetAPIClient(cliConfig Config) *openapi.APIClient {
config.AddDefaultHeader("x-organization-id", cliConfig.OrganizationID)
config.AddDefaultHeader("x-environment-id", cliConfig.EnvironmentID)
config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", cliConfig.Jwt))
if os.Getenv("TRACETEST_DEV_FORCE_URL") == "true" {
if config.HTTPClient == nil {
config.HTTPClient = http.DefaultClient
}
if config.HTTPClient.Transport == nil {
config.HTTPClient.Transport = http.DefaultTransport
}

if t, ok := config.HTTPClient.Transport.(*http.Transport); ok {
if t.TLSClientConfig == nil {
t.TLSClientConfig = &tls.Config{}
}

t.TLSClientConfig.InsecureSkipVerify = true
}
}

config.Scheme = cliConfig.Scheme
config.Host = strings.TrimSuffix(cliConfig.Endpoint, "/")
Expand Down

0 comments on commit 9a86b59

Please sign in to comment.