Hi,
I am trying to setup an Opensearch Cluster with OpenID with Keycloak. I am running locally (With Vagrant) to see if I can get it all to work, before I build my infra at AWS. So i generated some self signed certficates btw.
I have setup a Keycloak (18.0.2) with Nginx running on https://keycloak.example.com
. I have created a realm monitoring
and a (Access Type Public) client named dashboard
. Created a mapper User Realm Role
with a Token Claim Name of roles
. In my realm, I have created a role named all_access
.
I have a basic setup of 2 OpenSearch 2.1.0 instances in a cluster and a single dashoard 2.1.0 instance, running on https://opensearch.example.com
.
I have the following opensearch-dashboard.yml
file:
server.name: os_dashboards
server.host: "0.0.0.0"
opensearch.hosts: [https://opensearch-node1:9200, https://opensearch-node2:9200]
opensearch.username: kibanaserver
opensearch.password: kibanaserver
server.ssl.enabled: true
server.ssl.certificate: /usr/share/opensearch-dashboards/config/certificates/os-dashboards/os-dashboards.pem
server.ssl.key: /usr/share/opensearch-dashboards/config/certificates/os-dashboards/os-dashboards.key
opensearch.ssl.certificateAuthorities:
[/usr/share/opensearch-dashboards/config/certificates/ca/ca.pem]
opensearch.ssl.verificationMode: full
opensearch.requestHeadersWhitelist: ["securitytenant", "authorization"]
opensearch_security.multitenancy.enabled: false
opensearch_security.multitenancy.tenants.enable_global: true
opensearch_security.multitenancy.tenants.enable_private: false
opensearch_security.multitenancy.tenants.preferred: ["Private", "Global"]
opensearch_security.readonly_mode.roles: ["kibana_read_only"]
opensearch_security.multitenancy.enable_filter: false
opensearch_security.auth.type: "openid"
opensearch_security.openid.connect_url: https://keycloak.example.com/auth/realms/monitoring/.well-known/openid-configuration
opensearch_security.openid.base_redirect_url: https://opensearch.example.com:5601
opensearch_security.openid.client_id: dashboard
opensearch_security.openid.header: "Authorization"
# opensearch_security.openid.client_secret: YitqxX5cRHgrvtTVulDC08qbnfwzleM2
opensearch_security.openid.root_ca: /usr/share/opensearch-dashboards/config/certificates/ca/ca.pem
opensearch_security.openid.verify_hostnames: false
I have the following config.yml
for the security plugin:
_meta:
type: "config"
config_version: 2
config:
dynamic:
http:
anonymous_auth_enabled: false
authc:
basic_internal_auth_domain:
http_enabled: true
transport_enabled: true
order: 0
http_authenticator:
type: basic
challenge: false
authentication_backend:
type: internal
openid_auth_domain:
http_enabled: true
transport_enabled: true
order: 1
http_authenticator:
type: openid
challenge: false
config:
openid_connect_idp:
enable_ssl: true
verify_hostnames: false
pemtrustedcas_filepath: /usr/share/opensearch/config/certificates/ca/ca.pem
subject_key: preferred_username
roles_key: roles
openid_connect_url: https://keycloak.example.com/auth/realms/monitoring/.well-known/openid-configuration
skip_users:
- kibanaserver
authentication_backend:
type: noop
So far, to various topic here on this forum this seems all correct. I have used a vanilla role_mappings.yml
, but I changed the all_access
mapping to:
all_access:
reserved: false
backend_roles:
- "admin"
users:
- wdijkerman
description: "Maps admin to all_access"
Started the cluster, executed the command:
sudo docker compose exec os01 bash -c "cd plugins/opensearch-security/tools/ && chmod +x securityadmin.sh && bash ./securityadmin.sh -cd ../../../config/opensearch-security/ -icl -nhnv -cacert ../../../config/certificates/ca/ca.pem -cert ../../../config/certificates/ca/admin.pem -key ../../../config/certificates/ca/admin.key -h localhost"
And when I open the dashboard on “https://opensearch.example.com:5601” I am redirected to the Keycloak login page in the monitoring
realm, fill in my credentials of a user that I manually created in Keycloak and once I click login, I get a 401 Unauthorized. But when I use curl:
curl -ks \
-d "client_id=dashboard" \
-d "username=wdijkerman" \
-d "password=password" \
-d "grant_type=password" \
"https://keycloak.example.com/auth/realms/monitoring/protocol/openid-connect/token"
I get some output, like the access_token
:
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJMd0RYamIzbEVwZHQwRlRTT3JEd0Q5N2ZZaDRobGhJS3RmeHlBeHdzUi1JIn0.eyJleHAiOjE2NTg3NjA1MjAsImlhdCI6MTY1ODc2MDIyMCwianRpIjoiMzdiYTRmOWUtMzNlOC00Y2YxLWIzZGYtOGVhN2NlM2E1NWEzIiwiaXNzIjoiaHR0cHM6Ly9rZXljbG9hay5leGFtcGxlLmNvbS9hdXRoL3JlYWxtcy9tb25pdG9yaW5nIiwic3ViIjoiMWMwZjkwM2UtOWE1ZC00MDEwLWEzYjgtMmMxZGJkNDliNjZhIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiZGFzaGJvYXJkIiwic2Vzc2lvbl9zdGF0ZSI6ImY2MzY3MDQ4LTNjNTYtNGEyMy1hMTc2LTdlMzU3ZjYzM2IxOCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiIl0sInNjb3BlIjoiZW1haWwgcHJvZmlsZSIsInNpZCI6ImY2MzY3MDQ4LTNjNTYtNGEyMy1hMTc2LTdlMzU3ZjYzM2IxOCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoiV2VybmVyIERpamtlcm1hbiIsInByZWZlcnJlZF91c2VybmFtZSI6IndkaWprZXJtYW4iLCJnaXZlbl9uYW1lIjoiV2VybmVyIiwiZmFtaWx5X25hbWUiOiJEaWprZXJtYW4iLCJlbWFpbCI6Im1lQGV4YW1wbGUuY29tIn0.glZUdPlFUnmMqLITQzrMksqTJOciuHNSULCmdXnqdCXvLiTmBJDgQHqGwN53ahZuUgZtZ2hPoQ5V6rVHqddn8d-WfuEPLkUvGaPAZn67sd9qhIH8fWchxIFl7KvLC_RN9xPBniD-6e1ZPj6uYo76a7nc-nmVIC2L_D3iaYDEyoibPsWbJknPmSE7hjkv0csRfNnuZQhUSxi6zGDh3u9jqUMGRgNnYi4VxaZjVDUXtZzI6QFef9Jxr72fXD1yw3N33bu1HxLZk6oQFk--jp7UkXHT88fx9mnpqs5f_68T7E5GCt0BLbyIFNG1hjLDnLXtGxRu4kZ3j6JV7YTfp3-U6g
The only error I see in Opensearch nodes is:
[2022-07-25T14:47:12,988][WARN ][o.o.s.h.HTTPBasicAuthenticator] [os01] No 'Basic Authorization' header, send 401 and 'WWW-Authenticate Basic'
Then I created a mapper in my dashboard
client, with User Client Role
and also used the Token Claim Name of roles
and same error message, but I then have something in my token:
eyJhbGciOiJSUzI1N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BgMOiCDlKLl8nwsFpzrc780xRzpvb3qqjPOKr1qrnEXqdh3QoVHyCy6LDMDnwLYOSsmK79D2ivCRsgcthXid9VVxNCaf55yxekqWK_04ktO0dksfEhspmbdHrHLWK6b83WTHxQ9XN5VOL6IH_4VJeXjH8rdkyIWPoaO9sdO87GDTlmREYcKv0jipFYZEpRpPz9oAQg
So at the moment, I have really no idea what I am doing wrong. I probably overlook something, but searching on “opensearch openid” here on the forum I found lots of topics, but I tried to apply/verify my setup but no luck so far. I need help, I don’t see the problem right now.
This is all locally, so if you need additional info or screenshots please let me know. Thanks in advance!
Kind regards,
Werner