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

do not try to drop roles in mysql hardening #649

Merged
merged 34 commits into from Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0bf528d
do not try to drop roles in mysql hardening
Mar 8, 2023
8d5143b
try to fix IS_ROLE
Mar 22, 2023
0675167
do not create role for now!
Mar 22, 2023
a689290
try to fix IS_ROLE
Mar 22, 2023
4c5a5de
try to fix IS_ROLE
Mar 22, 2023
dc58342
try to fix IS_ROLE
Mar 22, 2023
66adae0
try to fix IS_ROLE
Mar 22, 2023
92e6cad
try to fix IS_ROLE
Mar 22, 2023
bd72131
try to fix IS_ROLE
Mar 22, 2023
2c18d3a
use if for role detection
schurzi Apr 5, 2023
3671501
use separate task for role detection
schurzi Nov 10, 2023
216b56f
lint
schurzi Nov 10, 2023
c59a4d4
fix role path
schurzi Nov 11, 2023
4756a62
reduce dir dependencies
schurzi Nov 11, 2023
8f51601
trigger workflow
schurzi Nov 11, 2023
665edd5
re-add working directories
schurzi Nov 11, 2023
b07ac77
test removing requirements
schurzi Nov 11, 2023
3368618
try local path
schurzi Nov 11, 2023
219ec19
try symlink fix
schurzi Nov 11, 2023
79dc1d5
check mode for status var
schurzi Nov 11, 2023
6681e0b
correct query
schurzi Nov 11, 2023
ec8811a
use like to coerce collation
schurzi Nov 11, 2023
35df355
add tests for roles
schurzi Nov 11, 2023
ee1fec3
correct indentation
schurzi Nov 11, 2023
fdf7bbd
correct hostname in test
schurzi Nov 11, 2023
2f53602
extend role check
schurzi Nov 11, 2023
9978472
drop role after test for inspec
schurzi Nov 11, 2023
0c8c96a
collate for opensuse
schurzi Nov 11, 2023
fb22b24
better compare for utf8
schurzi Nov 11, 2023
bf177ad
one last time ...
schurzi Nov 11, 2023
7437f68
onece more ...
schurzi Nov 11, 2023
8e97184
test wirth modified inspec profile
schurzi Nov 11, 2023
3c73f8a
use release version of inspec profile again
schurzi Nov 11, 2023
655cb49
add note to temporary fix
schurzi Nov 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/mysql_hardening.yml
Expand Up @@ -79,6 +79,16 @@ jobs:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
if: ${{ startsWith(matrix.molecule_distro, 'Debian') }}

# Molecule has problems detecting the proper location for installing roles
# https://github.com/ansible/molecule/issues/3806
# we do not set a custom role path, but the automatically determined install path used is not compatible with the location molecule expects the role
# see CI logs of this action "INFO Set ANSIBLE_ROLES_PATH" should not be present, since we do not set a custom path
# we have to find a proper way to configure this
- name: Temporary fix for roles
schurzi marked this conversation as resolved.
Show resolved Hide resolved
run: |
mkdir -p /home/runner/.ansible
ln -s /home/runner/work/ansible-collection-hardening/ansible-collection-hardening/ansible_collections/devsec/hardening/roles /home/runner/.ansible/roles

- name: Test with molecule
run: |
molecule --version
Expand Down
17 changes: 17 additions & 0 deletions molecule/mysql_hardening/prepare_tasks/mysql_users.yml
Expand Up @@ -13,3 +13,20 @@
- "CREATE USER 'user'@'keep' IDENTIFIED BY 'keep';"
- "CREATE USER 'user'@'192.168.%' IDENTIFIED BY 'keep';"
login_unix_socket: "{{ login_unix_socket | default(omit) }}"

- name: Detect role support on MySQL
community.mysql.mysql_query:
query: >
SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'user'
AND COLUMN_NAME = 'is_role';
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
register: mysql_role_support

- name: create roles for test
community.mysql.mysql_query:
query:
- "CREATE ROLE 'role_keep';"
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when:
- mysql_role_support.rowcount[0] > 0
16 changes: 16 additions & 0 deletions molecule/mysql_hardening/verify_tasks/mysql_users.yml
Expand Up @@ -23,3 +23,19 @@
- '"user@192.168.0.2" in mysql_users_list'
- '"user@keep" in mysql_users_list'
- '"user@192.168.%" in mysql_users_list'

- name: Detect role support on MySQL
community.mysql.mysql_query:
query: >
SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'user'
AND COLUMN_NAME = 'is_role';
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
register: mysql_role_support

- name: assert that roles remain
ansible.builtin.assert:
that:
- '"role_keep@" in mysql_users_list'
when:
- mysql_role_support.rowcount[0] > 0
16 changes: 14 additions & 2 deletions roles/mysql_hardening/tasks/mysql_secure_installation.yml
Expand Up @@ -46,6 +46,16 @@
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
when: mysql_remove_remote_root

- name: Detect role support on MySQL version >= 5.7.6 or Mariadb version >= 10.4.0
community.mysql.mysql_query:
query: >
SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'user'
AND COLUMN_NAME = 'is_role';
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
register: mysql_role_support
check_mode: false

- name: Get all users that have no authentication_string on MySQL version >= 5.7.6 or Mariadb version >= 10.4.0
community.mysql.mysql_query:
query: >
Expand All @@ -55,7 +65,8 @@
OR authentication_string="")
AND USER NOT IN ('mysql.sys',
'mysqlxsys',
'mariadb.sys');
'mariadb.sys')
{{ 'AND CONVERT(is_role USING utf8) = "N"' if mysql_role_support.rowcount[0] > 0 }};
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
register: mysql_users_wo_passwords_or_auth_string
check_mode: false
Expand All @@ -75,7 +86,8 @@
OR authentication_string="")
AND USER NOT IN ('mysql.sys',
'mysqlxsys',
'mariadb.sys');
'mariadb.sys')
{{ 'AND is_role = "N"' if mysql_role_support.rowcount[0] > 0 }};
login_unix_socket: "{{ login_unix_socket | default(omit) }}"
register: mysql_users_wo_passwords
check_mode: false
Expand Down