Skip to content

Commit 41640f9

Browse files
committed
[config/configgrpc] Return PerRPCCredentials error instead of swallowing it
getGrpcDialOptions returned the outer (nil) err rather than perr when a client auth extension's PerRPCCredentials() failed, so the error was silently swallowed and the gRPC client was built without the intended per-RPC credentials instead of failing. Return perr, and add a test exercising the failure path via extensionauthtest.NewErr, which was previously untested (every auth test used NewNopClient, whose PerRPCCredentials returns a nil error). Assisted-by: Claude Opus 4.8 Signed-off-by: Pavel Lazureykis <pavel@lazureykis.dev>
1 parent 00f6354 commit 41640f9

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp)
7+
component: pkg/config/configgrpc
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Return the error when a gRPC client auth extension's PerRPCCredentials() fails instead of silently swallowing it
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [99999]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
Previously a failure from the configured client auth extension's PerRPCCredentials() was
20+
discarded and getGrpcDialOptions returned a nil error, so the gRPC client was built without
21+
the intended per-RPC credentials instead of failing.
22+
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: [user]

config/configgrpc/configgrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (cc *ClientConfig) getGrpcDialOptions(
436436

437437
perRPCCredentials, perr := grpcAuthenticator.PerRPCCredentials()
438438
if perr != nil {
439-
return nil, err
439+
return nil, perr
440440
}
441441
opts = append(opts, grpc.WithPerRPCCredentials(perRPCCredentials))
442442
}

config/configgrpc/configgrpc_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ func TestAllGrpcClientSettings(t *testing.T) {
263263
}
264264
}
265265

266+
func TestGetGRPCDialOptionsPerRPCCredentialsError(t *testing.T) {
267+
cc := ClientConfig{
268+
Endpoint: "localhost:1234",
269+
TLS: configtls.ClientConfig{Insecure: true},
270+
Auth: configoptional.Some(configauth.Config{AuthenticatorID: testAuthID}),
271+
}
272+
extensions := map[component.ID]component.Component{
273+
testAuthID: extensionauthtest.NewErr(errors.New("per-rpc credentials failure")),
274+
}
275+
_, err := cc.getGrpcDialOptions(context.Background(), extensions, componenttest.NewNopTelemetrySettings(), []ToClientConnOption{})
276+
require.Error(t, err)
277+
assert.ErrorContains(t, err, "per-rpc credentials failure")
278+
}
279+
266280
func TestSanitizeEndpoint(t *testing.T) {
267281
cfg := NewDefaultClientConfig()
268282
cfg.Endpoint = "dns://authority/backend.example.com:4317"

0 commit comments

Comments
 (0)