Skip to content

[configauth] Deprecate Authentication in favor of authentication.Config #12904

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_naming-configauth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: configauth

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate `configauth.Authentication` in favor of `configauth.AuthenticationConfig`.

# One or more tracking issues or pull requests related to the change
issues: [12875]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
13 changes: 8 additions & 5 deletions config/configauth/configauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ var (
errNotServer = errors.New("requested authenticator is not a server authenticator")
)

// Authentication defines the auth settings for the receiver.
type Authentication struct {
// Deprecated: [v0.125.0] Use AuthenticationConfig instead.
type Authentication = AuthenticationConfig

// AuthenticationConfig defines the auth settings for the receiver.
type AuthenticationConfig struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are fine with having to add a more specific name to any other config struct we add to this package that is fine by me

// AuthenticatorID specifies the name of the extension to use in order to authenticate the incoming data point.
AuthenticatorID component.ID `mapstructure:"authenticator,omitempty"`
// prevent unkeyed literal initialization
Expand All @@ -32,7 +35,7 @@ type Authentication struct {

// GetServerAuthenticator attempts to select the appropriate extensionauth.Server from the list of extensions,
// based on the requested extension name. If an authenticator is not found, an error is returned.
func (a Authentication) GetServerAuthenticator(_ context.Context, extensions map[component.ID]component.Component) (extensionauth.Server, error) {
func (a AuthenticationConfig) GetServerAuthenticator(_ context.Context, extensions map[component.ID]component.Component) (extensionauth.Server, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if server, ok := ext.(extensionauth.Server); ok {
return server, nil
Expand All @@ -46,7 +49,7 @@ func (a Authentication) GetServerAuthenticator(_ context.Context, extensions map
// GetHTTPClientAuthenticator attempts to select the appropriate extensionauth.Client from the list of extensions,
// based on the component id of the extension. If an authenticator is not found, an error is returned.
// This should be only used by HTTP clients.
func (a Authentication) GetHTTPClientAuthenticator(_ context.Context, extensions map[component.ID]component.Component) (extensionauth.HTTPClient, error) {
func (a AuthenticationConfig) GetHTTPClientAuthenticator(_ context.Context, extensions map[component.ID]component.Component) (extensionauth.HTTPClient, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if client, ok := ext.(extensionauth.HTTPClient); ok {
return client, nil
Expand All @@ -59,7 +62,7 @@ func (a Authentication) GetHTTPClientAuthenticator(_ context.Context, extensions
// GetGRPCClientAuthenticator attempts to select the appropriate extensionauth.Client from the list of extensions,
// based on the component id of the extension. If an authenticator is not found, an error is returned.
// This should be only used by gRPC clients.
func (a Authentication) GetGRPCClientAuthenticator(_ context.Context, extensions map[component.ID]component.Component) (extensionauth.GRPCClient, error) {
func (a AuthenticationConfig) GetGRPCClientAuthenticator(_ context.Context, extensions map[component.ID]component.Component) (extensionauth.GRPCClient, error) {
if ext, found := extensions[a.AuthenticatorID]; found {
if client, ok := ext.(extensionauth.GRPCClient); ok {
return client, nil
Expand Down
4 changes: 2 additions & 2 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type ClientConfig struct {
Authority string `mapstructure:"authority,omitempty"`

// Auth configuration for outgoing RPCs.
Auth *configauth.Authentication `mapstructure:"auth,omitempty"`
Auth *configauth.AuthenticationConfig `mapstructure:"auth,omitempty"`

// Middlewares for the gRPC client.
Middlewares []configmiddleware.Config `mapstructure:"middlewares,omitempty"`
Expand Down Expand Up @@ -197,7 +197,7 @@ type ServerConfig struct {
Keepalive *KeepaliveServerConfig `mapstructure:"keepalive,omitempty"`

// Auth for this receiver
Auth *configauth.Authentication `mapstructure:"auth,omitempty"`
Auth *configauth.AuthenticationConfig `mapstructure:"auth,omitempty"`

// Include propagates the incoming connection's metadata to downstream consumers.
IncludeMetadata bool `mapstructure:"include_metadata,omitempty"`
Expand Down
12 changes: 6 additions & 6 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
WaitForReady: true,
BalancerName: "round_robin",
Authority: "pseudo-authority",
Auth: &configauth.Authentication{AuthenticatorID: testAuthID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: testAuthID},
},
host: &mockHost{
ext: map[component.ID]component.Component{
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
WaitForReady: true,
BalancerName: "round_robin",
Authority: "pseudo-authority",
Auth: &configauth.Authentication{AuthenticatorID: testAuthID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: testAuthID},
},
host: &mockHost{
ext: map[component.ID]component.Component{
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
WaitForReady: true,
BalancerName: "round_robin",
Authority: "pseudo-authority",
Auth: &configauth.Authentication{AuthenticatorID: testAuthID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: testAuthID},
},
host: &mockHost{
ext: map[component.ID]component.Component{
Expand Down Expand Up @@ -413,7 +413,7 @@ func TestGrpcServerAuthSettings(t *testing.T) {
Endpoint: "0.0.0.0:1234",
},
}
gss.Auth = &configauth.Authentication{
gss.Auth = &configauth.AuthenticationConfig{
AuthenticatorID: mockID,
}

Expand Down Expand Up @@ -492,15 +492,15 @@ func TestGRPCClientSettingsError(t *testing.T) {
err: "failed to resolve authenticator \"doesntexist\": authenticator not found",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: doesntExistID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: doesntExistID},
},
host: &mockHost{ext: map[component.ID]component.Component{}},
},
{
err: "no extensions configuration available",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: doesntExistID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: doesntExistID},
},
host: &mockHost{},
},
Expand Down
4 changes: 2 additions & 2 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type ClientConfig struct {
Headers map[string]configopaque.String `mapstructure:"headers,omitempty"`

// Auth configuration for outgoing HTTP calls.
Auth *configauth.Authentication `mapstructure:"auth,omitempty"`
Auth *configauth.AuthenticationConfig `mapstructure:"auth,omitempty"`

// The compression key for supported compression types within collector.
Compression configcompression.Type `mapstructure:"compression,omitempty"`
Expand Down Expand Up @@ -384,7 +384,7 @@ func NewDefaultServerConfig() ServerConfig {

type AuthConfig struct {
// Auth for this receiver.
configauth.Authentication `mapstructure:",squash"`
configauth.AuthenticationConfig `mapstructure:",squash"`

// RequestParameters is a list of parameters that should be extracted from the request and added to the context.
// When a parameter is found in both the query string and the header, the value from the query string will be used.
Expand Down
26 changes: 13 additions & 13 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestHTTPClientSettingsError(t *testing.T) {
err: "failed to resolve authenticator \"dummy\": authenticator not found",
settings: ClientConfig{
Endpoint: "https://localhost:1234/v1/traces",
Auth: &configauth.Authentication{AuthenticatorID: dummyID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: dummyID},
},
},
}
Expand Down Expand Up @@ -387,7 +387,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
name: "with_auth_configuration_and_no_extension",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: dummyID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: dummyID},
},
shouldErr: true,
host: &mockHost{
Expand All @@ -400,7 +400,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
name: "with_auth_configuration_and_no_extension_map",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: dummyID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: dummyID},
},
shouldErr: true,
host: componenttest.NewNopHost(),
Expand All @@ -409,7 +409,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
name: "with_auth_configuration_has_extension",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: mockID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: mockID},
},
shouldErr: false,
host: &mockHost{
Expand All @@ -422,7 +422,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
name: "with_auth_configuration_has_extension_and_headers",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: mockID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: mockID},
Headers: map[string]configopaque.String{"foo": "bar"},
},
shouldErr: false,
Expand All @@ -436,7 +436,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
name: "with_auth_configuration_has_extension_and_compression",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.MustNewID("mock")},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: component.MustNewID("mock")},
Compression: configcompression.TypeGzip,
},
shouldErr: false,
Expand All @@ -450,7 +450,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
name: "with_auth_configuration_has_err_extension",
settings: ClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: mockID},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: mockID},
},
shouldErr: true,
host: &mockHost{
Expand Down Expand Up @@ -844,7 +844,7 @@ func TestHttpCorsWithSettings(t *testing.T) {
AllowedOrigins: []string{"*"},
},
Auth: &AuthConfig{
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: mockID,
},
},
Expand Down Expand Up @@ -1154,7 +1154,7 @@ func TestServerAuth(t *testing.T) {
hss := ServerConfig{
Endpoint: "localhost:0",
Auth: &AuthConfig{
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: mockID,
},
},
Expand Down Expand Up @@ -1188,7 +1188,7 @@ func TestServerAuth(t *testing.T) {
func TestInvalidServerAuth(t *testing.T) {
hss := ServerConfig{
Auth: &AuthConfig{
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: nonExistingID,
},
},
Expand All @@ -1204,7 +1204,7 @@ func TestFailedServerAuth(t *testing.T) {
hss := ServerConfig{
Endpoint: "localhost:0",
Auth: &AuthConfig{
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: mockID,
},
},
Expand Down Expand Up @@ -1234,7 +1234,7 @@ func TestFailedServerAuthWithErrorHandler(t *testing.T) {
hss := ServerConfig{
Endpoint: "localhost:0",
Auth: &AuthConfig{
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: mockID,
},
},
Expand Down Expand Up @@ -1420,7 +1420,7 @@ func TestAuthWithQueryParams(t *testing.T) {
Endpoint: "localhost:0",
Auth: &AuthConfig{
RequestParameters: []string{"auth"},
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: mockID,
},
},
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestUnmarshalConfig(t *testing.T) {
},
WriteBufferSize: 512 * 1024,
BalancerName: "round_robin",
Auth: &configauth.Authentication{AuthenticatorID: component.MustNewID("nop")},
Auth: &configauth.AuthenticationConfig{AuthenticatorID: component.MustNewID("nop")},
},
}, cfg)
}
Expand Down
4 changes: 2 additions & 2 deletions extension/extensionauth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"google.golang.org/grpc/credentials"
)

// HTTPClient is an optional Extension interface that can be used as an HTTP authenticator for the configauth.Authentication option.
// HTTPClient is an optional Extension interface that can be used as an HTTP authenticator for the configauth.AuthenticationConfig option.
// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their
// names from the Authentication configuration.
type HTTPClient interface {
// RoundTripper returns a RoundTripper that can be used to authenticate HTTP requests.
RoundTripper(base http.RoundTripper) (http.RoundTripper, error)
}

// GRPCClient is an optional Extension interface that can be used as a gRPC authenticator for the configauth.Authentication option.
// GRPCClient is an optional Extension interface that can be used as a gRPC authenticator for the configauth.AuthenticationConfig option.
// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their
// names from the Authentication configuration.
type GRPCClient interface {
Expand Down
2 changes: 1 addition & 1 deletion extension/extensionauth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
)

// Server is an optional Extension interface that can be used as an authenticator for the configauth.Authentication option.
// Server is an optional Extension interface that can be used as an authenticator for the configauth.AuthenticationConfig option.
// Authenticators are then included as part of OpenTelemetry Collector builds and can be referenced by their
// names from the Authentication configuration. Each Server is free to define its own behavior and configuration options,
// but note that the expectations that come as part of Extensions exist here as well. For instance, multiple instances of the same
Expand Down
2 changes: 1 addition & 1 deletion extension/zpagesextension/zpagesextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestZPagesExtensionBadAuthExtension(t *testing.T) {
ServerConfig: confighttp.ServerConfig{
Endpoint: "localhost:0",
Auth: &confighttp.AuthConfig{
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: component.MustNewIDWithName("foo", "bar"),
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/configauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ import (

func TestConfmapMarshalConfigAuth(t *testing.T) {
conf := confmap.New()
require.NoError(t, conf.Marshal(configauth.Authentication{}))
require.NoError(t, conf.Marshal(configauth.AuthenticationConfig{}))
assert.Equal(t, map[string]any{}, conf.ToStringMap())
}
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestUnmarshalConfig(t *testing.T) {
HTTP: &HTTPConfig{
ServerConfig: confighttp.ServerConfig{
Auth: &confighttp.AuthConfig{
Authentication: configauth.Authentication{
Authentication: configauth.AuthenticationConfig{
AuthenticatorID: component.MustNewID("test"),
},
},
Expand Down
Loading