管理 IBM Cloud Direct Link 的 IAM 访问权
IBM Cloud® Identity and Access Management (IAM) 控制账户中用户对 Direct Link 网关的访问。 必须为访问您账户中的Direct Link服务的每个用户分配具有 IAM 角色的访问策略。 查看以下角色,操作和更多信息,以帮助确定分配对 Direct Link的访问权的最佳方法。
IBM Cloud® Direct Link 支持客户本地资源与经典和虚拟私有云 (VPC) 基础结构中托管的 IBM Cloud 资源之间的连接。
您在帐户中为用户分配的访问策略确定用户可以在所选服务或特定实例的上下文中执行的操作。 直接链接可将允许的操作自定义并定义为允许在服务上执行的操作。 每个操作都映射到可以分配给用户的 IAM 平台或服务角色。
如果特定角色及其操作不符合您要处理的用例,那么可以 创建定制角色 并选取要包含的操作。
IAM 访问策略允许在不同级别授予访问权限。 一些选项包括
- 跨帐户中的 Direct Link 服务实例进行访问
- 对帐户中单个服务实例的访问权
- 对实例中特定资源的访问权
查看下表,其中概述了使用 Direct Link 服务时每个角色允许的任务类型。 平台管理角色使用户能够在平台级别对服务资源执行任务,例如,分配用户对服务的访问权限以及创建或删除实例。
Direct Link没有服务访问角色,这使得用户无法访问Direct Link并能够调用Direct Link API。 有关映射到每个角色的确切操作的信息,请参阅 Direct Link Connect 和 Direct Link Dedicated。
平台角色 | 操作描述 | 操作示例 |
---|---|---|
管理员 | 允许用户将 Direct Link IAM 访问策略分配给其他用户。 | Create gateway Delete gateway Edit gateway Add a virtual connection to a gateway* Remove a virtual connection from a gateway* Edit a virtual connection (API only) Update user access policies for the service |
编辑者 | 执行所有操作,包括管理网关和虚拟连接。 | Create gateway Delete gateway Edit gateway Add a virtual connection to a gateway* Remove a virtual connection from a gateway* Edit a virtual connection (API only) |
查看者/操作员 | 执行不改变资源状态的操作。 | List gateways Get gateways List a gateway's virtual connections View a gateway's virtual connections Retrieve gateway-related information (completion notice of authorization) View incoming connection requests* |
* To add or remove virtual connections to VPCs, or to accept or reject a connection request, the user must also have Editor or Administrator platform-access role permissions to the VPC. 请参阅 VPC: IAM 入门 以获取更多信息。
注:
- 所有Direct Link资源都存在于资源组中。 创建 Direct Link 资源需要对所选资源组的“编辑者”访问权。
- 有关在控制台中分配用户角色的信息,请参阅 管理资源访问。
在控制台中分配对 Direct Link 的访问权
控制台分配访问权限的常用方法:
- 每个用户的访问策略。 您可以从控制台中的“管理 > 访问权 (IAM) > 用户”页面管理每个用户的访问策略。 有关分配 IAM 访问权的步骤的信息,请参阅 管理对资源的访问权。
- 访问组。 访问组用于简化访问管理,方法是一次性分配对组的访问权,然后您可以根据需要在组中添加或除去用户以控制其访问权。 您可以从控制台中的“管理 > 访问权 (IAM) > 访问组”页面管理访问组及其访问权。 有关更多信息,请参阅 在控制台中分配对组的访问权。
跨帐户虚拟连接的授权注意事项
下表显示跨帐户虚拟连接的授权更改。
跨帐户虚拟连接意味着网关存在于 IBM Cloud 帐户中,并且该网关中的虚拟连接会连接到另一个 IBM Cloud 帐户中的 VPC。 这种设置需要特别的授权考虑,因为对象(直接链接和 VPC)及其资源组在两个账户中都不存在。
相关帐户 | 功能 | 所需的权限 |
---|---|---|
网关帐户 | 此表中未提及的任何功能。 | 没有权限更改。 |
网关帐户 | 创建和删除跨帐户虚拟连接。 | directlink.dedicated.edit 或 directlink.connect.edit 创建或删除时不需要 VPC 授权。 |
网络帐户 | 查看只读网关和虚拟连接。 | 服务级别 directlink.dedicated.view 或 directlink.connect.view |
网络帐户 | 接受和拒绝暂挂连接。 | 服务级别 directlink.dedicated.view 或 directlink.connect.view 更新已连接 VPC 上的授权。 |
网络帐户 | DELETE 附加虚拟连接。 |
服务级别 directlink.dedicated.view 或 directlink.connect.view 更新已连接 VPC 上的授权。 |
在 CLI 中分配对 Direct Link 的访问权
有关分配,除去和复审访问权的逐步指示信息,请参阅 使用 CLI 分配访问资源。 以下示例显示了用于将 Editor
角色分配给用户的命令:
使用 directlink
作为服务名称。 此外,请在角色名称周围使用引号,这些名称与此处的示例类似,但不止一个单词。
ibmcloud iam user-policy-create USER@EXAMPLE.COM --service-name directlink --roles Editor
使用 API 分配对 Direct Link 的访问权
有关分配、删除和审查访问权限的逐步说明,请参阅 使用 API 分配资源访问权限 或 创建策略 API 文档。 下表中的角色云资源名称 (CRN) 用于分配对 API 的访问权。
角色名称 | 角色 CRN |
---|---|
查看者 | crn:v1:bluemix:public:directlink::::serviceRole:Viewer |
运算符 | crn:v1:bluemix:public:directlink::::serviceRole:Operator |
编辑者 | crn:v1:bluemix:public:directlink::::serviceRole:Editor |
管理员 | crn:v1:bluemix:public:directlink::::serviceRole:Administrator |
读者 | crn:v1:bluemix:public:directlink::::serviceRole:Reader |
写入者 | crn:v1:bluemix:public:directlink::::serviceRole:Writer |
管理者 | crn:v1:bluemix:public:directlink::::serviceRole:Manager |
使用 directlink
作为服务名称,并参考角色 ID 值表,确保您使用的 CRN 值正确无误。
以下策略向帐户中的所有 serviceName=directlink
资源分配用户“写入者”角色。
curl -X POST 'https://iam.cloud.ibm.com/v1/policies' -H 'Authorization: Bearer $TOKEN' -H 'Content-Type: application/json' -d '{
"type": "access",
"description": "Writer role for Direct Link",
"subjects": [
{
"attributes": [{
"name": "iam_id",
"value": "IBMid-123453user"
}]
}],
"roles": [{
"roles_id": "crn:v1:bluemix:public:directlink::::serviceRole:Writer"
}],
"resources": [{
"attributes": [
{
"name": "accountId",
"value": "1234567890987654321"
},
{
"name": "serviceName",
"value": "directlink"
}]
}]
SubjectAttribute subjectAttribute = new SubjectAttribute.Builder()
.name("iam_id")
.value("IBMid-123453user")
.build();
PolicySubject policySubjects = new PolicySubject.Builder()
.addAttributes(subjectAttribute)
.build();
PolicyRole policyRoles = new PolicyRole.Builder()
.roleId("crn:v1:bluemix:public:directlink::::serviceRole:Writer")
.build();
ResourceAttribute accountIdResourceAttribute = new ResourceAttribute.Builder()
.name("accountId")
.value("ACCOUNT_ID")
.operator("stringEquals")
.build();
ResourceAttribute serviceNameResourceAttribute = new ResourceAttribute.Builder()
.name("serviceName")
.value("directlink")
.operator("stringEquals")
.build();
PolicyResource policyResources = new PolicyResource.Builder()
.addAttributes(accountIdResourceAttribute)
.addAttributes(serviceNameResourceAttribute)
.build();
CreatePolicyOptions options = new CreatePolicyOptions.Builder()
.type("access")
.subjects(Arrays.asList(policySubjects))
.roles(Arrays.asList(policyRoles))
.resources(Arrays.asList(policyResources))
.build();
Response<Policy> response = service.createPolicy(options).execute();
Policy policy = response.getResult();
System.out.println(policy);
policy_subjects = PolicySubject(
attributes=[SubjectAttribute(name='iam_id', value='IBMid-123453user')])
policy_roles = PolicyRole(
role_id='crn:v1:bluemix:public:directlink::::serviceRole:Writer')
account_id_resource_attribute = ResourceAttribute(
name='accountId', value='ACCOUNT_ID')
service_name_resource_attribute = ResourceAttribute(
name='serviceName', value='directlink')
policy_resources = PolicyResource(
attributes=[account_id_resource_attribute,
service_name_resource_attribute])
policy = iam_policy_management_service.create_policy(
type='access',
subjects=[policy_subjects],
roles=[policy_roles],
resources=[policy_resources]
).get_result()
print(json.dumps(policy, indent=2))
subjectAttribute := &iampolicymanagementv1.SubjectAttribute{
Name: core.StringPtr("iam_id"),
Value: core.StringPtr("IBMid-123453user"),
}
policySubjects := &iampolicymanagementv1.PolicySubject{
Attributes: []iampolicymanagementv1.SubjectAttribute{*subjectAttribute},
}
policyRoles := &iampolicymanagementv1.PolicyRole{
RoleID: core.StringPtr("crn:v1:bluemix:public:directlink::::serviceRole:Writer"),
}
accountIDResourceAttribute := &iampolicymanagementv1.ResourceAttribute{
Name: core.StringPtr("accountId"),
Value: core.StringPtr("ACCOUNT_ID"),
Operator: core.StringPtr("stringEquals"),
}
serviceNameResourceAttribute := &iampolicymanagementv1.ResourceAttribute{
Name: core.StringPtr("serviceName"),
Value: core.StringPtr("directlink"),
Operator: core.StringPtr("stringEquals"),
}
policyResources := &iampolicymanagementv1.PolicyResource{
Attributes: []iampolicymanagementv1.ResourceAttribute{
*accountIDResourceAttribute, *serviceNameResourceAttribute}
}
options := iamPolicyManagementService.NewCreatePolicyOptions(
"access",
[]iampolicymanagementv1.PolicySubject{*policySubjects},
[]iampolicymanagementv1.PolicyRole{*policyRoles},
[]iampolicymanagementv1.PolicyResource{*policyResources},
)
policy, response, err := iamPolicyManagementService.CreatePolicy(options)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(policy, "", " ")
fmt.Println(string(b))
const policySubjects = [
{
attributes: [
{
name: 'iam_id',
value: 'IBMid-123453user',
},
],
},
];
const policyRoles = [
{
role_id: 'crn:v1:bluemix:public:directlink::::serviceRole:Writer',
},
];
const accountIdResourceAttribute = {
name: 'accountId',
value: 'ACCOUNT_ID',
operator: 'stringEquals',
};
const serviceNameResourceAttribute = {
name: 'serviceName',
value: 'directlink',
operator: 'stringEquals',
};
const policyResources = [
{
attributes: [accountIdResourceAttribute, serviceNameResourceAttribute]
},
];
const params = {
type: 'access',
subjects: policySubjects,
roles: policyRoles,
resources: policyResources,
};
iamPolicyManagementService.createPolicy(params)
.then(res => {
examplePolicyId = res.result.id;
console.log(JSON.stringify(res.result, null, 2));
})
.catch(err => {
console.warn(err)
});
Curl 示例 2
以下策略将用户“写入者”角色分配给帐户中类型为 dedicated
的所有 serviceName=directlink
资源。
curl -X POST 'https://iam.cloud.ibm.com/v1/policies' -H 'Authorization: Bearer $TOKEN' -H 'Content-Type: application/json' -d '{
"type": "access",
"description": "Writer role for Direct Link Dedicated",
"subjects": [
{
"attributes": [{
"name": "iam_id",
"value": "IBMid-123453user"
}]
}],
"roles": [{
"roles_id": "crn:v1:bluemix:public:directlink::::serviceRole:Writer"
}],
"resources": [{
"attributes": [
{
"name": "accountId",
"value": "1234567890987654321"
},
{
"name": "serviceName",
"value": "directlink"
},
{
"name": "dedicatedId",
"value": "*"
}]
}]
使用 Terraform 分配对 directlink
的访问权
以下示例用于为 directlink
分配 Editor
角色:
使用 directlink
作为服务名称。
resource "ibm_iam_user_policy" "policy" {
ibm_id = "test@example.com"
roles = ["Editor"]
resources {
service = "directlink"
}
}
有关更多信息,请参阅 ibm_iam_user_policy。