Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIDC auth, custom configs #63

Merged
merged 6 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ This ansible playbook supports the following,
- Configure TLS/SSL for OpenSearch transport layer(Nodes to Nodes communication) and REST API layer
- Generate self-signed certificates to configure TLS/SSL for opensearch
- Configure the Internal Users Database with limited users and user-defined passwords
- Configuration of authentication and authorization via OpenID
- Overriding default settings with your own
- Install and configure the Apache2.0 opensource OpenSearch Dashboards

### Prerequisite
Expand Down Expand Up @@ -87,13 +89,53 @@ cluster_type: single-node

You should set the reserved users(`admin` and `kibanaserver`) password using `admin_password` and `kibanaserver_password` variables.

If you define your own internal users (in addition to the reserved `admin` and `kibanaserver`) in custom configuration
files, then passwords to them should be set via variables on the principle of `<username>_password`

It will install and configure the opensearch. Once the deployment completed, you can access the opensearch Dashboards with user `admin` and password which you provided for variable `admin_password`.

# Deploy with ansible playbook - run the playbook as non-root user which have sudo privileges,
ansible-playbook -i inventories/opensearch/hosts opensearch.yml --extra-vars "admin_password=Test@123 kibanaserver_password=Test@6789" --become

**Note**: Change the user details in `ansible_user` parameter in `inventories/opensearch/hosts` inventory file.

### OpenID authentification
To enable authentication via OpenID, you need to change the `auth_type` variable in the inventory file
`inventories/opensearch/group_vars/all/all.yml` by setting the value `oidc` and prescribe the necessary settings
in the `oidc:` block.

### Custom configuration files

To override the default settings files, you need to put your settings in the `files` directory. The files should be
named exactly the same as the original ones (internal_users.yml, roles.yml, tenants.yml, etc.)

Especially note the file `files/internal_users.yml`. If it exists and the `copy_custom_security_configs: true` setting is enabled,
then only in this case the task of setting passwords for internal users from variables is started. If the file `internal_users.yml`
is not located in the `files` directory, but, for example, in one of its subdirectories, then playbook will not work correctly

### IaC (Infrastructure-as-Code)

If you want to use the role not only for the initial deployment of the cluster, but also for further management of it,
then set the `iac_enable` parameter to `true`.

By default, if the /tmp/opensearch-nodecerts directory with certificates exists on the server from which the playbook
is launched, it is assumed that the configuration has not changed and some settings are not copied to the target servers.

Conversely, if the /tmp/opensearch-nodecerts directory does not exist on the server from which the playbook is launched,
then new certificates and settings are generated and they are copied to the target servers.

If you use this repository not only for the initial deployment of the cluster, but also for its automatic configuration
via CI/CD, then new certificates will be generated every time the pipeline is launched, overwriting existing ones, which
is not always necessary if the cluster is already in production.

When iac_enable enabling, and all the cluster servers have all the necessary certificates, they will not be copied again.
If at least on one server (for example, when adding a new server to the cluster) if there is not at least one certificate
from the list, then all certificates on all cluster servers will be updated

Also, if the option is enabled, the settings files will be updated with each execution (previously, the settings were
updated only if the /tmp/opensearch-nodecerts directory was missing on the server from which the playbook was launched
and new certificates were generated)

## Contributing

See [developer guide](DEVELOPER_GUIDE.md) and [how to contribute to this project](CONTRIBUTING.md).
Expand Down
26 changes: 26 additions & 0 deletions files/internal_users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# This is the internal user database
# The hash value is a bcrypt hash and can be generated with plugin/tools/hash.sh

_meta:
type: "internalusers"
config_version: 2

# Define your internal users here

admin:
hash: "{{ admin_password }}"
reserved: true
backend_roles:
- "admin"
description: "admin user"

kibanaserver:
hash: "{{ kibanaserver_password }}"
reserved: true
description: "kibanaserver user"

logstash:
hash: "{{ logstash_password }}"
reserved: true
description: "logstash user"
54 changes: 54 additions & 0 deletions files/roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
_meta:
type: "roles"
config_version: 2


