Dineshkumar Yadav created RANGER-5875:
-----------------------------------------

             Summary: OpenSearch access audit search misses accessType values 
that differ in case
                 Key: RANGER-5875
                 URL: https://issues.apache.org/jira/browse/RANGER-5875
             Project: Ranger
          Issue Type: Task
          Components: Ranger
            Reporter: Dineshkumar Yadav
            Assignee: Dineshkumar Yadav


{{GET /service/assets/accessAudit?accessType=...}} returns no rows from 
OpenSearch when the stored access type does not match the lowercased, 
Solr-escaped query. The same filter works against Solr.

Hive and other plugins write the access type as produced by the authorizer, for 
example {{SELECT}} or {{{}METADATA OPERATION{}}}. 
{{OpenSearchAuditDestination}} stores that string on the {{access}} field. The 
OpenSearch mapping defines {{access}} as a {{{}keyword{}}}, so the indexed 
token keeps the original case. Solr defines the same field as 
{{key_lower_case}} (keyword tokenizer plus lowercase filter), and {{SolrUtil}} 
queries it as a Lucene query string, so {{accessType=SELECT}} becomes 
{{access:select}} and matches.

The OpenSearch query path lowercases the parameter, escapes it with Solr's 
{{{}ClientUtils.escapeQueryChars{}}}, and sends a {{{}match_phrase{}}}. 
{{SELECT}} is queried as {{{}select{}}}, which does not match the keyword 
{{{}SELECT{}}}. {{METADATA OPERATION}} is queried as {{{}metadata\ 
operation{}}}. A {{match_phrase}} treats the backslash as part of the text, so 
that value does not match either. The database audit search is also different: 
it uses a partial match on {{{}accessType{}}}.

Fix:
 * Build exact string filters, except the {{text}} field {{{}reason{}}}, as a 
case-insensitive {{term}} query on the original value. Do not Solr-escape that 
value.
 * Add a {{key_lower_case}} normalizer (custom normalizer with the 
{{lowercase}} filter) to the keyword audit fields that Solr types as 
{{{}key_lower_case{}}}. Leave {{id}} as a plain {{{}keyword{}}}, matching 
Solr's case-sensitive {{string}} field.
 * Register that normalizer in index settings when 
{{OpenSearchIndexBootStrapper}} creates the audit index. The schema file is 
loaded as mappings only, so a mapping that names {{key_lower_case}} fails 
unless the setting exists.

The normalizer applies only to an index created after this change. The {{term}} 
query is still required: a normalizer does not stop the old escaped 
{{match_phrase}} from missing values that contain spaces or query characters.

Test plan:
 * Create a new OpenSearch audit index and confirm {{access}} uses the 
{{key_lower_case}} normalizer.
 * Write audits with access types {{SELECT}} and {{{}METADATA OPERATION{}}}.
 * {{{}accessType=SELECT{}}}, {{{}accessType=select{}}}, and 
{{accessType=METADATA OPERATION}} each return the matching rows.
 * A {{reason}} filter still matches.
 * Solr audit search behavior is unchanged.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to