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

Default the ContainerUser to rootless users on .NET 8 and above #393

Merged
merged 3 commits into from
Mar 21, 2023

Conversation

baronfel
Copy link
Member

Fix #373

Defaults the ContainerUser to platform-specific non-root users when targeting .NET 8 and above.

@@ -19,6 +19,8 @@ public class CapturingLogger : ILogger
private List<BuildErrorEventArgs> _errors = new();
public IReadOnlyList<BuildErrorEventArgs> Errors {get { return _errors; } }

public List<string> AllMessages => Errors.Select(e => e.Message!).Concat(Warnings.Select(w => w.Message!)).Concat(Messages.Select(m => m.Message!)).ToList();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this as a helper while debugging tests.

@@ -16,12 +16,13 @@ public class ParseContainerPropertiesTests
[DockerDaemonAvailableFact]
public void Baseline()
{
var (project, _) = ProjectInitializer.InitProject(new () {
var (project, _, d) = ProjectInitializer.InitProject(new () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to dispose the ProjectCollection to ensure that the binlogs get written, again to help with debugging.

{
["NETCoreSdkVersion"] = sdkVersion,
["_TargetFrameworkVersionWithoutV"] = tfm,
["TargetFrameworkVersion"] = tfm,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the ProjectInitializer to use TFM instead of the private property, and 'generate' the private property as part of the method call. This seemed less surprising.

Comment on lines +160 to +165
[InlineData("v8.0", "linux-x64", "64198")]
[InlineData("v8.0", "win-x64", "ContainerUser")]
[InlineData("v7.0", "linux-x64", null)]
[InlineData("v7.0", "win-x64", null)]
[InlineData("v9.0", "linux-x64", "64198")]
[InlineData("v9.0", "win-x64", "ContainerUser")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our boundary conditions are:

  • 2 OS's
  • 3 ranges - less than 8.0, 8.0 exactly, and greater than 8.0

So these 6 tests should cover all permutations.

@@ -11,6 +11,7 @@
OR $(NETCoreSdkVersion.Contains('-')) == false
)
)">true</_IsSDKContainerAllowedVersion>
<_ContainerIsTargetingNet8TFM>$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0'))</_ContainerIsTargetingNet8TFM>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few private properties to make conditions read a bit easier.

@baronfel baronfel requested a review from a team March 17, 2023 18:56
Copy link
Member

@vlada-shubina vlada-shubina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Do we have an e2e test to cover this scenario?

@baronfel
Copy link
Member Author

@vlada-shubina added one now - but it introduced a bit of noise as I had to make some code changes to make analyzers in .NET 8 happy.

@baronfel
Copy link
Member Author

Correction - I was able to write one locally but it would require us to move to a .NET 8 SDK - I'm not sure that we want to do this. The test build a net8.0 MinimalTestApp, set the user to app, and then ran the container with docker run to ensure everything still worked (which it did).

@baronfel baronfel merged commit 1628927 into main Mar 21, 2023
@baronfel baronfel deleted the dotnet-8-container-user branch March 21, 2023 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default .NET 8 container images to use the app user
2 participants