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 0da877d
Show file tree
Hide file tree
Showing 2 changed files with 34 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(StringUtil.Loc("ApkAddShadowFailed"));
}
}

useShadowIfAlpine = shadowPreinstalled || userIdIsOutsideAdduserCommandRange;
}

if (isAlpineBasedImage && !userIdIsLarge)
if (isAlpineBasedImage && !useShadowIfAlpine)
{
addGroup = (groupName) => $"addgroup {groupName}";
addGroupWithId = (groupName, groupId) => $"addgroup -g {groupId} {groupName}";
Expand Down
1 change: 1 addition & 0 deletions src/Misc/layoutbin/en-US/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"AgentWithSameNameAlreadyExistInPool": "Pool {0} already contains an agent with name {1}.",
"AllowContainerUserRunDocker": "Allow user '{0}' run any docker command without SUDO.",
"AlreadyConfiguredError": "Cannot configure the agent because it is already configured. To reconfigure the agent, run 'config.cmd remove' or './config.sh remove' first.",
"ApkAddShadowFailed": "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. Check network availability or use a docker image with the 'shadow' package preinstalled.",
"ArgumentNeeded": "'{0}' has to be specified.",
"ArtifactCustomPropertiesNotJson": "Artifact custom properties is not valid JSON: '{0}'",
"ArtifactCustomPropertyInvalid": "Artifact custom properties must be prefixed with 'user-'. Invalid property: '{0}'",
Expand Down

0 comments on commit 0da877d

Please sign in to comment.