Skip to content

Commit 91cf706

Browse files
authored
Merge branch 'master' into dudik/multi-config
2 parents 308e398 + cf90183 commit 91cf706

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

tracer/src/Datadog.Trace/AppSec/ApiSec/ApiSecurity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ApiSecurity(SecuritySettings securitySettings, int maxRouteSize = 4096)
3232
_apmTracingEnabled = securitySettings.ApmTracingEnabled;
3333
_minTimeBetweenReprocessTimeSpan = TimeSpan.FromSeconds(securitySettings.ApiSecuritySampleDelay);
3434
_maxRoutesSize = maxRouteSize;
35-
_endpointsCollectionEnabled = securitySettings.ApiSecurityEndpointCollectionEnabled;
35+
_endpointsCollectionEnabled = securitySettings is { ApiSecurityEndpointCollectionEnabled: true, AppsecEnabled: true };
3636
_endpointsCollectionMessageLimit = securitySettings.ApiSecurityEndpointCollectionMessageLimit;
3737
}
3838

tracer/src/Datadog.Trace/AppSec/SecuritySettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public SecuritySettings(IConfigurationSource? source, IConfigurationTelemetry te
132132
.Value;
133133

134134
ApiSecurityEndpointCollectionEnabled = config.WithKeys(ConfigurationKeys.AppSec.ApiSecurityEndpointCollectionEnabled)
135-
.AsBool(false);
135+
.AsBool(true);
136136

137137
ApiSecurityEndpointCollectionMessageLimit = config.WithKeys(ConfigurationKeys.AppSec.ApiSecurityEndpointCollectionMessageLimit)
138138
.AsInt32(300, val => val >= 0)

tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.AppSec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ internal class AppSec
122122
internal const string ApiSecuritySampleDelay = "DD_API_SECURITY_SAMPLE_DELAY";
123123

124124
/// <summary>
125-
/// with a default value of false, it allows a customer to disable the collection of endpoints for API Security.
125+
/// with a default value of true, it allows a customer to disable the collection of endpoints for API Security.
126126
/// </summary>
127127
internal const string ApiSecurityEndpointCollectionEnabled = "DD_API_SECURITY_ENDPOINT_COLLECTION_ENABLED";
128128

tracer/src/Datadog.Trace/Debugger/ExceptionAutoInstrumentation/ExceptionReplaySettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public ExceptionReplaySettings(IConfigurationSource? source, IConfigurationTelem
2222
source ??= NullConfigurationSource.Instance;
2323
var config = new ConfigurationBuilder(source, telemetry);
2424

25-
var erEnabledResult = config.WithKeys(ConfigurationKeys.Debugger.ExceptionReplayEnabled).AsBoolResult();
25+
#pragma warning disable CS0612 // Type or member is obsolete
26+
var erEnabledResult = config.WithKeys(ConfigurationKeys.Debugger.ExceptionReplayEnabled, fallbackKey: ConfigurationKeys.Debugger.ExceptionDebuggingEnabled).AsBoolResult();
27+
#pragma warning restore CS0612 // Type or member is obsolete
2628
Enabled = erEnabledResult.WithDefault(false);
2729
CanBeEnabled = erEnabledResult.ConfigurationResult is not { IsValid: true, Result: false };
2830

tracer/test/Datadog.Trace.Security.IntegrationTests/ApiSecurity/AspNetCoreEndpoints.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ protected AspNetCoreEndpoints(AspNetCoreTestFixture fixture, ITestOutputHelper o
3333
_fixture = fixture;
3434
_fixture.SetOutput(outputHelper);
3535

36-
// Endpoints collection is a feature independent of AppSec and the main API Security feature
37-
SetEnvironmentVariable(ConfigurationKeys.AppSec.Enabled, "0");
36+
SetEnvironmentVariable(ConfigurationKeys.AppSec.Enabled, "1");
3837
SetEnvironmentVariable(ConfigurationKeys.AppSec.ApiSecurityEnabled, "0");
3938
SetEnvironmentVariable(ConfigurationKeys.AppSec.ApiSecurityEndpointCollectionEnabled, enableEndpointsCollection.ToString());
4039

tracer/test/Datadog.Trace.Security.Unit.Tests/ApiSec/EndpointsCollectionTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public void GivenConfiguration_WhenApiSecEnabledAndEndpointsCollectionEnabled_Is
2020
{
2121
var settings = new CustomSettingsForTests(new Dictionary<string, object>
2222
{
23+
{ ConfigurationKeys.AppSec.Enabled, true },
2324
{ ConfigurationKeys.AppSec.ApiSecurityEnabled, true },
2425
{ ConfigurationKeys.AppSec.ApiSecurityEndpointCollectionEnabled, true }
2526
});
@@ -35,6 +36,7 @@ public void GivenConfiguration_WhenApiSecDisabledAndEndpointsCollectionEnabled_I
3536
{
3637
var settings = new CustomSettingsForTests(new Dictionary<string, object>
3738
{
39+
{ ConfigurationKeys.AppSec.Enabled, true },
3840
{ ConfigurationKeys.AppSec.ApiSecurityEnabled, false },
3941
{ ConfigurationKeys.AppSec.ApiSecurityEndpointCollectionEnabled, true }
4042
});
@@ -44,11 +46,25 @@ public void GivenConfiguration_WhenApiSecDisabledAndEndpointsCollectionEnabled_I
4446
apisec.CanCollectEndpoints().Should().BeTrue();
4547
}
4648

49+
[Fact]
50+
public void GivenConfiguration_WhenAppsecDisabled_IsEndpointsNotCollected()
51+
{
52+
var settings = new CustomSettingsForTests(new Dictionary<string, object>
53+
{
54+
{ ConfigurationKeys.AppSec.Enabled, false },
55+
});
56+
var security = new SecuritySettings(settings, NullConfigurationTelemetry.Instance);
57+
var apisec = new ApiSecurity(security);
58+
59+
apisec.CanCollectEndpoints().Should().BeFalse();
60+
}
61+
4762
[Fact]
4863
public void GivenConfiguration_WhenEndpointsCollectionDisabled_IsEndpointsNotCollected()
4964
{
5065
var settings = new CustomSettingsForTests(new Dictionary<string, object>
5166
{
67+
{ ConfigurationKeys.AppSec.Enabled, true },
5268
{ ConfigurationKeys.AppSec.ApiSecurityEndpointCollectionEnabled, false }
5369
});
5470
var security = new SecuritySettings(settings, NullConfigurationTelemetry.Instance);

0 commit comments

Comments
 (0)