Skip to content

Harden mysql client execution for AzureMysqlDeploymentV2 task - #22484

Open
Gayatri Jaiswal (v-gayatrij) wants to merge 26 commits into
masterfrom
users/v-gayjaiswal/AzureMySqlDeployment-msrc-fix
Open

Gayatri Jaiswal (v-gayatrij) wants to merge 26 commits into
masterfrom
users/v-gayjaiswal/AzureMySqlDeployment-msrc-fix

Conversation

@v-gayatrij

@v-gayatrij Gayatri Jaiswal (v-gayatrij) commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Context

Associated WI: AB#2459100


Task Name

AzureMysqlDeploymentV2


Description

This PR adds the --binary-mode flag to every mysql client invocation performed by the task (both inline -e execution and file/stdin-based script execution). This causes the client to treat script content strictly as SQL, disabling client-side meta-commands.

The flag is applied unconditionally by the task and cannot be overridden or disabled via any task input — user-supplied additional arguments are appended before the enforced flag, so the secure behavior always takes effect regardless of what a script or caller attempts to pass.

No changes were made to how ordinary SQL (including quoted string literals, SQL comments,
and DELIMITER-based multi-statement definitions) is parsed or executed.


Risk Assessment (Low / Medium / High)

Low


Change Behind Feature Flag (Yes / No)

No


Tech Design / Approach

  • Design has been written and reviewed.
  • Any architectural decisions, trade-offs, and alternatives are captured.

Documentation Changes Required (Yes/No)

Indicate whether related documentation needs to be updated.

  • User guides, API specs, system diagrams, or runbooks are updated.

Unit Tests Added or Updated (Yes / No)

Yes


Additional Testing Performed

Manual regression + security validation performed on test organization

  • Confirmed the hardening flag is present on every mysql client invocation the task performs (both inline execute and file/stdin execution paths), on Windows and Linux agents.
  • Verified multiple categories of client-side meta-command usage.
  • Verified the flag cannot be disabled via cannot be overridden or disabled via any task input — user-supplied additional arguments are appended before the enforced flag,
  • Verified full backward compatibility for legitimate SQL content: quoted string literals (including Windows-style file paths), SQL comments, and DELIMITER-based multi-statement scripts (e.g., trigger/procedure definitions) all continue to execute successfully and unmodified.
  • No regressions observed in ordinary task functionality across all scenarios tested.

Logging Added/Updated (Yes/No)

  • Appropriate log statements are added with meaningful messages.
  • Logging does not expose sensitive data.
  • Log levels are used correctly (e.g., info, warn, error).

Telemetry Added/Updated (Yes/No)

  • Custom telemetry (e.g., counters, timers, error tracking) is added as needed.
  • Events are tagged with proper metadata for filtering and analysis.
  • Telemetry is validated in staging or test environments.

Rollback Scenario and Process (Yes/No)

  • Rollback plan is documented.

Dependency Impact Assessed and Regression Tested (Yes/No)

Yes. Only the task's own invocation of the mysql client is affected; no other task, module, or shared package is impacted. Minimum supported mysql client version confirmed to support the flag used.


Checklist

  • Related issue linked (if applicable)
  • Task version was bumped — see versioning guide
  • Verified the task behaves as expected

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@v-gayatrij Gayatri Jaiswal (v-gayatrij) changed the title Harden mysql client execution Harden mysql client execution for AzureMysqlDeploymentV2 task Sep 8, 2026
@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

Comment thread Tasks/AzureMysqlDeploymentV2/sql/MysqlClient.ts Outdated
@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

/**
* Reject a bare "--" token in user-supplied additional arguments, which
* is not a supported value for this input and could interfere with
* enforced security options. See internal security tracking for details.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep public source comments neutral and remove the reference to internal security tracking. This can describe the validation as preventing unsupported arguments from interfering with task-managed client options without exposing private tracking context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated comment

@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

return;
}
const tokens = Utility.argStringToArray(additionalArguments);
if (tokens.some(token => token === '--')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- is not the only additional argument that can negate the task-managed behavior here. Beginning with MySQL 8.4.6, --commands can re-enable client commands even when --binary-mode is set. Because this validation still permits command-enabling forms such as --commands and --commands=ON, the intended restriction is not guaranteed on those clients. Please reject those forms as well and add a file-execution regression test.

@v-gayatrij Gayatri Jaiswal (v-gayatrij) Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added commands options to rejection list and file-execution regression test

@v-gayatrij

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

*/
private _validateAdditionalArguments(additionalArguments: string): void {
for (const token of Utility.argStringToArray(additionalArguments)) {
const optionName = token.split('=', 1)[0].toLowerCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL accepts unambiguous prefixes for long options, so --command=ON is resolved as --commands=ON. Here, however, optionName remains --command, which is not in the exact-name set, so the task-managed behavior can still be overridden. Please reject spellings that MySQL resolves to --commands (including valid abbreviations) and add a regression test for --command=ON.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per this, commands option cannot enable client commands when --binary-mode is set.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants