Commit graph

47 commits

Author SHA1 Message Date
Laurent Indermuehle
7f6d5f5622
cut option maria_role as it as nothing to do with roles
This was introduced in #189. To my knowledge, there is no difference
between MySQL and MariaDB regarding roles or when you call a user by
its name alone. Both works if the host it '%'. Same for roles.
2023-10-11 16:51:51 +02:00
Laurent Indermuehle
34505c9b4f
add option to not summarize all privileges
We summarize ALL for mysql_info, but mysql_user needs to compare
actual privileges with the ones provided by ansible.
2023-10-11 16:51:51 +02:00
Laurent Indermuehle
7036490e7e
spelling 2023-10-11 16:51:51 +02:00
Laurent Indermuehle
970897cc46
Revert non relevant changes to have cleaner patch 2023-10-11 16:51:50 +02:00
Laurent Indermuehle
dbfc252ca5
add real name for MySQL 8 privileges 2023-10-11 16:51:50 +02:00
Laurent Indermuehle
5477603583
Revert "sync fork with upstream main"
This reverts commit 77593b7a91e8d417eead0d3d5366ba991c767565.
I imported PR569 to be able to test on my fork, but to avoid polluting
this patch I now revert those commit.
2023-10-11 16:51:50 +02:00
Laurent Indermuehle
d38caa264f
change struct to be able to call a specific sub-list 2023-10-11 16:51:50 +02:00
Laurent Indermuehle
f79ee2b83c
Update variable name for consistency 2023-10-11 16:51:49 +02:00
Laurent Indermuehle
56582f52a2
sanity 2023-10-11 16:51:49 +02:00
Laurent Indermuehle
0bcfdb72ab
fix users with multiple schemas with ALL PRIVILEGES only showing first 2023-10-11 16:51:49 +02:00
Laurent Indermuehle
eee4225ec4
Add shortening of ALL PRIVILEGES for MySQL 8 that return a big list 2023-10-11 16:51:49 +02:00
Laurent Indermuehle
77c7beb514
fix case when fetch return a tuple instead of a dict 2023-10-11 16:51:47 +02:00
Laurent Indermuehle
08b7842001
cut newlines added by accident 2023-10-11 16:51:47 +02:00
Laurent Indermuehle
093fe79e17
add missing option (forgotten in previous commit) 2023-10-11 16:51:45 +02:00
Laurent Indermuehle
6123d77b99
fix malformed SQL query 2023-10-11 16:51:45 +02:00
Laurent Indermuehle
bd944f7bf9
add host in case multiple accounts uses the same username 2023-10-11 16:51:45 +02:00
Laurent Indermuehle
fa6eded000
fix KeyError 0 2023-10-11 16:51:45 +02:00
Laurent Indermuehle
9f34b926bf
fix returned value since get_resource_limit is used by other methods 2023-10-11 16:51:45 +02:00
Laurent Indermuehle
248b30cad6
fix get_resource_limit to work with MariaDB and MySQL
I was getting KeyError 0
2023-10-11 16:51:44 +02:00
Laurent Indermuehle
089e1c3fb1
add a get_server_type module_utils method to detect MySQL vs MariaDB 2023-10-11 16:51:44 +02:00
Laurent Indermuehle
2054241920
Fix KeyError 0 2023-10-11 16:51:43 +02:00
Laurent Indermuehle
123b73aa3f
attempt to fix KeyError 0 in privileges_get 2023-10-11 16:51:43 +02:00
Laurent Indermuehle
028089da6d
attempt to use privileges_get 2023-10-11 16:51:43 +02:00
Laurent Indermuehle
7f2f141275
revert changes to get_grants() 2023-10-11 16:51:43 +02:00
Laurent Indermuehle
31a5eb8739
Debug error "0"
This debug output this:

