Hello, I have a problem when I try to use JWT token provided by AWS Cognito.
Specifically I add this configuration to my elasticsearch.yml, on elastic cloud:
xpack:
security:
authc:
realms:
oidc:
oidc1:
order: 2
rp.client_id: "7ixxxxxxx"
rp.response_type: "code"
rp.requested_scopes: ["openid", "email", "profile"]
rp.redirect_uri: "https://xxx/api/security/oidc/callback"
rp.post_logout_redirect_uri: "https://xxx/security/logged_out"
op.issuer: "https://cognito-xyx.amazonaws.com/avbc"
op.authorization_endpoint: "https://xxx.auth.eu-central-1.amazoncognito.com/oauth2/authorize"
op.token_endpoint: "https://xxx.auth.eu-central-1.amazoncognito.com/oauth2/token"
op.userinfo_endpoint: "https://xxx.auth.eu-central-1.amazoncognito.com/oauth2/userInfo"
op.jwkset_path: "https://cxxx.amazonaws.com/yyyy/.well-known/jwks.json"
op.endsession_endpoint: "https://xxxx/logout"
claims.principal: sub
claims.groups: cognito:groups
and this configuration on kibana.yml:
xpack.security.authc.providers:
oidc.oidc1:
order: 0
realm: oidc1
description: "Login with Cognito"
Now when I use Kibana I can login using the Cognito user; when I try to use elasticsearch REST API, using Postman in this case, first I retrieve the JWT token from Cognito pool, and after I use it like:
curl --location --request POST 'https://elasticsearch_url/_search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyxxxx' \
--data '{
"size": 10000
}'
but I get this error message:
{
"error": {
"root_cause": [
{
"type": "security_exception",
"reason": "unable to authenticate with provided credentials and anonymous access is not allowed for this request",
"additional_unsuccessful_credentials": "oauth2 token: invalid token",
"header": {
"WWW-Authenticate": [
"Basic realm=\"security\", charset=\"UTF-8\"",
"Bearer realm=\"security\"",
"ApiKey"
]
}
}
],
"type": "security_exception",
"reason": "unable to authenticate with provided credentials and anonymous access is not allowed for this request",
"additional_unsuccessful_credentials": "oauth2 token: invalid token",
"header": {
"WWW-Authenticate": [
"Basic realm=\"security\", charset=\"UTF-8\"",
"Bearer realm=\"security\"",
"ApiKey"
]
}
},
"status": 401
}
Some additional infos:
- The Elasticsearch version used is 8.17.4.
- The Conigto user pool is cofigured to use the Authorization code grant with scopes [email, openid,profile].
Someone can help me to understand this problem?
Thank you in advance.
E.