Closed alexmg closed 3 hours ago
This should fix it https://github.com/microsoft/kernel-memory/pull/852
Thanks @dluc. I started a PR and have some unit tests if you're interested in adding those.
public sealed class SensitiveDataLoggerTests : IDisposable
{
private const string EnvironmentVariableName = "ASPNETCORE_ENVIRONMENT";
[Fact]
[Trait("Category", "UnitTest")]
public void ItCanBeEnabledInDevelopmentEnvironment()
{
Environment.SetEnvironmentVariable(EnvironmentVariableName, "Development");
SensitiveDataLogger.Enabled = true;
Assert.True(SensitiveDataLogger.Enabled);
}
[Theory]
[InlineData("Staging")]
[InlineData("Production")]
[Trait("Category", "UnitTest")]
public void ItCannotBeEnabledInNonDevelopmentEnvironments(string environment)
{
Environment.SetEnvironmentVariable(EnvironmentVariableName, environment);
Assert.Throws<ApplicationException>(() => SensitiveDataLogger.Enabled = true);
}
[Theory]
[InlineData("Development")]
[InlineData("Staging")]
[InlineData("Production")]
[Trait("Category", "UnitTest")]
public void ItCanBeDisabledForAllEnvironments(string environment)
{
Environment.SetEnvironmentVariable(EnvironmentVariableName, environment);
SensitiveDataLogger.Enabled = false;
Assert.False(SensitiveDataLogger.Enabled);
}
public void Dispose() => Environment.SetEnvironmentVariable(EnvironmentVariableName, null);
}
Unit tests welcome :-) Release with the fix in progress
I will open a PR with the additional unit tests.
Should be fixed in 0.90.241021.1, could you confirm?
Thanks!!
I can confirm this is now fixed. 👍
Thank you for the quick turnaround on the fix @dluc!
Context / Scenario
Starting from tag
0.80.241017.2
the service cannot be started in a Docker container when theASPNETCORE_ENVIRONMENT
environment variable is to anything other thanDevelopment
.What happened?
The exception below is thrown as soon as the service starts.
This is a result of a recent change to disable sensitive logging as the very first line of code during startup.
The
SensitiveDataLogger
will throw an exception when the property setter is called unless the environmentDevelopment
. This occurs regardless of the value the property is being set to. Because the container image runs using theProduction
environment (as it should) the exception is thrown, and the service fails to start.Importance
I cannot use Kernel Memory
Platform, Language, Versions
Docker image:
kernelmemory/service:0.80.241017.2
Relevant log output
No response