반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

[Predix] Understanding Platform Services 3


Using UAAC to Create an OAuth2 Client

UAA Dashboard 대신 UAAC (UAA Command-Line Interface)를 사용하여 OAuth2 클라이언트를 만들 수 있습니다.

UAAC를 사용하여 UAA 인스턴스를 관리 할 수 있습니다. command-line 인터페이스 설치에 대한 자세한 내용은 https://github.com/cloudfoundry/cf-uaac를 참조하십시오.

    1. UAA 인스턴스를 원하는 대상으로 지정하십시오.
    uaac target <uaa_instance_url>
   
    <uaa_instance_url>은 신뢰할 수있는 발급자의 URL입니다 (예 :


https://11fa0273-9e2a-37e2-9d06-2c95a1f4f5ea.predix-uaa.run.aws-usw02-pr.ice.predix.io . UAA 인스턴스를 응용 프로그램에 바인딩 한 후 VCAP_SERVICES 환경 변수에서이 URL을 검색 할 수 있습니다.
   
    2.  administrative client를 사용해 로그인 하세요.
    uaac token client get admin
   
    3. 프롬프트에서 administrative client secret 을 정하세요.
   
    4. 아래 명령어를 사용해서 OAuth2 client 를 생성하세요.
    uaac client add [client_name]
    --authorities "uaa.resource"
    --scope "openid"
    --autoapprove "openid"
    --authorized_grant_types [authorization_code|implicit|password|client_credentials|refresh_token]
    --redirect_uri [redirect_uri_1, redirect_uri_2, ...]
   
    범위 및 authorized_grant_types와 같은 UAA 옵션에 대한 자세한 내용은 https://github.com/GESoftware-CF/uaa/blob/master/docs/UAA-APIs.rst에서 UAA 설명서를 참조하십시오.
   



Updating the OAuth2 Client for Services

OAuth2 클라이언트를 업데이트하여 각 플랫폼 서비스에 특정한 권한 또는 범위를 추가하는 절차.

응용 프로그램이 플랫폼 서비스에 액세스 할 수있게하려면 JSON Web Token (JWT)에 플랫폼 서비스에 필요한 범위가 있어야합니다. 예를 들어 액세스 제어 서비스에 필요한 일부 범위는 acs.policies.read acs.policies.write입니다. 서비스에 필요한 전체 범위 목록은 각 서비스의 관련 섹션을 참조하십시오.

OAuth2 클라이언트는 권한 부여를 사용하여 액세스 토큰을 요청합니다. OAuth2는 4 가지 부여 유형을 정의합니다. 사용한 권한 부여 유형에 따라 필요한 JWT를 생성하도록 OAuth2 클라이언트를 업데이트해야합니다. OAuth2 클라이언트 생성 방법에 대한 자세한 내용은 OAuth2 클라이언트 생성을 참조하십시오.

UAA 인스턴스를 만들면 UAA 인스턴스를 구성 할 수 있도록 admin client가 자동으로 만들어집니다. admin client에는 기본적으로 필요한 권한 및 범위가 지정됩니다.

UAA 대시 보드를 사용하여 추가 클라이언트를 만드는 경우 기본적으로 클라이언트는 client_credentials 부여 유형에 대해 만들어집니다. 또한 필요한 권한과 범위 중 일부가 자동으로 클라이언트에 추가됩니다. 각 서비스에 특정한 권한이나 범위를 추가해야합니다.

또한 admin client에는 기본적으로 사용자 암호를 변경할 수있는 권한이 지정되지 않습니다. 사용자 암호를 업데이트하거나 변경해야하는 경우 uaa.admin 권한을 admin client에 추가해야합니다.

다음 절차는 클라이언트 자격 증명 권한 부여를 사용하는 OAuth2 클라이언트를 업데이트하는 데 필요한 단계를 보여줍니다.

1. Console view에서 서비스가 위치한 공간을 선택하십시오.
2. 서비스 인스턴스 페이지에서 구성해야하는 UAA 인스턴스를 선택하십시오.
3. 서비스 인스턴스 구성 옵션을 선택하십시오.
4. UAA 대시 보드 로그인 페이지에서 관리자 클라이언트 비밀번호를 지정하고 로그인을 클릭하십시오.
5. UAA 대시 보드에서 클라이언트 관리 탭을 선택합니다.
   클라이언트 관리 탭에는 클라이언트 및 서비스 인스턴스의 두 섹션이 있습니다. 서비스 인스턴스 섹션은 서비스에 대해 생성 한 서비스 인스턴스를 표시합니다.

   참고 : 여기에 표시된 서비스 인스턴스는 구성하려는 UAA를 사용하여 만든 인스턴스입니다. 다른 UAA 인스턴스를 사용하여 만든 서비스 인스턴스는이 페이지에 표시되지 않습니다.
  
6. 서비스 인스턴스 섹션에서 클라이언트를 업데이트해야하는 서비스의 + 클라이언트 인증 옵션을 클릭합니다.
7. 목록에서 기존 클라이언트를 선택하거나 새 클라이언트 추가 옵션을 선택하십시오. 새 클라이언트를 추가하기로 선택한 경우 OAuth2 클라이언트 생성의 단계를 따르십시오.
8. Submit을 클릭하십시오.
9. 클라이언트 관리 탭에서 이전 단계에서 추가 한 클라이언트에 해당하는 편집 아이콘을 클릭하십시오.
10. 클라이언트 편집 양식에서 다음 값을 지정하십시오.


Field


Description
Authorized Grant Types Choose one or more of the following grant types:
  • authorization_code

    When you use the authorization code grant type, the client directs the resource owner to UAA, which in turn directs the resource owner back to the client with the authorization code.

  • client_credentials

    When you use the client credentials grant type, the OAuth2 endpoint in UAA accepts the client ID and client secret and provides Access Tokens.

  • password

    When you use the resource owner password credentials grant type, the OAuth2 endpoint in UAA accepts the username and password and provides Access Tokens.

  • refresh_token

    The refresh tokens are credentials used to obtain access tokens. You can choose this option to obtain refresh token from UAA. You can then use the refresh token to obtain a new access token from UAA when the current access token becomes invalid or expires, or to obtain additional access tokens with identical or narrower scope.

  • implicit

    When you use the implicit grant type, UAA directly issues an Access Token to the client without authenticating the client. This reduces the number of round trips required to obtain an access token.

For more information on grant types, see RFC 6749.

Redirect URI Specify a redirect URI to redirect the client after login (for example, http://example-app.com/welcome).

This URI is used when you start using UAA as service provider for your external Identify provider.

Scopes By default, the client is assigned a few required scopes. For a new client, an administrator can select the scopes to be added based on the selected grant type.

If you select the authorization_code, password and implicit grant type, you must update the scopes with service specific scopes.

For a complete list of required scopes, see Authorities or Scopes Required for Platform Services.

For a list of available UAA scopes, see Scopes Authorized by the UAA.

Authorities By default, the client is assigned a few required authorities. For a new client, an administrator can select the authorities to be added based on the selected grant type.

If you select the client_credentials grant type, you must update the authorities with service specific authorities.

For a complete list of scopes to be added for each service, see Authorities or Scopes Required for Platform Services.

For a list of available UAA authorities, see Scopes Authorized by the UAA.

Auto Approved Scopes Specify scopes that can be approved automatically for the client without explicit approval from the resource owner.
Allowed Providers Specify the names of the external identity providers, if any. This field is required if you are using external identity providers with UAA as a service provider.
Access Token Validity Specifies the access token expiration time in ms.
Refresh Token Validity Specifies the refresh token expiration time in ms.

Next Steps:

You can complete the following additional tasks in UAA Dashboard:

  • If you are using authorization grant type as Authorization Code, Implicit, or Resource Owner Password, you can manage users in UAA.
  • You can create password policies for user passwords.
  • You can set up external identity provider or use UAA as an identity provider. See Managing Identity Providers.

If you have completed your OAuth2 client setup, you can bind your application to your service instance.




Authorities or Scopes Required for Platform Services

새 OAuth2 클라이언트를 만들면 클라이언트에 기본 범위와 권한이 할당됩니다. 각 서비스에 특정한 권한이나 범위를 추가해야합니다.

다음 표에는 OAuth2 클라이언트에 추가해야하는 각 플랫폼 서비스에 대한 범위와 권한이 나열되어 있습니다.

Service Name
Authorities/Scopes
Access Control
  • acs.policies.read
  • acs.policies.write
  • acs.attributes.read
  • acs.attributes.write
  • predix-acs.zones.<acs_instance_guid>.user

    This value is added by default if you use the UAA Dashboard. It is also generated in the VCAP_SERVICES environment variable as oauth-scope when you bind your application to your ACS service instance.

Tenant Management
  • tms.tenant.read
  • tms.tenant.write
  • predix-tms.zones.<tms_instance_guid>.user (added by default)
Analytics Catalog analytics.zones.<service_instance_guid>.user (added by default)
Analytics Runtime analytics.zones.<service_instance_guid>.user (added by default)
Asset predix-asset.zones.<service_instance_guid>.user (added by default)
Event Hub
  • Publish
    • predix-event-hub.zones.<Predix-Zone-Id>.user
    • predix-event-hub.zones.<Predix-Zone-Id>.wss.publish
    • predix-event-hub.zones.<Predix-Zone-Id>.grpc.publish
  • Subscribe
    • predix-event-hub.zones.<Predix-Zone-Id>.user
    • predix-event-hub.zones.<Predix-Zone-Id>.grpc.subscribe
Time Series
  • Data ingestion
    • timeseries.zones.<Predix-Zone-Id>.user (added by default)
    • timeseries.zones.<Predix-Zone-Id>.ingest
  • Data queries
    • timeseries.zones.<Predix-Zone-Id>.user (added by default)
    • timeseries.zones.<Predix-Zone-Id>.query
View
  • views.zones.<view_instanceId>.user (added by default)
  • views.admin.user
  • views.power.user

   
Updating the OAuth2 Client Using UAAC

Predix.io의 그래픽 사용자 인터페이스 대신 UAAC를 사용하여 OAuth2 클라이언트를 업데이트하기위한 선택적 절차.

응용 프로그램이 플랫폼 서비스에 액세스 할 수있게하려면 JSON Web Token (JWT)에 플랫폼 서비스에 필요한 범위가 있어야합니다. 예를 들어 액세스 제어 서비스에 필요한 일부 범위는 acs.policies.read acs.policies.write입니다. 서비스에 필요한 전체 범위 목록은 각 서비스의 관련 섹션을 참조하십시오.

OAuth2 클라이언트는 권한 부여를 사용하여 액세스 토큰을 요청합니다. OAuth2는 4 가지 부여 유형을 정의합니다. 사용한 권한 부여 유형에 따라 필요한 JWT를 생성하도록 OAuth2 클라이언트를 업데이트해야합니다. OAuth2 클라이언트 생성 방법에 대한 자세한 내용은 OAuth2 클라이언트 생성을 참조하십시오.






Updating the OAuth2 Client that uses Client Credentials Authorization Grant Types

Before you begin
이 절차에서는 UAAC (UAA Command Line Interface)를 사용합니다. UAAC 설치에 대한 자세한 내용은 https://github.com/cloudfoundry/cf-uaac를 참조하십시오.

다음 절차는 클라이언트 자격 증명 권한 부여를 사용하는 OAuth2 클라이언트를 업데이트하는 데 필요한 단계를 보여줍니다.

Procedure

1. UAA 인스턴스를 원하는 대상으로 지정하십시오.
uaac target <uaa_instance_url>
<uaa_instance_url>은 신뢰할 수있는 발급자의 URL입니다 (예 : https://11fa0273-9e2a-37e2-9d06-2c95a1f4f5ea.predix-uaa.run.aws-usw02-pr.ice.predix.io). UAA 인스턴스를 응용 프로그램에 바인딩 한 후 VCAP_SERVICES 환경 변수에서이 URL을 검색 할 수 있습니다.

2. Administrative client 를 사용해서 UAAC에 로그인 하세요.
uaac token client get admin
프롬프트에  <client_secret> 을 명시하세요.

3. UAA안의 플랫폼 서비스에 대해 필요한 그룹을 생성합니다.
uaac group add <service_scope>

여기서 <service_scope>는 서비스를 위해 만들어야하는 그룹입니다.

Predix 플랫폼 서비스에 필요한 그룹은 다음과 같습니다.


Service Name


Authorities
Access Control
  • acs.policies.read
  • acs.policies.write
  • acs.attributes.read
  • acs.attributes.write
  • predix-acs.zones.<acs_instance_guid>.user
Tenant Management
  • tms.tenant.read
  • tms.tenant.write
  • predix-tms.zones.<tms_instance_guid>.user
Analytics Catalog analytics.zones.<service_instance_guid>.user
Analytics Runtime analytics.zones.<service_instance_guid>.user
Asset predix-asset.zones.<service_instance_guid>.user
Time Series
  • Data ingestion
    • timeseries.zones.<Predix-Zone-Id>.user
    • timeseries.zones.<Predix-Zone-Id>.ingest
  • Data queries
    • timeseries.zones.<Predix-Zone-Id>.user
    • timeseries.zones.<Predix-Zone-Id>.query
View
  • views.zones.<view_instanceId>.user
  • views.admin.user
  • views.power.user


   
4. UAA에 새로운 유저를 생성합니다. 이 유저는 플랫폼 서비스의 administer 입니다.
Note :  이미 해당 유저가 있으면 이 단계는 건너뛰어도 괜찮습니다.
uaac user add <user_name> -p [password] --emails <user_name>@example.com

5. 필요한 scope 들에 멤버십을 할당합니다.
uaac member add <service_scope> <user_name>

콤마로 분리해 여러개의 유저를 명시할 수 있습니다.

6. OAuth2 클라이언트를 플랫폼 서비스에 필요한 범위로 업데이트하십시오.
uaac client update <client_name>
\ --scope <service_scopes>
\ --authorized_grant_types <grant_type>
\ --authorities uaa.resource

<grant_type>은 authorization_code, 암시 적, 암호 및 refresh_token 중 하나 일 수도 있고 조합 일 수도 있습니다. 여러 부여 유형을 쉼표로 구분 된 목록으로 지정할 수 있습니다.

7. administrative user를 사용해서 UAAC에 로그인 합니다.
uaac token owner get <service_client> <service_user>

프롬프트에 <client_secret>을 명시합니다.

8. 토큰에서 범위가 업데이트되었는지 확인하려면 다음 명령을 사용하십시오.
uaac token decode



Connecting Your Application to a Platform Service Instance

작성한 서비스 인스턴스와 응용 프로그램 사이의 통신을 설정하려면 응용 프로그램을 서비스 인스턴스에 바인드하십시오.

Before You Begin

Cloud Foundry에 애플리케이션을 배포하십시오.

응용 프로그램을 서비스 인스턴스에 바인딩하면 Cloud Foundry는 VCAP_SERVICES 환경 변수에 서비스의 연결 정보를 제공합니다. Cloud Foundry 런타임은 환경에 대해 배포 된 응용 프로그램과 통신하기 위해 VCAP_SERVICES 환경 변수를 사용합니다.

VCAP_SERVICES 환경 변수에서 다음 인스턴스 정보를 검색 할 수 있습니다.

    서비스 인스턴스의 instance_uri.
    instance_GUID는 서비스 인스턴스의 zoneID입니다.
    서비스 인스턴스에 액세스하기위한 HTTP 헤더 정보. 그것은 다음을 포함합니다 :
        Predix-Zone-Id로서의 http-header-name
        http-header-value
    인스턴스의 oauth 범위. 최종 사용자 토큰은 범위가 특정 서비스 인스턴스에 액세스해야합니다.

UAA 서비스 인스턴스에 바인딩하는 경우 instance_uri 및 instance_GUID 외에도 다음 정보가 표시됩니다.

    인스턴스에 대한 uaa_instance_issuerId. issuerID는 인증에 UAA 인스턴스를 사용하는 다른 서비스의 인스턴스를 만들 때 필요합니다.






Procedure
1. Cloud Foundry에 로그인 할 때는 Cloud Foundry CLI 를 사용합니다.
cf login -a <API_Endpoint>

<API_Endpoint>의 값은 Predix.io 사용자 계정에 등록 할 때 받게되는 Predix 환영 전자 메일에서 사용할 수 있습니다. Predix.io 등록에 따라 <API_Endpoint> 값은 다음 중 하나입니다.


    Predix US-West

    https://api.system.aws-usw02-pr.ice.predix.io
    Predix US-East

    https://api.system.asv-pr.ice.predix.io
    Predix Japan

    https://api.system.aws-jp01-pr.ice.predix.io
    Predix UK

    https://api.system.dc-uk01-pr.ice.predix.io

For example,

cf login -a https://api.system.aws-usw02-pr.ice.predix.io

이러면 아래와 같은 화면을 보실 겁니다.

Email> <your_predix_login> 
Password> <your_predix_password> 
Authenticating...OK 
Targeted org <your_predix_org> 
Targeted space dev     
API endpoint: https://api.system.aws-usw02-pr.ice.predix.io (API version: <version>)   
User: <your_predix_login> 
Org:  <your_predix_org>  
Space: dev



2. 다음 명령을 입력하여 응용 프로그램을 서비스 인스턴스에 바인드하십시오.
cf bind-service <your_app_name> <service_instance_name>

응용 프로그램이 <service_instance_name> 인스턴스에 바인딩되고 다음 메시지가 반환됩니다.

Binding service <service_instance_name> to app <your_app_name> in org predix-platform / space predix as userx@ge.com...
OK
TIP: Use 'cf restage' to ensure your env variable changes take effect

3. 아래와 같은 명령어를 사용해 binding 을 verify 합니다.
cf env <your_app_name>

응용 프로그램 myApp를 UAA 인스턴스에 바인딩하면 다음 메시지가 반환됩니다.

Getting env variables for app myApp in org predix-platform / space security as userx@ge.com...
OK
...
  ],
  "predix-uaa": [
        {
        "credentials":
        {
         "issuerId":
          "https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io/oauth/token",
         "uri": 
           "https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io",
          "zone": {
                    "http-header-name": "X-Identity-Zone-Id",
                    "http-header-value": "ff27c315-d027-4d1d-a30c-64f49b369ed9"
                   }
        },
        "label":
        "predix-uaa",
        "name":
        "my_uaa_instance",
        "plan":
        "free",
        "tags":
        []
        }
        ],


       
이 예제에서는 아래와 같은 값들이 표시됩니다.


    uaa_instance_issuerId = https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io/oauth/token
    uaa_instance_uri = https://ff27c315-d027-4d1d-a30c-64f49b369ed9.predix-uaa.run.aws-usw02-pr.ice.predix.io
    uaa_instance_GUID = ff27c315-d027-4d1d-a30c-64f49b369ed9

응용 프로그램 myApp를 ACS 서비스 인스턴스에 바인딩하면 다음 메시지가 반환됩니다.

Getting env variables for app myApp in org predix-platform / space security as userx@ge.com...
OK
...
  ],
"predix-acs": [
   {
    "credentials": {
     "uri": "https://predix-acs.run.aws-usw02-pr.ice.predix.io",
     "zone": {
      "http-header-name": "Predix-Zone-Id",
      "http-header-value": "9615a95a-9275-4a82-926d-89f06cbe04e1",
      "oauth-scope": "predix-acs.zones.9615a95a-9275-4a82-926d-89f06cbe04e1.user"
     }
    },
    "label": "predix-acs",
    "name": "acs-sample-instance",
    "plan": "Tiered",
    "provider": null,
    "syslog_drain_url": null,
    "tags": []
   }
  ],
 
  이 예제에서는 아래와 같은 값들이 표시됩니다.
 
 
    acs_instance_uri = https://predix-acs.run.aws-usw02-pr.ice.predix.io
    acs_instance_GUID = 9615a95a-9275-4a82-926d-89f06cbe04e1
    http-header-name = Predix-Zone-Id
    http-header-value = 9615a95a-9275-4a82-926d-89f06cbe04e1
    oauth-scope = predix-acs.zones.9615a95a-9275-4a82-926d-89f06cbe04e1.user

반응형