-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from newrelic/release/v1.4.0
CSEC Java Agent Release Target 1.4.0
- Loading branch information
Showing
42 changed files
with
3,602 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
dependencies { | ||
implementation(project(":newrelic-security-api")) | ||
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") | ||
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") | ||
|
||
implementation("jakarta.servlet:jakarta.servlet-api:4.0.4") | ||
implementation("org.glassfish.main.web:web-core:5.1.0") | ||
implementation("org.eclipse.persistence:javax.persistence:2.2.1") | ||
} | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.glassfish' } | ||
} | ||
|
||
verifyInstrumentation { | ||
// maven-metadata.xml for this artifact only shows the latest version. | ||
// This is the file that's read when trying to resolve a range of versions, such as [3.0,6.0). | ||
// Therefore, range-based versions will not work here. | ||
passes 'org.glassfish.main.web:web-core:[3.1.2,)' | ||
excludeRegex 'org.glassfish.main.web:web-core:.*(RC|M)[0-9]*$' | ||
} | ||
|
||
site { | ||
title 'Glassfish' | ||
type 'Appserver' | ||
versionOverride '[3.0,6.0)' | ||
} |
27 changes: 27 additions & 0 deletions
27
...rity/glassfish/src/main/java/org/apache/catalina/connector/Connector_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* | ||
* * Copyright 2020 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.apache.catalina.connector; | ||
|
||
import com.newrelic.api.agent.security.NewRelicSecurity; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
@Weave(type = MatchType.ExactClass, originalName = "org.apache.catalina.connector.Connector") | ||
public abstract class Connector_Instrumentation { | ||
|
||
public void start() { | ||
|
||
NewRelicSecurity.getAgent().setApplicationConnectionConfig(getPort(), getScheme()); | ||
Weaver.callOriginal(); | ||
} | ||
|
||
public abstract int getPort(); | ||
|
||
public abstract String getScheme(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.jedis-1.4.0' } | ||
} | ||
|
||
dependencies { | ||
implementation(project(":newrelic-security-api")) | ||
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") | ||
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") | ||
implementation("redis.clients:jedis:1.4.0") | ||
testImplementation('org.testcontainers:testcontainers:1.17.1') | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'redis.clients:jedis:[1.4.0,3.0.0)' | ||
exclude 'redis.clients:jedis:2.7.1' | ||
exclude 'redis.clients:jedis:2.7.2' | ||
excludeRegex 'redis.clients:jedis:.*-(m|rc|RC)[0-9]*' | ||
} | ||
|
||
site { | ||
title 'Jedis' | ||
type 'Datastore' | ||
} |
52 changes: 52 additions & 0 deletions
52
....0/src/main/java/com/newrelic/agent/security/instrumentation/jedis_1_4_0/JedisHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.newrelic.agent.security.instrumentation.jedis_1_4_0; | ||
|
||
import com.newrelic.api.agent.security.NewRelicSecurity; | ||
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; | ||
import com.newrelic.api.agent.security.schema.AbstractOperation; | ||
import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityException; | ||
import com.newrelic.api.agent.security.schema.operation.RedisOperation; | ||
|
||
import java.util.List; | ||
|
||
public class JedisHelper { | ||
public static final String NR_SEC_LOCK_ATTRIB_NAME = "JEDIS_OPERATION_LOCK_"; | ||
public static AbstractOperation preprocessSecurityHook(String command, List<Object> args, String klass, String method) { | ||
try { | ||
if (!NewRelicSecurity.isHookProcessingActive() || NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()){ | ||
return null; | ||
} | ||
RedisOperation operation = new RedisOperation(klass, method, command, args); | ||
NewRelicSecurity.getAgent().registerOperation(operation); | ||
return operation; | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
if (e instanceof NewRelicSecurityException) { | ||
throw e; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static void registerExitOperation(boolean isProcessingAllowed, AbstractOperation operation) { | ||
try { | ||
if (operation == null || !isProcessingAllowed || !NewRelicSecurity.isHookProcessingActive() || | ||
NewRelicSecurity.getAgent().getSecurityMetaData().getRequest().isEmpty()) { | ||
return; | ||
} | ||
NewRelicSecurity.getAgent().registerExitEvent(operation); | ||
} catch (Throwable ignored){} | ||
} | ||
|
||
public static void releaseLock(int hashCode) { | ||
try { | ||
GenericHelper.releaseLock(NR_SEC_LOCK_ATTRIB_NAME, hashCode); | ||
} catch (Throwable ignored) {} | ||
} | ||
|
||
public static boolean acquireLockIfPossible(int hashCode) { | ||
try { | ||
return GenericHelper.acquireLockIfPossible(NR_SEC_LOCK_ATTRIB_NAME, hashCode); | ||
} catch (Throwable ignored) {} | ||
return false; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...on-security/jedis-1.4.0/src/main/java/redis/clients/jedis/Connection_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package redis.clients.jedis; | ||
|
||
import com.newrelic.agent.security.instrumentation.jedis_1_4_0.JedisHelper; | ||
import com.newrelic.api.agent.security.NewRelicSecurity; | ||
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; | ||
import com.newrelic.api.agent.security.schema.AbstractOperation; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.Connection") | ||
public abstract class Connection_Instrumentation { | ||
protected Connection sendCommand(final Protocol.Command cmd, final byte[]... args) { | ||
boolean isLockAcquired = JedisHelper.acquireLockIfPossible(cmd.hashCode()); | ||
AbstractOperation operation = null; | ||
if(isLockAcquired && args != null) { | ||
List<Object> argList = new ArrayList<>(); | ||
for (byte[] arg : args) { | ||
Object dataByBytes = NewRelicSecurity.getAgent() | ||
.getSecurityMetaData() | ||
.getCustomAttribute(GenericHelper.NR_SEC_CUSTOM_SPRING_REDIS_ATTR + arg.hashCode(), Object.class); | ||
|
||
if (dataByBytes != null) { | ||
argList.add(dataByBytes); | ||
} else { | ||
argList.add(new String(arg)); | ||
} | ||
} | ||
operation = JedisHelper.preprocessSecurityHook(cmd.name(), argList, this.getClass().getName(), "sendCommand"); | ||
} | ||
Connection returnValue = null; | ||
try { | ||
returnValue = Weaver.callOriginal(); | ||
} finally { | ||
if (isLockAcquired) { | ||
JedisHelper.releaseLock(cmd.hashCode()); | ||
} | ||
} | ||
JedisHelper.registerExitOperation(isLockAcquired, operation); | ||
return returnValue; | ||
} | ||
} |
Oops, something went wrong.