Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NR-347851: Send iastTestIdentifier in HC & Only send instance-count WS header if its value is > 0 #364

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import com.newrelic.agent.security.instrumentator.utils.ApplicationInfoUtils;
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.collectorconfig.CollectorConfig;
import com.newrelic.agent.security.intcodeagent.models.javaagent.ApplicationInfoBean;
import com.newrelic.agent.security.intcodeagent.models.javaagent.Identifier;
import com.newrelic.agent.security.intcodeagent.models.javaagent.JAHealthCheck;
import com.newrelic.agent.security.intcodeagent.properties.BuildInfo;
import com.newrelic.agent.security.intcodeagent.websocket.WSUtils;
import com.newrelic.api.agent.security.instrumentation.helpers.GrpcClientRequestReplayHelper;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
Expand Down Expand Up @@ -68,7 +68,7 @@ public static AgentInfo getInstance(){
}

public void initialiseHC(){
jaHealthCheck = new JAHealthCheck(applicationUUID);
jaHealthCheck = new JAHealthCheck();
}

public ApplicationInfoBean getApplicationInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class JAHealthCheck extends AgentBasicInfo {

private Boolean scanActive = false;

private AtomicInteger invokedHookCount;
private final AtomicInteger invokedHookCount;

private IdentifierEnvs kind;

private EventStats eventStats;
private final EventStats eventStats;

private ThreadPoolStats threadPoolStats;

Expand All @@ -49,8 +49,9 @@ public class JAHealthCheck extends AgentBasicInfo {

private SchedulerRuns schedulerRuns = new SchedulerRuns();

private String iastTestIdentifier;

public JAHealthCheck(String applicationUUID) {
public JAHealthCheck() {
super();
this.invokedHookCount = new AtomicInteger(0);
this.threadPoolStats = new ThreadPoolStats();
Expand All @@ -59,6 +60,7 @@ public JAHealthCheck(String applicationUUID) {
this.eventStats = new EventStats();
this.setKind(AgentInfo.getInstance().getApplicationInfo().getIdentifier().getKind());
this.procStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();
this.iastTestIdentifier = AgentConfig.getInstance().getScanControllers().getIastTestIdentifier();
if(AgentConfig.getInstance().getAgentMode().getScanSchedule().getNextScanTime() != null) {
this.csecActivationTime = AgentConfig.getInstance().getAgentMode().getScanSchedule().getNextScanTime().getTime();
} else {
Expand Down Expand Up @@ -90,6 +92,7 @@ public JAHealthCheck(JAHealthCheck jaHealthCheck) {
this.csecActivationTime = jaHealthCheck.getCsecActivationTime();
this.iastDataRequestTime = jaHealthCheck.getIastDataRequestTime();
this.scanActive = jaHealthCheck.getScanActive();
this.iastTestIdentifier = jaHealthCheck.getIastTestIdentifier();
logger.log(LogLevel.INFO, String.format(HC_CREATED, JsonConverter.toJSON(this)), JAHealthCheck.class.getName());
}

Expand Down Expand Up @@ -212,6 +215,14 @@ public long getIastDataRequestTime() {
return iastDataRequestTime;
}

public String getIastTestIdentifier() {
return iastTestIdentifier;
}

public void setIastTestIdentifier(String iastTestIdentifier) {
this.iastTestIdentifier = iastTestIdentifier;
}

public void reset(){
this.setInvokedHookCount(0);
this.stats.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.newrelic.agent.security.AgentInfo;
import com.newrelic.agent.security.instrumentator.dispatcher.DispatcherPool;
import com.newrelic.agent.security.instrumentator.httpclient.RestRequestThreadPool;
import com.newrelic.agent.security.instrumentator.utils.AgentUtils;
import com.newrelic.agent.security.instrumentator.utils.INRSettingsKey;
import com.newrelic.agent.security.intcodeagent.controlcommand.ControlCommandProcessor;
import com.newrelic.agent.security.intcodeagent.controlcommand.ControlCommandProcessorThreadPool;
Expand Down Expand Up @@ -71,7 +70,7 @@ public class WSClient extends WebSocketClient {

private WebSocketImpl connection = null;

private Map<String, String> noticeErrorCustomParameters = new HashMap<>();
private final Map<String, String> noticeErrorCustomParameters = new HashMap<>();


private SSLContext createSSLContext() throws Exception {
Expand Down Expand Up @@ -157,7 +156,9 @@ private WSClient() throws URISyntaxException {
this.addHeader("NR-CSEC-IGNORED-VUL-CATEGORIES", AgentConfig.getInstance().getAgentMode().getSkipScan().getIastDetectionCategory().getDisabledCategoriesCSV());
this.addHeader("NR-CSEC-PROCESS-START-TIME", String.valueOf(ManagementFactory.getRuntimeMXBean().getStartTime()));
this.addHeader("NR-CSEC-IAST-TEST-IDENTIFIER", AgentConfig.getInstance().getScanControllers().getIastTestIdentifier());
this.addHeader("NR-CSEC-IAST-SCAN-INSTANCE-COUNT", String.valueOf(AgentConfig.getInstance().getScanControllers().getScanInstanceCount()));
if (AgentConfig.getInstance().getScanControllers().getScanInstanceCount() >= 0) {
this.addHeader("NR-CSEC-IAST-SCAN-INSTANCE-COUNT", String.valueOf(AgentConfig.getInstance().getScanControllers().getScanInstanceCount()));
}
Proxy proxy = proxyManager();
if(proxy != null) {
this.setProxy(proxy);
Expand Down Expand Up @@ -314,7 +315,7 @@ public void onError(Exception ex) {
NewRelic.noticeError(new SecurityNoticeError(CONNECTION_CLOSED_BY + ex.getClass().getSimpleName(), ex), noticeErrorCustomParameters, true);
logger.logInit(LogLevel.SEVERE, String.format(IAgentConstants.WS_CONNECTION_UNSUCCESSFUL_INFO, AgentConfig
.getInstance().getConfig().getK2ServiceInfo().getValidatorServiceEndpointURL(),
ex.toString(), ex.getCause()),
ex, ex.getCause()),
WSClient.class.getName());
logger.log(LogLevel.FINER, String.format(IAgentConstants.WS_CONNECTION_UNSUCCESSFUL, AgentConfig.getInstance().getConfig().getK2ServiceInfo().getValidatorServiceEndpointURL()),
ex,
Expand Down
Loading