-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: mask sensitive log data (#290)
* chore: mask sensitive log data Refs: CPLP-3255 --------- Co-authored-by: Norbert Truchsess <[email protected]> Reviewed-by: Norbert Truchsess <[email protected]>
- Loading branch information
Showing
8 changed files
with
228 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
<!-- | ||
- Copyright (c) 2021, 2023 BMW Group AG | ||
- Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
- | ||
- See the NOTICE file(s) distributed with this work for additional | ||
- information regarding copyright ownership. | ||
- | ||
- This program and the accompanying materials are made available under the | ||
- terms of the Apache License, Version 2.0 which is available at | ||
- https://www.apache.org/licenses/LICENSE-2.0. | ||
- | ||
- Unless required by applicable law or agreed to in writing, software | ||
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
- License for the specific language governing permissions and limitations | ||
- under the License. | ||
- | ||
- SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Framework.Logging</AssemblyName> | ||
<RootNamespace>Org.Eclipse.TractusX.Portal.Backend.Framework.Logging</RootNamespace> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" /> | ||
<PackageReference Include="Serilog" Version="3.0.1" /> | ||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" /> | ||
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.2" /> | ||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" /> | ||
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" /> | ||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<!-- | ||
- Copyright (c) 2021, 2023 BMW Group AG | ||
- Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
- | ||
- See the NOTICE file(s) distributed with this work for additional | ||
- information regarding copyright ownership. | ||
- | ||
- This program and the accompanying materials are made available under the | ||
- terms of the Apache License, Version 2.0 which is available at | ||
- https://www.apache.org/licenses/LICENSE-2.0. | ||
- | ||
- Unless required by applicable law or agreed to in writing, software | ||
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
- License for the specific language governing permissions and limitations | ||
- under the License. | ||
- | ||
- SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Framework.Logging</AssemblyName> | ||
<RootNamespace>Org.Eclipse.TractusX.Portal.Backend.Framework.Logging</RootNamespace> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" /> | ||
<PackageReference Include="Serilog" Version="3.0.1" /> | ||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" /> | ||
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.2" /> | ||
<PackageReference Include="Serilog.Enrichers.Sensitive" Version="1.7.3" /> | ||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" /> | ||
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" /> | ||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/framework/Framework.Logging/MaskingOperator/SecretOperator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Serilog.Enrichers.Sensitive; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Logging.MaskingOperator; | ||
|
||
public class SecretOperator : RegexMaskingOperator | ||
{ | ||
private const string SecretPattern = "(secret|password)=(.*?)&"; | ||
|
||
public SecretOperator() | ||
: base(SecretPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled) | ||
{ | ||
} | ||
|
||
protected override string PreprocessMask(string mask, Match match) => $"{match.Groups[1]}={mask}&"; | ||
|
||
protected override bool ShouldMaskInput(string input) => input.Contains("secret=", StringComparison.InvariantCultureIgnoreCase) || input.Contains("password=", StringComparison.InvariantCultureIgnoreCase); | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/framework/Framework.Logging.Tests/Framework.Logging.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!-- | ||
- Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
- | ||
- See the NOTICE file(s) distributed with this work for additional | ||
- information regarding copyright ownership. | ||
- | ||
- This program and the accompanying materials are made available under the | ||
- terms of the Apache License, Version 2.0 which is available at | ||
- https://www.apache.org/licenses/LICENSE-2.0. | ||
- | ||
- Unless required by applicable law or agreed to in writing, software | ||
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
- License for the specific language governing permissions and limitations | ||
- under the License. | ||
- | ||
- SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AssemblyName>Org.Eclipse.TractusX.Portal.Backend.Framework.Logging.Tests</AssemblyName> | ||
<RootNamespace>Org.Eclipse.TractusX.Portal.Backend.Framework.Logging.Tests</RootNamespace> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AutoFixture.AutoFakeItEasy" Version="4.18.0" /> | ||
<PackageReference Include="FakeItEasy" Version="7.4.0" /> | ||
<PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" /> | ||
<PackageReference Include="xunit" Version="2.5.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\framework\Framework.Logging\Framework.Logging.csproj" /> | ||
<ProjectReference Include="..\..\shared\Tests.Shared\Tests.Shared.csproj" /> | ||
</ItemGroup> | ||
</Project> |
46 changes: 46 additions & 0 deletions
46
tests/framework/Framework.Logging.Tests/SecretOperatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.Framework.Logging.MaskingOperator; | ||
using Serilog.Enrichers.Sensitive; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Logging.Tests; | ||
|
||
public class SecretOperatorTests | ||
{ | ||
[Theory] | ||
[InlineData("foobarsecret=1234&deadbeef", "foobarsecret=****&deadbeef", true)] | ||
[InlineData("foobarpassword=1234&deadbeef", "foobarpassword=****&deadbeef", true)] | ||
[InlineData("foobarSecret=1234&deadbeefPassword=5678&", "foobarSecret=****&deadbeefPassword=****&", true)] | ||
[InlineData("foobarpasssword=1234&deadbeef", null, false)] | ||
public void Mask_ReturnsExpected(string input, string matchResult, bool match) | ||
{ | ||
//Arrange | ||
var sut = new SecretOperator(); | ||
|
||
//Act | ||
var result = sut.Mask(input, "****"); | ||
|
||
//Assert | ||
result.Should().Match<MaskingResult>(x => | ||
x.Match == match && | ||
x.Result == matchResult | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
global using AutoFixture; | ||
global using AutoFixture.AutoFakeItEasy; | ||
global using FakeItEasy; | ||
global using FluentAssertions; | ||
global using Xunit; |