|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Configuring Anonymous Authentication in OpenSearch |
| 4 | +authors: |
| 5 | + - smortex |
| 6 | +date: 2023-12-14 14:20:00 -1000 |
| 7 | +category: |
| 8 | + - technical-posts |
| 9 | +meta_keywords: anonymous, authentication, authorization |
| 10 | +meta_description: Learn how to set up OpenSearch for anonymous authentication |
| 11 | +--- |
| 12 | + |
| 13 | +The OpenSearch Security plugin has support multiple authentication backends. |
| 14 | +It is also possible to enable anonymous authentication to allow access to OpenSearch without prior identification. |
| 15 | +In this article, we configure anonymous authentication which is disabled by default. |
| 16 | + |
| 17 | +## Enable anonymous authentication in OpenSearch |
| 18 | + |
| 19 | +Anonymous access to OpenSearch is done in the Security plugin by modifying `opensearch-security/config.yml` and reloading the configuration with `securityadmin.sh`. |
| 20 | + |
| 21 | +Ensure `anonymous_auth_enabled` is set to true: |
| 22 | + |
| 23 | +```yaml |
| 24 | +config: |
| 25 | + dynamic: |
| 26 | + http: |
| 27 | + anonymous_auth_enabled: true |
| 28 | +``` |
| 29 | +
|
| 30 | +Then, inject the new configuration (this will replace the configuration, exercise caution if you have changed OpenSearch configuration outside of these files): |
| 31 | +
|
| 32 | +``` |
| 33 | +OPENSEARCH_JAVA_HOME=/usr/share/opensearch/jdk /usr/share/opensearch/plugins/opensearch-security/tools/securityadmin.sh \ |
| 34 | + -cacert /etc/opensearch/root-ca.pem \ |
| 35 | + -cert /etc/opensearch/kirk.pem \ |
| 36 | + -key /etc/opensearch/kirk-key.pem \ |
| 37 | + -cd /etc/opensearch/opensearch-security |
| 38 | +``` |
| 39 | + |
| 40 | +## Enable anonymous authentication in OpenSearch-Dashboards |
| 41 | + |
| 42 | + |
| 43 | +Now that OpenSearch anonymous access is enabled, we must enable it in OpenSearch Dashboards by modifing `opensearch_dashboards.yml` and adding the following line: |
| 44 | + |
| 45 | +```yaml |
| 46 | +opensearch_security.auth.anonymous_auth_enabled: true |
| 47 | +``` |
| 48 | +
|
| 49 | +When done, we restart the `opensearch-dashboards` service. |
| 50 | + |
| 51 | +When accessing OpenSearch Dashboards from a browser, you will automatically log in as the **opendistro_security_anonymous** user. It is possible to authenticate as another user after logging out: the usual log in screen will be presented, with a new "Log in as anonymous" button. |
| 52 | + |
| 53 | +## Adjusting premissions of anonymous users |
| 54 | + |
| 55 | +With the default OpenSearch configuartion, the **opendistro_security_anonymous** user has the *backend role* `opendistro_security_anonymous_backendrole` and the *role* `own_index`. |
| 56 | +This is not sufficient to access OpenSearch data and roles must be mapped to the `opendistro_security_anonymous_backendrole` *backend role* to grant access. |
| 57 | + |
| 58 | +There is no one-size-fit-all configuration, so we will consider some simple use cases. |
| 59 | + |
| 60 | +Configuration can be done using the OpenSearch Dashboards user interface as an administrator, or by modifing the Security plugin configuration in `opensearch-security/roles_mapping.yml` and applying changes with `securityadmin.sh`. |
| 61 | + |
| 62 | +### Provide read-only access to anonymous users |
| 63 | + |
| 64 | +Map the `readall` and `kibana_user` roles to the `opendistro_security_anonymous_backendrole` backend role: |
| 65 | + |
| 66 | +``` |
| 67 | +kibana_user: |
| 68 | + reserved: false |
| 69 | + backend_roles: |
| 70 | + - "kibanauser" |
| 71 | + - "opendistro_security_anonymous_backendrole" # <--- added |
| 72 | + description: "Maps kibanauser to kibana_user" |
| 73 | +
|
| 74 | +readall: |
| 75 | + reserved: false |
| 76 | + backend_roles: |
| 77 | + - "readall" |
| 78 | + - "opendistro_security_anonymous_backendrole" # <--- added |
| 79 | +``` |
| 80 | + |
| 81 | +### Provide full access to anonymous users |
| 82 | + |
| 83 | +Map the `all_access` role to the `opendistro_security_anonymous_backendrole` backend role: |
| 84 | + |
| 85 | +``` |
| 86 | +all_access: |
| 87 | + reserved: false |
| 88 | + backend_roles: |
| 89 | + - "admin" |
| 90 | + - "opendistro_security_anonymous_backendrole" # <--- added |
| 91 | + description: "Maps admin to all_access" |
| 92 | +``` |
| 93 | + |
| 94 | +## Conclusion |
| 95 | + |
| 96 | +In this article, we saw how to enable anonymous access to OpenSearch Dashboards. |
| 97 | + |
| 98 | +In your deployment, you will likely create custom roles to give access to a subset of your data through [document-level](https://opensearch.org/docs/latest/security/access-control/document-level-security/) or [field-level](https://opensearch.org/docs/latest/security/access-control/field-level-security/) security. |
0 commit comments