openstack4j를 활용해 keystone 인증은 

http://www.openstack4j.com/learn/getting-started



openstack4j의 keystone 인증 방식(v2.0) 관련 예제는 다음과 같다. 



import org.openstack4j.api.OSClient.{OSClientV2, OSClientV3}

import org.openstack4j.core.transport.Config

import org.openstack4j.model.common.Identifier

import org.openstack4j.openstack.OSFactory



      val os: OSClientV2 = OSFactory.builderV2()

        .endpoint("https://internal.k8s.openstack.google.io:5000/v2.0")

        .credentials("sam","password")

        .tenantName("admin")

        .authenticate()


      println(os.getAccess.getToken)

      

     

결과



KeystoneToken{id=3a735957bd0c45d3b64242e0edd150cb, created=Wed Feb 07 20:51:37 KST 2018, expires=Thu Feb 08 11:51:37 KST 2018, tenant=KeystoneTenant{id=ae17dbd7165142808e074579360a8b9c, name=admin, description=NULL, enabled=true}}




v3 인증 방식(https://github.com/ContainX/openstack4j)을 사용하려면 여러 방식이 있다.

sing Identity V3 authentication you basically have 4 options:

(1) authenticate with project-scope

OSClientV3 os = OSFactory.builderV3()
                .endpoint("http://<fqdn>:5000/v3")
                .credentials("admin", "secret", Identifier.byId("user domain id"))
                .scopeToProject(Identifier.byId("project id"))
                .authenticate());

(2) authenticate with domain-scope

OSClientV3 os = OSFactory.builderV3()
                .endpoint("http://<fqdn>:5000/v3")
                .credentials("admin", "secret", Identifier.byId("user domain id"))
                .scopeToDomain(Identifier.byId("domain id"))
                .authenticate());

(3) authenticate unscoped

OSClientV3 os = OSFactory.builderV3()
                .endpoint("http://<fqdn>:5000/v3")
                .credentials("user id", "secret")
                .authenticate();

(4) authenticate with a token

OSClientV3 os = OSFactory.builderV3()
                .endpoint("http://<fqdn>:5000/v3")
                .token("token id")
                .scopeToProject(Identifier.byId("project id"))
                .authenticate());

실제로 아래와 같이 테스트해보면 안되기도 한다.


      val domainid = Identifier.byName("Default")


      val os: OSClientV3 = OSFactory.builderV3()

        .endpoint("https://internal.k8s.openstack.google.io:5000/v3")

        .credentials("sam","password",domainid)

        .scopeToDomain(domainid)

        .authenticate()


      OSFactory.enableHttpLoggingFilter(true)


      println(os.getToken)



인증만 할꺼라 json으로 파싱해서 보내는것이 나은 듯 하다.. ㄷ ㄷ 


예제의 도메인을 그대로 참조해서 

https://internal.k8s.openstack.google.io:5000/v3/auth/tokens 엔드 포인트에 다음 json을 body로 보낸다.


import play.api.libs.json._
val json: JsValue = Json.parse(s"""
{
"auth" : {
"identity": {
"methods": [ "password" ],
"password": {
"user": {
"name": "${userId}",
"domain": { "name" : "Default" },
"password": "${password}"
}
}
}
}
}
"""
)


post 결과는 다음과 같다. 


{  

   "token":{  

      "issued_at":"2018-02-07T20:42:58.000000Z",

      "audit_ids":[  

         "111123132"

      ],

      "methods":[  

         "password"

      ],

      "expires_at":"2018-02-08T20:42:58.000000Z",

      "user":{  

         "domain":{  

            "id":"default",

            "name":"Default"

         },

         "id":"1a1a1aasfdadf",

         "name":"sam"

      }

   }

}







'Cloud' 카테고리의 다른 글

fluentd 정규식 확인하기  (0) 2018.04.10
[fluentd] format json  (0) 2018.04.10
[k8s] 쿠버네티스의 로그 수집 툴  (0) 2018.02.06
[k8s] postgresql 운영 - stateful (펌질)  (0) 2018.01.25
[fluentd]의 fluent-plugin-forest(forest)  (0) 2018.01.22
Posted by '김용환'
,