You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ranger.apache.org by "mneethiraj (via GitHub)" <gi...@apache.org> on 2026/03/02 00:42:10 UTC
[PR] RANGER-5505: update RangerEmbeddedAuthorizer to support caller provided audit handler [ranger]
mneethiraj opened a new pull request, #864:
URL: https://github.com/apache/ranger/pull/864
## What changes were proposed in this pull request?
- added RangerEmbeddedAuthorizer.authorize() methods that take caller provided `RangerAuthzAuditHandler` instances to handle generated audit logs
## How was this patch tested?
- verified that all unit tests pass successfully
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RANGER-5505: update RangerEmbeddedAuthorizer to support caller provided audit handler [ranger]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #864:
URL: https://github.com/apache/ranger/pull/864#discussion_r2870081747
##########
authz-embedded/src/main/java/org/apache/ranger/authz/embedded/RangerEmbeddedAuthorizer.java:
##########
@@ -48,17 +48,19 @@ public class RangerEmbeddedAuthorizer extends RangerAuthorizer {
private static final Logger LOG = LoggerFactory.getLogger(RangerEmbeddedAuthorizer.class);
private final RangerAuthzConfig config;
+ private final String appType;
private final Map<String, RangerAuthzPlugin> plugins = new HashMap<>();
public RangerEmbeddedAuthorizer(Properties properties) {
super(properties);
- this.config = new RangerAuthzConfig(properties);
+ this.config = new RangerAuthzConfig(properties);
+ this.appType = config.getAppType();
}
@Override
public void init() throws RangerAuthzException {
- AuditProviderFactory.getInstance().init(config.getAuditProperties(), "ranger-authz");
+ AuditProviderFactory.getInstance().init(config.getAuditProperties(), config.getAppType());
Review Comment:
`init()` now passes `config.getAppType()` directly to `AuditProviderFactory.init()`. If `ranger.authz.app.type` is not set (blank/null), this changes prior behavior (previously always used "ranger-authz") and can result in empty `%app-type%` token expansion in audit destinations and inconsistent audit initialization. Consider defaulting to the previous value (e.g., "ranger-authz") when the property is blank, and use the same effective appType consistently (field vs config lookup).
##########
authz-embedded/src/main/java/org/apache/ranger/authz/embedded/RangerEmbeddedAuthorizer.java:
##########
@@ -93,45 +96,28 @@ public RangerAuthzResult authorize(RangerAuthzRequest request) throws RangerAuth
public RangerMultiAuthzResult authorize(RangerMultiAuthzRequest request) throws RangerAuthzException {
validateRequest(request);
- RangerAuthzPlugin plugin = getOrCreatePlugin(request.getContext().getServiceName(), request.getContext().getServiceType());
- RangerMultiAuthzResult result = new RangerMultiAuthzResult(request.getRequestId());
+ RangerAuthzPlugin plugin = getOrCreatePlugin(request.getContext().getServiceName(), request.getContext().getServiceType());
+ String appType = StringUtils.isNotBlank(this.appType) ? this.appType : plugin.getPlugin().getAppId();
- if (request.getAccesses() != null) {
- int allowedCount = 0;
- int deniedCount = 0;
- int notDeterminedCount = 0;
+ try (RangerAuthzAuditHandler auditHandler = new RangerAuthzAuditHandler(appType)) {
+ return authorize(request, plugin, auditHandler);
+ }
+ }
- result.setAccesses(new ArrayList<>(request.getAccesses().size()));
+ public RangerAuthzResult authorize(RangerAuthzRequest request, RangerAuthzAuditHandler auditHandler) throws RangerAuthzException {
+ validateRequest(request);
- try (RangerAuthzAuditHandler auditHandler = new RangerAuthzAuditHandler(plugin.getPlugin())) {
- for (RangerAccessInfo accessInfo : request.getAccesses()) {
- RangerAuthzRequest authzRequest = new RangerAuthzRequest(null, request.getUser(), accessInfo, request.getContext());
- RangerAuthzResult authzResult = authorize(authzRequest, plugin, auditHandler);
+ RangerAuthzPlugin plugin = getOrCreatePlugin(request.getContext().getServiceName(), request.getContext().getServiceType());
- if (authzResult.getDecision() == AccessDecision.ALLOW) {
- allowedCount++;
- } else if (authzResult.getDecision() == AccessDecision.DENY) {
- deniedCount++;
- } else if (authzResult.getDecision() == AccessDecision.NOT_DETERMINED) {
- notDeterminedCount++;
- }
+ return authorize(request, plugin, auditHandler);
+ }
- result.getAccesses().add(authzResult);
- }
- }
+ public RangerMultiAuthzResult authorize(RangerMultiAuthzRequest request, RangerAuthzAuditHandler auditHandler) throws RangerAuthzException {
+ validateRequest(request);
- if (allowedCount == request.getAccesses().size()) {
- result.setDecision(AccessDecision.ALLOW);
- } else if (deniedCount == request.getAccesses().size()) {
- result.setDecision(AccessDecision.DENY);
- } else if (notDeterminedCount == request.getAccesses().size()) {
- result.setDecision(AccessDecision.NOT_DETERMINED);
- } else {
- result.setDecision(AccessDecision.PARTIAL);
- }
- }
+ RangerAuthzPlugin plugin = getOrCreatePlugin(request.getContext().getServiceName(), request.getContext().getServiceType());
- return result;
+ return authorize(request, plugin, auditHandler);
}
Review Comment:
New overloads `authorize(..., RangerAuthzAuditHandler)` were added, but existing unit tests only exercise the no-arg audit-handler variants. Please add tests that call these new overloads to verify the caller-provided handler is actually used for both single and multi-authorize flows (and that audit events are flushed/observable when the handler is closed by the caller).
##########
authz-embedded/src/main/java/org/apache/ranger/authz/embedded/RangerAuthzConfig.java:
##########
@@ -46,6 +47,10 @@ public String[] getInitServices() {
return initServices.split(",");
}
+ public String getAppType() {
+ return properties.getProperty(PROP_APP_TYPE);
+ }
Review Comment:
`RangerAuthzConfig.getAppType()` is newly introduced but currently has no unit test coverage. Adding a small test case that sets `ranger.authz.app.type` and asserts `getAppType()` returns it would help prevent regressions, especially since this value now impacts audit initialization.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RANGER-5505: update RangerEmbeddedAuthorizer to support caller provided audit handler [ranger]
Posted by "mneethiraj (via GitHub)" <gi...@apache.org>.
mneethiraj commented on code in PR #864:
URL: https://github.com/apache/ranger/pull/864#discussion_r2879671144
##########
authz-embedded/src/main/java/org/apache/ranger/authz/embedded/RangerAuthzAuditHandler.java:
##########
@@ -44,7 +43,7 @@ public void processResult(RangerAccessResult result) {
AuthzAuditEvent auditEvent = getAuthzEvents(result);
if (auditEvent != null) {
- auditEvent.setAgentId(plugin.getAppId());
+ auditEvent.setAgentId(appType);
Review Comment:
This is by-design. The caller is expected to set `appType` to desired value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RANGER-5505: update RangerEmbeddedAuthorizer to support caller provided audit handler [ranger]
Posted by "mneethiraj (via GitHub)" <gi...@apache.org>.
mneethiraj merged PR #864:
URL: https://github.com/apache/ranger/pull/864
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] RANGER-5505: update RangerEmbeddedAuthorizer to support caller provided audit handler [ranger]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #864:
URL: https://github.com/apache/ranger/pull/864#discussion_r2870185249
##########
authz-embedded/src/main/java/org/apache/ranger/authz/embedded/RangerAuthzAuditHandler.java:
##########
@@ -44,7 +43,7 @@ public void processResult(RangerAccessResult result) {
AuthzAuditEvent auditEvent = getAuthzEvents(result);
if (auditEvent != null) {
- auditEvent.setAgentId(plugin.getAppId());
+ auditEvent.setAgentId(appType);
Review Comment:
`processResult()` sets `auditEvent.setAgentId(appType)` unconditionally. If a caller constructs this handler with a blank/whitespace `appType`, audits will end up with an empty `agent` field (and `RangerDefaultAuditHandler` defaults won't overwrite because the value is non-null). Consider normalizing `appType` in the constructor (e.g., trim-to-null) and/or only setting agentId when `appType` is non-blank so defaults can apply.
##########
authz-embedded/src/main/java/org/apache/ranger/authz/embedded/RangerAuthzAuditHandler.java:
##########
@@ -66,4 +65,8 @@ public void processResults(Collection<RangerAccessResult> results) {
public void close() {
auditEvents.forEach(super::logAuthzAudit);
}
+
+ protected Collection<AuthzAuditEvent> getAuditEvents() {
+ return auditEvents;
+ }
Review Comment:
`getAuditEvents()` returns the mutable internal `auditEvents` collection. Since this is the same collection later iterated in `close()`, any subclass/caller that modifies it can accidentally drop or duplicate audit logging. Returning an unmodifiable view or a defensive copy would avoid exposing internal state.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org