Add HTTP basic auth and no-auth support for prometheus-sink#6595
Add HTTP basic auth and no-auth support for prometheus-sink#6595graytaylor0 merged 2 commits intoopensearch-project:mainfrom
Conversation
Signed-off-by: ps48 <pshenoy36@gmail.com>
1d9d7a6 to
5d6ed88
Compare
| } | ||
|
|
||
| private static String buildAuthHeader(final PrometheusSinkConfiguration config) { | ||
| if (config.getAuthentication() != null && config.getAuthentication().getHttpBasic() != null) { |
There was a problem hiding this comment.
Should BasicAuthCredentials.username and BasicAuthCredentials.password have @NotNull annotations (like BearerTokenOptions does for its fields)? As-is, a config with authentication.http_basic: {} would pass validation but seems this line would encode "null:null" into the Base64 header. Could be a follow-up if you want to keep this PR scoped.
There was a problem hiding this comment.
Added @NotNull to both username and password fields, preventing authentication.http_basic: {} from silently encoding "null:null" into the Base64 auth header.
| .method(SdkHttpMethod.POST) | ||
| .uri(URI.create(url)) | ||
| .putHeader("Content-Encoding", config.getEncoding().toString()) | ||
| .putHeader("Content-Encoding", config.getEncoding().name().toLowerCase()) |
| when(sinkConfig.getAwsConfig()).thenReturn(null); | ||
| when(sinkConfig.getUrl()).thenReturn("http://localhost:9090/api/v1/write"); | ||
| final byte[] bytes = UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8); | ||
| when(httpStatus.code()).thenReturn(200); | ||
| when(httpData.array()).thenReturn(bytes); | ||
| when(aggregatedHttpResponse.status()).thenReturn(httpStatus); | ||
| when(aggregatedHttpResponse.content()).thenReturn(httpData); |
There was a problem hiding this comment.
Nit: the new tests repeat the same mock setup block (~6 lines each). Could extract a helper to reduce boilerplate. Not blocking.
There was a problem hiding this comment.
this should be fine for now. May be something for later improvement when we add TLS support
| @AssertTrue(message = "encoding or content_type or remote_write_version is incorrect.") | ||
| @AssertTrue(message = "Cannot use both AWS SigV4 and authentication options. Choose one.") | ||
| boolean isValidAuthConfig() { | ||
| return !(awsConfig != null && authentication != null); |
There was a problem hiding this comment.
Should this also reject configs where authentication.bearer_token is set? Since bearer token isn't wired up yet, it would silently fall through to unauthenticated requests. Maybe an additional @AssertTrue validator or a check here?
There was a problem hiding this comment.
Added isValidBearerTokenConfig() validator with @AssertTrue that rejects configs where authentication.bearer_token is set, since it's not yet implemented and would silently fall through to unauthenticated.
and add null checks Signed-off-by: ps48 <pshenoy36@gmail.com>
|
Also tested the AMP support locally making sure AMP ITs still work as expected: |
|
@kkondaka adding the screenshot of the AMP sink test result: |

Description
No-auth / plain HTTP support
awsconfig optional by removing@NotNullfromawsConfigfield inPrometheusSinkConfigurationhttp://URLs —isValidConfig()previously requiredhttps://only, now accepts bothhttp://andhttps://isValidAwsConfig()cross-validation that enforceshttps://only whenawsblock is presentx-amz-content-sha256header only when AWS SigV4 signer is configured (was unconditionally sent on every request)Content-Encodingheader value — changed from.toString()(producedSNAPPY) to.name().toLowerCase()(producessnappy), matching the Prometheus Remote Write specHTTP Basic authentication
AuthenticationOptionsandBasicAuthCredentialsconfig classes intoPrometheusSinkConfigurationauthenticationfield with@JsonPropertyand@ValidannotationsAuthorizationheader at construction time inPrometheusHttpSenderand inject it into outbound requestsisValidAuthConfig()cross-validation that rejects mutually exclusiveaws+authenticationconfigs (SigV4 and basic auth would conflict on theAuthorizationheader)README rewrite
Test coverage
http://URL is invalidhttp://URL without AWS is validx-amz-content-sha256header when AWS config is absentAuthorization: Basic <base64>headerAuthorizationheader when authentication is not configuredPrometheusSinkinitializes with basic auth configPrometheusSinkinitializes without AWS configIssues Resolved
Resolves #6594
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.