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

Pull upstream #2178

Merged
merged 22 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
01fd044
Escaping key and quoting it to avoid key based command injection (#2062)
nikola-jokic Aug 23, 2022
cba19c4
Release notes for 2.296.0 (#2078)
AvaStancu Aug 23, 2022
5989479
Validate lines and columns for Annotations (#2082)
konradpabjan Aug 24, 2022
95459de
docker: escape key-value pair as -e KEY and VALUE being environment v…
nikola-jokic Aug 31, 2022
5e0c2ef
2.296.1 Release (#2092) (#2099)
fhammerl Sep 2, 2022
7578675
fix ACTIONS_RUNNER_CONTAINER_HOOKS name in ADR (#2098)
nikola-jokic Sep 6, 2022
ed191b7
Port hotfix to main branch (#2108)
thboop Sep 9, 2022
6e6410d
fix for issue #2009 - composite summary file (#2077)
ruvceskistefan Sep 12, 2022
32845a5
Bump @actions/core from 1.2.6 to 1.9.1 in /src/Misc/expressionFunc/ha…
rentziass Sep 15, 2022
6cdd272
Remove unused imports (#2124)
JoannaaKL Sep 15, 2022
3a1c897
Remove unused imports (#2126)
JoannaaKL Sep 15, 2022
0678e8d
Add Release branches to pull request spec (#2134)
thboop Sep 19, 2022
15cbadb
Add file commands for save-state and set-output (#2118)
rentziass Sep 26, 2022
ae2f4a6
POC: Windows arm64 runner build (#2022)
thboop Sep 26, 2022
bc67f99
Add link to blog post to node 12 warn (#2156)
takost Sep 26, 2022
01ff38f
2.297.0 release notes (#2155)
thboop Sep 26, 2022
dca4f67
Adding a new vars context for non-secret variables (#2096)
tauhid621 Sep 30, 2022
9492691
Avastancu/joannaakl/service container error log (#2110)
JoannaaKL Oct 3, 2022
920fba9
Add warning for users using deprecated commands (#2164)
rentziass Oct 4, 2022
4935be5
Prepare release notes for v2.298.0 (#2169)
rentziass Oct 4, 2022
1379ed2
Fix incorrect template vars to show SHA for WIN-ARM64 (#2171)
fhammerl Oct 4, 2022
86d0ee8
Backport 2.298.1 (#2175)
fhammerl Oct 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docker: escape key-value pair as -e KEY and VALUE being environment v…
…ar (#2091)

* docker: escape key-value pair as -e KEY and VALUE being environment var

* removed code duplication, removed unused method and test
  • Loading branch information
nikola-jokic authored Aug 31, 2022
commit 95459dea5f9a131ec084e2e2b53e8c87f61db81e
13 changes: 10 additions & 3 deletions src/Runner.Worker/Container/DockerCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public async Task<int> DockerBuild(IExecutionContext context, string workingDire
public async Task<string> DockerCreate(IExecutionContext context, ContainerInfo container)
{
IList<string> dockerOptions = new List<string>();
IDictionary<string, string> environment = new Dictionary<string, string>();
// OPTIONS
dockerOptions.Add($"--name {container.ContainerDisplayName}");
dockerOptions.Add($"--label {DockerInstanceLabel}");
Expand Down Expand Up @@ -135,7 +136,8 @@ public async Task<string> DockerCreate(IExecutionContext context, ContainerInfo
}
else
{
dockerOptions.Add(DockerUtil.CreateEscapedOption("-e", env.Key, env.Value));
environment.Add(env.Key, env.Value);
dockerOptions.Add(DockerUtil.CreateEscapedOption("-e", env.Key));
}
}

Expand Down Expand Up @@ -183,7 +185,7 @@ public async Task<string> DockerCreate(IExecutionContext context, ContainerInfo
dockerOptions.Add($"{container.ContainerEntryPointArgs}");

var optionsString = string.Join(" ", dockerOptions);
List<string> outputStrings = await ExecuteDockerCommandAsync(context, "create", optionsString);
List<string> outputStrings = await ExecuteDockerCommandAsync(context, "create", optionsString, environment);

return outputStrings.FirstOrDefault();
}
Expand Down Expand Up @@ -443,6 +445,11 @@ public Task<int> DockerLogin(IExecutionContext context, string configFileDirecto
}

private async Task<List<string>> ExecuteDockerCommandAsync(IExecutionContext context, string command, string options)
{
return await ExecuteDockerCommandAsync(context, command, options, null);
}

private async Task<List<string>> ExecuteDockerCommandAsync(IExecutionContext context, string command, string options, IDictionary<string, string> environment)
{
string arg = $"{command} {options}".Trim();
context.Command($"{DockerPath} {arg}");
Expand Down Expand Up @@ -470,7 +477,7 @@ await processInvoker.ExecuteAsync(
workingDirectory: context.GetGitHubContext("workspace"),
fileName: DockerPath,
arguments: arg,
environment: null,
environment: environment,
requireExitCodeZero: true,
outputEncoding: null,
cancellationToken: CancellationToken.None);
Expand Down
9 changes: 0 additions & 9 deletions src/Runner.Worker/Container/DockerUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ public static string CreateEscapedOption(string flag, string key)
return $"{flag} \"{EscapeString(key)}\"";
}

public static string CreateEscapedOption(string flag, string key, string value)
{
if (String.IsNullOrEmpty(key))
{
return "";
}
return $"{flag} \"{EscapeString(key)}={EscapeString(value)}\"";
}

private static string EscapeString(string value)
{
return value.Replace("\\", "\\\\").Replace("\"", "\\\"");
Expand Down
27 changes: 0 additions & 27 deletions src/Test/L0/Container/DockerUtilL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,5 @@ public void CreateEscapedOption_keyOnly(string input, string escaped)
}
Assert.Equal(expected, actual);
}

[Theory]
[Trait("Level", "L0")]
[Trait("Category", "Worker")]
[InlineData("HOME", "", "HOME", "")]
[InlineData("HOME alpine:3.8 sh -c id #", "HOME alpine:3.8 sh -c id #", "HOME alpine:3.8 sh -c id #", "HOME alpine:3.8 sh -c id #")]
[InlineData("HOME \"alpine:3.8 sh -c id #", "HOME \"alpine:3.8 sh -c id #", "HOME \\\"alpine:3.8 sh -c id #", "HOME \\\"alpine:3.8 sh -c id #")]
[InlineData("HOME \\\"alpine:3.8 sh -c id #", "HOME \\\"alpine:3.8 sh -c id #", "HOME \\\\\\\"alpine:3.8 sh -c id #", "HOME \\\\\\\"alpine:3.8 sh -c id #")]
[InlineData("HOME \\\\\"alpine:3.8 sh -c id #", "HOME \\\\\"alpine:3.8 sh -c id #", "HOME \\\\\\\\\\\"alpine:3.8 sh -c id #", "HOME \\\\\\\\\\\"alpine:3.8 sh -c id #")]
[InlineData("HOME \"\"alpine:3.8 sh -c id #", "HOME \"\"alpine:3.8 sh -c id #", "HOME \\\"\\\"alpine:3.8 sh -c id #", "HOME \\\"\\\"alpine:3.8 sh -c id #")]
[InlineData("HOME \\\"\"alpine:3.8 sh -c id #", "HOME \\\"\"alpine:3.8 sh -c id #", "HOME \\\\\\\"\\\"alpine:3.8 sh -c id #", "HOME \\\\\\\"\\\"alpine:3.8 sh -c id #")]
[InlineData("HOME \"\\\"alpine:3.8 sh -c id #", "HOME \"\\\"alpine:3.8 sh -c id #", "HOME \\\"\\\\\\\"alpine:3.8 sh -c id #", "HOME \\\"\\\\\\\"alpine:3.8 sh -c id #")]
public void CreateEscapedOption_keyValue(string keyInput, string valueInput, string escapedKey, string escapedValue)
{
var flag = "--example";
var actual = DockerUtil.CreateEscapedOption(flag, keyInput, valueInput);
string expected;
if (String.IsNullOrEmpty(keyInput))
{
expected = "";
}
else
{
expected = $"{flag} \"{escapedKey}={escapedValue}\"";
}
Assert.Equal(expected, actual);
}
}
}