Skip to content

RANGER-5736: Fix MariaDB grant failure during Ranger Admin DB setup - #1144

Open
ramackri wants to merge 3 commits into
masterfrom
RANGER-5736-patch
Open

RANGER-5736: Fix MariaDB grant failure during Ranger Admin DB setup#1144
ramackri wants to merge 3 commits into
masterfrom
RANGER-5736-patch

Conversation

@ramackri

@ramackri ramackri commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes Ranger Admin and KMS database setup failure on MariaDB when dba_script.py grants privileges to a host-specific admin user (e.g. 'rangeradmin'@'ranger-db' or 'rangerkms'@'ranger-db.rangernw'). MariaDB returns MySQL error 1133 (Can't find any matching row in the user table) after wildcard/localhost grants when FLUSH PRIVILEGES runs between grants.

Ranger Docker's DB_FLAVOR=MYSQL path uses MariaDB (Dockerfile.ranger-mysql), not Oracle MySQL Server. This change detects MariaDB at runtime via SELECT VERSION() and applies MariaDB-specific grant order, flush timing, and a one-time user recreate/retry on failure. Oracle MySQL and all other DB flavor classes (PostgresConf, OracleConf, SqlServerConf, SqlAnywhereConf) are unchanged.

Jira: https://issues.apache.org/jira/browse/RANGER-5736

Changes

  • Detect MariaDB in MysqlConf using SELECT VERSION() in both security-admin/scripts/dba_script.py and kms/scripts/dba_script.py
  • MariaDB only: grant @db_host before @'%' / @'localhost', run FLUSH PRIVILEGES once at the end, drop/recreate user and retry grant once on failure
  • Non-MariaDB MySQL: preserve original grant order and flush-after-each-grant behavior
  • Add detect_server_type() and user_hosts() helpers; keep grant/flush logic inline in grant_xa_db_user()
  • No changes to init_mysql.sql or other DB flavor setup paths

Manual testing — Ranger Admin

Ran security-admin/scripts/dba_script.py -q (JDK 17) against Docker-backed databases using the corresponding Ranger Admin install properties (db_host=ranger-db where applicable):

DB flavor Server Result Notes
MYSQL (MariaDB path) MariaDB 10.7.3 + init_mysql.sql PASS Host-specific grant first; single FLUSH; recreate/retry if needed
MYSQL (non-MariaDB path) Oracle MySQL 8.0.36 + init_mysql.sql PASS Original grant/flush sequence preserved
POSTGRES PostgreSQL 13.16 PASS No MariaDB logic involved
MSSQL SQL Server 2022 PASS No MariaDB logic involved
ORACLE Oracle Free 23 PASS No MariaDB logic involved
SQLA (SQL Anywhere) Not tested No SQL Anywhere image in ranger-docker

Verified the original failure is reproducible on MariaDB 10.7.3 and 10.11 with the pre-fix grant+flush sequence, and that the patched script completes successfully on MariaDB without modifying init_mysql.sql.

Manual testing — Ranger KMS

Mirrored the same MysqlConf fix in kms/scripts/dba_script.py (KMS Docker hits the same 1133 grant failure). Ran kms/scripts/dba_script.py -q (JDK 17) using KMS Docker install properties (db_host=ranger-db.rangernw, db_user=rangerkms, db_name=rangerkms):

DB flavor Server Result Notes
MYSQL (MariaDB path) MariaDB 10.7.3 PASS Grants 'rangerkms'@'ranger-db.rangernw' first; single FLUSH at end
MYSQL (non-MariaDB path) Oracle MySQL 8.0.36 PASS Non-MariaDB path; per-grant FLUSH preserved
POSTGRES PostgreSQL 13.16 PASS No MariaDB logic involved
MSSQL SQL Server 2022 PASS Requires rangerkms DB + login/user (same as Docker init_mssql.sh)
ORACLE Oracle Free 23.6 PASS No MariaDB logic involved
SQLA (SQL Anywhere) Not tested No SQL Anywhere image in ranger-docker

ramk and others added 2 commits August 11, 2026 12:13
MariaDB returns error 1133 when dba_script.py grants privileges to a
host-specific user after wildcard grants with FLUSH PRIVILEGES. Detect
MariaDB at runtime and adjust grant order, flush timing, and retry logic
without changing behavior for Oracle MySQL or other DB flavors.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep grant/flush logic inline in grant_xa_db_user; retain only
detect_server_type() and user_hosts() as small MariaDB-specific helpers.

Co-authored-by: Cursor <cursoragent@cursor.com>
Apply the same MysqlConf MariaDB detection, host order, flush timing,
and grant retry logic to kms/scripts/dba_script.py for KMS Docker installs.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant