implementing-gcp-organization-policy-constraints
实施 GCP 组织策略约束,在整个资源层次结构中强制执行安全防护栏,限制危险配置并在组织、文件夹和项目级别确保合规性。
Best use case
implementing-gcp-organization-policy-constraints is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
实施 GCP 组织策略约束,在整个资源层次结构中强制执行安全防护栏,限制危险配置并在组织、文件夹和项目级别确保合规性。
Teams using implementing-gcp-organization-policy-constraints should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/implementing-gcp-organization-policy-constraints/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How implementing-gcp-organization-policy-constraints Compares
| Feature / Agent | implementing-gcp-organization-policy-constraints | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
实施 GCP 组织策略约束,在整个资源层次结构中强制执行安全防护栏,限制危险配置并在组织、文件夹和项目级别确保合规性。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 实施 GCP 组织策略约束
## 概述
GCP 组织策略服务(Organization Policy Service)对云资源提供集中化和程序化的控制。组织策略通过配置约束来限制一个或多个 Google Cloud 服务,可在组织、文件夹或项目级别强制执行。它们通过阻止外部 IP、要求加密和最小化未授权访问来提升安全性。策略变更可能需要最多 15 分钟才能生效。
## 前置条件
- 拥有 Organization Administrator 角色的 GCP 组织
- 已配置并完成身份验证的 `gcloud` CLI
- 用于策略管理的 Terraform 或 gcloud
- 组织策略管理员 IAM 角色(`roles/orgpolicy.policyAdmin`)
## 核心概念
### 约束类型
1. **列表约束(List Constraints)**:允许或拒绝特定值(如允许的区域)
2. **布尔约束(Boolean Constraints)**:启用或禁用某项功能(如禁用串行端口访问)
3. **自定义约束(Custom Constraints)**:针对特定资源字段的用户自定义规则(预览版)
### 策略继承
策略从具有强制执行策略的最低祖先节点继承。如果没有祖先节点配置策略,则应用 Google 的托管默认行为。
## 核心安全约束
### 限制 VM 外部 IP 地址
```bash
# 拒绝所有 VM 使用外部 IP 地址
gcloud resource-manager org-policies set-policy \
--organization=ORGANIZATION_ID \
policy.yaml
```
policy.yaml:
```yaml
constraint: constraints/compute.vmExternalIpAccess
listPolicy:
allValues: DENY
```
### 限制资源位置
```bash
gcloud org-policies set-policy \
--organization=ORGANIZATION_ID \
location-policy.yaml
```
location-policy.yaml:
```yaml
constraint: constraints/gcp.resourceLocations
listPolicy:
allowedValues:
- "in:us-locations"
- "in:eu-locations"
```
### 禁用默认服务账号创建
```yaml
constraint: constraints/iam.automaticIamGrantsForDefaultServiceAccounts
booleanPolicy:
enforced: true
```
### 要求 SSH 使用 OS Login
```yaml
constraint: constraints/compute.requireOsLogin
booleanPolicy:
enforced: true
```
### 禁用串行端口访问
```yaml
constraint: constraints/compute.disableSerialPortAccess
booleanPolicy:
enforced: true
```
### 强制统一存储桶级访问
```yaml
constraint: constraints/storage.uniformBucketLevelAccess
booleanPolicy:
enforced: true
```
### 限制 Cloud SQL 公共 IP
```yaml
constraint: constraints/sql.restrictPublicIp
booleanPolicy:
enforced: true
```
### 禁用服务账号密钥创建
```yaml
constraint: constraints/iam.disableServiceAccountKeyCreation
booleanPolicy:
enforced: true
```
## Terraform 实现
```hcl
resource "google_organization_policy" "restrict_vm_external_ip" {
org_id = var.org_id
constraint = "constraints/compute.vmExternalIpAccess"
list_policy {
deny {
all = true
}
}
}
resource "google_organization_policy" "restrict_locations" {
org_id = var.org_id
constraint = "constraints/gcp.resourceLocations"
list_policy {
allow {
values = ["in:us-locations", "in:eu-locations"]
}
}
}
resource "google_organization_policy" "require_os_login" {
org_id = var.org_id
constraint = "constraints/compute.requireOsLogin"
boolean_policy {
enforced = true
}
}
resource "google_folder_organization_policy" "dev_folder_external_ip" {
folder = google_folder.dev.name
constraint = "constraints/compute.vmExternalIpAccess"
list_policy {
allow {
values = ["projects/dev-project/zones/us-central1-a/instances/bastion-host"]
}
}
}
```
## 试运行测试
在强制执行前,使用 Policy Intelligence 工具测试变更影响:
```bash
# 创建试运行策略以监控影响
gcloud org-policies set-policy \
--organization=ORGANIZATION_ID \
dry-run-policy.yaml
```
dry-run-policy.yaml:
```yaml
constraint: constraints/compute.vmExternalIpAccess
listPolicy:
allValues: DENY
dryRunSpec: true
```
```bash
# 检查试运行策略的违规情况
gcloud org-policies list-custom-constraints \
--organization=ORGANIZATION_ID
```
## 自定义约束
```yaml
# custom-constraint.yaml
name: organizations/ORGANIZATION_ID/customConstraints/custom.disableGKEAutoUpgrade
resourceTypes:
- container.googleapis.com/NodePool
methodTypes:
- CREATE
- UPDATE
condition: "resource.management.autoUpgrade == true"
actionType: DENY
displayName: 拒绝 GKE 节点池自动升级
description: 防止在 GKE 节点池上启用自动升级,以实现受控升级
```
```bash
gcloud org-policies set-custom-constraint custom-constraint.yaml
```
## 监控与合规
### 列出活跃策略
```bash
gcloud org-policies list --organization=ORGANIZATION_ID
```
### 描述特定策略
```bash
gcloud org-policies describe constraints/compute.vmExternalIpAccess \
--organization=ORGANIZATION_ID
```
### 使用 Cloud Asset Inventory 审计策略违规
```bash
gcloud asset search-all-resources \
--scope=organizations/ORGANIZATION_ID \
--query="policy:constraints/compute.vmExternalIpAccess"
```
## 推荐基线策略
| 约束 | 类型 | 范围 | 用途 |
|------|------|------|------|
| compute.vmExternalIpAccess | 列表/拒绝 | 组织 | 防止 VM 使用公网 IP |
| gcp.resourceLocations | 列表/允许 | 组织 | 限制为已批准区域 |
| iam.disableServiceAccountKeyCreation | 布尔 | 组织 | 强制使用 Workload Identity |
| compute.requireOsLogin | 布尔 | 组织 | 强制 SSH 使用 OS Login |
| storage.uniformBucketLevelAccess | 布尔 | 组织 | 强制统一存储桶访问 |
| sql.restrictPublicIp | 布尔 | 组织 | 禁止 Cloud SQL 公网访问 |
| compute.disableSerialPortAccess | 布尔 | 组织 | 禁用串行端口 |
| compute.disableNestedVirtualization | 布尔 | 组织 | 禁止嵌套虚拟化 |
## 参考资料
- GCP 组织策略约束: https://docs.google.com/resource-manager/docs/organization-policy/org-policy-constraints
- GCP Policy Intelligence: https://cloud.google.com/policy-intelligence
- CIS GCP 基础基准Related Skills
performing-dmarc-policy-enforcement-rollout
执行从 p=none 监控到 p=quarantine 再到 p=reject 执行的分阶段 DMARC 推进,确保所有合法邮件来源在封锁未授权发件人之前完成认证。
performing-content-security-policy-bypass
通过利用错误配置、JSONP 端点、不安全指令和策略注入技术,分析并绕过内容安全策略(CSP)实现,以实现跨站脚本攻击。
implementing-zero-trust-with-hashicorp-boundary
使用 HashiCorp Boundary 实现具备动态凭据代理、会话录制和 Vault 集成的身份感知零信任基础设施访问管理。
implementing-zero-trust-with-beyondcorp
使用身份感知代理(IAP,Identity-Aware Proxy)、上下文感知访问策略、设备信任验证和 Access Context Manager,部署 Google BeyondCorp Enterprise 零信任访问控制,对 GCP 资源和内部应用强制执行基于身份和安全态势的访问。
implementing-zero-trust-network-access
通过配置身份感知代理、微分段、基于条件访问策略的持续验证,以及在 AWS、Azure 和 GCP 环境中以 BeyondCorp 风格的架构替代传统 VPN 访问,在云环境中实施零信任网络访问(ZTNA)。
implementing-zero-trust-network-access-with-zscaler
使用 Zscaler 实施零信任网络访问(Zero Trust Network Access,ZTNA),通过 Zscaler Private Access(ZPA)配置应用分段、访问策略和连接器,替代传统 VPN 架构
implementing-zero-trust-in-cloud
本技能指导组织按照 NIST SP 800-207 和 Google BeyondCorp 原则在云环境中实施零信任(Zero Trust)架构,涵盖以身份为中心的访问控制、微分段(Micro-Segmentation)、持续验证、设备信任评估,以及部署身份感知代理(Identity-Aware Proxy)以消除 AWS、Azure 和 GCP 环境中的隐式网络信任。
implementing-zero-trust-for-saas-applications
使用 CASB、SSPM、条件访问策略、OAuth 应用治理和会话控制,为 SaaS 应用实施零信任访问控制, 对云托管服务强制执行身份验证、设备合规性检查和数据保护。
implementing-zero-trust-dns-with-nextdns
将 NextDNS 实施为零信任 DNS 过滤层,提供加密解析、威胁情报阻断、隐私保护,以及跨所有端点的组织策略执行。
implementing-zero-standing-privilege-with-cyberark
部署 CyberArk Secure Cloud Access,通过基于时间、权限和审批控制的即时访问,在混合云和多云环境中消除常设权限。
implementing-zero-knowledge-proof-for-authentication
零知识证明(ZKP)允许证明者在不泄露秘密本身的情况下证明对某个秘密(如密码或私钥)的了解。本技能实现 Schnorr 身份识别协议和使用离散对数问题的简化 ZKPP,使服务器永远不需要获取用户密码即可完成认证。
implementing-web-application-logging-with-modsecurity
配置带有 OWASP 核心规则集(CRS)的 ModSecurity WAF,实现 Web 应用程序日志记录, 调整规则以减少误报,分析审计日志进行攻击检测,并为应用程序特定威胁实现自定义 SecRules。 分析师配置 SecRuleEngine、SecAuditEngine 和 CRS 偏执级别,以在安全覆盖范围和运营稳定性之间取得平衡。 适用于涉及 WAF 配置、ModSecurity 规则调整、Web 应用审计日志或 CRS 部署的场景。