14.1.1.3 토큰 기반 인증 Config File 설정
유저가 OCI CLI의 Config File 설정을 위해서 크게 API singing key 기반 인증과 토큰 기반 인증이 있습니다. (OCI에 배포된 인스턴스와 자원을 위해서는 다른 추가적인 방법도 있습니다.) 토큰 기반 인증은 웹브라우저를 통해 로그인하면 생성되는 세션 토큰을 이용하는 방식입니다. 토큰은 기본 TTL이 1시간으로 만료되기전에 갱신하여 사용할 수 있습니다.
토큰을 통한 OCI CLI 인증 설정하기
-
웹브라우저 실행이 가능한 위치에서 다음 명령을 실행합니다.
oci session authenticate
-
사용할 리전을 선택합니다.
-
웹브라우저가 자동 실행되면, OCI 콘솔에 로그인하여 인증합니다.
-
인증이 완료되면 $HOME/.oci/config 파일이 생성됩니다.
-
실행결과
$ oci session authenticate Enter a region by index or name(e.g. 1: af-johannesburg-1, 2: ap-chiyoda-1, 3: ap-chuncheon-1, 4: ap-dcc-canberra-1, 5: ap-hyderabad-1, 6: ap-ibaraki-1, 7: ap-melbourne-1, 8: ap-mumbai-1, 9: ap-osaka-1, 10: ap-seoul-1, 11: ap-singapore-1, 12: ap-sydney-1, 13: ap-tokyo-1, 14: ca-montreal-1, 15: ca-toronto-1, 16: eu-amsterdam-1, 17: eu-dcc-dublin-1, 18: eu-dcc-dublin-2, 19: eu-dcc-milan-1, 20: eu-dcc-milan-2, 21: eu-dcc-rating-1, 22: eu-dcc-rating-2, 23: eu-frankfurt-1, 24: eu-jovanovac-1, 25: eu-madrid-1, 26: eu-marseille-1, 27: eu-milan-1, 28: eu-paris-1, 29: eu-stockholm-1, 30: eu-zurich-1, 31: il-jerusalem-1, 32: me-abudhabi-1, 33: me-dcc-muscat-1, 34: me-dubai-1, 35: me-jeddah-1, 36: mx-queretaro-1, 37: sa-santiago-1, 38: sa-saopaulo-1, 39: sa-vinhedo-1, 40: uk-cardiff-1, 41: uk-gov-cardiff-1, 42: uk-gov-london-1, 43: uk-london-1, 44: us-ashburn-1, 45: us-chicago-1, 46: us-gov-ashburn-1, 47: us-gov-chicago-1, 48: us-gov-phoenix-1, 49: us-langley-1, 50: us-luke-1, 51: us-phoenix-1, 52: us-sanjose-1): 3 Please switch to newly opened browser window to log in! You can also open the following URL in a web browser window to continue: https://login.ap-chuncheon-1.oraclecloud.com/v1/oauth2/authorize?action=login&client_id=iaas_console&response_type=token+id_token&nonce=0eef1383-857d-4fa1-8814-074710ef1a76&scope=openid&public_key=eyJrdHkiOiAiUlNBIiwgIm4iOiAid3Z6U0dTd1d6Vk16bWt4XzZaaE5jelAzQmtsQWNYNXJQRDJ0V080X2dkRllPWlBUb2dRTC1JdHU4R2tLWDdGRk5DMC1SOGIxclBYRE9hcDZoc1gtQ1A2dmRyM1N3bDFXZ3ZyWHNOZl9nM2JOMkRvVVAyUGVsUUtMVVNweE1Fa25kUGVQaGVuLU92RVRTMkVfQmg3SHgyczNKcXVGWmJlWjZMa2p5aGVxa1N3cmg2UkxNQjB4dWNDb3FmTE9OOHBTc2lPZmltU2syLTVHbFRZMHNMWE9JeU9Zd01wbXdELVFZMUlaWlhja1FhRUYzVVJqRTd3S055ZTJvcGtqNDVHdGlnZlR3T0QzWFlzT1Joc1o3MjBTejYwSl9aRmlZSnNXb3NMeEo4bXZiVFRDNVltMmY5U2xaLUNIeHVpRlR3dk5fTmd6QURJdUR4eGFpZUFYZnhvSzNRIiwgImUiOiAiQVFBQiIsICJraWQiOiAiSWdub3JlZCJ9&redirect_uri=http%3A%2F%2Flocalhost%3A8181 Completed browser authentication process! Config written to: /Users/kildong/.oci/config Try out your newly created session credentials with the following example command: oci iam region list --config-file /Users/kildong/.oci/config --profile DEFAULT --auth security_token $
-
-
생성된 config 파일을 보면 아래와 같이 토큰 파일을 기반으로 하고 있습니다.
$ cat .oci/config [DEFAULT] fingerprint=30:31:c9:4a:79:d2:63:93:d8:cc:1e:55:13:ef:21:71 key_file=/Users/kildong/.oci/sessions/DEFAULT/oci_api_key.pem tenancy=ocid1.tenancy.oc1..aaaaaaaaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx region=ap-chuncheon-1 security_token_file=/Users/kildong/.oci/sessions/DEFAULT/token
-
다음 명령으로 테스트합니다.
oci os ns get --profile DEFAULT --auth security_token 또는 oci os ns get --auth security_token
-
실행결과
$ oci os ns get --profile DEFAULT --auth security_token { "data": "xxxxxxxxxxxx" }
-
토큰 유효성 검사
-
다음과 같이 토큰 유효성과 유효시간을 확인할 수 있습니다.
$ oci session validate --profile DEFAULT --auth security_token
-
실행 예시
$ oci session validate --profile DEFAULT --auth security_token Session is valid until 2023-05-10 11:48:52
-
토큰 리프레쉬
-
토큰 기본 TTL은 1시간입니다. 다음고 같이 리프레쉬 할 수 있습니다.
oci session refresh --profile DEFAULT
-
실행 예시
$ oci session refresh --profile DEFAULT Attempting to refresh token from https://auth.ap-chuncheon-1.oraclecloud.com/v1/authentication/refresh Successfully refreshed token $ oci session validate --profile DEFAULT --auth security_token Session is valid until 2023-05-10 12:13:11
-
참고 문서
- Oracle Cloud Infrastructure Documentation > Token-based Authentication for the CLI
- OCI Command Line Interface Installation and Configuration on Linux Instance - Part 1
- OCI Command Line Interface Installation and Configuration on Windows Instance - Part 2
이 글은 개인으로서, 개인의 시간을 할애하여 작성된 글입니다. 글의 내용에 오류가 있을 수 있으며, 글 속의 의견은 개인적인 의견입니다.