Skip to content
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

[exporter/datadog] Error returned from authAPI.Validate is not propagated #33935

Closed
RonFed opened this issue Jul 7, 2024 · 5 comments · Fixed by #33944
Closed

[exporter/datadog] Error returned from authAPI.Validate is not propagated #33935

RonFed opened this issue Jul 7, 2024 · 5 comments · Fixed by #33944
Labels
bug Something isn't working exporter/datadog Datadog components priority:p2 Medium

Comments

@RonFed
Copy link

RonFed commented Jul 7, 2024

Component(s)

exporter/datadog

What happened?

Description

The error returned from Validate is not returned. I'm not sure if this is intentional or not. From debugging this and entering an invalid API key I see an error of 403 forbidden is returned but only logged.

func ValidateAPIKey(ctx context.Context, apiKey string, logger *zap.Logger, apiClient *datadog.APIClient) error {
logger.Info("Validating API key.")
authAPI := datadogV1.NewAuthenticationApi(apiClient)
resp, httpresp, err := authAPI.Validate(GetRequestContext(ctx, apiKey))
if err == nil && resp.Valid != nil && *resp.Valid {
logger.Info("API key validation successful.")
return nil
}
if err != nil {
logger.Warn("Error while validating API key", zap.Error(err))
return nil
}
logger.Warn(ErrInvalidAPI.Error())
return WrapError(ErrInvalidAPI, httpresp)
}

Collector version

v0.104.0

Environment information

No response

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

@RonFed RonFed added bug Something isn't working needs triage New item requiring triage labels Jul 7, 2024
@github-actions github-actions bot added the exporter/datadog Datadog components label Jul 7, 2024
Copy link
Contributor

github-actions bot commented Jul 7, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@RonFed RonFed changed the title Error returned from authAPI.Validate is not propagated [exporter/datadog] Error returned from authAPI.Validate is not propagated Jul 7, 2024
@mx-psi
Copy link
Member

mx-psi commented Jul 8, 2024

@RonFed This is intentional and mimics the behavior of the Datadog Agent. To propagate the error you can set api::fail_on_invalid_key to true. Let me know if that is what you were looking for.

@mx-psi mx-psi added question Further information is requested waiting for author and removed bug Something isn't working needs triage New item requiring triage labels Jul 8, 2024
@RonFed
Copy link
Author

RonFed commented Jul 8, 2024

@mx-psi I have tried this config but it still causes the error to not get propagated, since the function above is not returning it, it doesn't get sent in the error channel and the check for the configuration you proposed is not catching it in

// client to send running metric to the backend & perform API key validation
errchan := make(chan error)
if isMetricExportV2Enabled() {
apiClient := clientutil.CreateAPIClient(
params.BuildInfo,
cfg.Metrics.TCPAddrConfig.Endpoint,
cfg.ClientConfig)
go func() { errchan <- clientutil.ValidateAPIKey(ctx, string(cfg.API.Key), params.Logger, apiClient) }()
exp.metricsAPI = datadogV2.NewMetricsApi(apiClient)
} else {
client := clientutil.CreateZorkianClient(string(cfg.API.Key), cfg.Metrics.TCPAddrConfig.Endpoint)
go func() { errchan <- clientutil.ValidateAPIKeyZorkian(params.Logger, client) }()
exp.client = client
}
if cfg.API.FailOnInvalidKey {
if err := <-errchan; err != nil {
return nil, err
}
}
return exp, nil
}

@mx-psi
Copy link
Member

mx-psi commented Jul 8, 2024

I am taking a look at this. I filed #33944 but I am a bit confused as to why the endpoint would be returning 403 for something that should not need authentication, so I am checking internally as well :)

@mx-psi mx-psi added bug Something isn't working priority:p2 Medium and removed question Further information is requested waiting for author labels Jul 8, 2024
@mx-psi mx-psi closed this as completed in 418b308 Jul 8, 2024
@mx-psi
Copy link
Member

mx-psi commented Jul 8, 2024

This will be fixed in v0.105.0, thanks for taking the time to report it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working exporter/datadog Datadog components priority:p2 Medium
Projects
None yet
2 participants