indexes_full_access:
reserved: false
index_permissions:
- index_patterns:
- "*"
allowed_actions:
- "*"
tenant_permissions:
- tenant_patterns:
- "*"
allowed_actions:
- "kibana_all_write"
# ----------------------------------------------------
indexes_security_search_full_access:
reserved: true
index_permissions:
- index_patterns:
- "kube-apiserver-audit-*"
- "syslog-*"
allowed_actions:
- "indices:data/read/search*"
- "read"
- "view_index_metadata"
tenant_permissions:
- tenant_patterns:
- "SECURITY"
allowed_actions:
- "kibana_all_write"
# ----------------------------------------------------
indexes_web_search_full_access:
reserved: true
index_permissions:
- index_patterns:
- "ingress-nginx-*"
- "mywebapp-*"
allowed_actions:
- "indices:data/read/search*"
- "read"
- "view_index_metadata"
tenant_permissions:
- tenant_patterns:
- "WEB"
allowed_actions:
- "kibana_all_write"
# ----------------------------------------------------
# Restrict users so they can only view visualization and dashboard on OpenSearchDashboards
kibana_read_only:
reserved: true
59 changes: 59 additions & 0 deletions files/roles_mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
# In this file users, backendroles and hosts can be mapped to Security roles.
# Permissions for OpenSearch roles are configured in roles.yml

_meta:
type: "rolesmapping"
config_version: 2

kibana_server:
reserved: true
users:
- "kibanaserver"

logstash:
reserved: true
users:
- "logstash"

# Define your roles mapping here
all_access:
reserved: false
backend_roles:
- "admin"
- "opensearch_admin"
description: "Maps admin to all_access"
# ----------------------------------------------------
indexes_full_access:
reserved: false
backend_roles:
- "opensearch_admin"
description: "Maps admin to indexes_full_access"
# ----------------------------------------------------
own_index:
reserved: false
users:
- "*"
description: "Allow full access to an index named like the username"
# ----------------------------------------------------
readall:
reserved: false
backend_roles:
- "opensearch_index_read_all"
# ----------------------------------------------------
indexes_security_search_full_access:
reserved: true
backend_roles:
- "opensearch_index_read_all"
- "opensearch_index_read_security"
description: "Maps users to indexes_security_search_full_access"
# ----------------------------------------------------
indexes_web_search_full_access:
reserved: true
backend_roles:
- "opensearch_index_read_all"
- "opensearch_index_read_web"
description: "Maps users to indexes_web_search_full_access"



12 changes: 12 additions & 0 deletions files/tenants.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
_meta:
type: "tenants"
config_version: 2

# Define your tenants here
SECURITY:
reserved: false
description: "Tenant for security logs (e.g. kubernetes audit or opensearch audit)"
WEB:
reserved: false
description: "Tenant for web-app logs"
62 changes: 62 additions & 0 deletions inventories/opensearch/group_vars/all/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,65 @@ cluster_type: multi-node
os_user: opensearch

os_dashboards_user: opensearch-dashboards

# Number of days that certificates are valid
cert_valid_days: 730
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for 730? Can we have an empty space if null default as 1yr ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value was before my edits, so I left it the same. Probably this period was optimal. I have set 10 years for myself, because I do not see the need for frequent certificate changes in the cluster.


# Auth type: 'internal' or 'oidc' (OpenID). Default: internal
auth_type: internal

# OIDC settings
oidc:
description: "Authenticate via IdP"
# OpenID server URI
connect_url: https://oidc.example.com/auth/realms/<realm name>/.well-known/openid-configuration
# The JWT token field that contains the user name
subject_key: preferred_username
# the JWT token field that contains a list of user roles
roles_key: roles
# Scopes
scopes: "openid profile email"
# The address of Dashboards to redirect the user to after successful authentication
dashboards_url: http(s)://<dashboards address>.example.com
# IdP client ID
client_id: opensearch
# IdP client secret
client_secret: "00000000-0000-0000-0000-000000000000"

# Overwrite demo configurations with your own
copy_custom_security_configs: false

# To override demo configurations, you can use your own configuration files.
# Place them in the "files" directory. Specify the path to the files
custom_security_plugin_configs:
- files/tenants.yml
- files/roles.yml
- files/roles_mapping.yml
- files/internal_users.yml

