为 NSX-v CLI 创建一个用户并分配 API 角色/权限
search cancel

为 NSX-v CLI 创建一个用户并分配 API 角色/权限

book

Article ID: 307670

calendar_today

Updated On:

Products

VMware NSX for vSphere

Issue/Introduction

免责声明:本文为 Creating a User for NSX CLI and Assigning api roles/permissions (2150736) 的翻译版本。尽管我们会不断努力为本文提供最佳翻译版本,但本地化的内容可能会过时。有关最新内容,请参见英文版本。


 

本文介绍了创建 NSX-v CLI 用户(用于仅针对 NSX Manager 运行 API 调用)的过程。

在标准 NSX-v 安装中,默认情况下,仅具有 API 特权(无 vSphere Web Client 特权)的帐户就只有 NSX Manager 的“admin”帐户了。是可以使用 vSphere SSO 帐户与 NSX API 交互的,但是,这也会允许 vSphere Web Client 访问(尽管在未授予特定 vCenter 权限的情况下登录后无法查看或访问任何内容)。

但是,通过 SSO 用户运行 API 时,审核日志将显示“admin”帐户(而不是这个特定用户)已完成此 API。通过创建特定 API 角色,用户可以审核其环境并且了解运行 API 的具体位置。

Environment

VMware NSX for vSphere 6.1.x
VMware NSX for vSphere 6.2.x

Resolution

  1. 在 NSX cli 上创建用户,然后分配正确的权限。

    nsxmgr(config)#
    nsxmgr(config)# user api_username password plaintext <password>
    nsxmgr(config)#
    nsxmgr(config)# user api_username privilege web-interface
    nsxmgr(config)# exit
    nsxmgr#
    nsxmgr# write memory


    注意,如果运行第二条命令后看到以下错误消息,请联系 VMware 技术支持。

    “错误: 无法添加特权
    (ERROR: could not add privilege)”

  2. 确认用户已创建。

    nsxmgr#
    nsxmgr# show running-config
    Building configuration...
    Current configuration:
    !
    user api_username
    !
    ntp server au.pool.ntp.org
    !
    ip name server 10.10.3.24
    !
    hostname nsxmgr
    !
    interface mgmt.
    ip address 10.10.3.4/24
    !
    ip route 0.0.0.0/0 10.10.3.1
    !
    web-manager
    nsxmgr#

  3. 通过 API 创建新用户,以便用户显示为通过 CLI 创建。请确保以审核员身份启动新用户,以便后续对其进行修改。

    POST https://%3cnsx-manager-ip/ Address>/api/2.0/services/usermgmt/role/<userId>?isCli=true

    <accessControlEntry>
    <role>new-role</role>
    <resource>
    <resourceId>resource-num</resourceId>
    </resource>
    </accessControlEntry>
    Example:
    POST
    https://%3cnsx-ip%3e/api/2.0/services/usermgmt/role/api_username?isCli=true
    <accessControlEntry>
    <role>auditor</role>
    <resource>
    <resourceId>globalroot-0</resourceId>
    </resource>
    </accessControlEntry<br>
  4. 确认已在 NSX Manager gui 中创建新用户并且显示其源为 NSX CLI 用户。(转到“Networking and Security”->“NSX Manager”->“管理器 IP”->“管理”->“用户”)

  5. 您现在可以在 GUI 中更改该用户的角色,也可以运行以下 API 修改该用户。

    PUT https://<NSX-Manager-IP-Address>/api/2.0/services/usermgmt/role/<userId>
    <accessControlEntry>
    <role>role</role>
    <resource>
    <resourceId>resource-num</resourceId>
    </resource>
    </accessControlEntry>

    示例:
    PUT
    https://%3cnsx-ip/api/2.0/services/usermgmt/role/api_username
    <accessControlEntry>
    <role>enterprise_admin</role>
    <resource>
    <resourceId>globalroot-0</resourceId>
    </resource>
    </accessControlEntry>
    possible roles:
    super_user (System Administrator)
    vshield_admin (NSX Administrator)
    enterprise_admin(Enterprise Admin)
    security_admin (Security Administrator)
    auditor (Auditor)

Additional Information