Skip to content

fix(aks-diagnostic): move SAS token off argv to an environment variable - #9883

Open
Calvin S. (calvin197) wants to merge 4 commits into
mainfrom
security/aks-diagnostic-sas-token-env
Open

Calvin S. (calvin197) wants to merge 4 commits into
mainfrom
security/aks-diagnostic-sas-token-env

Conversation

@calvin197

@calvin197 Calvin S. (calvin197) commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

  • Add AKS_DIAGNOSTIC_SAS_TOKEN as the preferred way to provide the diagnostic SAS token, avoiding exposure in the process argv.
  • Retain the original positional token and optional positional file_path, including the existing default behavior.
  • Additive --file-path supports env-only custom paths and explicitly overrides positional file_path.
  • Deliberately add no new stderr warning, so legacy console output remains unchanged.
  • Retain the original named positionals; unused handleArgs is not removed.
  • Upload HTTP/retry logic is unchanged.

Which issue(s) this PR fixes

  • ADO: 37518923 (parent 37518878)

Validation

  • Pinned-main differential tests compare full-script observed upload/file/retry/exit/stdout/stderr behavior exactly with mocked I/O: 18 tests plus 200 Hypothesis examples.
  • Python 3.9/3.12 compatibility jobs passed at the current head.
  • This is not live RP/VM validation; RP adoption is still needed for actual argv exposure reduction.
  • No claim is made that the entire CI passed (VHD/E2E are still running).

The SAS token used to authenticate blob uploads was a required positional
CLI argument, exposing it to any local process able to read this
process's command line (e.g. via /proc/<pid>/cmdline), rather than only
to whoever invoked the script.

Add support for passing it via the AKS_DIAGNOSTIC_SAS_TOKEN environment
variable (preferred, takes precedence when both are set), which does not
appear in argv. The positional CLI argument is kept as a deprecated
fallback for backward compatibility with any existing external callers -
this script is baked onto the VHD standalone (no in-repo caller invokes
it; vhdbuilder/packer/packer_source.sh only copies the file), so there is
no way to enumerate or update every caller in this change. Using it now
prints a warning to stderr pointing at the env var instead.

To make the new optional sas_token positional unambiguous against the
pre-existing optional file_path positional, file_path is now the
--file-path flag rather than a second positional argument (two optional
trailing positionals cannot otherwise be told apart by argparse).

Also removed the unused handleArgs() function: dead code (zero call
sites, confirmed via repo-wide search) that carried the exact same
argv-based SAS token exposure as a legacy positional-args fallback.

No change to the actual upload behavior/HTTP logic.

Verified locally:
  - python3 -m py_compile and pyflakes both pass with no warnings/errors.
  - Manually exercised all argument-resolution paths: missing token (both
    env var and positional absent) now errors with a clear message;
    env-var-only invocation succeeds and the token does not appear in the
    process's argv (checked via ps/cmdline); positional-only invocation
    still works and emits the deprecation warning; when both are set, the
    env var wins and no warning is printed. --help output reviewed for
    correctness.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 350c2577-7031-4d0d-adc1-e99d053fc981
@calvin197
Calvin S. (calvin197) requested review from a team as code owners October 23, 2026 07:50
Copilot AI balanced review requested due to automatic review settings October 23, 2026 07:50
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Windows Unit Test Results

  3 files   21 suites   1m 4s ⏱️
789 tests 789 ✅ 0 💤 0 ❌
815 runs  815 ✅ 0 💤 0 ❌

Results for commit f911184.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

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.

🟡 Changes recommended

Previously supported invocations with a positional custom file path now fail argument parsing, breaking compatibility for external callers.

1 open issue
What changed in this PR

This PR adds an environment-variable option for diagnostic upload credentials, reducing command-line exposure of SAS tokens in the standalone VHD script.

Changes:

  • Prefer AKS_DIAGNOSTIC_SAS_TOKEN, retaining a deprecated positional token fallback.
  • Replace the positional custom file path with --file-path and update usage documentation.
  • Remove the unused handleArgs() function without changing upload HTTP logic.
File Description
parts/​linux/​cloud-init/​artifacts/​aks-diagnostic.py Updates credential resolution, argument parsing, warnings, and usage examples.

Review effort: Balanced

The previous commit converted file_path from a positional argument to
a --file-path flag to resolve an argparse ambiguity with the new
optional sas_token positional. That broke the pre-existing 4-argument
invocation style (container url sas_token file_path), which is a real
regression for any external caller still using it.

