Skip to content

Commit 0d1c171

Browse files
fix(security): Fix Ranger plugin deserialisation to ignore unknown fields (#26315)
## Description Fix Ranger plugin deserialisation to ignore unknown fields. The Hive Ranger plugin was failing to fetch policies from Ranger servers with versions newer than 2.1.0. The failure was due to Jackson throwing - > UnrecognizedPropertyException for fields like category > in RangerServiceDef$RangerAccessTypeDef. This change configures the ObjectMapper to ignore unknown properties during deserialization, allowing the plugin to work with newer Ranger servers without failing. ## Motivation and Context Support current client features even with upgraded Ranger instance version > 2.1.0 ## Impact <!---Describe any public API or user-facing feature change or any performance impact--> ## Test Plan Modified the test policy file to include an extra field, which would cause deserialization to fail. Updated ObjectMapper to ignore unknown properties to prevent exceptions. ## Contributor checklist - [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards). - [ ] PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced. - [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality. - [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines). - [ ] Adequate tests were added if applicable. - [ ] CI passed. ## Release Notes Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below. ``` == NO RELEASE NOTE == ```
1 parent 415fbb3 commit 0d1c171

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

presto-hive/src/main/java/com/facebook/presto/hive/security/ranger/RangerBasedAccessControl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import static com.facebook.presto.spi.security.AccessDeniedException.denySelectColumns;
6767
import static com.facebook.presto.spi.security.AccessDeniedException.denyShowColumnsMetadata;
6868
import static com.facebook.presto.spi.security.AccessDeniedException.denyShowCreateTable;
69+
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
6970
import static com.google.common.base.Suppliers.memoizeWithExpiration;
7071
import static com.google.common.collect.ImmutableSet.toImmutableSet;
7172
import static java.lang.String.format;
@@ -80,7 +81,8 @@
8081
public class RangerBasedAccessControl
8182
implements ConnectorAccessControl
8283
{
83-
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
84+
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
85+
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
8486
private static final JsonCodec<Users> USER_INFO_CODEC = jsonCodec(Users.class);
8587
private static final JsonCodec<List<String>> ROLES_INFO_CODEC = listJsonCodec(String.class);
8688

@@ -133,7 +135,7 @@ private ServicePolicies getHiveServicePolicies(RangerBasedAccessControlConfig co
133135
return OBJECT_MAPPER.readValue(httpClient.execute(request, createStringResponseHandler()).getBody(), ServicePolicies.class);
134136
}
135137
catch (IOException e) {
136-
throw new PrestoException(HIVE_RANGER_SERVER_ERROR, format("Unable to fetch policies from %s hive service end point", config.getRangerHiveServiceName()));
138+
throw new PrestoException(HIVE_RANGER_SERVER_ERROR, format("Unable to fetch policies from %s hive service end point", config.getRangerHiveServiceName()), e);
137139
}
138140
}
139141

presto-hive/src/test/resources/com.facebook.presto.hive.security.ranger/default-allow-all.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
"impliedGrants": [],
9595
"itemId": 1,
9696
"label": "select",
97-
"name": "select"
97+
"name": "select",
98+
"category": "data"
9899
},
99100
{
100101
"impliedGrants": [],

0 commit comments

Comments
 (0)