当前位置: 首页 > Skill >

Alibabacloud Cfw Internet Firewall Protect

Alibabacloud Cfw Internet Firewall Protect

Alibabacloud Cfw Internet Firewall Protect

在阿里云上管理云防火墙(CFW)公网IP保护开关,用于启用或关闭防火墙保护。

0.0.1 2026.11.26 339
获取Skill文件查看使用说明
作 者:陆言 许可证: 更新时间:2026.11.26
本文目录展开

Operation Routing

Identify the user's intent, then route to the matching execution path:

User Intent Execution Path
Query asset protection status, list assets, check which IPs are protected/unprotected fw-switch.sh query with filters
Enable/disable protection for specific IPs fw-switch.sh enable/disable --ips "ip1,ip2,..."
Enable/disable protection for a region fw-switch.sh enable/disable --regions "cn-hangzhou,..."
Enable/disable protection for a resource type (e.g. all ECS public IPs) fw-switch.sh enable/disable --resource-types "EcsPublicIP,..."
Enable/disable protection for all IPv4 or IPv6 assets fw-switch.sh enable/disable --ip-version 4 or 6
Combined filter (e.g. Beijing region + ECS public IP + IPv4) fw-switch.sh enable/disable --regions cn-beijing --resource-types EcsPublicIP --ip-version 4
Enable/disable protection for ALL public IPs at once fw-switch.sh enable-all/disable-all --yes
Enable protection for assets matching a condition (name, label, etc.) Multi-step: query → filter → enable by IP list (see below)
Query auto-protection settings for new assets auto-protect.sh query
Modify auto-protection settings auto-protect.sh modify --enable/--disable <types> --yes

Parameters can be freely combined. The --ips, --regions, --resource-types, and --ip-version options work together — provide at least one.

Conditional Multi-Step Workflow

When the user's filter criteria cannot be directly passed to the API (e.g. "enable protection for all instances whose name contains Dify"), orchestrate a multi-step workflow:

  1. Query: Run fw-switch.sh query with available filters (status, region, resource type). Paginate through results if total_count exceeds page size.
  2. Filter: From the returned Assets array, filter by the user's condition (instance name match, specific attributes, etc.). The key fields in each asset: Name (instance name), InternetAddress (public IP), IntranetAddress (private IP), ProtectStatus, ResourceType, RegionID, BindInstanceId, BindInstanceName.
  3. Impact Preview (Phase 1): Present the matched assets summary to the user for confirmation (follow the summary format in "Protection Switch Workflow").
  4. Execute (Phase 2): Collect the InternetAddress values from matched assets into a comma-separated list, then call fw-switch.sh enable/disable --ips "ip1,ip2,...".
  5. Verify (Phase 3): Poll status to confirm the operation completed (follow the polling strategy in "Protection Switch Workflow").

Edge Case Handling for Step 2 (Filter Results):

Filter Result Phase 2 Action
Matched assets exist, some/all have ProtectStatus=closed enable --ips "all_matched_ips" (include both open and closed — API is idempotent)
Matched assets exist, ALL already ProtectStatus=open enable --ips "all_matched_ips" (still call — idempotent rule)
Zero assets match the filter condition Use the user's original broader dimensions instead: enable --regions <region> --resource-types <type> or enable --ip-version <ver>. If no broader dimension is available, call enable-all --yes as fallback. Never skip Phase 2.

This pattern applies to any condition-based operation — name matching, tag filtering, status-based bulk operations, etc.

Check CLI Environment

Before any operation, validate the CLI environment:

bash scripts/validate-cli.sh --check-permission

Check results and remediate:

  • cli_installed = false → run --install-guide for installation instructions
  • cli_version_ok = false → CLI version below 3.3.3, reinstall or update
  • auto_plugin_install = false → run aliyun configure set --auto-plugin-install true
  • credential_valid = false → no profile configured, run aliyun configure to add one
  • permission_check = false → credentials are invalid/expired or the identity lacks yundun-cloudfirewall:DescribeAssetList; check AccessKey status and refer to references/ram-policies.md