# By default, if the /tmp/opensearch-nodecerts directory with certificates
# exists on the server from which the playbook is launched, it is assumed
# that the configuration has not changed and some settings are not copied
# to the target servers.
#
# Conversely, if the /tmp/opensearch-nodecerts directory does not exist on
# the server from which the playbook is launched, then new certificates and
# settings are generated and they are copied to the target servers.
#
# If you use this repository not only for the initial deployment of the
# cluster, but also for its automatic configuration via CI/CD, then new
# certificates will be generated every time the pipeline is launched,
# overwriting existing ones, which is not always necessary if the cluster is
# already in production.
#
# When iac_enable enabling, and all the cluster servers have all the necessary
# certificates, they will not be copied again. If at least on one server (for
# example, when adding a new server to the cluster) if there is not at least one
# certificate from the list, then all certificates on all cluster servers will
# be updated
#
# Also, if the option is enabled, the settings files will be updated with each
# execution (previously, the settings were updated only if the
# /tmp/opensearch-nodecerts directory was missing on the server from which the
# playbook was launched and new certificates were generated)
iac_enable: false
3 changes: 3 additions & 0 deletions roles/linux/dashboards/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ os_nodes_dashboards: |-
{%- endfor %}

systemctl_path: /etc/systemd/system

# Auth type: 'internal' or 'oidc' (OpenID). Default: internal
auth_type: internal
26 changes: 21 additions & 5 deletions roles/linux/dashboards/tasks/dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
dest: "/tmp/opensearch-dashboards.tar.gz"
register: download

- name: Dashboards Install | Create opensearch user
- name: Dashboards Install | Create opensearch dashboard user
user:
name: "{{ os_dashboards_user }}"
state: present
shell: /bin/bash
when: download.changed
shell: /bin/false
create_home: true
home: "{{ os_dashboards_home }}"
when: download.changed or iac_enable

- name: Dashboards Install | Create home directory
file:
path: "{{ os_dashboards_home }}"
state: directory
owner: "{{ os_dashboards_user }}"
group: "{{ os_dashboards_user }}"
when: download.changed
when: download.changed or iac_enable

- name: Dashboards Install | Extract the tar file
command: chdir=/tmp/ tar -xvzf opensearch-dashboards.tar.gz -C "{{ os_dashboards_home }}" --strip-components=1
when: download.changed
when: download.changed or iac_enable

- name: Dashboards Install | Copy Configuration File
template:
Expand All @@ -34,6 +36,20 @@
mode: 0644
backup: yes

- name: Dashboards Install | Set the file ownerships
file:
dest: "{{ os_dashboards_home }}"
owner: "{{ os_dashboards_user }}"
group: "{{ os_dashboards_user }}"
recurse: yes

- name: Dashboards Install | Set the folder permission
file:
dest: "{{ os_conf_dir }}"
owner: "{{ os_dashboards_user }}"
group: "{{ os_dashboards_user }}"
mode: 0700

- name: Dashboards Install | create systemd service
template:
src: dashboards.service
Expand Down
12 changes: 12 additions & 0 deletions roles/linux/dashboards/templates/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ opensearch_security.multitenancy.tenants.preferred: ["Private", "Global"]
opensearch_security.readonly_mode.roles: ["kibana_read_only"]
# Use this setting if you are running dashboards without https
opensearch_security.cookie.secure: false


# OpenID settings
{% if auth_type == 'oidc' %}
opensearch_security.auth.type: openid
opensearch_security.openid.base_redirect_url: "{{ oidc.dashboards_url }}"
opensearch_security.openid.client_id: "{{ oidc.client_id }}"
opensearch_security.openid.scope: "{{ oidc.scopes }}"
opensearch_security.openid.client_secret: "{{ oidc.client_secret }}"
opensearch_security.openid.connect_url: "{{ oidc.connect_url }}"
opensearch_security.openid.verify_hostnames: true
{% endif %}
3 changes: 3 additions & 0 deletions roles/linux/opensearch/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ os_sec_plugin_tools_path: /usr/share/opensearch/plugins/opensearch-security/tool
os_api_port: 9200

systemctl_path: /etc/systemd/system

# Auth type: 'internal' or 'oidc' (OpenID). Default: internal
auth_type: internal
10 changes: 6 additions & 4 deletions roles/linux/opensearch/tasks/opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
user:
name: "{{ os_user }}"
state: present
shell: /bin/bash
when: download.changed
shell: /bin/false
create_home: true
home: "{{ os_home }}"
when: download.changed or iac_enable

- name: OpenSearch Install | Create home directory
file:
path: "{{ os_home }}"
state: directory
owner: "{{ os_user }}"
group: "{{ os_user }}"
when: download.changed
when: download.changed or iac_enable

- name: OpenSearch Install | Extract the tar file
command: chdir=/tmp/ tar -xvzf opensearch.tar.gz -C "{{ os_home }}" --strip-components=1
when: download.changed
when: download.changed or iac_enable

- name: OpenSearch Install | Copy Configuration File
blockinfile:
Expand Down
Loading