이 항목에서는 API를 사용할 때 NSX 세션 기반 인증을 사용하여 JSESSIONID 쿠키를 생성하는 방법을 설명합니다. 이 방법을 사용하여 사용자 이름과 암호를 입력해야 하는 횟수를 줄입니다. 이 유형의 인증을 vIDM 및 LDAP 인증과 함께 사용할 수 있습니다.

NSX는 몇 가지 다른 메커니즘을 사용하여 NSX 사용자를 인증합니다. 여기에는 다음이 포함됩니다.

  • HTTP 인증
  • 세션 기반 인증
  • 주체 ID 또는 인증서 기반 인증
  • vIDM 및 CSP(Cloud Service Platform)를 사용하는 Single Sign-On

NSX는 사용자 이름과 암호를 사용하여 세션 생성 중에 세션 쿠키를 생성합니다. 세션 쿠키가 생성되면 후속 API 요청은 선택적으로 사용자 이름 및 암호 자격 증명 대신 이 세션 쿠키를 사용할 수 있습니다. 세션 상태는 세션 쿠키를 생성한 특정 NSX Manager에 해당합니다. 클라이언트가 NSX Manager에 대한 요청을 수행하는 경우 클라이언트에서 제공하는 세션 쿠키가 관리자가 생성한 쿠키 중 하나와 일치하는 경우에만 클라이언트에서 인증을 받을 수 있습니다. 사용자가 NSX Manager에서 로그아웃하면 세션 쿠키가 NSX Manager의 역방향 프록시에서 즉시 제거되며 재사용할 수 없습니다. 유휴 세션이 자동으로 시간 초과되거나 API를 사용하여 삭제할 수 있습니다.

API 요청을 사용한 액세스는 감사 로그 세부 정보를 생성합니다. 이 로깅은 항상 사용하도록 설정되며, 사용하지 않도록 설정할 수 없습니다. 세션 감사는 시스템 시작 시 시작됩니다. 감사 로그 메시지는 로그 메시지의 구조화된 데이터 부분에 텍스트 audit="true"를 포함합니다.

이 예에서는 cURL을 사용하여 API 호출에 대한 세션 기반 인증을 생성하는 방법을 설명합니다.