Note: credential_valid only reflects whether a profile exists in aliyun configure list. Real credential validity is verified by permission_check, which calls the actual CFW business API — invalid/expired AccessKey will fail there.

Show full installation guide:

bash scripts/validate-cli.sh --install-guide

After environment checks pass, ensure plugins are up-to-date:

aliyun plugin update

API Version Note: Cloudfw uses CLI plugin mode (aliyun-cli-cloudfw). The API version is managed internally by the plugin (actual version: 2017-12-07). Call CFW commands using the default invocation — do NOT pass --version. The plugin rejects any external version override and will error with unchecked version. The call_cfw_api function in common.sh is designed accordingly and does not include --version.

AI-Mode Lifecycle

Before any CLI invocation, enable AI-mode:

aliyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-cfw-internet-firewall-protect"

Before delivering the final response (success, failure, error, or user cancellation), always disable AI-mode:

aliyun configure ai-mode disable

AI-mode is only for Agent Skill execution and MUST NOT remain enabled after the skill stops running.

RAM Policy and Permission Handling

The RAM Action prefix for Cloud Firewall is yundun-cloudfirewall, NOT cloudfw. Read references/ram-policies.md for the full permission list.

Permission Failure Handling: When any command or API call fails due to permission errors at any point during execution, follow this process:

  1. Read references/ram-policies.md to get the full list of permissions required by this Skill
  2. Guide the user through requesting the necessary permissions
  3. Pause and wait until the user confirms that the required permissions have been granted

Query Assets

bash scripts/fw-switch.sh query [options]

Available filters: --region, --status (open/closed/opening/closing), --resource-type, --search (IP or instance ID), --ip-version (4/6), --member-uid. Each filter accepts a single value.

For multi-region or multi-resource-type queries, the DescribeAssetList API only supports single-value filters. Make separate calls per region or per resource type in parallel, then merge the results. Example: to query both cn-hangzhou and cn-beijing EcsPublicIP assets, call fw-switch.sh query --region cn-hangzhou --resource-type EcsPublicIP and fw-switch.sh query --region cn-beijing --resource-type EcsPublicIP separately.

Pagination: --page (default 1), --page-size (default 10). Check TotalCount in the response to determine if more pages exist.

The response returns the raw API JSON with an Assets array. Each asset contains: InternetAddress, IntranetAddress, ProtectStatus, ResourceType, RegionID, Name, BindInstanceId, BindInstanceName, ResourceInstanceId, IpVersion, MemberUid.

Present results to the user in a readable format. For ProtectStatus: open = protected, closed = unprotected, opening = enabling, closing = disabling.

Enable / Disable Protection Workflow

All enable/disable/enable-all/disable-all operations follow a three-phase workflow: Impact Preview → User Confirmation → Execute → Result Verification. Skipping any phase may lead to unintended changes or unverified outcomes.

⚠️ MANDATORY: Non-Interactive Execution Rule When running as an Agent (non-interactive mode), --yes is implicit user confirmation. You MUST complete ALL three phases unconditionally:

  • Phase 1 shows 0 affected assets → still execute Phase 2 and Phase 3. Do NOT stop.
  • Phase 1 shows all assets already in desired state → still execute Phase 2 and Phase 3. Do NOT stop.
  • NEVER terminate the workflow after Phase 1 alone. NEVER output "no action needed" without completing Phase 2+3.
  • The sequence Phase 1 → Phase 2 → Phase 3 is unconditionally mandatory in every execution path, regardless of Phase 1 results.

Phase 1: Impact Preview

Before executing, query the assets that will be affected and present a human-friendly summary:

  • enable operation: query --status closed + same filter dimensions to show assets that will gain protection
  • disable operation: query --status open + same filter dimensions to show assets that will lose protection
  • enable-all: query --status closed to show all currently unprotected assets
  • disable-all: query --status open to show all currently protected assets

Use --page-size 50 for the preview query. If TotalCount exceeds one page, paginate to collect all data for accurate statistics.

Summarize the result to the user:

  • If total ≤ 5 assets: list all (IP, instance name, region, resource type)
  • If total > 5 assets: list 3 representative examples, then summarize the rest with region distribution

Example format:

This operation will enable firewall protection for the following 45 unprotected public IPs:

1. 47.96.xx.xx (ECS instance web-server-01, cn-hangzhou, EcsPublicIP)
2. 120.55.xx.xx (NAT gateway nat-prod, cn-hangzhou, NatEIP)
3. 39.108.xx.xx (ECS instance api-gateway, cn-beijing, EcsPublicIP)
...and 42 more public IPs across cn-hangzhou(25), cn-beijing(12), cn-shanghai(5).

Confirm execution?

For disable and disable-all, additionally warn: disabling protection means traffic no longer passes through Cloud Firewall, access control policies and intrusion detection will stop working.

Wait for explicit user confirmation before proceeding to Phase 2.

Phase 2: Execute

After user confirms, run the actual enable/disable command. If using a condition-based IP list from the preview query, pass the collected IPs via --ips.

⚠️ MANDATORY: Idempotent Execution Rule Even if Phase 1 shows all target assets are already in the desired state (e.g., all open when enabling, or 0 unprotected assets found), you MUST still execute the enable/disable command. The API is idempotent — calling it on already-protected assets is safe and returns success. Do NOT skip Phase 2 based on current status or zero-count results.

Examples of WRONG behavior:

  • "All assets are already protected, no action needed" → WRONG, must still call the API
  • "No unprotected assets found, skipping execution" → WRONG, must still call the API

Phase 3: Result Verification

After execution, poll the asset status to verify the operation took effect:

  1. Initial wait: sleep 5 seconds
  2. Query: Run fw-switch.sh query with the same filters, check if assets transitioned to the expected status
  3. Adaptive polling: If not all assets have transitioned:
    • Poll every 5 seconds
    • Estimate: ~5 seconds per 20 assets
    • Maximum total polling: 30 seconds
  4. Report results using the same summary style (examples + count):
    • All transitioned: "✓ Done. Firewall protection enabled for all 45 public IPs."
    • Partial within 30s: "38/45 assets completed. 7 still in progress (status: opening). Check the Cloud Firewall console to confirm final status."
    • Timeout: "Waited 30 seconds. 12 assets have not completed the status transition. Large-scale changes may take longer — check the Cloud Firewall console to confirm."

Expected status transitions:

  • enable → closed → opening → open
  • disable → open → closing → closed

Treat opening/closing as "in progress" — the operation was accepted but not yet complete.

Enable / Disable Protection

By IP, Region, Resource Type, or IP Version

bash scripts/fw-switch.sh enable [options]
bash scripts/fw-switch.sh disable [options]

Options: --ips, --regions, --resource-types, --ip-version, --member-uid, --dry-run.

At least one filter dimension is required. They can be combined freely:

# Single dimension
bash scripts/fw-switch.sh enable --ips "1.2.3.4,5.6.7.8"
bash scripts/fw-switch.sh enable --ip-version 6

# Combined dimensions
bash scripts/fw-switch.sh enable --regions "cn-beijing" --resource-types "EcsPublicIP" --ip-version 4

Use --dry-run to preview the CLI command before execution. This is recommended when the user provides many IPs or combined filters, so they can verify the parameters.

Read references/resource-types.md for the complete list of valid resource type values.

All Public IPs

bash scripts/fw-switch.sh enable-all --yes [--instance-id <id>]
bash scripts/fw-switch.sh disable-all --yes [--instance-id <id>]

These operations affect every public IP under the account. In non-interactive (Agent) mode, --yes is treated as implicit user confirmation — do NOT wait for explicit user input before passing it.

Impact preview is especially important for these operations — always run Phase 1 to show the user exactly how many assets will be affected before proceeding.

⚠️ MANDATORY: Idempotent Execution Rule for enable-all / disable-all Even if Phase 1 shows 0 unprotected assets (all already open for enable-all) or 0 protected assets (all already closed for disable-all), you MUST still execute the command. Do NOT output "All assets are already in the target state, no action needed" and stop — that skips Phase 2 and Phase 3.

Auto-Protection Settings

Query Current Settings

bash scripts/auto-protect.sh query

Returns a ResourceTypeAutoEnable map showing which resource types have auto-protection enabled (new assets of that type will be automatically protected).

Modify Settings

Incremental mode (recommended):

bash scripts/auto-protect.sh modify --enable "EIP,NatEIP" --disable "SlbEIP" --yes

The script reads the current config, merges the changes, and submits the full config. This avoids accidentally overwriting other settings.

⚠️ MANDATORY: Idempotent Execution Rule for auto-protect modify When the user requests enabling certain resource types, you MUST call auto-protect.sh modify --enable <types> --yes regardless of what the current config shows.

  • Even if auto-protect.sh query shows the requested types are already true, still execute the modify command. The API call is idempotent and safe.
  • Do NOT conclude "no modification needed" or skip modify based on query results alone.
  • Examples of WRONG behavior:
    • Query shows EcsPublicIP: true → "Already enabled, no action needed" → WRONG, must still call modify
    • Query shows all requested types already enabled → "Config is already in the target state, skipping" → WRONG, must still call modify

Full config mode:

bash scripts/auto-protect.sh modify --config '{"EIP":true,"NatEIP":false,...}' --yes

Use --dry-run to preview the merged config before applying. The --yes flag is required for execution.

Multi-Account Operations

All operations support --member-uid <uid> to operate on a member account's assets. When the user manages multiple accounts under a management account, ask which account they want to operate on and pass the member UID.

Handle Errors

When an API call fails, the scripts output a JSON error with error_code and error_message, plus diagnostic guidance to stderr. Common scenarios:

  • ErrorInstanceOpenIpNumExceed / ErrorGeneralInstanceSpecFull: protection quota or instance spec reached the limit — suggest upgrading the CFW edition.
  • ErrorBandwidthPenalty: bandwidth overuse enforcement — advise waiting or contacting support.
  • ErrorInstanceStatusNotNormal: instance may be unpaid or abnormal — check CFW console.
  • ErrorParamsNotEnough: at least one filter dimension is required for enable/disable.
  • ErrorAuthentication / NoPermission: credential or permission issue — run validate-cli.sh and check references/ram-policies.md.

For the full error code reference, read references/api-errors.md.

Script Reference

Script Purpose Key Params
fw-switch.sh query Query assets and protection status --region, --status, --resource-type, --search, --ip-version, --member-uid, --new-resource-tag, --page, --page-size
fw-switch.sh enable Enable protection (flexible filters) --ips, --regions, --resource-types, --ip-version, --member-uid
fw-switch.sh disable Disable protection (flexible filters) same as enable
fw-switch.sh enable-all Enable ALL public IP protection --instance-id, --yes
fw-switch.sh disable-all Disable ALL public IP protection --instance-id, --yes
auto-protect.sh query Query auto-protection config (none)
auto-protect.sh modify Modify auto-protection config --enable, --disable, --config, --region, --yes
validate-cli.sh Check CLI and credentials --check-permission

All scripts support --dry-run and --help. Exit codes: 0 = success, 1 = parameter error, 2 = API error.

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,019
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,014
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,014
Skill 文件
  • SKILL.md
    • Operation Routing
    • Conditional Multi-Step Workflow
    • Check CLI Environment
    • AI-Mode Lifecycle
    • RAM Policy and Permission Handling
    • Query Assets
    • Enable / Disable Protection Workflow
      • Phase 1: Impact Preview
      • Phase 2: Execute
      • Phase 3: Result Verification
    • Enable / Disable Protection
      • By IP, Region, Resource Type, or IP Version
      • All Public IPs
    • Auto-Protection Settings
      • Query Current Settings
      • Modify Settings
    • Multi-Account Operations
    • Handle Errors
    • Script Reference
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期