-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Setup BWC repos, Install BWC and Setup RBAC #126
Changes from 28 commits
ab143a0
6d05514
dca13a3
3098871
b850d58
c287cc3
b3772fc
8548acc
a09cb88
ac4cd06
69fd550
1aa9d35
ea34e3c
22f86a1
1c1ebd0
bd198f2
17d7045
aaccdab
18da115
a5f2478
b7d84e7
a343cd6
6ff9e0b
e1977f0
5318182
9a5dee6
df65ee2
2fd65e8
56d0587
c1d98a9
8837fff
48dcd6b
b4843f3
76084dd
15ac7e6
9891ed2
9b5ff73
a729179
51ff517
7baa909
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
# BWC PackageCloud repository to install: enterprise, enterprise-unstable, staging-enterprise, staging-enterprise-unstable. | ||
bwc_pkg_repo: "enterprise" | ||
# 'latest' to get latest version or numeric like '2.1.1' | ||
bwc_version: latest | ||
# used only if 'bwc_version' is numeric | ||
bwc_revision: 1 | ||
|
||
# BWC license to install BWC enterprise bits | ||
master_token: "{{ bwc_license }}" | ||
|
||
# Specify roles and assignments for BWC RBAC. | ||
# Roles are pushed as YML files to /opt/stackstorm/rbac/roles | ||
# Assignments are pushed as YML files to /opt/stackstorm/rbac/assignments/ | ||
# The schema for roles and assignments follow the exact schema definition | ||
# define in https://bwc-docs.brocade.com/rbac.html#defining-roles-and-permission-grants | ||
# and https://bwc-docs.brocade.com/rbac.html#defining-user-role-assignments. | ||
|
||
bwc_rbac_default_roles: [] | ||
|
||
bwc_rbac_default_assignments: | ||
- name: "{{ st2_system_user }}" | ||
roles: | ||
- admin | ||
|
||
- name: "{{ st2_auth_username }}" | ||
roles: | ||
- system_admin | ||
|
||
bwc_rbac: | ||
roles: "{{ bwc_rbac_default_roles }}" | ||
|
||
assignments: "{{ bwc_rbac_default_assignments }}" | ||
|
||
|
||
# By specifying a valid configuration for LDAP, | ||
# (See https://bwc-docs.brocade.com/authentication.html#ldap ) | ||
# LDAP auth backend is setup for st2 and BWC. | ||
# Note that you just need to provide the backend_kwargs. | ||
bwc_ldap: | ||
backend_kwargs: {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
|
||
- name: reload bwc_rbac | ||
become: yes | ||
command: st2-apply-rbac-definitions --config-file /etc/st2/st2.conf |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
galaxy_info: | ||
description: Install BWC Entperprise components, setup RBAC and LDAP | ||
author: lakshmi-kannan | ||
company: StackStorm | ||
license: Apache 2.0 | ||
min_ansible_version: 2.2 | ||
platforms: | ||
- name: Ubuntu | ||
versions: | ||
- trusty | ||
- xenial | ||
- name: EL | ||
versions: | ||
- 6 | ||
- 7 | ||
categories: | ||
- stackstorm | ||
- BWC | ||
- Brocade Workflow Composer | ||
- repositories | ||
- packagecloud | ||
dependencies: | ||
- role: st2repos | ||
- role: st2 | ||
- role: st2web | ||
- role: bwc_repos |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
|
||
- name: Assert that master_token is specified | ||
fail: msg="License key must be supplied for BWC enterprise installation." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed in this file, since you include that check in previous step |
||
when: bwc_license is not defined | ||
|
||
- name: Install prereqs (Debian) | ||
become: yes | ||
apt: | ||
name: "{{ item }}" | ||
state: present | ||
with_items: | ||
- debian-archive-keyring | ||
- apt-transport-https | ||
|
||
# This is the exact key as the open source repo but this behavior might change. | ||
- name: Add keys to keyring | ||
become: yes | ||
apt_key: | ||
id: 418A7F2FB0E1E6E7EABF6FE8C2E73424D59097AB | ||
url: https://packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/gpgkey | ||
state: present | ||
|
||
- name: "Add packagecloud.io repository: StackStorm/{{ bwc_pkg_repo }}" | ||
become: yes | ||
no_log: yes | ||
apt_repository: | ||
filename: "StackStorm_{{ bwc_pkg_repo }}" | ||
repo: 'deb https://{{ bwc_read_token }}:@packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} main' | ||
state: present | ||
update_cache: yes | ||
register: added_bwc_deb_repository |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
|
||
- name: Assert that master_token is specified | ||
fail: msg="License key must be supplied for BWC enterprise installation." | ||
when: bwc_license is not defined | ||
|
||
- name: Create packagecloud dir | ||
become: yes | ||
file: | ||
path: "/etc/packagecloud" | ||
mode: "u=rwx,g=rx,o=rx" | ||
owner: st2 | ||
group: st2 | ||
state: directory | ||
|
||
- name: Get read token for repo from packagecloud | ||
become: yes | ||
no_log: yes | ||
uri: | ||
url: https://{{ bwc_license }}:@packagecloud.io/install/repositories/StackStorm/{{ bwc_pkg_repo }}/tokens.text | ||
creates: "/etc/packagecloud/StackStorm_{{ bwc_pkg_repo }}_read_token.txt" # Don't download if file already exists | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following our previous case when we rotated What will happen if user changes Eg. if user changes the license - Ansible should update apt/yum repository too with new read token. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Unfortunately, if I generate a token every time, it would cause idempotency failures. If I do what I did, then installation with fail if they swapped the license. But I think this is fine. It fails out with an error. Another approach is to ask user for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like I could force There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What we can do is to additionally generate the hash from the If hash changed (eg. user provided new license), - then we request new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can address this in a different PR. I am not too keen on adding more scope to this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deal. Feel free to create an issue for this then so maybe someone else could pick it up. |
||
dest: "/etc/packagecloud/StackStorm_{{ bwc_pkg_repo }}_read_token.txt" | ||
force_basic_auth: yes | ||
method: POST | ||
status_code: 201,200 | ||
headers: | ||
Content-Type: "application/x-www-form-urlencoded" | ||
body: "name={{ ansible_nodename }}" | ||
|
||
- name: Set bwc_read_token variable | ||
become: yes | ||
no_log: yes | ||
set_fact: | ||
bwc_read_token: "{{ lookup('file', '/etc/packagecloud/StackStorm_{{ bwc_pkg_repo }}_read_token.txt') }}" | ||
|
||
- name: Add BWC enterprise repos on {{ ansible_distribution }} | ||
include: bwc_repos_{{ ansible_pkg_mgr }}.yml | ||
tags: | ||
- BWC repos | ||
- StackStorm enterprise | ||
register: bwc_repo_added | ||
when: bwc_read_token != '' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
|
||
# Fixes "Failure talking to yum: Cannot retrieve repository metadata (repomd.xml) for repository: StackStorm_stable. Please verify its path and try again" when installing st2 | ||
- name: Update ca-certificates package | ||
become: yes | ||
yum: | ||
name: ca-certificates | ||
state: latest | ||
tags: skip_ansible_lint | ||
|
||
- name: "Add packagecloud.io repository: StackStorm/{{ bwc_pkg_repo }}" | ||
become: yes | ||
no_log: yes | ||
yum_repository: | ||
name: "StackStorm_{{ bwc_pkg_repo }}" | ||
description: "StackStorm_{{ bwc_pkg_repo }}" | ||
file: "StackStorm_{{ bwc_pkg_repo }}" | ||
baseurl: https://{{ bwc_read_token }}:@packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/el/{{ ansible_distribution_major_version }}/$basearch | ||
repo_gpgcheck: yes | ||
gpgkey: "https://{{ bwc_read_token }}:@packagecloud.io/StackStorm/{{ bwc_pkg_repo }}/gpgkey" | ||
sslcacert: /etc/pki/tls/certs/ca-bundle.crt | ||
metadata_expire: 300 | ||
gpgcheck: no | ||
enabled: yes | ||
sslverify: yes | ||
register: added_bwc_rpm_repository |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
|
||
- name: Setup st2.conf auth backend to LDAP | ||
become: yes | ||
# Unfortunately, ``with_dict`` also logs the dict which could leak passwords. | ||
no_logs: yes | ||
ini_file: | ||
dest: /etc/st2/st2.conf | ||
section: auth | ||
option: backend | ||
value: ldap | ||
backup: yes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notify st2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we also have to set the backend_kwargs before restarting. See next step. I did notify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include notify for every task where its needed logically (ex: changing the conf file), its less error prone since "next task" could be removed, adjusted or never ran because of some conditional. It doesn't matter how many times we call Ansible handlers, - they will be executed in the end of entire play run in any way. See "Handlers: Running Operations On Change": http://docs.ansible.com/ansible/playbooks_intro.html with better explanation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, good to know about that. |
||
# Don't even setup LDAP if backend_kwargs is not defined | ||
with_dict: "{{ bwc_ldap.backend_kwargs | default({}) }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see So you probably want something like: when: bwc_ldap.backend_kwargs is defined and bwc_ldap.backend_kwargs|length > 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also @lakshmi-kannan
Just interesting fact. |
||
notify: | ||
- restart st2api | ||
- restart st2stream | ||
|
||
- name: Setup st2.conf auth backend_kwargs for LDAP | ||
become: yes | ||
# Unfortunately, ``with_dict`` also logs the dict which could leak passwords. | ||
no_log: yes | ||
ini_file: | ||
dest: /etc/st2/st2.conf | ||
section: auth | ||
option: backend_kwargs | ||
value: "{{ bwc_ldap.backend_kwargs | to_json | string }}" | ||
backup: yes | ||
with_dict: "{{ bwc_ldap.backend_kwargs | default({}) }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, when: bwc_ldap.backend_kwargs is defined and bwc_ldap.backend_kwargs|length > 0 |
||
notify: | ||
- restart st2api | ||
- restart st2stream |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
|
||
- name: Add BWC enterprise repos | ||
include: bwc_repos_setup.yml | ||
tags: | ||
- BWC repos | ||
- StackStorm enterprise | ||
|
||
- name: Install latest bwc-enterprise package | ||
become: yes | ||
package: | ||
name: bwc-enterprise | ||
state: latest | ||
register: bwc_installed | ||
when: bwc_repo_added|success and bwc_version == "latest" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need |
||
tags: | ||
- bwc | ||
- st2 enterprise | ||
- skip_ansible_lint | ||
|
||
- name: Install pinned bwc-enterprise package | ||
become: yes | ||
package: | ||
name: bwc-enterprise={{ bwc_version }}-{{ bwc_revision }} | ||
state: present | ||
register: bwc_installed | ||
when: bwc_repo_added|success and bwc_version != "latest" | ||
tags: | ||
- bwc | ||
- st2 enterprise | ||
|
||
- name: Setup RBAC and setup roles and assignments if bwc_rbac is defined | ||
include: "rbac.yml" | ||
when: bwc_installed|success and bwc_rbac is defined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need |
||
|
||
- name: Setup LDAP and set up LDAP configuration | ||
include: "ldap.yml" | ||
when: bwc_installed|success and bwc_ldap is defined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here to avoid unecessary check |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
|
||
- name: Create BWC RBAC directories | ||
become: yes | ||
file: | ||
path: "{{ item }}" | ||
mode: "u=rwx,g=rx,o=rx" | ||
owner: st2 | ||
group: st2 | ||
state: directory | ||
with_items: | ||
- /opt/stackstorm/rbac/assignments | ||
- /opt/stackstorm/rbac/roles | ||
|
||
- name: Copy default RBAC roles to /opt/stackstorm/rbac/roles directory | ||
become: yes | ||
template: | ||
src: rbac_roles/roles.yml.j2 | ||
dest: /opt/stackstorm/rbac/roles/{{ item.name }}.yaml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing any file in Make sure we run that thing for other tasks in this file. |
||
owner: st2 | ||
group: st2 | ||
with_items: "{{ bwc_rbac_default_roles }}" | ||
|
||
- name: Copy user defined RBAC roles to /opt/stackstorm/rbac/roles directory | ||
become: yes | ||
template: | ||
src: rbac_roles/roles.yml.j2 | ||
dest: /opt/stackstorm/rbac/roles/{{ item.name }}.yaml | ||
owner: st2 | ||
group: st2 | ||
with_items: "{{ bwc_rbac.roles }}" | ||
when: bwc_rbac.roles is defined | ||
|
||
- name: Copy default RBAC assignments to /opt/stackstorm/rbac/assignments directory | ||
become: yes | ||
template: | ||
src: rbac_assignments/assignments.yml.j2 | ||
dest: /opt/stackstorm/rbac/assignments/{{ item.name }}.yaml | ||
owner: st2 | ||
group: st2 | ||
with_items: "{{ bwc_rbac_default_assignments }}" | ||
|
||
- name: Copy user defined RBAC assignments to /opt/stackstorm/rbac/assignments directory | ||
become: yes | ||
template: | ||
src: rbac_assignments/assignments.yml.j2 | ||
dest: /opt/stackstorm/rbac/assignments/{{ item.name }}.yaml | ||
owner: st2 | ||
group: st2 | ||
with_items: "{{ bwc_rbac.assignments }}" | ||
when: bwc_rbac.assignments is defined | ||
|
||
- name: Enable RBAC in st2 configuration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enable auth maybe? |
||
become: yes | ||
ini_file: | ||
dest: /etc/st2/st2.conf | ||
section: rbac | ||
option: enable | ||
value: True | ||
backup: yes | ||
notify: | ||
- restart st2 | ||
- reload bwc_rbac | ||
- restart st2api |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
|
||
username: {{ item.name }} | ||
roles: | ||
{{ item.roles | to_nice_yaml }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we found indentation fix for https://github.com/StackStorm/ansible-st2/pull/126/files#r106033276 this must be the right way: in case if someday |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
|
||
name: {{ item.name }} | ||
description: {{ item.description }} | ||
permission_grants: | ||
{{ item.permission_grants | to_nice_json }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://gist.github.com/lakshmi-kannan/0f5f073311a40d209d3e19c7cab3e864 for why I had to use to_nice_json as opposed to to_nice_yaml. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I played with this ---
name: {{ item.name }}
description: {{ item.description }}
permission_grants:
{{ item.permission_grants | to_nice_yaml(2) | indent(2) }} Which will generate: ---
name: basic
description: This role has access only to action core.remote in pack 'core'
permission_grants:
- permission_types:
- action_execute
resource_uid: action:core:remote Related issue: ansible/ansible#16207 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
- st2web | ||
- nodejs | ||
- st2smoketests | ||
- bwc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define all vars used in this role with comments, as well as include them in
README.md
.