Fix properly: capture the trailing sas_token/file_path positionals
together via nargs='*' and resolve them by count after parsing, so
every pre-existing invocation shape - (), (token,), (token, file_path)
- behaves exactly as before. --file-path remains available as the
preferred way to set a custom path when the token itself comes from
the AKS_DIAGNOSTIC_SAS_TOKEN env var (no token positional at all).

Verified locally: re-ran all argument-resolution paths, specifically
including the previously-broken old 4-positional-argument form
(container url token file_path) with a real file on disk, confirming
it resolves file_path correctly and reaches the upload call. Also
re-verified the new env-var + --file-path combination, the "too many
arguments" error path, and that the SAS token still does not appear in
the process's argv when sourced from the environment variable.
python3 -m py_compile and pyflakes both pass with no warnings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 350c2577-7031-4d0d-adc1-e99d053fc981
Copilot AI balanced review requested due to automatic review settings October 23, 2026 08:00

Copilot AI left a comment

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.

🟢 Approval recommended

The scoped changes preserve legacy invocation forms, and focused verification found no blocking issues with token precedence or argument handling.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@calvin197
Calvin S. (calvin197) marked this pull request as draft October 23, 2026 08:04
@cameronmeissner

Copy link
Copy Markdown
Contributor

Calvin S. (@calvin197) we should sync with John on this change - we'll need to update how we invoke this script on the RP side

@calvin197
Calvin S. (calvin197) marked this pull request as ready for review November 3, 2026 18:13
Run both scripts with identical inputs and compare upload requests, file reads, exits, retries and console output. Cover known RP calls and 200 Hypothesis examples, allowing only the existing deprecation warning. Run the compatibility suite in CI on Python 3.9 and 3.12.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 350c2577-7031-4d0d-adc1-e99d053fc981
Copilot AI balanced review requested due to automatic review settings November 10, 2026 02:18

Copilot AI left a comment

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.

🔵 Needs a closer look

An explicitly empty file path now falls back to the default archive instead of failing validation, breaking backward compatibility and risking an unintended upload.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Empty file path silently uploads the default archive

parts/​linux/​cloud-init/​artifacts/​aks-diagnostic.py:104

🟡 Medium Risk — 🔄 Backward Compatibility: An explicitly empty file path (for example, a quoted unset path variable in an existing caller) is now replaced with the default archive. Previously, validation rejected that empty path; where the default logs.zip exists, the same invocation now uploads it instead. Check for None rather than truthiness so an explicitly invalid path still fails instead of silently uploading a different file.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 350c2577-7031-4d0d-adc1-e99d053fc981
Copilot AI balanced review requested due to automatic review settings November 10, 2026 07:50
@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
test 0% ❌
windows 27% ❌
staging_cse_windows Package 1 71% ➖
debug 0% ❌
provisioningscripts 2% ❌
parts_windows Package 1 73% ➖
Summary 39% (1983 / 7220) ❌

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
shellspec spec 30% ❌
Summary 30% (4912 / 16591) ❌

Copilot AI left a comment

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.

🟡 Changes recommended

Positional-token invocations omit the promised deprecation warning, leaving existing callers without notice to move credentials from argv to AKS_DIAGNOSTIC_SAS_TOKEN.

1 open issue

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
github.com/Azure/agentbaker/aks-node-controller 73% ➖
github.com/Azure/agentbaker/aks-node-controller/common 100% ✔
github.com/Azure/agentbaker/aks-node-controller/helpers 68% ➖
github.com/Azure/agentbaker/aks-node-controller/parser 88% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/gpu 100% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils 92% ✔
github.com/Azure/agentbaker/aks-node-controller/utils 0% ❌
github.com/Azure/agentbaker/apiserver 24% ❌
github.com/Azure/agentbaker/cmd 0% ❌
github.com/Azure/agentbaker/cmd/starter 0% ❌
github.com/Azure/agentbaker/fuzz/api 0% ❌
github.com/Azure/agentbaker/hotfix/render-nodecustomdata 35% ❌
github.com/Azure/agentbaker/pkg/agent 79% ➖
github.com/Azure/agentbaker/pkg/agent/datamodel 77% ➖
github.com/Azure/agentbaker/pkg/agent/toggles 0% ❌
github.com/Azure/agentbaker/pkg/vhdbuilder/datamodel 87% ✔
Summary 76% (6093 / 8041) ➖

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues are recorded for the environment-based SAS token change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

3 participants