Skip to content

Commit 3305af5

Browse files
author
Ramesh Mani
committed
RANGER-5520:Audit Server refactoring to segregate audit ingestion and dispatching functionality - Fix merge conflict
2 parents 1d941e0 + 21520b7 commit 3305af5

282 files changed

Lines changed: 13548 additions & 5178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ env:
3333
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3
3434

3535
jobs:
36-
build-8:
36+
build-17:
3737
runs-on: ubuntu-22.04
3838
timeout-minutes: 60
3939
steps:
@@ -47,12 +47,12 @@ jobs:
4747
key: maven-repo-${{ hashFiles('**/pom.xml') }}
4848
restore-keys: |
4949
maven-repo-
50-
- name: Set up JDK 8
50+
- name: Set up JDK 17
5151
uses: actions/setup-java@v5
5252
with:
53-
java-version: '8'
53+
java-version: '17'
5454
distribution: 'temurin'
55-
- name: build (8)
55+
- name: build (17)
5656
run: mvn -T 8 clean verify --no-transfer-progress -B -V
5757

5858
- name: run code coverage
@@ -69,49 +69,20 @@ jobs:
6969
- name: Upload artifacts
7070
uses: actions/upload-artifact@v7
7171
with:
72-
name: target-8
73-
path: target/*
74-
75-
build-11:
76-
needs:
77-
- build-8
78-
runs-on: ubuntu-22.04
79-
timeout-minutes: 60
80-
steps:
81-
- uses: actions/checkout@v6
82-
- name: Cache for maven dependencies
83-
uses: actions/cache/restore@v5
84-
with:
85-
path: |
86-
~/.m2/repository/*/*/*
87-
!~/.m2/repository/org/apache/ranger
88-
key: maven-repo-${{ hashFiles('**/pom.xml') }}
89-
restore-keys: |
90-
maven-repo-
91-
- name: Set up JDK 11
92-
uses: actions/setup-java@v5
93-
with:
94-
java-version: '11'
95-
distribution: 'temurin'
96-
- name: build (11)
97-
run: mvn -T 8 clean verify -pl '!knox-agent' --no-transfer-progress -B -V
98-
- name: Upload artifacts
99-
uses: actions/upload-artifact@v7
100-
with:
101-
name: target-11
72+
name: target-17
10273
path: target/*
10374

10475
services-docker-build:
10576
needs:
106-
- build-8
77+
- build-17
10778
runs-on: ubuntu-24.04 # bumping os version for more disk space
10879
timeout-minutes: 60 # bumping timeout to allow containers to come up
10980
steps:
11081
- uses: actions/checkout@v6
111-
- name: Download build-8 artifacts
82+
- name: Download build-17 artifacts
11283
uses: actions/download-artifact@v8
11384
with:
114-
name: target-8
85+
name: target-17
11586

11687
- name: Copy artifacts for docker build
11788
run: |
@@ -177,15 +148,15 @@ jobs:
177148
178149
plugins-docker-build:
179150
needs:
180-
- build-8
151+
- build-17
181152
runs-on: ubuntu-24.04 # bumping os version for more disk space
182153
timeout-minutes: 60 # bumping timeout to allow containers to come up
183154
steps:
184155
- uses: actions/checkout@v6
185-
- name: Download build-8 artifacts
156+
- name: Download build-17 artifacts
186157
uses: actions/download-artifact@v8
187158
with:
188-
name: target-8
159+
name: target-17
189160

190161
- name: Copy artifacts for docker build
191162
run: |

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ name: docs
1818

1919
on:
2020
push:
21-
branches: [ ranger_5353, master ]
21+
branches: [ dev, master ]
2222

2323
permissions:
2424
contents: write

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Ranger is built using [Apache Maven](https://maven.apache.org/). To run Ranger:
5454

5555
## Regular Build Process
5656

57-
1. Check out the code from GIT repository
57+
1. Check out the code from GIT repository and make sure JAVA_HOME & PATH environment variables are properly set (JDK17).
5858

5959
2. On the root folder, please execute the following Maven command:
6060

@@ -120,6 +120,10 @@ Ranger is built using [Apache Maven](https://maven.apache.org/). To run Ranger:
120120

121121
4. Modify the install.properties file with appropriate variables
122122

123-
5. - If the module has setup.sh, execute ./setup.sh
123+
5. - export/ set JAVA_OPTS environment variable.
124+
```
125+
JAVA_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED --add-exports=java.base/sun.net.dns=ALL-UNNAMED --add-exports=java.base/sun.net.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-exports=java.xml.crypto/com.sun.org.apache.xml.internal.security.utils=ALL-UNNAMED"
126+
```
127+
- If the module has setup.sh, execute ./setup.sh
124128
- If the install.sh file does not exists, execute ./enable-<component>-plugin.sh
125129

agents-audit/core/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,5 @@
106106
<artifactId>mockito-core</artifactId>
107107
<scope>test</scope>
108108
</dependency>
109-
<dependency>
110-
<groupId>org.testng</groupId>
111-
<artifactId>testng</artifactId>
112-
<scope>test</scope>
113-
</dependency>
114109
</dependencies>
115110
</project>

agents-audit/core/src/test/java/org/apache/ranger/audit/utils/RangerJSONAuditWriterTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ public void verifyFileRolloverWithAppend() throws Exception {
101101

102102
reset(jsonAuditWriter);
103103

104-
assertTrue(jsonAuditWriter.logJSON(Collections.singleton("Last log file will be opened in append mode and this event will be written")));
105-
assertTrue(jsonAuditWriter.logJSON(Collections.singleton("This event will also be written in append mode")));
106-
Path auditPath1 = jsonAuditWriter.auditPath;
104+
final Path auditPath1;
105+
synchronized (jsonAuditWriter) {
106+
assertTrue(jsonAuditWriter.logJSON(Collections.singleton("Last log file will be opened in append mode and this event will be written")));
107+
assertTrue(jsonAuditWriter.logJSON(Collections.singleton("This event will also be written in append mode")));
108+
auditPath1 = jsonAuditWriter.auditPath;
109+
}
110+
assertNotNull(auditPath1);
107111

108112
Thread.sleep(6000);
109113

@@ -118,6 +122,7 @@ public void verifyFileRolloverWithAppend() throws Exception {
118122

119123
// ensure the same rolled over file is not used for append
120124
assertNotEquals(auditPath1, jsonAuditWriter.auditPath);
125+
assertNotNull(jsonAuditWriter.auditPath, "second write should create a new audit file path");
121126

122127
// cleanup
123128
jsonAuditWriter.fileSystem.deleteOnExit(auditPath1);
@@ -165,14 +170,19 @@ public void verifyFileRolloverAfterThreshold() throws Exception {
165170
jsonAuditWriter.fileRolloverSec = 5; // in seconds
166171
jsonAuditWriter.init(props, "test", "localfs", auditConfigs);
167172

168-
assertTrue(jsonAuditWriter.logJSON(Collections.singleton("First file created and added this line!")));
169-
Path auditPath1 = jsonAuditWriter.auditPath;
173+
final Path auditPath1;
174+
synchronized (jsonAuditWriter) {
175+
assertTrue(jsonAuditWriter.logJSON(Collections.singleton("First file created and added this line!")));
176+
auditPath1 = jsonAuditWriter.auditPath;
177+
}
178+
assertNotNull(auditPath1);
170179

171180
Thread.sleep(6000);
172181

173182
assertNull(jsonAuditWriter.ostream);
174183
assertNull(jsonAuditWriter.logWriter);
175184
assertTrue(jsonAuditWriter.logJSON(Collections.singleton("Second file created since rollover happened!")));
185+
assertNotNull(jsonAuditWriter.auditPath, "second write should create a new audit file path");
176186

177187
// cleanup
178188
jsonAuditWriter.fileSystem.deleteOnExit(auditPath1);

agents-audit/dest-auditserver/pom.xml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
<artifactId>jackson-jaxrs-json-provider</artifactId>
3838
<version>${fasterxml.jackson.version}</version>
3939
</dependency>
40+
<dependency>
41+
<groupId>javax.ws.rs</groupId>
42+
<artifactId>javax.ws.rs-api</artifactId>
43+
<version>${javax.ws.rs-api.version}</version>
44+
</dependency>
4045
<dependency>
4146
<groupId>org.apache.ranger</groupId>
4247
<artifactId>ranger-audit-core</artifactId>
@@ -47,6 +52,21 @@
4752
<artifactId>ranger-plugins-common</artifactId>
4853
<version>${project.version}</version>
4954
</dependency>
55+
<dependency>
56+
<groupId>org.glassfish.jersey.core</groupId>
57+
<artifactId>jersey-client</artifactId>
58+
<version>${jersey-client.version}</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.glassfish.jersey.inject</groupId>
62+
<artifactId>jersey-hk2</artifactId>
63+
<version>${jersey-client.version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.glassfish.jersey.media</groupId>
67+
<artifactId>jersey-media-json-jackson</artifactId>
68+
<version>${jersey-client.version}</version>
69+
</dependency>
5070
<dependency>
5171
<groupId>org.slf4j</groupId>
5272
<artifactId>slf4j-api</artifactId>
@@ -60,10 +80,5 @@
6080
<version>${slf4j.version}</version>
6181
<scope>test</scope>
6282
</dependency>
63-
<dependency>
64-
<groupId>org.testng</groupId>
65-
<artifactId>testng</artifactId>
66-
<scope>test</scope>
67-
</dependency>
6883
</dependencies>
6984
</project>

agents-audit/dest-auditserver/src/main/java/org/apache/ranger/audit/destination/RangerAuditServerDestination.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@
1919

2020
package org.apache.ranger.audit.destination;
2121

22-
import com.sun.jersey.api.client.ClientResponse;
23-
import com.sun.jersey.api.client.WebResource;
2422
import org.apache.commons.lang3.StringUtils;
2523
import org.apache.hadoop.conf.Configuration;
2624
import org.apache.hadoop.security.UserGroupInformation;
2725
import org.apache.http.HttpStatus;
2826
import org.apache.ranger.audit.model.AuditEventBase;
2927
import org.apache.ranger.audit.model.AuthzAuditEvent;
3028
import org.apache.ranger.audit.provider.MiscUtil;
29+
import org.apache.ranger.plugin.authn.DefaultJwtProvider;
3130
import org.apache.ranger.plugin.util.RangerRESTClient;
3231
import org.slf4j.Logger;
3332
import org.slf4j.LoggerFactory;
3433

34+
import javax.ws.rs.client.Entity;
35+
import javax.ws.rs.client.WebTarget;
36+
import javax.ws.rs.core.MediaType;
37+
import javax.ws.rs.core.Response;
38+
3539
import java.security.PrivilegedExceptionAction;
3640
import java.util.Collection;
3741
import java.util.HashMap;
@@ -85,6 +89,10 @@ public void init(Properties props, String propPrefix) {
8589

8690
this.restClient = new RangerRESTClient(url, sslConfigFileName, config);
8791

92+
if (AUTH_TYPE_JWT.equalsIgnoreCase(authType)) {
93+
this.restClient.setJwtProvider(new DefaultJwtProvider("ranger.plugin.policy.rest.client", config));
94+
}
95+
8896
this.restClient.setRestClientConnTimeOutMs(connTimeoutMs);
8997
this.restClient.setRestClientReadTimeOutMs(readTimeoutMs);
9098
this.restClient.setMaxRetryAttempts(maxRetryAttempts);
@@ -180,6 +188,8 @@ private boolean sendBatch(Collection<AuditEventBase> events, RangerRESTClient re
180188
queryParams.put(QUERY_PARAM_APP_ID, appId);
181189
}
182190

191+
Response response = null;
192+
183193
try {
184194
final UserGroupInformation user = MiscUtil.getUGILoginUser();
185195
final boolean isSecureMode = isKerberosAuthenticated();
@@ -190,10 +200,8 @@ private boolean sendBatch(Collection<AuditEventBase> events, RangerRESTClient re
190200
LOG.debug("Sending audit batch of {} events. SecureMode: {}, User: {}", events.size(), isSecureMode, user != null ? user.getUserName() : "null");
191201
}
192202

193-
final ClientResponse response;
194-
195203
if (isSecureMode) {
196-
response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<ClientResponse>) () -> {
204+
response = MiscUtil.executePrivilegedAction((PrivilegedExceptionAction<Response>) () -> {
197205
try {
198206
return postAuditEvents(restClient, queryParams, events);
199207
} catch (Exception e) {
@@ -210,7 +218,7 @@ private boolean sendBatch(Collection<AuditEventBase> events, RangerRESTClient re
210218

211219
if (status == HttpStatus.SC_OK) {
212220
if (LOG.isDebugEnabled()) {
213-
LOG.debug("Audit batch sent successfully. {} events delivered. Response: {}", events.size(), response.getEntity(String.class));
221+
LOG.debug("Audit batch sent successfully. {} events delivered. Response: {}", events.size(), response.readEntity(String.class));
214222
}
215223

216224
ret = true;
@@ -219,7 +227,7 @@ private boolean sendBatch(Collection<AuditEventBase> events, RangerRESTClient re
219227

220228
try {
221229
if (response.hasEntity()) {
222-
errorBody = response.getEntity(String.class);
230+
errorBody = response.readEntity(String.class);
223231
}
224232
} catch (Exception e) {
225233
LOG.debug("Failed to read error response body", e);
@@ -242,27 +250,33 @@ private boolean sendBatch(Collection<AuditEventBase> events, RangerRESTClient re
242250
LOG.error("Failed to send audit batch of {} events. Error: {}", events.size(), e.getMessage(), e);
243251

244252
ret = false;
253+
} finally {
254+
if (response != null) {
255+
try {
256+
response.close();
257+
} catch (Exception e) {
258+
LOG.debug("Error closing HTTP response", e);
259+
}
260+
}
245261
}
246262

247263
return ret;
248264
}
249265

250-
private ClientResponse postAuditEvents(RangerRESTClient restClient, Map<String, String> params, Collection<AuditEventBase> events) {
266+
private Response postAuditEvents(RangerRESTClient restClient, Map<String, String> params, Collection<AuditEventBase> events) {
251267
LOG.debug("Posting {} audit events to {}", events.size(), REST_RELATIVE_PATH_POST);
252268

253-
WebResource webResource = restClient.getResource(REST_RELATIVE_PATH_POST);
269+
WebTarget target = restClient.getResource(REST_RELATIVE_PATH_POST);
254270

255271
if (params != null && !params.isEmpty()) {
256272
for (Map.Entry<String, String> entry : params.entrySet()) {
257-
webResource = webResource.queryParam(entry.getKey(), entry.getValue());
273+
target = target.queryParam(entry.getKey(), entry.getValue());
258274
}
259275
}
260276

261-
return webResource
262-
.accept("application/json")
263-
.type("application/json")
264-
.entity(events)
265-
.post(ClientResponse.class);
277+
return target.request(MediaType.APPLICATION_JSON_TYPE)
278+
.accept(MediaType.APPLICATION_JSON_TYPE)
279+
.post(Entity.entity(events, MediaType.APPLICATION_JSON_TYPE));
266280
}
267281

268282
private static Configuration createRESTClientConfiguration(Properties props, String propPrefix, String authType) {

agents-audit/dest-cloudwatch/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,5 @@
5252
<artifactId>slf4j-api</artifactId>
5353
<version>${slf4j.version}</version>
5454
</dependency>
55-
56-
<!-- Test -->
57-
<dependency>
58-
<groupId>org.testng</groupId>
59-
<artifactId>testng</artifactId>
60-
<scope>test</scope>
61-
</dependency>
6255
</dependencies>
6356
</project>

agents-audit/dest-es/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,5 @@
207207
<artifactId>slf4j-api</artifactId>
208208
<version>${slf4j.version}</version>
209209
</dependency>
210-
211-
<!-- Test -->
212-
<dependency>
213-
<groupId>org.testng</groupId>
214-
<artifactId>testng</artifactId>
215-
<scope>test</scope>
216-
</dependency>
217210
</dependencies>
218211
</project>

0 commit comments

Comments
 (0)