-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[configtls] [config/configgrpc] Use configtls.NewDefaultClientConfig(), configtls.NewDefaultConfig() and configtls.NewDefaultServerConfig() #11638
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,11 +102,10 @@ func TestDefaultGrpcClientSettings(t *testing.T) { | |
tt, err := componenttest.SetupTelemetry(componentID) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) | ||
|
||
clientConfig := configtls.NewDefaultClientConfig() | ||
clientConfig.Insecure = true | ||
gcs := &ClientConfig{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most/all of these first cases, wouldn't you want to use the NewDefaultClientConfig at the outer level, rather than only on the inner TLSSetting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look! This suggested change should be done for all the test cases or only the initial ones? PR includes changes only to migrate to new configtls.NewDefaultClientConfig(). If the community is okay, I am willing to create an issue to track this and create separate PR addressing this. Please share your thoughts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please ignore my comment if it doesn't match the requirements. I just thought it odd that we'd use one and not the other. I'm new here. :) |
||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
TLSSetting: clientConfig, | ||
} | ||
opts, err := gcs.getGrpcDialOptions(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings(), []ToClientConnOption{}) | ||
require.NoError(t, err) | ||
|
@@ -117,11 +116,10 @@ func TestGrpcClientExtraOption(t *testing.T) { | |
tt, err := componenttest.SetupTelemetry(componentID) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) | ||
|
||
clientConfig := configtls.NewDefaultClientConfig() | ||
clientConfig.Insecure = true | ||
gcs := &ClientConfig{ | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
TLSSetting: clientConfig, | ||
} | ||
extraOpt := grpc.WithUserAgent("test-agent") | ||
opts, err := gcs.getGrpcDialOptions( | ||
|
@@ -139,7 +137,8 @@ func TestAllGrpcClientSettings(t *testing.T) { | |
tt, err := componenttest.SetupTelemetry(componentID) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) | ||
|
||
clientConfig := configtls.NewDefaultClientConfig() | ||
clientConfig.Insecure = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. false by default |
||
tests := []struct { | ||
settings ClientConfig | ||
name string | ||
|
@@ -153,9 +152,7 @@ func TestAllGrpcClientSettings(t *testing.T) { | |
}, | ||
Endpoint: "localhost:1234", | ||
Compression: configcompression.TypeGzip, | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: false, | ||
}, | ||
TLSSetting: clientConfig, | ||
Keepalive: &KeepaliveClientConfig{ | ||
Time: time.Second, | ||
Timeout: time.Second, | ||
|
@@ -182,9 +179,7 @@ func TestAllGrpcClientSettings(t *testing.T) { | |
}, | ||
Endpoint: "localhost:1234", | ||
Compression: configcompression.TypeSnappy, | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: false, | ||
}, | ||
TLSSetting: clientConfig, | ||
Keepalive: &KeepaliveClientConfig{ | ||
Time: time.Second, | ||
Timeout: time.Second, | ||
|
@@ -211,9 +206,7 @@ func TestAllGrpcClientSettings(t *testing.T) { | |
}, | ||
Endpoint: "localhost:1234", | ||
Compression: configcompression.TypeZstd, | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: false, | ||
}, | ||
TLSSetting: clientConfig, | ||
Keepalive: &KeepaliveClientConfig{ | ||
Time: time.Second, | ||
Timeout: time.Second, | ||
|
@@ -375,15 +368,15 @@ func TestGrpcServerAuthSettings(t *testing.T) { | |
} | ||
|
||
func TestGrpcClientConfigInvalidBalancer(t *testing.T) { | ||
clientConfig := configtls.NewDefaultClientConfig() | ||
clientConfig.Insecure = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Insecure is false by default |
||
settings := ClientConfig{ | ||
Headers: map[string]configopaque.String{ | ||
"test": "test", | ||
}, | ||
Endpoint: "localhost:1234", | ||
Compression: "gzip", | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: false, | ||
}, | ||
TLSSetting: clientConfig, | ||
Keepalive: &KeepaliveClientConfig{ | ||
Time: time.Second, | ||
Timeout: time.Second, | ||
|
@@ -398,6 +391,15 @@ func TestGrpcClientConfigInvalidBalancer(t *testing.T) { | |
} | ||
|
||
func TestGRPCClientSettingsError(t *testing.T) { | ||
clientConfigCADoesntExist := configtls.NewDefaultClientConfig() | ||
clientConfigCADoesntExist.Config = configtls.Config{ | ||
CAFile: "/doesnt/exist", | ||
} | ||
clientConfigCADoesntExist.Insecure = false | ||
clientConfigCADoesntExist.ServerName = "" | ||
|
||
clientConfigWithInsecure := configtls.NewDefaultClientConfig() | ||
clientConfigWithInsecure.Insecure = true | ||
tests := []struct { | ||
settings ClientConfig | ||
err string | ||
|
@@ -409,14 +411,8 @@ func TestGRPCClientSettingsError(t *testing.T) { | |
Headers: nil, | ||
Endpoint: "", | ||
Compression: "", | ||
TLSSetting: configtls.ClientConfig{ | ||
Config: configtls.Config{ | ||
CAFile: "/doesnt/exist", | ||
}, | ||
Insecure: false, | ||
ServerName: "", | ||
}, | ||
Keepalive: nil, | ||
TLSSetting: clientConfigCADoesntExist, | ||
Keepalive: nil, | ||
}, | ||
}, | ||
{ | ||
|
@@ -425,14 +421,8 @@ func TestGRPCClientSettingsError(t *testing.T) { | |
Headers: nil, | ||
Endpoint: "", | ||
Compression: "", | ||
TLSSetting: configtls.ClientConfig{ | ||
Config: configtls.Config{ | ||
CertFile: "/doesnt/exist", | ||
}, | ||
Insecure: false, | ||
ServerName: "", | ||
}, | ||
Keepalive: nil, | ||
TLSSetting: clientConfigCADoesntExist, | ||
Keepalive: nil, | ||
}, | ||
}, | ||
{ | ||
|
@@ -454,32 +444,26 @@ func TestGRPCClientSettingsError(t *testing.T) { | |
{ | ||
err: "unsupported compression type \"zlib\"", | ||
settings: ClientConfig{ | ||
Endpoint: "localhost:1234", | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
Endpoint: "localhost:1234", | ||
TLSSetting: clientConfigWithInsecure, | ||
Compression: "zlib", | ||
}, | ||
host: &mockHost{}, | ||
}, | ||
{ | ||
err: "unsupported compression type \"deflate\"", | ||
settings: ClientConfig{ | ||
Endpoint: "localhost:1234", | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
Endpoint: "localhost:1234", | ||
TLSSetting: clientConfigWithInsecure, | ||
Compression: "deflate", | ||
}, | ||
host: &mockHost{}, | ||
}, | ||
{ | ||
err: "unsupported compression type \"bad\"", | ||
settings: ClientConfig{ | ||
Endpoint: "localhost:1234", | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
Endpoint: "localhost:1234", | ||
TLSSetting: clientConfigWithInsecure, | ||
Compression: "bad", | ||
}, | ||
host: &mockHost{}, | ||
|
@@ -504,7 +488,7 @@ func TestUseSecure(t *testing.T) { | |
Headers: nil, | ||
Endpoint: "", | ||
Compression: "", | ||
TLSSetting: configtls.ClientConfig{}, | ||
TLSSetting: configtls.NewDefaultClientConfig(), | ||
Keepalive: nil, | ||
} | ||
dialOpts, err := gcs.getGrpcDialOptions(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings(), []ToClientConnOption{}) | ||
|
@@ -632,6 +616,22 @@ func TestHttpReception(t *testing.T) { | |
require.NoError(t, err) | ||
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) }) | ||
|
||
clientConfigWithInsecure := configtls.NewDefaultClientConfig() | ||
clientConfigWithInsecure.Insecure = true | ||
|
||
clientConfigWithCAFile := configtls.NewDefaultClientConfig() | ||
clientConfigWithCAFile.Config = configtls.Config{ | ||
CAFile: filepath.Join("testdata", "ca.crt"), | ||
} | ||
clientConfigWithCAFile.ServerName = "localhost" | ||
|
||
clientConfigWithCertAndKeyFile := configtls.NewDefaultClientConfig() | ||
clientConfigWithCertAndKeyFile.Config = configtls.Config{ | ||
CAFile: filepath.Join("testdata", "ca.crt"), | ||
CertFile: filepath.Join("testdata", "client.crt"), | ||
KeyFile: filepath.Join("testdata", "client.key"), | ||
} | ||
clientConfigWithCertAndKeyFile.ServerName = "localhost" | ||
tests := []struct { | ||
name string | ||
tlsServerCreds *configtls.ServerConfig | ||
|
@@ -641,9 +641,7 @@ func TestHttpReception(t *testing.T) { | |
{ | ||
name: "noTLS", | ||
tlsServerCreds: nil, | ||
tlsClientCreds: &configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
tlsClientCreds: &clientConfigWithInsecure, | ||
}, | ||
{ | ||
name: "TLS", | ||
|
@@ -654,12 +652,7 @@ func TestHttpReception(t *testing.T) { | |
KeyFile: filepath.Join("testdata", "server.key"), | ||
}, | ||
}, | ||
tlsClientCreds: &configtls.ClientConfig{ | ||
Config: configtls.Config{ | ||
CAFile: filepath.Join("testdata", "ca.crt"), | ||
}, | ||
ServerName: "localhost", | ||
}, | ||
tlsClientCreds: &clientConfigWithCAFile, | ||
}, | ||
{ | ||
name: "NoServerCertificates", | ||
|
@@ -668,13 +661,8 @@ func TestHttpReception(t *testing.T) { | |
CAFile: filepath.Join("testdata", "ca.crt"), | ||
}, | ||
}, | ||
tlsClientCreds: &configtls.ClientConfig{ | ||
Config: configtls.Config{ | ||
CAFile: filepath.Join("testdata", "ca.crt"), | ||
}, | ||
ServerName: "localhost", | ||
}, | ||
hasError: true, | ||
tlsClientCreds: &clientConfigWithCAFile, | ||
hasError: true, | ||
}, | ||
{ | ||
name: "mTLS", | ||
|
@@ -686,14 +674,7 @@ func TestHttpReception(t *testing.T) { | |
}, | ||
ClientCAFile: filepath.Join("testdata", "ca.crt"), | ||
}, | ||
tlsClientCreds: &configtls.ClientConfig{ | ||
Config: configtls.Config{ | ||
CAFile: filepath.Join("testdata", "ca.crt"), | ||
CertFile: filepath.Join("testdata", "client.crt"), | ||
KeyFile: filepath.Join("testdata", "client.key"), | ||
}, | ||
ServerName: "localhost", | ||
}, | ||
tlsClientCreds: &clientConfigWithCertAndKeyFile, | ||
}, | ||
{ | ||
name: "NoClientCertificate", | ||
|
@@ -705,13 +686,8 @@ func TestHttpReception(t *testing.T) { | |
}, | ||
ClientCAFile: filepath.Join("testdata", "ca.crt"), | ||
}, | ||
tlsClientCreds: &configtls.ClientConfig{ | ||
Config: configtls.Config{ | ||
CAFile: filepath.Join("testdata", "ca.crt"), | ||
}, | ||
ServerName: "localhost", | ||
}, | ||
hasError: true, | ||
tlsClientCreds: &clientConfigWithCAFile, | ||
hasError: true, | ||
}, | ||
{ | ||
name: "WrongClientCA", | ||
|
@@ -723,15 +699,8 @@ func TestHttpReception(t *testing.T) { | |
}, | ||
ClientCAFile: filepath.Join("testdata", "server.crt"), | ||
}, | ||
tlsClientCreds: &configtls.ClientConfig{ | ||
Config: configtls.Config{ | ||
CAFile: filepath.Join("testdata", "ca.crt"), | ||
CertFile: filepath.Join("testdata", "client.crt"), | ||
KeyFile: filepath.Join("testdata", "client.key"), | ||
}, | ||
ServerName: "localhost", | ||
}, | ||
hasError: true, | ||
tlsClientCreds: &clientConfigWithCertAndKeyFile, | ||
hasError: true, | ||
}, | ||
} | ||
// prepare | ||
|
@@ -801,12 +770,11 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) { | |
go func() { | ||
_ = srv.Serve(ln) | ||
}() | ||
|
||
clientConfig := configtls.NewDefaultClientConfig() | ||
clientConfig.Insecure = true | ||
gcs := &ClientConfig{ | ||
Endpoint: "unix://" + ln.Addr().String(), | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
Endpoint: "unix://" + ln.Addr().String(), | ||
TLSSetting: clientConfig, | ||
} | ||
grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings()) | ||
require.NoError(t, errClient) | ||
|
@@ -979,7 +947,8 @@ func TestClientInfoInterceptors(t *testing.T) { | |
t.Run(tt.name, func(t *testing.T) { | ||
mock := &grpcTraceServer{} | ||
var l net.Listener | ||
|
||
clientConfig := configtls.NewDefaultClientConfig() | ||
clientConfig.Insecure = true | ||
// prepare the server | ||
{ | ||
gss := &ServerConfig{ | ||
|
@@ -1005,10 +974,8 @@ func TestClientInfoInterceptors(t *testing.T) { | |
// prepare the client and execute a RPC | ||
{ | ||
gcs := &ClientConfig{ | ||
Endpoint: l.Addr().String(), | ||
TLSSetting: configtls.ClientConfig{ | ||
Insecure: true, | ||
}, | ||
Endpoint: l.Addr().String(), | ||
TLSSetting: clientConfig, | ||
} | ||
|
||
tel, err := componenttest.SetupTelemetry(componentID) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: The term "clientConfig" is highly overloaded in this context, I wonder if it would be better to rename this local "tlsSettings" or something similar.