프로시저

  1. NSX Manager에서 인증을 받고 헤더에서 xsrf를 검색하는 새 세션 쿠키를 생성하려면:
    # curl -v -k -c session.txt -X POST -d '[email protected]&j_password=SecretPwsd3c4d' https://<manager-ip>/api/session/create 2>&1 > /dev/null | grep -i xsrf < x-xsrf-token: 5a764b19-5ad2-4727-974d-510acbc171c8

    이 예에서 cURL 명령은 관리자에서 인증받고, 세션 쿠키를 sessions.txt 파일에 배치하고, headers.txt 파일에 모든 HTTP 응답 헤더를 기록합니다. headers.txt의 헤더 중 하나인 x-xsrf-token 헤더를 사용하여 후속 요청에 제공해야 합니다.

    사용자 이름에 @에 대한 표준 유니코드/URI 인코딩을 사용할 수도 있습니다.

    세션 컨텐츠의 예는 다음과 같습니다.

    # cat session.txt
          # Netscape HTTP Cookie File
          # https://curl.haxx.se/docs/http-cookies.html
          # This file was generated by libcurl! Edit at your own
            risk.
          # HttpOnly_172.182.183.135 FALSE / TRUE 0 JSESSIONID CFG588DF6DGF493C0EAEFC62685C42E1
  2. 두 개의 세션을 생성해야 하는 경우 두 세션이 모두 유효하도록 session.txt 파일의 이름을 변경합니다.
    # curl -v -k -c session1.txt -X POST -d 'j_username= [email protected]&j_password=SecretPwsd3c4d' https://<manager-ip>/api/session/create 2>&1 > /dev/null | grep -i xsrf < x-xsrf-token: cbce48f3-48fc-46c0-a8e7-f2f55ebf8e15
    # curl -v -k -c session2.txt -X POST -d 'j_username= [email protected]&j_password=SecretPwsd3c4d' https://<manager-ip>/api/session/create 2>&1 > /dev/null | grep -i xsrf < x-xsrf-token: abf1fa2c-86d5-47e4-9a0a-242424dd1761
  3. 후속 호출의 경우 이전 단계의 세션 쿠키 및 xsrf 헤더를 사용합니다.
    # curl -k -b session.txt -H "x-xsrf-token: 5a764b19-5ad2-4727-974d-510acbc171c8"
          https://10.182.183.135/policy/api/v1/infra/segments
          {
            "results" : [ {
              "type" : "ROUTED",
              "subnets" : [ {
                "gateway_address" : "192.168.10.1/24",
                "network" : "192.168.10.0/24"
              } ],
              "connectivity_path" :
            "/infra/tier-1s/test_t1",
              "transport_zone_path" :
            "/infra/sites/default/enforcement-points/default/transport-zones/1b3a2f36-bfd1-443e-a0f6-4de01abc963e",
              "advanced_config" : {
                "address_pool_paths" : [ ],
                "hybrid" : false,
                "multicast" : true,
                "inter_router" : false,
                "local_egress" : false,
                "urpf_mode" : "STRICT",
                "connectivity" : "ON"
              },
              "admin_state" : "UP",
              "replication_mode" : "MTEP",
              "resource_type" : "Segment",
              "id" : "seg1",
              "display_name" : "seg1",
              "path" : "/infra/segments/seg1",
              "relative_path" : "seg1",
              "parent_path" : "/infra",
              "unique_id" :
            "6573d2c9-f4f9-4b37-b410-71bded8857c3",
              "marked_for_delete" : false,
              "overridden" : false,
              "_create_user" : "admin",
              "_create_time" : 1633331197569,
              "_last_modified_user" : "admin",
              "_last_modified_time" : 1633331252660,
              "_system_owned" : false,
              "_protection" : "NOT_PROTECTED",
              "_revision" : 1
            } ],
            "result_count" : 1,
            "sort_by" : "display_name",
            "sort_ascending" : true
        
    클러스터의 다른 노드에서 동일한 세션 쿠키를 사용하는 경우 다음 오류 메시지를 나타내며 명령이 실패합니다.
    The credentials were incorrect or the account specified has been locked.","error_code":403.

    세션이 만료되면 NSX Manager는 403 금지됨 HTTP 응답으로 대응합니다. 그런 다음, 새 세션 쿠키 및 x-xsrf-token을 획득해야 합니다.

  4. 세션 만료 설정을 구성하려면 connection_timeout API 명령을 사용합니다. 기본 세션 만료는 1800초(30분)입니다.
    1. GET https://<nsx-mgr>/api/v1/cluster/api-service를 사용하여 현재 구성의 스크린샷을 볼 수 있습니다.
      GET https://<nsx-mgr>/api/v1/cluster/api-service
      {
          "session_timeout": 1800,
          "connection_timeout": 30,
          "protocol_versions": [
              {
                  "name": "TLSv1.1",
                  "enabled": true
              },
              {
                  "name": "TLSv1.2",
                  "enabled": true
              }
          ],
          "cipher_suites": [
              {
                  "name": "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
                  "enabled": true
              },
              {
                  "name": "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
                  "enabled": true
              },
              {
                  "name": "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
                  "enabled": true
              },
              {
                  "name": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
                  "enabled": true
              },
              {
                  "name": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
                  "enabled": true
              },
              {
                  "name": "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
                  "enabled": true
              },
              {
                  "name": "TLS_RSA_WITH_AES_128_CBC_SHA",
                  "enabled": true
              },
              {
                  "name": "TLS_RSA_WITH_AES_128_CBC_SHA256",
                  "enabled": true
              },
              {
                  "name": "TLS_RSA_WITH_AES_128_GCM_SHA256",
                  "enabled": true
              },
              {
                  "name": "TLS_RSA_WITH_AES_256_CBC_SHA",
                  "enabled": true
              },
              {
                  "name": "TLS_RSA_WITH_AES_256_CBC_SHA256",
                  "enabled": true
              },
              {
                  "name": "TLS_RSA_WITH_AES_256_GCM_SHA384",
                  "enabled": true
              }        ,
              {
                  "name": "TLS_ECDSA_WITH_AES_256_GCM_SHA384",
                  "enabled": true
              }
          ],
          "redirect_host": "",
          "client_api_rate_limit": 100,
          "global_api_concurrency_limit": 199,
          "client_api_concurrency_limit": 40,
          "basic_authentication_enabled": true,
          "cookie_based_authentication_enabled": true,
          "resource_type": "ApiServiceConfig",
          "id": "reverse_proxy_config",
          "display_name": "reverse_proxy_config",
          "_create_time": 1658339081246,
          "_create_user": "system",
          "_last_modified_time": 1658339081246,
          "_last_modified_user": "system",
          "_system_owned": false,
          "_protection": "NOT_PROTECTED",
          "_revision": 0
      }
      
    2. 원하는 값으로 JSON을 편집하고 _revision을 제외한 모든 밑줄 필드(_xxxxx)를 제거합니다.
       GET https://<nsx-mgr>/api/v1/cluster/api-service
      {
          "global_api_concurrency_limit": 199,
          "client_api_rate_limit": 100,
          "client_api_concurrency_limit": 40,
          "connection_timeout": 30,
          "redirect_host": "",
          "cipher_suites": [     
            {"enabled": true, "name": "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"},
            {"enabled": true, "name": "TLS_RSA_WITH_AES_256_GCM_SHA384"},
            {"enabled": true, "name": "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"},
            {"enabled": true, "name": "TLS_RSA_WITH_AES_128_GCM_SHA256"}
            {"enabled": true, "name": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384}",
            {"enabled": true, "name": "TLS_RSA_WITH_AES_256_CBC_SHA256"},
            {"enabled": true, "name": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"},
            {"enabled": true, "name": "TLS_RSA_WITH_AES_256_CBC_SHA"},
            {"enabled": true, "name": "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"},
            {"enabled": true, "name": "TLS_RSA_WITH_AES_128_CBC_SHA256"},
            {"enabled": false, "name": "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"},
            {"enabled": true, "name": "TLS_RSA_WITH_AES_128_CBC_SHA"},
        
            {"enabled": true, "name": "TLS_ECDSA_WITH_AES_256_GCM_SHA384"},
          ],
            "protocol_versions": [
              {"enabled": true, "name": "TLSv1.1"},
          {"enabled": true, "name": "TLSv1.2"}
        ]    
          "_revision": 0
      }
      
    3. PUT https://<nsx-mgr>/api/v1/cluster/api-service를 사용하여 현재 구성을 수정합니다.
  5. 세션 쿠키를 삭제하려면 /api/session/destroy API 명령을 사용합니다.
    curl -k -b cookies.txt -H "`grep x-xsrf-token headers.txt`" -X POST https://<nsx-manager>/api/session/destroy
    예:
    curl -k -b cookies.txt -H "`grep x-xsrf-token headers.txt`" https://$TESTHOST/api/session/destroy
    curl -k -b cookies.txt -H "`grep x-xsrf-token headers.txt`" https://$TESTHOST/api/v1/logical-ports
    응답:
    {
        "module_name" : "common-services",
        "error_message" : "The credentials were incorrect or the account specified has been locked.",
        "error_code" : "403"
    }
    

다음에 수행할 작업

세션 기반 지원 인증 서비스를 사용하여 사용자를 인증하기 위한 요구 사항을 검토하려면 VMware Identity Manager/Workspace ONE Access와 통합 또는 LDAP(Lightweight Directory Access Protocol)와 통합 항목을 참조하십시오.