Proxy-based authentication

If you already have a single sign-on (SSO) solution in place, you might want to use it as an authentication backend.

Most solutions work as a proxy in front of OpenSearch and the security plugin. If proxy authentication succeeds, the proxy adds the (verified) username and its (verified) roles in HTTP header fields. The names of these fields depend on the SSO solution you have in place.

The security plugin then extracts these HTTP header fields from the request and uses the values to determine the user’s permissions.

Enable proxy detection

To enable proxy detection for OpenSearch, configure it in the xff section of config.yml:

  1. ---
  2. _meta:
  3. type: "config"
  4. config_version: 2
  5. config:
  6. dynamic:
  7. http:
  8. anonymous_auth_enabled: false
  9. xff:
  10. enabled: true
  11. internalProxies: '192\.168\.0\.10|192\.168\.0\.11'
  12. remoteIpHeader: 'x-forwarded-for'

You can configure the following settings:

NameDescription
enabledEnables or disables proxy support. Default is false.
internalProxiesA regular expression containing the IP addresses of all trusted proxies. The pattern .* trusts all internal proxies.
remoteIpHeaderName of the HTTP header field that has the hostname chain. Default is x-forwarded-for.

To determine whether a request comes from a trusted internal proxy, the security plugin compares the remote address of the HTTP request with the list of configured internal proxies. If the remote address is not in the list, the plugin treats the request like a client request.

Enable proxy authentication

Configure the names of the HTTP header fields that carry the authenticated username and role(s) in in the proxy HTTP authenticator section:

  1. proxy_auth_domain:
  2. http_enabled: true
  3. transport_enabled: true
  4. order: 0
  5. http_authenticator:
  6. type: proxy
  7. challenge: false
  8. config:
  9. user_header: "x-proxy-user"
  10. roles_header: "x-proxy-roles"
  11. authentication_backend:
  12. type: noop
NameDescription
user_headerThe HTTP header field containing the authenticated username. Default is x-proxy-user.
roles_headerThe HTTP header field containing the comma-separated list of authenticated role names. The security plugin uses the roles found in this header field as backend roles. Default is x-proxy-roles.
roles_separatorThe separator for roles. Default is ,.

Enable extended proxy authentication

The security plugin has an extended version of the proxy type that lets you pass additional user attributes for use with document-level security. Aside from type: extended-proxy and attr_header_prefix, configuration is identical:

  1. proxy_auth_domain:
  2. http_enabled: true
  3. transport_enabled: true
  4. order: 0
  5. http_authenticator:
  6. type: extended-proxy
  7. challenge: false
  8. config:
  9. user_header: "x-proxy-user"
  10. roles_header: "x-proxy-roles"
  11. attr_header_prefix: "x-proxy-ext-"
  12. authentication_backend:
  13. type: noop
NameDescription
attr_header_prefixThe header prefix that the proxy uses to provide user attributes. For example, if the proxy provides x-proxy-ext-namespace: my-namespace, use ${attr.proxy.namespace} in document-level security queries.

Example

The following example uses an nginx proxy in front of a three-node OpenSearch cluster. For simplicity, we use hardcoded values for x-proxy-user and x-proxy-roles. In a real world example you would set these headers dynamically. The example also includes a commented header for use with the extended proxy.

  1. events {
  2. worker_connections 1024;
  3. }
  4. http {
  5. upstream opensearch {
  6. server node1.example.com:9200;
  7. server node2.example.com:9200;
  8. server node3.example.com:9200;
  9. keepalive 15;
  10. }
  11. server {
  12. listen 8090;
  13. server_name nginx.example.com;
  14. location / {
  15. proxy_pass https://opensearch;
  16. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  17. proxy_set_header x-proxy-user test;
  18. proxy_set_header x-proxy-roles test;
  19. #proxy_set_header x-proxy-ext-namespace my-namespace;
  20. }
  21. }
  22. }

The corresponding minimal config.yml looks like:

  1. ---
  2. _meta:
  3. type: "config"
  4. config_version: 2
  5. config:
  6. dynamic:
  7. http:
  8. xff:
  9. enabled: true
  10. internalProxies: '172.16.0.203' # the nginx proxy
  11. authc:
  12. proxy_auth_domain:
  13. http_enabled: true
  14. transport_enabled: true
  15. order: 0
  16. http_authenticator:
  17. type: proxy
  18. #type: extended-proxy
  19. challenge: false
  20. config:
  21. user_header: "x-proxy-user"
  22. roles_header: "x-proxy-roles"
  23. #attr_header_prefix: "x-proxy-ext-"
  24. authentication_backend:
  25. type: noop

The important part is to enable the X-Forwarded-For (XFF) resolution and set the IP(s) of the internal proxies correctly:

  1. enabled: true
  2. internalProxies: '172.16.0.203' # nginx proxy

In this case, nginx.example.com runs on 172.16.0.203, so add this IP to the list of internal proxies. Be sure to set internalProxies to the minimum number of IP addresses so that the security plugin only accepts requests from trusted IPs.

OpenSearch Dashboards proxy authentication

To use proxy authentication with OpenSearch Dashboards, the most common configuration is to place the proxy in front of OpenSearch Dashboards and let OpenSearch Dashboards pass the user and role headers to the security plugin.

In this case, the remote address of the HTTP call is the IP of OpenSearch Dashboards, because it sits directly in front of OpenSearch. Add the IP of OpenSearch Dashboards to the list of internal proxies:

  1. ---
  2. _meta:
  3. type: "config"
  4. config_version: 2
  5. config:
  6. dynamic:
  7. http:
  8. xff:
  9. enabled: true
  10. remoteIpHeader: "x-forwarded-for"
  11. internalProxies: '<opensearch-dashboards-ip-address>'

To pass the user and role headers that the authenticating proxy adds from OpenSearch Dashboards to the security plugin, add them to the HTTP header whitelist in opensearch_dashboards.yml:

  1. opensearch.requestHeadersWhitelist: ["securitytenant","Authorization","x-forwarded-for","x-proxy-user","x-proxy-roles"]

You must also enable the authentication type in opensearch_dashboards.yml:

  1. plugins.security.auth.type: "proxy"
  2. plugins.security.proxycache.user_header: "x-proxy-user"
  3. plugins.security.proxycache.roles_header: "x-proxy-roles"