Skip to content

Commit 309e97f

Browse files
committed
Add warning for DOTNET_EnableDiagnostics=0 or COMPlus_EnableDiagnostics=0
For .NET 8.0+ DOTNET_EnableDiagnostics=0 disables profiling, but we can't just set this to 1 because it breaks read-only containers for older versions of .NET so we log a warning instead.
1 parent f9b36b6 commit 309e97f

File tree

1 file changed

+13
-2
lines changed
  • src/Contrast.K8s.AgentOperator/Core/Reactions/Injecting/Patching/Agents

1 file changed

+13
-2
lines changed

src/Contrast.K8s.AgentOperator/Core/Reactions/Injecting/Patching/Agents/DotNetPatcher.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Contrast Security, Inc licenses this file to you under the Apache 2.0 License.
22
// See the LICENSE file in the project root for more information.
33

4-
using System;
5-
using System.Collections.Generic;
64
using Contrast.K8s.AgentOperator.Core.Reactions.Injecting.Patching.Utility;
75
using Contrast.K8s.AgentOperator.Core.State.Resources.Primitives;
86
using Contrast.K8s.AgentOperator.Options;
97
using k8s.Models;
8+
using NLog;
9+
using System;
10+
using System.Collections.Generic;
1011

1112
namespace Contrast.K8s.AgentOperator.Core.Reactions.Injecting.Patching.Agents;
1213

@@ -15,6 +16,8 @@ public class DotNetAgentPatcher : IAgentPatcher
1516
private readonly InjectorOptions _injectorOptions;
1617
public AgentInjectionType Type => AgentInjectionType.DotNetCore;
1718

19+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
20+
1821
public DotNetAgentPatcher(InjectorOptions injectorOptions)
1922
{
2023
_injectorOptions = injectorOptions;
@@ -44,6 +47,14 @@ public IEnumerable<V1EnvVar> GenerateEnvVars(PatchingContext context)
4447

4548
public void PatchContainer(V1Container container, PatchingContext context)
4649
{
50+
//Log a warning if we detect DOTNET_EnableDiagnostics=0 or COMPlus_EnableDiagnostics=0
51+
//We cant patch these to enable them because it will break a .NET 6.0 read-only container because it will attempt to create the IPC socket
52+
if (container.Env.FirstOrDefault("DOTNET_EnableDiagnostics")?.Value == "0" ||
53+
container.Env.FirstOrDefault("COMPlus_EnableDiagnostics")?.Value == "0")
54+
{
55+
Logger.Warn($"Detected 'DOTNET_EnableDiagnostics=0' or 'COMPlus_EnableDiagnostics=0' environment variable on '{context.WorkloadNamespace}/{context.WorkloadName}', dotnet-core agent may not attach correctly.");
56+
}
57+
4758
// This assumes this patch occurs after our generic patches.
4859
// Either the users sets this on the pod manually, or we set it from our config file.
4960
// We also assume the default is true.

0 commit comments

Comments
 (0)