This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 8684126a0 Fix #3384: Elasticsearch and OpenSearch Kamelets - log in
with an API key (#3387)
8684126a0 is described below
commit 8684126a0b92c55b1d6bb152d176e1f0c58676ef
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 24 11:11:41 2026 +0100
Fix #3384: Elasticsearch and OpenSearch Kamelets - log in with an API key
(#3387)
elasticsearch-index-sink, elasticsearch-search-action,
opensearch-index-sink and
opensearch-search-action get an apiKey option, set on the component bean of
the Kamelet next to
user and password. It uses the apiKey of the components from CAMEL-27479
and CAMEL-27480.
For Elasticsearch it is the encoded key or id:api_key. For OpenSearch 3.7
or later it is the
os_ API token. The key is sent only to the nodes of the cluster.
CAMEL-27497 is needed too: an unset {{?user}} of a Kamelet resolves from
the OS env var USER
(CAMEL-27498, for 4.25), and the components failed when apiKey and user
were both set.
The index-sink tests now also create a key with the REST API of the cluster
(Elasticsearch
/_security/api_key; OpenSearch turns on API tokens and creates one with
indices:data/write/bulk), and index a second document with only the key.
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
kamelets/elasticsearch-index-sink.kamelet.yaml | 9 +++
kamelets/elasticsearch-search-action.kamelet.yaml | 11 ++-
kamelets/opensearch-index-sink.kamelet.yaml | 9 +++
kamelets/opensearch-search-action.kamelet.yaml | 11 ++-
.../main/resources/META-INF/kamelets-index.json | 4 +-
.../kamelets/elasticsearch-index-sink.kamelet.yaml | 9 +++
.../elasticsearch-search-action.kamelet.yaml | 11 ++-
.../kamelets/opensearch-index-sink.kamelet.yaml | 9 +++
.../kamelets/opensearch-search-action.kamelet.yaml | 11 ++-
.../elasticsearch-index-sink-apikey-route.yaml | 51 ++++++++++++
.../elasticsearch-index-sink-route.citrus.it.yaml | 71 +++++++++++++++++
.../opensearch-index-sink-apikey-route.yaml | 51 ++++++++++++
.../opensearch-index-sink-route.citrus.it.yaml | 91 ++++++++++++++++++++++
13 files changed, 342 insertions(+), 6 deletions(-)
diff --git a/kamelets/elasticsearch-index-sink.kamelet.yaml
b/kamelets/elasticsearch-index-sink.kamelet.yaml
index 6305f73cf..80e2466dd 100644
--- a/kamelets/elasticsearch-index-sink.kamelet.yaml
+++ b/kamelets/elasticsearch-index-sink.kamelet.yaml
@@ -59,6 +59,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the `encoded` value that Elasticsearch gives when the key is
created, or its `id` and `api_key` joined with a colon (`id:api_key`). It is
sent in the `Authorization` header, only to the nodes of the cluster. Set
either `apiKey` or `user`, not both.
+ type: string
+ example: "bXktaWQ6bXkta2V5"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -140,6 +148,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git a/kamelets/elasticsearch-search-action.kamelet.yaml
b/kamelets/elasticsearch-search-action.kamelet.yaml
index a75a1bfc6..16ec23a4f 100644
--- a/kamelets/elasticsearch-search-action.kamelet.yaml
+++ b/kamelets/elasticsearch-search-action.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelElasticsearchTotalHits` header is the number of documents that match,
which can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
required:
- clusterName
- hostAddresses
@@ -60,6 +60,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the `encoded` value that Elasticsearch gives when the key is
created, or its `id` and `api_key` joined with a colon (`id:api_key`). It is
sent in the `Authorization` header, only to the nodes of the cluster. Set
either `apiKey` or `user`, not both.
+ type: string
+ example: "bXktaWQ6bXkta2V5"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -130,6 +138,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git a/kamelets/opensearch-index-sink.kamelet.yaml
b/kamelets/opensearch-index-sink.kamelet.yaml
index 1ce0311f6..48330189d 100644
--- a/kamelets/opensearch-index-sink.kamelet.yaml
+++ b/kamelets/opensearch-index-sink.kamelet.yaml
@@ -59,6 +59,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the token, which starts with `os_`, that OpenSearch gives
when the API token is created (OpenSearch 3.7 or later). It is sent in the
`Authorization` header, only to the nodes of the cluster. Set either `apiKey`
or `user`, not both.
+ type: string
+ example: "os_my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -140,6 +148,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git a/kamelets/opensearch-search-action.kamelet.yaml
b/kamelets/opensearch-search-action.kamelet.yaml
index 3346b4b10..5739836ab 100644
--- a/kamelets/opensearch-search-action.kamelet.yaml
+++ b/kamelets/opensearch-search-action.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelOpensearchTotalHits` header is the number of documents that match, which
can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
required:
- clusterName
- hostAddresses
@@ -60,6 +60,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the token, which starts with `os_`, that OpenSearch gives
when the API token is created (OpenSearch 3.7 or later). It is sent in the
`Authorization` header, only to the nodes of the cluster. Set either `apiKey`
or `user`, not both.
+ type: string
+ example: "os_my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -130,6 +138,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index adec1d16a..358e8eda0 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -795,7 +795,7 @@
"supportLevel" : "Preview",
"title" : "ElasticSearch Search Action",
"summary" : "Searches an index of Elasticsearch for each message, and
gives back the documents found, as a JSON array.",
- "description" : "Searches an index of Elasticsearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
Elasticsearch, use `elasticsearch-index-sink`; for OpenSearch, use
`opensearch-search-action`.\n\nInput: the body is the search. Text that starts
with `{` is a search in the Query DSL of [...]
+ "description" : "Searches an index of Elasticsearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
Elasticsearch, use `elasticsearch-index-sink`; for OpenSearch, use
`opensearch-search-action`.\n\nInput: the body is the search. Text that starts
with `{` is a search in the Query DSL of [...]
"group" : "ElasticSearch",
"namespace" : "Search",
"provider" : "Apache Software Foundation"
@@ -1735,7 +1735,7 @@
"supportLevel" : "Preview",
"title" : "OpenSearch Search Action",
"summary" : "Searches an index of OpenSearch for each message, and gives
back the documents found, as a JSON array.",
- "description" : "Searches an index of OpenSearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
OpenSearch, use `opensearch-index-sink`; for Elasticsearch, use
`elasticsearch-search-action`.\n\nInput: the body is the search. Text that
starts with `{` is a search in the Query DSL of Ope [...]
+ "description" : "Searches an index of OpenSearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
OpenSearch, use `opensearch-index-sink`; for Elasticsearch, use
`elasticsearch-search-action`.\n\nInput: the body is the search. Text that
starts with `{` is a search in the Query DSL of Ope [...]
"group" : "OpenSearch",
"namespace" : "Search",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
index 6305f73cf..80e2466dd 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
@@ -59,6 +59,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the `encoded` value that Elasticsearch gives when the key is
created, or its `id` and `api_key` joined with a colon (`id:api_key`). It is
sent in the `Authorization` header, only to the nodes of the cluster. Set
either `apiKey` or `user`, not both.
+ type: string
+ example: "bXktaWQ6bXkta2V5"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -140,6 +148,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
index a75a1bfc6..16ec23a4f 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelElasticsearchTotalHits` header is the number of documents that match,
which can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
required:
- clusterName
- hostAddresses
@@ -60,6 +60,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the `encoded` value that Elasticsearch gives when the key is
created, or its `id` and `api_key` joined with a colon (`id:api_key`). It is
sent in the `Authorization` header, only to the nodes of the cluster. Set
either `apiKey` or `user`, not both.
+ type: string
+ example: "bXktaWQ6bXkta2V5"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -130,6 +138,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
index 1ce0311f6..48330189d 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
@@ -59,6 +59,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the token, which starts with `os_`, that OpenSearch gives
when the API token is created (OpenSearch 3.7 or later). It is sent in the
`Authorization` header, only to the nodes of the cluster. Set either `apiKey`
or `user`, not both.
+ type: string
+ example: "os_my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -140,6 +148,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
index 3346b4b10..5739836ab 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelOpensearchTotalHits` header is the number of documents that match, which
can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
required:
- clusterName
- hostAddresses
@@ -60,6 +60,14 @@ spec:
format: password
x-descriptors:
- urn:camel:group:credentials
+ apiKey:
+ title: API Key
+ description: An API key to log in with, instead of `user` and
`password`. It is the token, which starts with `os_`, that OpenSearch gives
when the API token is created (OpenSearch 3.7 or later). It is sent in the
`Authorization` header, only to the nodes of the cluster. Set either `apiKey`
or `user`, not both.
+ type: string
+ example: "os_my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
enableSSL:
title: Enable SSL
description: If true, it connects with HTTPS. Set it to false for a
cluster that is reached with plain HTTP.
@@ -130,6 +138,7 @@ spec:
properties:
user: "{{?user}}"
password: "{{?password}}"
+ apiKey: "{{?apiKey}}"
from:
uri: kamelet:source
steps:
diff --git
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-apikey-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-apikey-route.yaml
new file mode 100644
index 000000000..98944bde4
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-apikey-route.yaml
@@ -0,0 +1,51 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+- route:
+ from:
+ uri: "timer:tick"
+ parameters:
+ period: "1000"
+ repeatCount: 1
+ steps:
+ - setHeader:
+ name: indexId
+ constant: 'order-2'
+ # the header takes precedence over the indexName option
+ - setHeader:
+ name: indexName
+ constant: 'orders'
+ - setBody:
+ constant: '{"order":"ORD-2","status":"shipped"}'
+ # logs in with an API key instead of a user
+ - to:
+ uri: "kamelet:elasticsearch-index-sink"
+ parameters:
+ hostAddresses: '{{elasticsearch.host}}:{{elasticsearch.port}}'
+ clusterName: 'docker-cluster'
+ apiKey: '{{es.api.key}}'
+ indexName: 'other'
+ enableSSL: false
+ # what the Kamelet gives: the Java type of the body and the
Content-Type
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - setHeader:
+ name: X-Content-Type
+ simple: "ct=${header.Content-Type}"
+ - to:
+ uri: "{{http.sink.url}}/result"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
index 30dce29de..06b395b2a 100644
---
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
@@ -95,3 +95,74 @@ actions:
status: 200
body:
data:
'{"_index":"orders","_id":"order-1","_version":1,"_seq_no":"@ignore@","_primary_term":"@ignore@","found":true,"_source":{"order":"ORD-1","status":"shipped"}}'
+
+ # an API key, created by the user elastic, and the Kamelet logs in with it
instead of the user
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ sendRequest:
+ POST:
+ path: "/_security/api_key"
+ contentType: "application/json"
+ headers:
+ - name: "Authorization"
+ value: "Basic citrus:encodeBase64('elastic:kamelets-Test-1')"
+ body:
+ data: '{"name": "kamelets"}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 200
+ extract:
+ body:
+ - path: "$.encoded"
+ variable: "es.api.key"
+
+ - camel:
+ cli:
+ run:
+ waitForRunningState: false
+ integration:
+ file: "elasticsearch/elasticsearch-index-sink-apikey-route.yaml"
+ systemProperties:
+ properties:
+ - name: "elasticsearch.host"
+ value: "${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}"
+ - name: "elasticsearch.port"
+ value: "${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ - name: "es.api.key"
+ value: "${es.api.key}"
+ - name: "http.sink.url"
+ value: "http://localhost:${search.server.port}"
+
+ - http:
+ server: "searchServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ body:
+ data: 'order-2'
+ - http:
+ server: "searchServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ sendRequest:
+ GET:
+ path: "/orders/_doc/order-2"
+ headers:
+ - name: "Authorization"
+ value: "Basic citrus:encodeBase64('elastic:kamelets-Test-1')"
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 200
+ body:
+ data:
'{"_index":"orders","_id":"order-2","_version":1,"_seq_no":"@ignore@","_primary_term":"@ignore@","found":true,"_source":{"order":"ORD-2","status":"shipped"}}'
diff --git
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-apikey-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-apikey-route.yaml
new file mode 100644
index 000000000..69a876151
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-apikey-route.yaml
@@ -0,0 +1,51 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+- route:
+ from:
+ uri: "timer:tick"
+ parameters:
+ period: "1000"
+ repeatCount: 1
+ steps:
+ - setHeader:
+ name: indexId
+ constant: 'order-2'
+ # the header takes precedence over the indexName option
+ - setHeader:
+ name: indexName
+ constant: 'orders'
+ - setBody:
+ constant: '{"order":"ORD-2","status":"shipped"}'
+ # logs in with an API key instead of a user
+ - to:
+ uri: "kamelet:opensearch-index-sink"
+ parameters:
+ hostAddresses: '{{opensearch.host}}:{{opensearch.port}}'
+ clusterName: 'docker-cluster'
+ apiKey: '{{os.api.key}}'
+ indexName: 'other'
+ enableSSL: false
+ # what the Kamelet gives: the Java type of the body and the
Content-Type
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - setHeader:
+ name: X-Content-Type
+ simple: "ct=${header.Content-Type}"
+ - to:
+ uri: "{{http.sink.url}}/result"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
index dabf84cb4..8c1aecb58 100644
---
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
@@ -33,6 +33,9 @@ actions:
value: "Kamelets-Test-2026!"
- name: "plugins.security.ssl.http.enabled"
value: "false"
+ # so that the admin can turn on API tokens
+ - name:
"plugins.security.unsupported.restapi.allow_securityconfig_modification"
+ value: "true"
- name: "cluster.routing.allocation.disk.threshold_enabled"
value: "false"
- name: "OPENSEARCH_JAVA_OPTS"
@@ -94,3 +97,91 @@ actions:
status: 200
body:
data:
'{"_index":"orders","_id":"order-1","_version":1,"_seq_no":"@ignore@","_primary_term":"@ignore@","found":true,"_source":{"order":"ORD-1","status":"shipped"}}'
+
+ # an API token, created by the user admin once API tokens are turned on, and
the Kamelet logs in with it instead of
+ # the user. Indexing needs the cluster permission indices:data/write/bulk
too.
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ sendRequest:
+ PATCH:
+ path: "/_plugins/_security/api/securityconfig"
+ contentType: "application/json"
+ headers:
+ - name: "Authorization"
+ value: "Basic citrus:encodeBase64('admin:Kamelets-Test-2026!')"
+ body:
+ data: '[{"op": "add", "path": "/config/dynamic/api_tokens",
"value": {"enabled": true}}]'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 200
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ sendRequest:
+ POST:
+ path: "/_plugins/_security/api/apitokens"
+ contentType: "application/json"
+ headers:
+ - name: "Authorization"
+ value: "Basic citrus:encodeBase64('admin:Kamelets-Test-2026!')"
+ body:
+ data: '{"name": "kamelets", "duration_seconds": 3600,
"cluster_permissions": ["cluster_monitor", "indices:data/write/bulk"],
"index_permissions": [{"index_pattern": ["orders*"], "allowed_actions":
["indices_all"]}]}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 200
+ extract:
+ body:
+ - path: "$.token"
+ variable: "os.api.key"
+
+ - camel:
+ cli:
+ run:
+ waitForRunningState: false
+ integration:
+ file: "opensearch/opensearch-index-sink-apikey-route.yaml"
+ systemProperties:
+ properties:
+ - name: "opensearch.host"
+ value: "${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}"
+ - name: "opensearch.port"
+ value: "${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ - name: "os.api.key"
+ value: "${os.api.key}"
+ - name: "http.sink.url"
+ value: "http://localhost:${search.server.port}"
+
+ - http:
+ server: "searchServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ body:
+ data: 'order-2'
+ - http:
+ server: "searchServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ sendRequest:
+ GET:
+ path: "/orders/_doc/order-2"
+ headers:
+ - name: "Authorization"
+ value: "Basic citrus:encodeBase64('admin:Kamelets-Test-2026!')"
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 200
+ body:
+ data:
'{"_index":"orders","_id":"order-2","_version":1,"_seq_no":"@ignore@","_primary_term":"@ignore@","found":true,"_source":{"order":"ORD-2","status":"shipped"}}'