@@ -3,7 +3,6 @@ package main
33import (
44 "context"
55 "crypto/tls"
6- "log"
76 "strings"
87
98 "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring"
@@ -13,11 +12,13 @@ import (
1312 "google.golang.org/grpc/keepalive"
1413)
1514
16- func dialAPIServer (ctx context.Context , addr string , allowInsecure bool , apiToken string ) (* grpc.ClientConn , error ) {
17- apiCreds := creds {Token : apiToken }
15+ func dialAPIServer (addr string , allowInsecure bool , apiToken string ) (* grpc.ClientConn , error ) {
16+ apiCreds := creds {
17+ Token : apiToken ,
18+ AllowInsecure : allowInsecure ,
19+ }
1820
1921 opts := []grpc.DialOption {
20- grpc .WithBlock (), //nolint:staticcheck,nolintlint // Will be removed in v2. TODO: Migrate to NewClient.
2122 grpc .WithPerRPCCredentials (apiCreds ),
2223 // Keep-alive is necessary to detect network failures in absence of writes from the client.
2324 // Without it, the agent would hang if the server disappears while waiting for a response.
@@ -40,7 +41,7 @@ func dialAPIServer(ctx context.Context, addr string, allowInsecure bool, apiToke
4041 }
4142 opts = append (opts , grpc .WithTransportCredentials (transportCreds ))
4243
43- return grpc .DialContext ( ctx , addr , opts ... ) //nolint:staticcheck,nolintlint // Will be removed in v2. TODO: Migrate to NewClient.
44+ return grpc .NewClient ( addr , opts ... )
4445}
4546
4647func grpcApiHost (addr string ) string {
@@ -53,7 +54,8 @@ func grpcApiHost(addr string) string {
5354}
5455
5556type creds struct {
56- Token string
57+ Token string
58+ AllowInsecure bool
5759}
5860
5961func (c creds ) GetRequestMetadata (ctx context.Context , uri ... string ) (map [string ]string , error ) {
@@ -63,7 +65,8 @@ func (c creds) GetRequestMetadata(ctx context.Context, uri ...string) (map[strin
6365}
6466
6567func (c creds ) RequireTransportSecurity () bool {
66- log .Printf ("RequireTransportSecurity" )
67- // XXX(mem): this is true
68- return false
68+ // Only require transport security when insecure mode is NOT enabled.
69+ // This allows the agent to use unencrypted connections for development/testing
70+ // when the -api-insecure flag is set, while enforcing TLS by default.
71+ return ! c .AllowInsecure
6972}
0 commit comments