Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisRumyantsev committed Jun 19, 2024
1 parent ca4875a commit 08175aa
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/Agent.Worker/ContainerOperationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,43 @@ private async Task StartContainerAsync(IExecutionContext executionContext, Conta
Func<string, string, string, string> addUserWithIdAndGroup;
Func<string, string, string> addUserToGroup;

bool userIdIsLarge = Int64.Parse(container.CurrentUserId) > 256000;
bool useShadowIfAlpine = false;

if (isAlpineBasedImage && userIdIsLarge)
if (isAlpineBasedImage)
{
await DockerExec(executionContext, container.ContainerId, "apk add shadow");
List<string> shadowInfoOutput = await DockerExec(executionContext, container.ContainerId, "apk list --installed | grep shadow");
bool shadowPreinstalled = false;

foreach (string shadowInfoLine in shadowInfoOutput)
{
if (shadowInfoLine.Contains("{shadow}", StringComparison.Ordinal))
{
Trace.Info("The 'shadow' package is preinstalled and therefore will be used.");
shadowPreinstalled = true;
break;
}
}

bool userIdIsOutsideAdduserCommandRange = Int64.Parse(container.CurrentUserId) > 256000;

if (userIdIsOutsideAdduserCommandRange && !shadowPreinstalled)
{
Trace.Info("User ID is outside the range of the 'adduser' command, therefore the 'shadow' package will be installed and used.");

try
{
await DockerExec(executionContext, container.ContainerId, "apk add shadow");
}
catch (InvalidOperationException)
{
throw new InvalidOperationException("The user ID is outside the range of the 'adduser' command. The alternative command 'useradd' cannot be used because the 'shadow' package is not preinstalled and it is not possible to install it.");
}
}

useShadowIfAlpine = shadowPreinstalled || userIdIsOutsideAdduserCommandRange;
}

if (isAlpineBasedImage && !userIdIsLarge)
if (isAlpineBasedImage && !useShadowIfAlpine)
{
addGroup = (groupName) => $"addgroup {groupName}";
addGroupWithId = (groupName, groupId) => $"addgroup -g {groupId} {groupName}";
Expand Down

0 comments on commit 08175aa

Please sign in to comment.