我正在尝试将 accessLevel 绑定到我在 google groups 中创建的组。我尝试通过 gcloud cli 在 terraform 中创建出价,并使用其余 API。所有 3 个都失败并出现 INVALID_ARGUMENT 异常。
我尝试了以下方法
地形:
resource "google_access_context_manager_access_policy" "access-policy" {
parent = "organizations/123456789"
title = "${var.ENV} Access Policy"
scopes = ["projects/${lookup(var.project_number, var.ENV)}"]
}
resource "google_access_context_manager_access_level" "firewall-console-access" {
parent = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}"
name = "accessPolicies/${google_access_context_manager_access_policy.access-policy.name}/accessLevels/firewall_console_access"
title = "firewall_console_access"
basic {
conditions {
ip_subnetworks = [
"182.0.0.0/24"
]
regions = [
"CA",
]
}
}
}
resource "google_access_context_manager_gcp_user_access_binding" "console-group-access" {
organization_id = "123456789"
group_key = "test-group-key"
access_levels = [
google_access_context_manager_access_level.firewall-console-access.name
]
}
结果:
范围访问策略和访问级别已成功创建:
gcloud access-context-manager levels list --policy 123456789
>>NAME: firewall_console_access TITLE: firewall_console_access LEVEL_TYPE: Basic
但是绑定失败并出现以下错误:
gcloud cli:
$ gcloud access-context-manager cloud-bindings create --level="accessPolicies/123456789/accessLevels/firewall_console_access" --group-key="test-group-key" --organization="123456789"
ERROR: (gcloud.access-context-manager.cloud-bindings.create) INVALID_ARGUMENT: Request contains an invalid argument.
API:
请求.json>>
{
"groupKey": "test-group-key",
"accessLevels": [ "accessPolicies/123456789/accessLevels/firewall_console_access" ]
}
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json; charset=utf-8" -d @request.json "https://accesscontextmanager.googleapis.com/v1/organizations/123456789/gcpUserAccessBindings"
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
编辑:
我认为这个错误可能是由于 accessPolicy 的范围位于项目级别,因此我创建了另一个绑定到我的组织默认策略的访问级别,并尝试在绑定中使用新的访问级别,同样的问题。
您需要将 google 组密钥 id 提供到组密钥中,用于获取组密钥 id 的 gcloud 命令是 gcloud 身份组描述 [电子邮件受保护]