Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
IshikaDawda committed Aug 9, 2024
2 parents 568def9 + 860024a commit b706ece
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 144 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The agent version.
agentVersion=1.4.0
jsonVersion=1.2.3
jsonVersion=1.2.4
# Updated exposed NR APM API version.
nrAPIVersion=8.12.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.newrelic.agent.security.instrumentator.httpclient;

import com.newrelic.agent.security.AgentConfig;
import com.newrelic.agent.security.AgentInfo;
import com.newrelic.agent.security.instrumentator.utils.INRSettingsKey;
import com.newrelic.agent.security.intcodeagent.filelogging.FileLoggerThreadPool;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.agent.security.intcodeagent.models.IASTDataTransferRequest;
Expand All @@ -10,14 +13,13 @@
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GrpcClientRequestReplayHelper;
import org.apache.commons.lang3.StringUtils;

import java.time.Instant;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -91,6 +93,10 @@ private void task() {

if (batchSize > 100 && remainingRecordCapacity > batchSize) {
request = new IASTDataTransferRequest(NewRelicSecurity.getAgent().getAgentUUID());
if (AgentConfig.getInstance().getConfig().getCustomerInfo() != null) {
request.setAppAccountId(AgentConfig.getInstance().getConfig().getCustomerInfo().getAccountId());
}
request.setAppEntityGuid(AgentInfo.getInstance().getLinkingMetadata().getOrDefault(INRSettingsKey.NR_ENTITY_GUID, StringUtils.EMPTY));

request.setBatchSize(batchSize);
request.setCompletedRequests(getEffectiveCompletedRequests());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.newrelic.agent.security.instrumentator.httpclient;

import com.newrelic.agent.security.AgentInfo;
import com.newrelic.agent.security.intcodeagent.filelogging.FileLoggerThreadPool;
import com.newrelic.agent.security.intcodeagent.models.javaagent.FuzzFailEvent;
import com.newrelic.agent.security.intcodeagent.websocket.EventSendPool;
import com.newrelic.api.agent.security.instrumentation.helpers.GrpcClientRequestReplayHelper;
Expand All @@ -23,7 +21,7 @@ public void run() {
// TODO: Add to fuzz fail count in HC and remove FuzzFailEvent if not needed.
Map<FuzzRequestBean, Throwable> fuzzFailMap = GrpcClientRequestReplayHelper.getInstance().getSingleRequestFromFuzzFailRequestQueue();
FuzzRequestBean request = (FuzzRequestBean) fuzzFailMap.keySet().toArray()[0];
FuzzFailEvent fuzzFailEvent = new FuzzFailEvent(AgentInfo.getInstance().getApplicationUUID());
FuzzFailEvent fuzzFailEvent = new FuzzFailEvent();
fuzzFailEvent.setFuzzHeader(request.getHeaders().get(ServletHelper.CSEC_IAST_FUZZ_REQUEST_ID));
EventSendPool.getInstance().sendEvent(fuzzFailEvent);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.newrelic.agent.security.instrumentator.httpclient;

import com.newrelic.agent.security.AgentInfo;
import com.newrelic.agent.security.intcodeagent.filelogging.FileLoggerThreadPool;
import com.newrelic.agent.security.intcodeagent.logging.IAgentConstants;
import com.newrelic.agent.security.intcodeagent.models.FuzzRequestBean;
Expand Down Expand Up @@ -137,7 +136,7 @@ public void fireRequest(FuzzRequestBean httpRequest, List<String> endpoints, int
e, RestRequestProcessor.class.getName());
RestRequestThreadPool.getInstance().getProcessedIds().putIfAbsent(fuzzRequestId, new HashSet<>());
// TODO: Add to fuzz fail count in HC and remove FuzzFailEvent if not needed.
FuzzFailEvent fuzzFailEvent = new FuzzFailEvent(AgentInfo.getInstance().getApplicationUUID());
FuzzFailEvent fuzzFailEvent = new FuzzFailEvent();
fuzzFailEvent.setFuzzHeader(request.header(ServletHelper.CSEC_IAST_FUZZ_REQUEST_ID));
EventSendPool.getInstance().sendEvent(fuzzFailEvent);
}
Expand Down Expand Up @@ -228,7 +227,7 @@ else if(response.code() >= 400){
e, RestRequestProcessor.class.getName());
RestRequestThreadPool.getInstance().getProcessedIds().putIfAbsent(fuzzRequestId, new HashSet<>());
// TODO: Add to fuzz fail count in HC and remove FuzzFailEvent if not needed.
FuzzFailEvent fuzzFailEvent = new FuzzFailEvent(AgentInfo.getInstance().getApplicationUUID());
FuzzFailEvent fuzzFailEvent = new FuzzFailEvent();
fuzzFailEvent.setFuzzHeader(request.header(ServletHelper.CSEC_IAST_FUZZ_REQUEST_ID));
EventSendPool.getInstance().sendEvent(fuzzFailEvent);
} catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static ApplicationInfoBean createApplicationInfoBean(Identifier identifie
AgentUtils.getInstance().getStatusLogValues().put(PROCESS_BINARY, NOT_AVAILABLE);
try {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
ApplicationInfoBean applicationInfoBean = new ApplicationInfoBean(vmpid, applicationUUID, STATIC);
ApplicationInfoBean applicationInfoBean = new ApplicationInfoBean(vmpid, STATIC);
applicationInfoBean.setStartTime(runtimeMXBean.getStartTime());
identifier.setCollectorIp(getIpAddress());
// TODO: Need to write platform agnostic alternative for this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
public class IASTDataTransferRequest {
private String jsonName = "iast-data-request";
private String applicationUUID;
private String appAccountId;
private String appEntityGuid;

private int batchSize;

Expand Down Expand Up @@ -65,6 +67,22 @@ public void setJsonName(String jsonName) {
this.jsonName = jsonName;
}

public String getAppAccountId() {
return appAccountId;
}

public void setAppAccountId(String appAccountId) {
this.appAccountId = appAccountId;
}

public String getAppEntityGuid() {
return appEntityGuid;
}

public void setAppEntityGuid(String appEntityGuid) {
this.appEntityGuid = appEntityGuid;
}

@Override
public String toString() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class AgentBasicInfo {
private String eventType;

private Map<String, String> linkingMetadata;
private String appAccountId;
private String appEntityGuid;
private String applicationUUID;

@JsonInclude
private static String policyVersion;
Expand All @@ -79,7 +82,9 @@ public AgentBasicInfo() {
setGroupName(AgentConfig.getInstance().getGroupName());
setNodeId(AgentInfo.getInstance().getLinkingMetadata().getOrDefault(INRSettingsKey.NR_ENTITY_GUID, StringUtils.EMPTY));
setLinkingMetadata(new HashMap<>(AgentInfo.getInstance().getLinkingMetadata()));
setAccountId(AgentConfig.getInstance().getConfig().getCustomerInfo().getAccountId());
setAppEntityGuid(AgentInfo.getInstance().getLinkingMetadata().getOrDefault(INRSettingsKey.NR_ENTITY_GUID, StringUtils.EMPTY));
setAppAccountId(AgentConfig.getInstance().getConfig().getCustomerInfo().getAccountId());
setApplicationUUID(AgentInfo.getInstance().getApplicationUUID());
if (this instanceof ApplicationInfoBean) {
setJsonName(JSON_NAME_APPLICATION_INFO_BEAN);
} else if (this instanceof JavaAgentEventBean) {
Expand Down Expand Up @@ -240,11 +245,27 @@ public void setLinkingMetadata(Map<String, String> linkingMetadata) {
this.linkingMetadata = linkingMetadata;
}

public String getAccountId() {
return accountId;
public String getAppAccountId() {
return appAccountId;
}

public void setAccountId(String accountId) {
this.accountId = accountId;
public void setAppAccountId(String appAccountId) {
this.appAccountId = appAccountId;
}

public String getAppEntityGuid() {
return appEntityGuid;
}

public void setAppEntityGuid(String appEntityGuid) {
this.appEntityGuid = appEntityGuid;
}

public String getApplicationUUID() {
return applicationUUID;
}

public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public class ApplicationInfoBean extends AgentBasicInfo {
*/
private Integer pid;

/**
* UUID per running application.
*/
private String applicationUUID;

/**
* name of running application.
*/
Expand Down Expand Up @@ -79,10 +74,9 @@ public void setLibraryPath(List<String> libraryPath) {

private Identifier identifier;

public ApplicationInfoBean(Integer pid, String applicationUUID, String agentAttachmentType) {
public ApplicationInfoBean(Integer pid, String agentAttachmentType) {
super();
this.pid = pid;
this.applicationUUID = applicationUUID;
this.runCommand = System.getProperty("sun.java.command");
this.userDir = System.getProperty("user.dir");
this.libraryPath = new ArrayList<String>();
Expand Down Expand Up @@ -121,14 +115,6 @@ public void setPid(Integer pid) {
this.pid = pid;
}

public String getApplicationUUID() {
return applicationUUID;
}

public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}

public String getApplicationName() {
return applicationName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

public class ApplicationURLMappings extends AgentBasicInfo{

private String applicationUUID;
private Set<ApplicationURLMapping> mappings;

public ApplicationURLMappings(Set<ApplicationURLMapping> mappings) {
Expand All @@ -26,12 +25,4 @@ public void setMappings(Set<ApplicationURLMapping> mappings) {
public String toString() {
return JsonConverter.toJSON(this);
}

public String getApplicationUUID() {
return applicationUUID;
}

public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class ErrorIncident extends AgentBasicInfo {

private String applicationUUID = AgentInfo.getInstance().getApplicationUUID();

private LogMessageException exception;

private Map<String, String> linkingMetadata;
Expand All @@ -23,14 +21,6 @@ public class ErrorIncident extends AgentBasicInfo {

private HttpRequest httpRequest;

public String getApplicationUUID() {
return applicationUUID;
}

public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}

public LogMessageException getException() {
return exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ public class ExitEventBean extends AgentBasicInfo {
private String executionId;
private String caseType;
private String k2RequestIdentifier;
private String applicationUUID;

public ExitEventBean() {
super();
}
Expand All @@ -17,7 +15,6 @@ public ExitEventBean(String executionId, String caseType) {
this();
this.executionId = executionId;
this.caseType = caseType;
this.applicationUUID = AgentInfo.getInstance().getApplicationUUID();
}

public String getExecutionId() {
Expand All @@ -44,14 +41,6 @@ public void setK2RequestIdentifier(String k2RequestIdentifier) {
this.k2RequestIdentifier = k2RequestIdentifier;
}

public String getApplicationUUID() {
return applicationUUID;
}

public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}

@Override
public String toString() {
return JsonConverter.toJSON(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@ public class FuzzFailEvent extends AgentBasicInfo {

private String fuzzHeader;

private String applicationUUID;

public String getApplicationUUID() {
return applicationUUID;
}

public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}

public FuzzFailEvent(String applicationUUID) {
public FuzzFailEvent() {
super();
this.applicationUUID = applicationUUID;
}

public String getFuzzHeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ public class HttpConnectionStat extends AgentBasicInfo {

private Collection<OutBoundHttp> httpConnections;

private String applicationUUID;

private Boolean isCached;

public HttpConnectionStat(Collection<OutBoundHttp> httpConnections, String applicationUUID, Boolean isCached) {
public HttpConnectionStat(Collection<OutBoundHttp> httpConnections, Boolean isCached) {
this.httpConnections = httpConnections;
this.applicationUUID = applicationUUID;
this.isCached = isCached;
}

Expand All @@ -34,14 +31,6 @@ public void setIsCached(Boolean isCached) {
this.isCached = isCached;
}

public String getApplicationUUID() {
return applicationUUID;
}

public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}

public String toString() {
return JsonConverter.toJSON(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class JAHealthCheck extends AgentBasicInfo {
private static final FileLoggerThreadPool logger = FileLoggerThreadPool.getInstance();
private static final String HC_CREATED = "Created Health Check: %s";

private String applicationUUID;

// private String protectedServer;

// private Set protectedDB;
Expand Down Expand Up @@ -60,7 +58,6 @@ public class JAHealthCheck extends AgentBasicInfo {

public JAHealthCheck(String applicationUUID) {
super();
this.applicationUUID = applicationUUID;
this.invokedHookCount = new AtomicInteger(0);
this.eventDropCount = new AtomicInteger(0);
this.eventProcessed = new AtomicInteger(0);
Expand All @@ -83,7 +80,6 @@ public JAHealthCheck(String applicationUUID) {

public JAHealthCheck(JAHealthCheck jaHealthCheck) {
super();
this.applicationUUID = jaHealthCheck.applicationUUID;
this.invokedHookCount = new AtomicInteger(jaHealthCheck.invokedHookCount.intValue());
this.eventDropCount = new AtomicInteger(jaHealthCheck.eventDropCount.intValue());
this.eventProcessed = new AtomicInteger(jaHealthCheck.eventProcessed.intValue());
Expand Down Expand Up @@ -113,20 +109,6 @@ public void setKind(IdentifierEnvs kind) {
this.kind = kind;
}

/**
* @return the applicationUUID
*/
public String getApplicationUUID() {
return applicationUUID;
}

/**
* @param applicationUUID the applicationUUID to set
*/
public void setApplicationUUID(String applicationUUID) {
this.applicationUUID = applicationUUID;
}

/**
* @return the eventDropCount
*/
Expand Down
Loading

0 comments on commit b706ece

Please sign in to comment.