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

mysql_hardening cannot work with mysql on freebsd #472

Closed
sdwilsh opened this issue Aug 13, 2021 · 4 comments · Fixed by #473
Closed

mysql_hardening cannot work with mysql on freebsd #472

sdwilsh opened this issue Aug 13, 2021 · 4 comments · Fixed by #473
Labels

Comments

@sdwilsh
Copy link
Contributor

sdwilsh commented Aug 13, 2021

Describe the bug
Due to this line of code, on FreeBSD it is always assumed that the distribution is mariadb because the package name is mysql80-server, not mysql-server.

Expected behavior
Either the system detects the right package or it is allowed to be user-overridden.

Actual behavior

TASK [devsec.hardening.mysql_hardening : get all users that have no authentication_string on MySQL version >= 5.7.6 or Mariadb version >= 10.4.0] ***************************************************************
skipping: [mysql.hogs.tswn.us]

TASK [devsec.hardening.mysql_hardening : get all users that have no password or authentication_string on MySQL version < 5.7.6 or Mariadb version < 10.4.0] *****************************************************
fatal: [mysql.hogs.tswn.us]: FAILED! => {"changed": false, "msg": "Cannot execute SQL 'SELECT GROUP_CONCAT(QUOTE(USER), '@', QUOTE(HOST) SEPARATOR ', ') AS users FROM mysql.user WHERE (length(password)=0 OR password=\"\") AND (length(authentication_string)=0 OR authentication_string=\"\") AND USER NOT IN ('mysql.sys', 'mysqlxsys', 'mariadb.sys');' args [None]: (1054, \"Unknown column 'password' in 'where clause'\")"}

Notably, if I ask mysql what version it is running, it properly reports version 8.0.25

Example Playbook

n/a - this is pretty obvious what is going on

OS / Environment

FreeBSD 12.2

Ansible Version

ansible 2.10.12
  config file = /home/sdwilsh/ansible-playbooks/ansible.cfg
  configured module search path = ['/home/sdwilsh/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Jun  2 2021, 10:49:15) [GCC 9.4.0]

Role Version

7.9.0

Additional context

Everything else about this playbook works, although I do have to set a number of variables in order to get this far.

sdwilsh added a commit to sdwilsh/ansible-playbooks that referenced this issue Aug 13, 2021
@sdwilsh
Copy link
Contributor Author

sdwilsh commented Aug 13, 2021

Everything else about this playbook works, although I do have to set a number of variables in order to get this far.

Just to elaborate on this, since this failing piece of code is pretty early, I know other stuff works because I was running with --check --diff and seeing what the changes would be before I actually ran it and got this error.

@rndmh3ro rndmh3ro added the bug label Aug 13, 2021
@rndmh3ro
Copy link
Member

Making the variable user-overridable seems like the best idea. Something like this:

- name: Check if MySQL or MariaDB is used
  set_fact:
    mysql_distribution: "{{ ansible_facts.packages['mysql-server'] is defined | ternary('mysql', 'mariadb') }}"
  when: not mysql_distribution

Do you weant to create a PR for this?

@sdwilsh
Copy link
Contributor Author

sdwilsh commented Aug 13, 2021

I can do that, but I wanted to make sure this was something y'all would take. I can also do a second PR for getting some of the platform variables for FreeBSD defined, if you'd like.

@rndmh3ro
Copy link
Member

I'd like both PRs! :)

sdwilsh added a commit to sdwilsh/ansible-collection-hardening that referenced this issue Aug 13, 2021
On some operating systems, the package for MySQL is not `mysql-server`,
and so the default check for this will not yield the correct result.
This change adds an escape hatch by letting the user set
`mysql_distribution`.  Additionally, it verifies that it is set to a
legal value if the user has set it.

Closes dev-sec#472
sdwilsh added a commit to sdwilsh/ansible-collection-hardening that referenced this issue Aug 13, 2021
On some operating systems, the package for MySQL is not `mysql-server`,
and so the default check for this will not yield the correct result.
This change adds an escape hatch by letting the user set
`mysql_distribution`.  Additionally, it verifies that it is set to a
legal value if the user has set it.

Closes dev-sec#472

Signed-off-by: Shawn Wilsher <656602+sdwilsh@users.noreply.github.com>
rndmh3ro added a commit that referenced this issue Aug 15, 2021
* [mysql_hardening] Allow setting the mysql_distribution

On some operating systems, the package for MySQL is not `mysql-server`,
and so the default check for this will not yield the correct result.
This change adds an escape hatch by letting the user set
`mysql_distribution`.  Additionally, it verifies that it is set to a
legal value if the user has set it.

Closes #472

Signed-off-by: Shawn Wilsher <656602+sdwilsh@users.noreply.github.com>

* Update roles/mysql_hardening/tasks/main.yml

Co-authored-by: Sebastian Gumprich <rndmh3ro@users.noreply.github.com>
divialth pushed a commit to divialth/ansible-collection-hardening that referenced this issue Aug 3, 2022
* [mysql_hardening] Allow setting the mysql_distribution

On some operating systems, the package for MySQL is not `mysql-server`,
and so the default check for this will not yield the correct result.
This change adds an escape hatch by letting the user set
`mysql_distribution`.  Additionally, it verifies that it is set to a
legal value if the user has set it.

Closes dev-sec#472

Signed-off-by: Shawn Wilsher <656602+sdwilsh@users.noreply.github.com>

* Update roles/mysql_hardening/tasks/main.yml

Co-authored-by: Sebastian Gumprich <rndmh3ro@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants