alibabacloud-sas-multiaccount-manage
Original:🇺🇸 English
Translated
4 scripts
Manage multiple Alibaba Cloud accounts and batch-export Security Center (SAS) baseline and vulnerability reports via the aliyun CLI and Python scripts. Supports account list refresh, enable/disable, concurrent batch export of cloud platform configuration check (baselineCspm), system baseline risk (exportHcWarning), Linux/Windows/application/emergency vulnerability results across all managed accounts. Use this skill when users need to manage SAS multi-account settings, export baseline or vulnerability compliance data, or merge multi-account security reports into a single file.
11installs
Added on
NPX Install
npx skill4agent add aliyun/alibabacloud-aiops-skills alibabacloud-sas-multiaccount-manageTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Alibaba Cloud Security Center Multi-Account Management and Baseline Report Export
Use aliyun CLI and Python scripts to manage multiple Alibaba Cloud accounts in a resource directory and batch-export Security Center baseline reports for each account.
Prerequisites and Environment Setup
1. Install Alibaba Cloud CLI
bash
# macOS
brew install aliyun-cli
# Or download from GitHub: https://github.com/aliyun/aliyun-cli/releasesCheck credentials:
bash
aliyun sts get-caller-identityIf the call fails, instruct the user to run and set up credentials (interactive step, must be completed by the user).
aliyun configure1.1 Configure AI mode and plugin mode (required)
This skill requires aliyun CLI plugin mode commands (kebab-case) and a fixed User-Agent declaration.
bash
# Keep plugins up to date
aliyun plugin update
# Install required product plugins if missing
aliyun plugin install --names aliyun-cli-sts,aliyun-cli-sas
# Enable AI mode and set required UA segment
aliyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent AlibabaCloud-Agent-Skills
# Optional checks / rollback
aliyun configure ai-mode show
aliyun configure ai-mode disable2. Install Python ≥ 3.6
bash
# Check version
python3 --version # Requires 3.6+, 3.9+ recommended3. Create Virtual Environment and Install Dependencies
Create a virtual environment in and install dependencies declared in :
<skill-path>/scripts/pyproject.tomlbash
cd scripts/
# Option A: use venv
python3 -m venv .venv
.venv/bin/pip install -e .
# Option B: use uv (optional)
uv sync
# Option C: if current Python version is unsupported, install as system dependencies
pip install -r requirements.txt4. Run Commands
All scripts must be executed with Python from the virtual environment (whether created via venv, uv, conda, etc.). This document uses in examples; replace it with your actual virtual environment path.
.venv/bin/pythonWorking Directory
accounts.json<skill-path>/scripts/scriptsaccounts.jsonbash
# Example: run from any directory
.venv/bin/python /path/to/scripts/accounts.py refreshFeature 1: Account Management (accounts.py
)
accounts.pyWorkflow
- First use: run to fetch account list from the resource directory.
refresh - Filter as needed: use to find target accounts and get AccountId.
search - Enable/disable control: use /
enableto decide which accounts participate in batch export.disable
Quick Start
Refresh account list
Fetch the latest account list from Alibaba Cloud resource directory and write to . Existing states are preserved; new accounts are enabled by default.
accounts.jsonenablebash
.venv/bin/python accounts.py refreshList all accounts
bash
.venv/bin/python accounts.py listSample output:
1225574417218097 cwx [enabled]
1234567890123456 prod-account [disabled]Search accounts
Fuzzy-search by DisplayName, returning AccountId and enable status.
bash
.venv/bin/python accounts.py search cwx
.venv/bin/python accounts.py search prodEnable / disable accounts
Control whether an account participates in subsequent batch exports.
bash
.venv/bin/python accounts.py enable 1225574417218097
.venv/bin/python accounts.py disable 1234567890123456accounts.json
Structure
accounts.jsonjson
[
{
"AccountId": "1225574417218097",
"DisplayName": "cwx",
"FolderId": "r-1Q4pqB",
"IsMaAccount": "NO",
"SasVersion": "0",
"enable": true
}
]Feature 2: Batch Baseline Export (baseline.py
)
baseline.pyLaunch export tasks concurrently for all accounts with . After polling completion, files are downloaded, extracted, and merged into a single Excel file.
enable=trueWorkflow
- Concurrent submission: submit requests for all enabled accounts (QPS ≤ 5).
export-record - Concurrent polling: poll for each account until export completes.
describe-export-info - Download and extract: download zip and extract xlsx.
- Merge output: merge all account xlsx files into one file via , appending a “Resource Directory Account” column.
merge.py - Cleanup temporary files: delete per-account temporary xlsx files after merge.
Prerequisites
- has been executed and account enable/disable configuration is complete.
accounts.py refresh - aliyun CLI is configured with valid credentials and has SAS and
export-recordpermissions.describe-export-info - Accounts must have Security Center purchased (free edition accounts are skipped automatically).
Export cloud platform configuration check results (CSPM)
Export results for all enabled accounts and merge into .
baselineCspmbaseline-cspm-merged-{date}.xlsxbash
# Export for all enabled accounts
.venv/bin/python baseline.py export-cspm
# Export for one specific account
.venv/bin/python baseline.py export-cspm --account-id 1225574417218097Export system baseline risk list
Export risk list (high/medium/low, all statuses) for all enabled accounts and merge into .
exportHcWarningsystem-warning-merged-{date}.xlsxbash
# Export for all enabled accounts
.venv/bin/python baseline.py export-system-warning
# Export for one specific account
.venv/bin/python baseline.py export-system-warning --account-id 1225574417218097Output Files
| File | Description |
|---|---|
| Merged cloud platform configuration check results, including “Resource Directory Account” column |
| Merged system baseline risk list, including “Resource Directory Account” column |
Error Handling
| Scenario | Behavior |
|---|---|
| Silently skip this account and continue others |
| Silently skip this account |
| Export failed (server-side error) | Print |
| All accounts skipped | Print message and exit without output file |
Feature 3: Batch Vulnerability Export (vuln.py
)
vuln.pyLaunch vulnerability export tasks concurrently for all accounts with . Supports four vulnerability types. After polling completion, files are downloaded, extracted, and merged automatically.
enable=trueWorkflow
- Concurrent submission: submit requests for all enabled accounts (QPS ≤ 5).
export-vul --force - Concurrent polling: poll for each account until export completes.
describe-vul-export-info --force - Download and extract: download zip and extract xlsx.
- Merge output: merge all account xlsx files into one file via , appending a “Resource Directory Account” column.
merge.py - Cleanup temporary files: delete per-account temporary xlsx files after merge.
When the current account is the same as the caller's primary account,is omitted automatically.--ResourceDirectoryAccountId
Prerequisites
- has been executed and account enable/disable configuration is complete.
accounts.py refresh - aliyun CLI is configured with valid credentials and has SAS and
export-vulpermissions.describe-vul-export-info - Accounts must have Security Center purchased (free edition accounts are skipped automatically).
Export Linux software vulnerabilities (CVE)
Export unresolved Linux software vulnerabilities (high/medium/low priority) for all enabled accounts and merge into .
vul-cve-merged-{date}.xlsxbash
# Export for all enabled accounts
.venv/bin/python vuln.py export-cve
# Export for one specific account
.venv/bin/python vuln.py export-cve --account-id 1225574417218097Export Windows system vulnerabilities
Export unresolved Windows system vulnerabilities (high/medium/low priority) for all enabled accounts and merge into .
vul-sys-merged-{date}.xlsxbash
.venv/bin/python vuln.py export-sys
.venv/bin/python vuln.py export-sys --account-id 1225574417218097Export application vulnerabilities (including SCA)
Export unresolved application vulnerabilities (ECS + container, including software composition analysis) for all enabled accounts and merge into .
vul-app-merged-{date}.xlsxbash
.venv/bin/python vuln.py export-app
.venv/bin/python vuln.py export-app --account-id 1225574417218097Export emergency vulnerabilities
Export emergency vulnerabilities (at-risk status) for all enabled accounts and merge into .
vul-emg-merged-{date}.xlsxbash
.venv/bin/python vuln.py export-emg
.venv/bin/python vuln.py export-emg --account-id 1225574417218097Output Files
| File | Description |
|---|---|
| Merged Linux software vulnerability list, including “Resource Directory Account” column |
| Merged Windows system vulnerability list, including “Resource Directory Account” column |
| Merged application vulnerability list (including SCA), including “Resource Directory Account” column |
| Merged emergency vulnerability list, including “Resource Directory Account” column |
Export Parameter Details
| Type | |
|---|---|
| |
| |
| |
| |
Error Handling
| Scenario | Behavior |
|---|---|
| Silently skip this account and continue others |
| Silently skip this account |
| Export failed (server-side error) | Print |
| All accounts skipped | Print message and exit without output file |
Notes
- Scripts must run in a virtual environment. Examples use ; replace with your actual virtual environment path.
.venv/bin/python - Manage aliyun CLI credentials with ; do not hardcode AK/SK.
aliyun configure - SAS API supports only two endpoints: (China mainland) and
cn-shanghai(outside China mainland).ap-southeast-1