Skip to content

Commit ff8e9f4

Browse files
committed
Merge 'main' into release branch
2 parents 24845a5 + c18c874 commit ff8e9f4

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

releaseNote.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Features
2-
- Allow registry credentials for job/service containers (#694)
2+
- Expose retention days in env for toolkit/artifacts package (#714)
3+
- Notify on unsecure commands (#731)
34

45
## Bugs
56
- N/A

src/Runner.Common/Constants.cs

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ public static class ReturnCode
140140

141141
public static readonly string InternalTelemetryIssueDataKey = "_internal_telemetry";
142142
public static readonly string WorkerCrash = "WORKER_CRASH";
143+
public static readonly string UnsupportedCommand = "UNSUPPORTED_COMMAND";
144+
public static readonly string UnsupportedCommandMessage = "The `{0}` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/";
145+
public static readonly string UnsupportedCommandMessageDisabled = "The `{0}` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/";
143146
}
144147

145148
public static class RunnerEvent
@@ -198,6 +201,7 @@ public static class Actions
198201
//
199202
// Keep alphabetical
200203
//
204+
public static readonly string AllowUnsupportedCommands = "ACTIONS_ALLOW_UNSECURE_COMMANDS";
201205
public static readonly string RunnerDebug = "ACTIONS_RUNNER_DEBUG";
202206
public static readonly string StepDebug = "ACTIONS_STEP_DEBUG";
203207
}

src/Runner.Worker/ActionCommandManager.cs

+69
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using GitHub.DistributedTask.Pipelines;
2+
using GitHub.DistributedTask.Pipelines.ContextData;
23
using GitHub.DistributedTask.WebApi;
34
using GitHub.Runner.Common.Util;
45
using GitHub.Runner.Worker.Container;
@@ -183,6 +184,40 @@ public sealed class SetEnvCommandExtension : RunnerService, IActionCommandExtens
183184

184185
public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container)
185186
{
187+
var configurationStore = HostContext.GetService<IConfigurationStore>();
188+
var isHostedServer = configurationStore.GetSettings().IsHostedServer;
189+
190+
var allowUnsecureCommands = false;
191+
bool.TryParse(Environment.GetEnvironmentVariable(Constants.Variables.Actions.AllowUnsupportedCommands), out allowUnsecureCommands);
192+
193+
// Apply environment from env context, env context contains job level env and action's env block
194+
#if OS_WINDOWS
195+
var envContext = context.ExpressionValues["env"] as DictionaryContextData;
196+
#else
197+
var envContext = context.ExpressionValues["env"] as CaseSensitiveDictionaryContextData;
198+
#endif
199+
if (!allowUnsecureCommands && envContext.ContainsKey(Constants.Variables.Actions.AllowUnsupportedCommands))
200+
{
201+
bool.TryParse(envContext[Constants.Variables.Actions.AllowUnsupportedCommands].ToString(), out allowUnsecureCommands);
202+
}
203+
204+
// TODO: Eventually remove isHostedServer and apply this to dotcom customers as well
205+
if (!isHostedServer && !allowUnsecureCommands)
206+
{
207+
throw new Exception(String.Format(Constants.Runner.UnsupportedCommandMessageDisabled, this.Command));
208+
}
209+
else if (!allowUnsecureCommands)
210+
{
211+
// Log Telemetry and let user know they shouldn't do this
212+
var issue = new Issue()
213+
{
214+
Type = IssueType.Warning,
215+
Message = String.Format(Constants.Runner.UnsupportedCommandMessage, this.Command)
216+
};
217+
issue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = Constants.Runner.UnsupportedCommand;
218+
context.AddIssue(issue);
219+
}
220+
186221
if (!command.Properties.TryGetValue(SetEnvCommandProperties.Name, out string envName) || string.IsNullOrEmpty(envName))
187222
{
188223
throw new Exception("Required field 'name' is missing in ##[set-env] command.");
@@ -282,6 +317,40 @@ public sealed class AddPathCommandExtension : RunnerService, IActionCommandExten
282317

283318
public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container)
284319
{
320+
var configurationStore = HostContext.GetService<IConfigurationStore>();
321+
var isHostedServer = configurationStore.GetSettings().IsHostedServer;
322+
323+
var allowUnsecureCommands = false;
324+
bool.TryParse(Environment.GetEnvironmentVariable(Constants.Variables.Actions.AllowUnsupportedCommands), out allowUnsecureCommands);
325+
326+
// Apply environment from env context, env context contains job level env and action's env block
327+
#if OS_WINDOWS
328+
var envContext = context.ExpressionValues["env"] as DictionaryContextData;
329+
#else
330+
var envContext = context.ExpressionValues["env"] as CaseSensitiveDictionaryContextData;
331+
#endif
332+
if (!allowUnsecureCommands && envContext.ContainsKey(Constants.Variables.Actions.AllowUnsupportedCommands))
333+
{
334+
bool.TryParse(envContext[Constants.Variables.Actions.AllowUnsupportedCommands].ToString(), out allowUnsecureCommands);
335+
}
336+
337+
// TODO: Eventually remove isHostedServer and apply this to dotcom customers as well
338+
if (!isHostedServer && !allowUnsecureCommands)
339+
{
340+
throw new Exception(String.Format(Constants.Runner.UnsupportedCommandMessageDisabled, this.Command));
341+
}
342+
else if (!allowUnsecureCommands)
343+
{
344+
// Log Telemetry and let user know they shouldn't do this
345+
var issue = new Issue()
346+
{
347+
Type = IssueType.Warning,
348+
Message = String.Format(Constants.Runner.UnsupportedCommandMessage, this.Command)
349+
};
350+
issue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = Constants.Runner.UnsupportedCommand;
351+
context.AddIssue(issue);
352+
}
353+
285354
ArgUtil.NotNullOrEmpty(command.Data, "path");
286355
context.Global.PrependPath.RemoveAll(x => string.Equals(x, command.Data, StringComparison.CurrentCulture));
287356
context.Global.PrependPath.Add(command.Data);

src/Runner.Worker/GitHubContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public sealed class GitHubContext : DictionaryContextData, IEnvironmentContextDa
2323
"ref",
2424
"repository",
2525
"repository_owner",
26+
"retention_days",
2627
"run_id",
2728
"run_number",
2829
"server_url",

src/runnerversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.273.4
1+
2.273.5

0 commit comments

Comments
 (0)