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

Added ShellTasksValidation audit action data to issues #4756

Merged
merged 11 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
6 changes: 6 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ public class AgentKnobs
new BuiltInDefaultKnobSource("0"));

// Misc
public static readonly Knob EnableTaskIssueAudit = new Knob(
nameof(EnableTaskIssueAudit),
"When true, enable issue source validation for the task.issue command to prevent extra audit events.",
new RuntimeKnobSource("AZP_ENABLE_TASK_AUDIT_ISSUES"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob EnableIssueSourceValidation = new Knob(
nameof(EnableIssueSourceValidation),
"When true, enable issue source validation for the task.issue command.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Agent.Sdk.Knob;
using Microsoft.TeamFoundation.DistributedTask.WebApi;
using Microsoft.VisualStudio.Services.Agent.Util;
using Microsoft.VisualStudio.Services.Common;

Expand Down Expand Up @@ -132,7 +133,13 @@ public static (bool, Dictionary<string, object>) ValidateInputArguments(
{
if (enableAudit && !enableValidation)
{
context.Warning(StringUtil.Loc("ProcessHandlerInvalidScriptArgs"));
var issue = new Issue
{
Type = IssueType.Warning,
Message = StringUtil.Loc("ProcessHandlerInvalidScriptArgs"),
};
issue.Data.Add("auditAction", "1"); // ShellTasksValidation = 1
KonstantinTyukalov marked this conversation as resolved.
Show resolved Hide resolved
context.AddIssue(issue);
}
if (enableValidation)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Agent.Sdk.Knob;
using Microsoft.TeamFoundation.DistributedTask.WebApi;
using Microsoft.VisualStudio.Services.Agent.Util;
using Newtonsoft.Json;
using System;
Expand Down Expand Up @@ -288,7 +289,13 @@ private void ValidateScriptArgs(

if (!shouldThrow && enableSecureArgumentsAudit)
{
ExecutionContext.Warning(StringUtil.Loc("ProcessHandlerInvalidScriptArgs"));
var issue = new Issue
{
Type = IssueType.Warning,
Message = StringUtil.Loc("ProcessHandlerInvalidScriptArgs"),
};
issue.Data.Add("auditAction", "1"); // ShellTasksValidation = 1
ExecutionContext.AddIssue(issue);
}
}
if (enableTelemetry && telemetry != null)
Expand Down
3 changes: 2 additions & 1 deletion src/Agent.Worker/TaskCommandExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ public void Execute(IExecutionContext context, Command command)
var eventProperties = command.Properties;
var data = command.Data;

if (AgentKnobs.EnableIssueSourceValidation.GetValue(context).AsBoolean())
if (AgentKnobs.EnableIssueSourceValidation.GetValue(context).AsBoolean()
|| AgentKnobs.EnableTaskIssueAudit.GetValue(context).AsBoolean())
{
ProcessIssueSource(context, command);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Agent.Worker/TaskRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ private async Task RunAsyncInternal()
runtimeVariables,
taskDirectory: definition.Directory);

if (AgentKnobs.EnableIssueSourceValidation.GetValue(ExecutionContext).AsBoolean())
if (AgentKnobs.EnableIssueSourceValidation.GetValue(ExecutionContext).AsBoolean()
|| AgentKnobs.EnableTaskIssueAudit.GetValue(ExecutionContext).AsBoolean())
{
if (Task.IsServerOwned.HasValue && Task.IsServerOwned.Value && IsCorrelationIdRequired(handler, definition))
{
Expand Down
Loading