Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions docs/changelog/137325.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 137325
summary: "Enable `_otlp` usage with `create_doc`, `auto_configure` privileges"
area: TSDB
type: "bug"
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,23 @@ public final class IndexPrivilege extends Privilege {
private static final Automaton CREATE_AUTOMATON = patterns(
"indices:data/write/index*",
"indices:data/write/bulk*",
"indices:data/write/simulate/bulk*"
"indices:data/write/simulate/bulk*",
"indices:data/write/otlp/*"
);
private static final Automaton CREATE_DOC_AUTOMATON = patterns(
"indices:data/write/index",
"indices:data/write/index[*",
"indices:data/write/index:op_type/create",
"indices:data/write/bulk*",
"indices:data/write/simulate/bulk*"
"indices:data/write/simulate/bulk*",
"indices:data/write/otlp/*"
);
private static final Automaton INDEX_AUTOMATON = patterns(
"indices:data/write/index*",
"indices:data/write/bulk*",
"indices:data/write/update*",
"indices:data/write/simulate/bulk*"
"indices:data/write/simulate/bulk*",
"indices:data/write/otlp/*"
);
private static final Automaton DELETE_AUTOMATON = patterns("indices:data/write/delete*", "indices:data/write/bulk*");
private static final Automaton WRITE_AUTOMATON = patterns("indices:data/write/*", TransportAutoPutMappingAction.TYPE.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected Settings restClientSettings() {
public void beforeTest() throws Exception {
exporter = OtlpHttpMetricExporter.builder()
.setEndpoint(getClusterHosts().getFirst().toURI() + "/_otlp/v1/metrics")
.addHeader("Authorization", basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray())))
.addHeader("Authorization", "ApiKey " + createApiKey())
.build();
meterProvider = SdkMeterProvider.builder()
.registerMetricReader(
Expand All @@ -109,6 +109,28 @@ public void beforeTest() throws Exception {
assertBusy(() -> assertOK(client().performRequest(new Request("GET", "_index_template/metrics-otel@template"))));
}

private static String createApiKey() throws IOException {
// Create API key with create_doc privilege for metrics-* index
Request createApiKeyRequest = new Request("POST", "/_security/api_key");
createApiKeyRequest.setJsonEntity("""
{
"name": "otel-metrics-test-key",
"role_descriptors": {
"metrics_writer": {
"index": [
{
"names": ["metrics-*"],
"privileges": ["create_doc", "auto_configure"]
}
]
}
}
}
""");
ObjectPath createApiKeyResponse = ObjectPath.createFromResponse(client().performRequest(createApiKeyRequest));
return createApiKeyResponse.evaluate("encoded");
}

@Override
public void tearDown() throws Exception {
meterProvider.close();
Expand Down