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

Troubleshoot 404s in Tomcat with AppSec enabled #7519

Closed
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 @@ -10,6 +10,7 @@
import datadog.trace.agent.tooling.muzzle.Reference;
import datadog.trace.agent.tooling.muzzle.ReferenceMatcher;
import datadog.trace.agent.tooling.muzzle.ReferenceProvider;
import datadog.trace.api.Config;
import datadog.trace.api.InstrumenterConfig;
import datadog.trace.api.ProductActivation;
import datadog.trace.api.config.ProfilingConfig;
Expand Down Expand Up @@ -227,9 +228,23 @@ public AppSec(String instrumentationName, String... additionalNames) {
super(instrumentationName, additionalNames);
}

private boolean applies() {
Set<String> disabled = Config.get().getDisabledAppSecInstrumentations();
if (disabled.contains("*")) {
return false;
}
if (disabled.contains(name())) {
return false;
}
if (disabled.contains(getClass().getSimpleName())) {
return false;
}
return true;
}

@Override
public boolean isApplicable(Set<TargetSystem> enabledSystems) {
return enabledSystems.contains(TargetSystem.APPSEC);
return enabledSystems.contains(TargetSystem.APPSEC) && applies();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class AppSecConfig {
public static final String API_SECURITY_ENABLED_EXPERIMENTAL =
"experimental.api-security.enabled";
public static final String API_SECURITY_REQUEST_SAMPLE_RATE = "api-security.request.sample.rate";
public static final String DISABLED_INSTRUMENTATIONS = "appsec.disabled-instrumentations";

public static final String APPSEC_SCA_ENABLED = "appsec.sca.enabled";
public static final String APPSEC_RASP_ENABLED = "appsec.rasp.enabled";
Expand Down
12 changes: 10 additions & 2 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
import static datadog.trace.api.config.AppSecConfig.APPSEC_TRACE_RATE_LIMIT;
import static datadog.trace.api.config.AppSecConfig.APPSEC_WAF_METRICS;
import static datadog.trace.api.config.AppSecConfig.APPSEC_WAF_TIMEOUT;
import static datadog.trace.api.config.AppSecConfig.DISABLED_INSTRUMENTATIONS;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_ADDITIONAL_CHILD_PROCESS_JVM_ARGS;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED;
import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL;
Expand Down Expand Up @@ -490,6 +491,7 @@
import static datadog.trace.util.CollectionUtils.tryMakeImmutableList;
import static datadog.trace.util.CollectionUtils.tryMakeImmutableSet;
import static datadog.trace.util.Strings.propertyNameToEnvironmentVariableName;
import static java.util.Collections.emptySet;

import datadog.trace.api.config.GeneralConfig;
import datadog.trace.api.config.ProfilingConfig;
Expand Down Expand Up @@ -763,6 +765,7 @@ static class HostNameHolder {
private final boolean appSecStandaloneEnabled;
private final boolean apiSecurityEnabled;
private final float apiSecurityRequestSampleRate;
private final Set<String> disabledAppSecInstrumentations;

private final IastDetectionMode iastDetectionMode;
private final int iastMaxConcurrentRequests;
Expand Down Expand Up @@ -1710,6 +1713,7 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
apiSecurityRequestSampleRate =
configProvider.getFloat(
API_SECURITY_REQUEST_SAMPLE_RATE, DEFAULT_API_SECURITY_REQUEST_SAMPLE_RATE);
disabledAppSecInstrumentations = configProvider.getSet(DISABLED_INSTRUMENTATIONS, emptySet());

iastDebugEnabled = configProvider.getBoolean(IAST_DEBUG_ENABLED, DEFAULT_IAST_DEBUG_ENABLED);

Expand Down Expand Up @@ -2931,6 +2935,10 @@ public float getApiSecurityRequestSampleRate() {
return apiSecurityRequestSampleRate;
}

public Set<String> getDisabledAppSecInstrumentations() {
return disabledAppSecInstrumentations;
}

public ProductActivation getIastActivation() {
return instrumenterConfig.getIastActivation();
}
Expand Down Expand Up @@ -4140,7 +4148,7 @@ private <T> Set<T> getSettingsSetFromEnvironment(

private <F, T> Set<T> convertSettingsSet(Set<F> fromSet, Function<F, Iterable<T>> mapper) {
if (fromSet.isEmpty()) {
return Collections.emptySet();
return emptySet();
}
Set<T> result = new LinkedHashSet<>(fromSet.size());
for (F from : fromSet) {
Expand Down Expand Up @@ -4220,7 +4228,7 @@ private static Set<String> parseStringIntoSetOfNonEmptyStrings(
private static <T> Set<T> convertStringSetToSet(
String setting, final Set<String> input, Function<String, T> mapper) {
if (input.isEmpty()) {
return Collections.emptySet();
return emptySet();
}
// Using LinkedHashSet to preserve original string order
final Set<T> result = new LinkedHashSet<>();
Expand Down