|
1 | 1 | using GitHub.DistributedTask.Pipelines;
|
| 2 | +using GitHub.DistributedTask.Pipelines.ContextData; |
2 | 3 | using GitHub.DistributedTask.WebApi;
|
3 | 4 | using GitHub.Runner.Common.Util;
|
4 | 5 | using GitHub.Runner.Worker.Container;
|
@@ -183,6 +184,40 @@ public sealed class SetEnvCommandExtension : RunnerService, IActionCommandExtens
|
183 | 184 |
|
184 | 185 | public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container)
|
185 | 186 | {
|
| 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 | + |
186 | 221 | if (!command.Properties.TryGetValue(SetEnvCommandProperties.Name, out string envName) || string.IsNullOrEmpty(envName))
|
187 | 222 | {
|
188 | 223 | throw new Exception("Required field 'name' is missing in ##[set-env] command.");
|
@@ -282,6 +317,40 @@ public sealed class AddPathCommandExtension : RunnerService, IActionCommandExten
|
282 | 317 |
|
283 | 318 | public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container)
|
284 | 319 | {
|
| 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 | + |
285 | 354 | ArgUtil.NotNullOrEmpty(command.Data, "path");
|
286 | 355 | context.Global.PrependPath.RemoveAll(x => string.Equals(x, command.Data, StringComparison.CurrentCulture));
|
287 | 356 | context.Global.PrependPath.Add(command.Data);
|
|
0 commit comments