Skip to content
Open
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
21 changes: 12 additions & 9 deletions cmd/synthetic-monitoring-agent/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"crypto/tls"
"log"
"strings"

"github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
Expand All @@ -13,11 +12,13 @@ import (
"google.golang.org/grpc/keepalive"
)

func dialAPIServer(ctx context.Context, addr string, allowInsecure bool, apiToken string) (*grpc.ClientConn, error) {
apiCreds := creds{Token: apiToken}
func dialAPIServer(addr string, allowInsecure bool, apiToken string) (*grpc.ClientConn, error) {
apiCreds := creds{
Token: apiToken,
AllowInsecure: allowInsecure,
}

opts := []grpc.DialOption{
grpc.WithBlock(), //nolint:staticcheck,nolintlint // Will be removed in v2. TODO: Migrate to NewClient.
grpc.WithPerRPCCredentials(apiCreds),
// Keep-alive is necessary to detect network failures in absence of writes from the client.
// Without it, the agent would hang if the server disappears while waiting for a response.
Expand All @@ -40,7 +41,7 @@ func dialAPIServer(ctx context.Context, addr string, allowInsecure bool, apiToke
}
opts = append(opts, grpc.WithTransportCredentials(transportCreds))

return grpc.DialContext(ctx, addr, opts...) //nolint:staticcheck,nolintlint // Will be removed in v2. TODO: Migrate to NewClient.
return grpc.NewClient(addr, opts...)
}

func grpcApiHost(addr string) string {
Expand All @@ -53,7 +54,8 @@ func grpcApiHost(addr string) string {
}

type creds struct {
Token string
Token string
AllowInsecure bool
}

func (c creds) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
Expand All @@ -63,7 +65,8 @@ func (c creds) GetRequestMetadata(ctx context.Context, uri ...string) (map[strin
}

func (c creds) RequireTransportSecurity() bool {
log.Printf("RequireTransportSecurity")
// XXX(mem): this is true
return false
// Only require transport security when insecure mode is NOT enabled.
// This allows the agent to use unencrypted connections for development/testing
// when the -api-insecure flag is set, while enforcing TLS by default.
return !c.AllowInsecure
}
2 changes: 1 addition & 1 deletion cmd/synthetic-monitoring-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func run(args []string, stdout io.Writer) error {

tenantCh := make(chan synthetic_monitoring.Tenant)

conn, err := dialAPIServer(ctx, config.GrpcApiServerAddr, config.GrpcInsecure, string(config.ApiToken))
conn, err := dialAPIServer(config.GrpcApiServerAddr, config.GrpcInsecure, string(config.ApiToken))
if err != nil {
return fmt.Errorf("dialing GRPC server %s: %w", config.GrpcApiServerAddr, err)
}
Expand Down
Loading