Users reported an IllegalStateException about column masking. I can reproduce it in the master branch:
It happens when there are several column masking policies on a table and not all of them are applied on the current user, i.e. some masking policies exist and apply on other users. Then if the current user query the table, the error occurs.
Start Impala cluster with Ranger authz enabled
Create a tmp table using your username.
Open the Ranger WebUI at http://localhost:6080/. Add two column masking policies:
- Masking default.tmp_tbl.id using HASH for user "non_owner"
- Masking default.tmp_tbl.name using REDACT for your username (quanlong in my case)
Refresh the policies in impala and query the table using your username.
The last query will fail with "ERROR: IllegalStateException: null".
The policy file is attached.
In RangerAuthorizationContext.stashAuditEvents(), we deduplicate the column masking audit events. There is a Precondition check that all events generated are column masking events:
However, it's possible that some SELECT events are generated during the analyzing phase at here:
Looks like if there is a column masking policy on a column and the policy doesn't target to the current user, Ranger plugin will generate a SELECT audit event. In this case, the first masking policy is on "id" column for user "non_owner". Then we get a SELECT event on this column. The second masking policy is on "name" column for the current user. We get a mask event as we expected.
We should deal with these non mask events correctly. On the other hand, we should replace all Precondition checks on the audit code paths with error loggings, since these should not fail a query.