[
  {'Grants for root@localhost': \"GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION\"},
  {'Grants for root@localhost': \"GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION\"}
],
[
  {'Grants for mysql.session@localhost': \"GRANT SUPER ON *.* TO 'mysql.session'@'localhost'\"},
  {'Grants for mysql.session@localhost': \"GRANT SELECT ON `performance_schema`.* TO 'mysql.session'@'localhost'\"},
  {'Grants for mysql.session@localhost': \"GRANT SELECT ON `mysql`.`user` TO 'mysql.session'@'localhost'\"}
 ],
 [
   {'Grants for mysql.sys@localhost': \"GRANT USAGE ON *.* TO 'mysql.sys'@'localhost'\"},
   {'Grants for mysql.sys@localhost': \"GRANT TRIGGER ON `sys`.* TO 'mysql.sys'@'localhost'\"},
   {'Grants for mysql.sys@localhost': \"GRANT SELECT ON `sys`.`sys_config` TO 'mysql.sys'@'localhost'\"}
 ],
 [
   {'Grants for root@%': \"GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION\"}
 ]

 I think something is wrong in the lambda and when grants art on ''@''.
2023-10-11 16:51:43 +02:00
Laurent Indermuehle
d7beeec410
WIP attempt to retrieve all users privileges 2023-10-11 16:51:42 +02:00
kmarse
033b4c74f9
Fix column uppercasing (#569)
* Add integrations tests for column case sensitive name

* add a warning when column_case_sensitive in not set

* add announce default will change in in 4.0.0

* fix tests for engine that don't wrap column in backticks

* add filter because only MySQL 5.7 is case sensitive for users privs

* add kmarse and myself to the authors

* add kmarse to the contributors list

---------

Co-authored-by: Laurent Indermühle <laurent.indermuehle@epfl.ch>
Co-authored-by: Andrew Klychkov <aklychko@redhat.com>
2023-10-06 16:08:46 +02:00
Maximilian Stinsky
526e674e6f
Add MAX_STATEMENT_TIME resource limit (#523)
* Add MAX_STATEMENT_TIME to resource_limits

* Move version check for resource_limits to implementations
2023-04-07 10:20:49 +02:00
Markus Bergholz
b34c23d07d
Fix revoke only grant (#503)
* fix

* test

* changelog
2023-02-08 09:24:35 +01:00
hubiongithub
8a579b42e3
add service name to plugin pam/auth_pam usage (#445)
* add service name to plugin pam/auth_pam usage

* typo fixed

* MySLQ is using identified with auth_pam by ...  instead of identified with pam using ... like mariadb does

* a : in description lines breaks yaml syntax

* clearify documentation and add changelog fragment

* Update changelogs/fragments/445_add_service_name_to_plugin_pam_auth_pam_usage.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/module_utils/user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
2023-01-03 09:47:11 +01:00
Diego Gullo
6ac89ca1f6
Display a more informative error when InvalidPrivsError is raised (#465) (#466)
* Display a more informative error when InvalidPrivsError is raised (Issue #465)

Co-authored-by: Laurent Indermühle <laurent.indermuehle@pm.me>
2022-12-06 13:12:01 +01:00
R.Sicart
2d75bc19b8
Fix privilege changing everytime (#438)
* Compare privileges from before and after manipulation

* Add unit tests

* Fix FIXME integration tests related to this issue

* Fix sanity check

* Fix assertion when appending privs in mysql_role_initial integration tests

* Fix pylint

* [ci-skip] Add changelog fragment

* Fix: missing fragment file extension

* Replace privileges_equal() by a comparison

* Fix: sanity pylint

* Fix: forgot to remove privileges_equal import from unit tests
2022-09-08 18:26:58 +02:00
R.Sicart
cc5cf98368
Fix: grant revoked priv (#434)
* Fix: exclude mysql 8 from test_mysql_user's 'Assert that priv did not change' test

* Add tests to verify that GRANT permission is present after user modification

* Fix: do not revoke GRANT permission when it's already allowed and present in priv parameter

* Deduplicate tests name

Easier to debug this way

* Fix assertions named 'GRANT permission is present'

* Only revoke grant option if it exists and absence is requested

* Fix assertion comments

* Fix: Only revoke grant option if it exists and absence is requested

* Avoid pointless revocations when ALL are granted

* Assert that priv did not change on mariadb also

* Fix: sanity and unity tests

* Format long lines

* Add changelog fragment

Co-authored-by: Laurent Indermühle <laurent.indermuehle@pm.me>
2022-09-02 13:40:06 +02:00
Andrew Klychkov
2a3f8f6506
Update licensing information (#390) 2022-06-03 11:47:03 +02:00
betanummeric
ed3935abec
mysql_user: add "update_password: on_new_username" argument, "password_changed" result field (#365)
* mysql_user: add value 'on_new_username' to argument 'update_password'

* mysql_user: return "password_changed" boolean (true if the user got a new password)

* mysql_user: optimize queries for existing passwords

* mysql_user: add integration tests for update_password argument

* mysql_user: add description for "update_password: on_new_username" argument

* add changelog fragment

* formatting (PEP8)

* Update changelogs/fragments/365-mysql_user-add-on_new_username-and-password_changed.yml

Co-authored-by: Benjamin MALYNOVYTCH <bmalynovytch@users.noreply.github.com>

* Update changelogs/fragments/365-mysql_user-add-on_new_username-and-password_changed.yml

Co-authored-by: Benjamin MALYNOVYTCH <bmalynovytch@users.noreply.github.com>

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update changelogs/fragments/365-mysql_user-add-on_new_username-and-password_changed.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update changelogs/fragments/365-mysql_user-add-on_new_username-and-password_changed.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Felix Hamme <felix.hamme@ionos.com>
Co-authored-by: Benjamin MALYNOVYTCH <bmalynovytch@users.noreply.github.com>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
2022-05-31 16:00:24 +02:00
Andrew Klychkov
8d114c7e39
mysql_user: fix parsing privs when a user has roles assigned to it (#341)
* mysql_user: fix parsing errors when a user has roles assigned

* Add a changelog fragment

* Fix a typo

* Fix CI
2022-05-12 09:36:21 +02:00
betanummeric
ba4fea67b1
mysql_user, mysql_role: add argument subtract_privs to revoke privileges explicitly (#333)
* add option subtract_privs to mysql_role and mysql_user

see https://github.com/ansible-collections/community.mysql/issues/331

* add integration tests for subtract_privs for mysql_role and mysql_user

* add changelog fragment for PR #333

* mysql_role, mysql_user: when subtract_privileges, don't grant unwanted privileges and don't revoke USAGE implicitly

* fix integration tests

* mysql_role, mysql_user: invalid privileges are ignored when subtract_privs is true -> document that and fix integration tests

* fix mysql_role integration tests

* fix mysql_role, mysql_user integration tests

* formatting

make the PEP8 check happy

* mysql_user and mysql_role: fix granting privileges when only the GRANT OPTION needs to be added

* mysql_user and mysql_role: log some updated privileges; explain integration test blind spot

* mysql_user and mysql_role: don't grant too much privileges

If only the grant option needs to be granted, at least one privilege needs to be granted to get valid syntax. USAGE is better for that than the existing privileges, because unwanted privileges would be re-added after revokation.

* mysql_user and mysql_role: fix type error

* Update changelogs/fragments/333-mysql_user-mysql_role-add-subtract_privileges-argument.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/mysql_role.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Felix Hamme <felix.hamme@ionos.com>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
2022-05-09 09:50:49 +02:00
bigo8525
1dcc5ec086
mysql_user: added flush privileges to write dynamic privs into db (#338)
* added flush privileges to write dynamic privs into db
Fixes https://github.com/ansible-collections/community.mysql/issues/120

* added changelog fragment

* Update changelogs/fragments/338-mysql_user_fix_missing_dynamic_privileges.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
2022-04-29 12:38:12 +02:00
Andrew Klychkov
3a452faeb0
Add IF EXISTS clause to DROP USER statement (#307)
* Add IF EXISTS clause to DROP USER statement

* Add a changelog fragment

* Fix exception
2022-03-15 13:41:55 +01:00
Andrew Klychkov
f00f06df76
Fix the collection to work with mysqlclient connector (#293)
* Integration tests: restrict exclusion mysqlclient + MariaDB only when testing the mysql_role module

* Fix

* Fix underlying issue

* Fix units

* Add changelog fragment
2022-03-14 10:03:47 +01:00
Jorge Rodriguez (A.K.A. Tiriel)
dd4700989f
Remove support for REQUIRESSL privilege (#244)
* Remove support for REQUIRESSL privilege

* Fix error search string
2021-12-01 07:56:04 +01:00
R.Sicart
727b638d13
Get rid of privs comparison (#243)
* Remove all code related to VALID_PRIVS and get_valid_privs()

* Add tests to update user with invalid privs

* Re-raise InvalidPrivsError when granting privileges

* Fix: compatibility with python2

* More explicit assertions as commented by Andersson007

* Add changelog fragment
2021-11-20 09:28:40 +01:00
Andrew Klychkov
bb3e9fd3fa
mysql_user: fix broken compatibility for priviledge aliases (#233)
* mysql_user: fix broken compatibility for priviledge aliases

* add changelog fragment

* fix changelog fragment

* Improve formatting
2021-10-18 15:25:00 +02:00
R.Sicart
0ce1fa1634
mysql_user: replace VALID_PRIVS by get_valid_privs() function (#217)
* mysql_user: replace VALID_PRIVS by get_valid_privs() function

* Add EXTRA_PRIVS in case we need to add more privs in the future

* Add changelog fragment
2021-09-23 11:53:37 +02:00
int32bit
663590689f
Fix wrong impl for mysql (#210)
If 'mariadb' in version info, the db instance should be mariadb(reverse in code) rather than mysql.
2021-08-25 09:21:24 +02:00
Andrew Klychkov
8a17e43eae
Fix sanity errors (#206) 2021-08-19 16:20:28 +02:00
Andrew Klychkov
ce2b269f84
mysql_role: new module (#189)
* mysql_role: new module

* fixes

* fixes

* Add the role class

* Check if role exists

* role.add()

* role.__get_members

* tmp

* tmp

* Change tests

* Fix

* Fix

* add_members()

* get_privs()

* tmp

* __extract_grants() filler version

* Before big work

* tmp

* drop()

* tmp

* tmp

* Big changes

* Fix

* append_members, detach_members, append_privs

* tmp

* admin option

* Add tests

* Add tests

* Fix tests

* Remove debug warning

* Fix tests

* Add documentation

* Fix MariaDB case

* Fix MariaDB

* Fix MariaDB

* Fix MariaDB

* Fix MariaDB

* Fix MariaDB

* Fix

* Fix

* Remove debug warning

* Add try-except block

* tmp

* tmp

* tmp

* Fix

* Add err handling

* Add user check

* Check admin in db

* Fix CI

* Fix CI

* Fix CI

* Fix CI

* Fix

* Add mutually exclusive options

* Small refactoring, documenting

* Documenting, refactoring

* Change docs

* Refactoring

* Refactoring

* Refactoring

* Add unit tests

* Update README.md
2021-08-10 13:30:34 +02:00