Skip to content

Commit a61e479

Browse files
authored
Enable _otlp usage with create_doc, auto_configure privileges (#137325)
Previously, the full `write` privilege was required, now the more fine-grained `create_doc` privilege is enough. It still checks the permissions in the internal _bulk request again. For example, the request would fail if we used the `index` instead of the `create` op_type within the `OTLPMetricsTransportAction`.
1 parent a328b58 commit a61e479

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

docs/changelog/137325.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 137325
2+
summary: "Enable `_otlp` usage with `create_doc`, `auto_configure` privileges"
3+
area: TSDB
4+
type: "bug"
5+
issues: []

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,23 @@ public final class IndexPrivilege extends Privilege {
9898
private static final Automaton CREATE_AUTOMATON = patterns(
9999
"indices:data/write/index*",
100100
"indices:data/write/bulk*",
101-
"indices:data/write/simulate/bulk*"
101+
"indices:data/write/simulate/bulk*",
102+
"indices:data/write/otlp/*"
102103
);
103104
private static final Automaton CREATE_DOC_AUTOMATON = patterns(
104105
"indices:data/write/index",
105106
"indices:data/write/index[*",
106107
"indices:data/write/index:op_type/create",
107108
"indices:data/write/bulk*",
108-
"indices:data/write/simulate/bulk*"
109+
"indices:data/write/simulate/bulk*",
110+
"indices:data/write/otlp/*"
109111
);
110112
private static final Automaton INDEX_AUTOMATON = patterns(
111113
"indices:data/write/index*",
112114
"indices:data/write/bulk*",
113115
"indices:data/write/update*",
114-
"indices:data/write/simulate/bulk*"
116+
"indices:data/write/simulate/bulk*",
117+
"indices:data/write/otlp/*"
115118
);
116119
private static final Automaton DELETE_AUTOMATON = patterns("indices:data/write/delete*", "indices:data/write/bulk*");
117120
private static final Automaton WRITE_AUTOMATON = patterns("indices:data/write/*", TransportAutoPutMappingAction.TYPE.name());

x-pack/plugin/otel-data/src/javaRestTest/java/org/elasticsearch/xpack/oteldata/otlp/OTLPMetricsIndexingRestIT.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected Settings restClientSettings() {
9696
public void beforeTest() throws Exception {
9797
exporter = OtlpHttpMetricExporter.builder()
9898
.setEndpoint(getClusterHosts().getFirst().toURI() + "/_otlp/v1/metrics")
99-
.addHeader("Authorization", basicAuthHeaderValue(USER, new SecureString(PASS.toCharArray())))
99+
.addHeader("Authorization", "ApiKey " + createApiKey())
100100
.build();
101101
meterProvider = SdkMeterProvider.builder()
102102
.registerMetricReader(
@@ -109,6 +109,28 @@ public void beforeTest() throws Exception {
109109
assertBusy(() -> assertOK(client().performRequest(new Request("GET", "_index_template/metrics-otel@template"))));
110110
}
111111

112+
private static String createApiKey() throws IOException {
113+
// Create API key with create_doc privilege for metrics-* index
114+
Request createApiKeyRequest = new Request("POST", "/_security/api_key");
115+
createApiKeyRequest.setJsonEntity("""
116+
{
117+
"name": "otel-metrics-test-key",
118+
"role_descriptors": {
119+
"metrics_writer": {
120+
"index": [
121+
{
122+
"names": ["metrics-*"],
123+
"privileges": ["create_doc", "auto_configure"]
124+
}
125+
]
126+
}
127+
}
128+
}
129+
""");
130+
ObjectPath createApiKeyResponse = ObjectPath.createFromResponse(client().performRequest(createApiKeyRequest));
131+
return createApiKeyResponse.evaluate("encoded");
132+
}
133+
112134
@Override
113135
public void tearDown() throws Exception {
114136
meterProvider.close();

0 commit comments

Comments
 (0)