# AWS CLI

{% hint style="info" %}
Okta를 통한 AWS Command Line Interface (AWS CLI) 인증 구성하는 가이드 입니다.

* "AWS IAM Identidy Center" 또는 "AWS Account Federation"이 Okta와 구성 되어 있어야 하며, \
  둘 중 구성된 AWS 환경에 따라 AWS CLI 구성이 다르기 때문에 아래 항목에서 구성된 AWS 환경의 가이드로 이동하여 AWS CLI 구성을 진행하시기 바랍니다.
  1. [AWS Account Federation (AWS Account 개별 구성 환경)](#id-1.-aws-account-federation)
  2. [AWS IAM Identity Center (AWS 관리형 페더레이션 환경)](#id-2-aws-iam-identity-center)
     {% endhint %}

{% hint style="success" %}
Okta를 통한 AWS CLI 인증 구성을 하면 아래 항목에 보안이 강화 됩니다.

1. 운영 리소스 감소 : CLI 접속 시 필요한 Access Key / Secret Key가 필요 없기 때문에 운영과 관리에 대한 부담이 줄어듭니다.
2. 보안 위험 감소 : 관리 권한의 Access Key가 아닌 Okta 인증 시 Account와 역할에 부여된 임시 키를 사용하기 때문에 보안의 리스크가 줄어듭니다.
3. 보안 및 감사 강화 : Okta의 MFA와 로그를 통해 사용자 접속 이력을 추적하고 다양한 인증 수단으로 보안을 강화할 수 있습니다.
   {% endhint %}

***

## 1. AWS Account Federation

{% hint style="warning" %}
구성 전 필수 조건

* AWS CLI 구성과 인증이 필요한 AWS Account에 대하여 검토하여, 해당 Account는 SAML 기반으로 AWS Account Federation 구성이 먼저 적용되어야 합니다.
* AWS Account Federation 구성 가이드는 아래 링크를 참고 바랍니다.
  * [AWS Federation: Single Account](/okta/management/app-integraiton/app-integration-guide/amazon-web-service/aws-federation-single-account.md) (Account 1개 일 경우)
  * [AWS Federation: Multi Account](/okta/management/app-integraiton/app-integration-guide/amazon-web-service/aws-federation-multi-account.md) (Account가 다수 일 경우)\
    &#x20;*<mark style="color:blue;">**- IAM에 구성한 IDP Name은 모든 Account에서 동일하여야 ARN 오류가 발생하지 않습니다.**</mark>*
    {% endhint %}

{% hint style="info" %}
Okta 공식 구성 가이드

* [Configure Okta as IdP for AWS CLI](https://help.okta.com/oie/en-us/content/topics/deploymentguides/aws/aws-configure-cli.htm)

&#x20;AWS CLI 전용 OIDC 앱을 Okta에서 Custom App으로 구성하며, SAML 기반으로 구성한 AWS Federation 구성 앱과 통합하여 Account / Role이 부여됩니다.
{% endhint %}

### 1.1 AWS CLI 용도의 OIDC Custom Application 구성

> * Okta 관리콘솔에서 "Applications" → "Create App Integration" 선택
>
>   <figure><img src="/files/6UPsUJWtLNHGc3kmfrkT" alt=""><figcaption></figcaption></figure>

> * "OIDC - OpenID Connect" 메소드와 "Native Application" 타입을 선택 후 "Next"를 클릭합니다.<br>
>
>   <figure><img src="/files/XFKYfYVEMOmmGsf8xaFO" alt=""><figcaption></figcaption></figure>

> * 아래 옵션 및 항목을 적용 후 "Save" 합니다.
>   * App integration name : AWS CLI
>   * Grant type :&#x20;
>     * "<mark style="color:blue;">**Device Authorization**</mark>" 옵션 체크
>     * Advanced 선택 후 "<mark style="color:blue;">**Token Exchange**</mark>" 옵션 체크
>
>       <figure><img src="/files/AF4akIQtfNW3teCZBC0G" alt=""><figcaption></figcaption></figure>
>   * Controlled access : "<mark style="color:blue;">**Skip group assignment for now**</mark>" 선택 후 "<mark style="color:blue;">**Save**</mark>"
>
>     <figure><img src="/files/PmWLVw5fd35JAtTxelWp" alt=""><figcaption></figcaption></figure>

> * Application이 생성되면 "General" 항목에서 "Client ID" 정보를 복사해둡니다.<br>
>
>   <figure><img src="/files/0eKDft7hSP0T2eOzjBgM" alt=""><figcaption></figcaption></figure>

### 1.2 AWS Account Federation에 AWS CLI 구성

> * 위에 복사한 AWS CLI 앱의 Client ID를 아래와 같이 <mark style="color:orange;">**AWS Account Federation 앱**</mark>에 설정합니다.\
>   &#x20;\> "AWS Account Federation" → "Sign On" → "Settings"에서 "<mark style="color:blue;">Edit</mark>" 선택
>
>   <figure><img src="/files/9MPYYggsxk4zjiOwwK1q" alt=""><figcaption></figcaption></figure>
>
>   &#x20;\> "Allowed Web SSO Client" 항목에 AWS CLI 앱의 <mark style="color:blue;">**Client ID를 입력**</mark>합니다.
>
>   <figure><img src="/files/zUbjBylb9kpYgsxjEycN" alt=""><figcaption></figcaption></figure>

> * 사용자 CLI 접속하는 사용자는 AWS Account Federation 앱과 동일하게 Assign 되어 있어야 합니다. <mark style="color:blue;">**(그룹을 통한 사용자 Assign 구성을 권장 드립니다.)**</mark>
>
>   <figure><img src="/files/iA8gwbxrU3dvWOKDhbum" alt=""><figcaption></figcaption></figure>

### 1.3 "okta-aws-cli" tool 설치 및 구성

* 기존 사용자 AWS CLI 접속의 "aws cli" tool이 아닌 <mark style="color:blue;">**"okta-aws-cli" tool을 통해 접속**</mark>하여야 Okta 인증 구성이 가능합니다.

{% hint style="info" %}
"okta-aws-cli" tool 설치가 필요하며, 아래 설치 가이드 링크를 참고 바랍니다.

* [Github : okta-aws-cli](https://github.com/okta/okta-aws-cli)

Windows 는 ["Chocolatey" 통해 설치](https://github.com/okta/okta-aws-cli?tab=readme-ov-file#windowschocolatey) / Mac OS는 ["Homebrew" 통해 설치](https://github.com/okta/okta-aws-cli?tab=readme-ov-file#osxhomebrew)
{% endhint %}

<figure><img src="/files/PBOG7Mjbc1HeLcuh1ylC" alt=""><figcaption></figcaption></figure>

* "okta-aws-cli" 설치 <mark style="color:blue;">**(CMD 관리자 권한 실행 필수)**</mark>

<figure><img src="/files/pfI4XY2dvmKtyY1xA1GX" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/LyU9UssSiLIYa1pi8UAJ" alt=""><figcaption><p>설치 내역 확인</p></figcaption></figure>

* "okta-aws-cli" 명령어 및 사용법

```
Usage:
  okta-aws-cli web [flags]

Flags:
  -k, --all-profiles                  Collect all profiles for a given IdP (implies aws-credentials file output format)
  -a, --aws-acct-fed-app-id string    AWS Account Federation app ID
  -i, --aws-iam-idp string            Preset IAM Identity Provider ARN
  -h, --help                          help for web
  -b, --open-browser                  Automatically open the activation URL with the system web browser
  -m, --open-browser-command string   Automatically open the activation URL with the given web browser command
  -q, --qr-code                       Print QR Code of activation URL

Global Flags:
  -w, --aws-credentials string        Path to AWS credentials file, only valid with format "aws-credentials" (default "C:\Users\{사용자}\.aws\credentials")
  -r, --aws-iam-role string           Preset IAM Role ARN
  -n, --aws-region string             Preset AWS Region
  -s, --aws-session-duration string   Session duration for role.
  -e, --cache-access-token            Cache Okta access token to reduce need for opening grant URL
  -g, --debug                         Print operational information to the screen for debugging purposes
  -d, --debug-api-calls               Verbosely print all API calls/responses to the screen
  -j, --exec                          Execute any shell commands after the '--' CLI arguments termination
  -x, --expiry-aws-variables          Emit x_security_token_expires value in profile block of AWS credentials file
  -f, --format string                 Output format. [aws-credentials|env-var|noop|process-credentials]
  -l, --legacy-aws-variables          Emit deprecated AWS Security Token value. WARNING: AWS CLI deprecated this value in November 2014 and is no longer documented
  -c, --oidc-client-id string         OIDC Client ID - web: OIDC native application, m2m: API service application
  -o, --org-domain string             Okta Org Domain
  -p, --profile string                AWS Profile
  -y, --short-user-agent              Set CLI's User-Agent header to okta-aws-cli so it can be used in a policy rule
  -z, --write-aws-credentials         Write the created/updated profile to the "C:\Users\{사용자}\.aws\credentials" file. WARNING: This can inadvertently remove dangling comments and extraneous formatting from the creds file.
```

### 1.4 사용자 경험 (인증 및 권한)

{% hint style="info" %}
해당 Okta CLI의 인증은 AWS Account Federation 앱을 통한 SAML 구성으로 Assume Role이 부여 됩니다.

* "aws cli" tool이 아닌 "okta-aws-cli" tool을 사용하기 때문에 에 구성된 "aws cli"에서 "credentials" 정보는 아래와 같이 확인하시고, <mark style="color:blue;">**모든 사용자에 대해 Okta 인증을 통해 AWS CLI 접속으로 전환한다면 "credentials" 정보에 대한 삭제 여부를 검토하시기 바랍니다.**</mark>
  * 기존 AWS CLI 연결에 대한 "aws configure" AWS 인증 정보 구성 체크
    * 명령어 : aws sts get-caller-identity

      <figure><img src="/files/k8Liq0A7WrqypSI2XgQc" alt=""><figcaption><p>"aws cli" tool 설치 되어 있어도 aws 인증 구성은 안되어 있는 상태를 확인하는 사항</p></figcaption></figure>

{% endhint %}

> * "okta-aws-cli"를 통한 인증
>
>   * 명령어 : okta-aws-cli web --oidc-client-id <mark style="color:orange;">**{AWS CLI 앱**</mark>**&#x20;**<mark style="color:red;">**Client ID**</mark><mark style="color:orange;">**}**</mark> --aws-acct-fed-app-id <mark style="color:orange;">**{AWS Account Federation**</mark>**&#x20;**<mark style="color:red;">**Application ID**</mark><mark style="color:orange;">**}**</mark> --org-domain <mark style="color:orange;">**{subdomain}**</mark>.okta.com -z
>
>     <figure><img src="/files/b6v340KdpNvH4Q4lVC4u" alt=""><figcaption><p>Okta 인증을 위한 URL 복사</p></figcaption></figure>
>
>   * 복사한 URL을 인터넷 브라우저로 연결하여 "다음" 선택합니다.&#x20;
>
>     <figure><img src="/files/Zd6WF3vZ6PAitmodGGBo" alt=""><figcaption></figcaption></figure>
>
>   * 사용자 인증을 진행 합니다.
>
>     <figure><img src="/files/fF3vJwtJ3WUNiVKwuK0S" alt=""><figcaption></figcaption></figure>
>
>   * 인증이 완료 되면 "장치 활성화 됨" 결과가 확인되며 브라우저를 닫습니다.
>
>     <figure><img src="/files/pb1beDLfAKYmUsLXY8rN" alt=""><figcaption></figcaption></figure>
>
>   * 그리고 아래와 같이 "credentials"의 인증 구성이 완료 됩니다.
>
>     <figure><img src="/files/ZxnG45A1i8zl24OeCmDF" alt=""><figcaption></figcaption></figure>

> * Okta 인증 구성 확인 <mark style="color:blue;">**(Assume Role)**</mark>
>   * 명령어 : aws sts get-caller-identity
>
>     <figure><img src="/files/fPrjYpTNm56ZiHqmcifl" alt=""><figcaption></figcaption></figure>
>   * "credentials" 정보 확인
>
>     <figure><img src="/files/PTRLoHp503v7fcKt6pkF" alt=""><figcaption></figcaption></figure>

> * 최종 Okta의 Assume Role을 통해 AWS 명령어 정상 실행여부 확인
>
>   <figure><img src="/files/bqRUAGqkJtvuIlCL2Qyx" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
사용자의 Multi Account / Role은 아래와 같이 선택할 수 있습니다.

* 다수의 Account / Role이 존재하는 사용자는 아래 인증 과정처럼,\
  &#x20;"Tab" 버튼 또는 "화살표" 방향으로 선택하여 사용자가 원하는 Account의 Role을 할당 받을 수 있습니다.

  <figure><img src="/files/AIABYQ8aLzOZxIfFupdz" alt=""><figcaption></figcaption></figure>
* "credentials"에는 한가지 Role만 AssumeRole 구성 및 업데이트 됩니다.

  <figure><img src="/files/Hff8x5HTqbeRH8kTUA6U" alt=""><figcaption></figcaption></figure>

{% endhint %}

***

## 2. AWS IAM Identity Center

{% hint style="info" %}

* "aws cli" tool에서 제공하는 SSO 기능을 활용하여 Okta와 인증 구성을 적용합니다.
  * AWS 공식 가이드 : [AWS CLI 설치 / 업데이트](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
    {% endhint %}

### 2.1 "aws cli" tool에 SSO 설정

> * AWS CLI 설치 및 버전 확인
>   * 명령어 :  aws --version&#x20;
>
>     <figure><img src="/files/3xeHEoaEx8JqRh782hdx" alt=""><figcaption></figcaption></figure>
> * AWS CLI 에 SSO 프로파일 설정
>
>   * 명령어 : aws configure sso
>
>     * SSO session name (Recommended): okta
>     * SSO start URL \[None]: <mark style="color:blue;">**{AWS access portal 로그인 URL}**</mark>
>     * SSO region \[None]: <mark style="color:blue;">**{AWS Identity Center 구성 region}**</mark>
>     * SSO registration scopes \[sso:account:access]: 무시(엔터)
>
>     <figure><img src="/files/yUFGEKbYeSMKoGZ8sLBu" alt=""><figcaption></figcaption></figure>
>
>     &#x20;
>
>   &#x20;<mark style="color:orange;">- AWS에서 "AWS access portal 로그인 URL", "AWS Identity Center 구성 region" 확인 방법</mark>
>
>   <figure><img src="/files/uJixPZrNYTa3DamPihbO" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

* Okta 대시보드에서 AWS IAM Identity Center를 통해 <mark style="color:orange;">**"AWS access portal 로그인 URL"**</mark>**,&#x20;**<mark style="color:orange;">**"AWS Identity Center 구성 region"**</mark>**&#x20;확인 방법**
  * Okta 대시보드에서 "<mark style="color:blue;">**AWS IAM Identity Center**</mark>" 접속

    <figure><img src="/files/eR2GH5vn0cKyfUcAwDil" alt=""><figcaption></figcaption></figure>

  * AWS CLI의 SSO 프로파일 구성할 AWS Account에 "<mark style="color:blue;">**액세스 키**</mark>" 선택<br>

    <figure><img src="/files/DkKxmVUqofrP9e8Hxksk" alt=""><figcaption></figcaption></figure>

  * "<mark style="color:blue;">**SSO start URL**</mark>**"**, "<mark style="color:blue;">**SSO region**</mark>" 정보를 확인할 수 있습니다.

    <figure><img src="/files/bgESs0JdYZSYBgSWzW86" alt=""><figcaption></figcaption></figure>

{% endhint %}

> * 입력 완료되면 아래와 같이 <mark style="color:blue;">**인증 링크가 생성**</mark>되며, 브라우저를 통해 AWS CLI SSO 구성의 인증을 진행합니다.
>
>   <figure><img src="/files/3TCOG3iEVoqIfQ3wp5LF" alt=""><figcaption></figcaption></figure>
>
>   * 사용자 인증 <mark style="color:blue;">**(AWS와 Okta 앱에 인증하려는 사용자가 생성되고 할당되어 있어야 합니다.)**</mark>\
>     ![](/files/OUgb6xCAnfIBoYr9j8Yq)<br>
>   * "<mark style="color:blue;">**엑세스 허용**</mark>" 선택\
>     ![](/files/3nXVjcNF6RYIFuq8fqjZ)<br>
>   * 권한 승인 완료\
>     ![](/files/8E2M1LKFdoXr0x4veoJY)<br>
> * 인증이 완료 되면 아래와 같이 SSO 프로파일의 추가 설정 단계가 진행 됩니다.
>   * Default client Region \[None]: <mark style="color:blue;">**{기본 Client 접속 region}**</mark>
>   * CLI default output format (json if not specified) \[None]: <mark style="color:blue;">**{json 권장}**</mark>
>   * Profile name \[AWS Role-AWS Account]: <mark style="color:blue;">**{선택사항}**</mark>\ <mark style="color:blue;">**>**</mark> <mark style="color:blue;"></mark><mark style="color:blue;">사용자가 다수의 Account와 Role이 할당되어 있어 각 역할에 따른 SSO 분리 구성이 필요하다면, 정확한 식별을 위해 명시하는 것을 권장 드립니다.</mark>
>
>     <figure><img src="/files/1XrWvbVhYlLOTTpCc9sP" alt=""><figcaption></figcaption></figure>

### 2.2  AWS SSO 프로파일을 통한 AWS CLI 실행

> * 위에서 생성 된 SSO 프로파일에 대해 정상적으로 구성되었는지 확인 합니다.
>   * 명령어 : aws sts get-caller-identity --profile <mark style="color:blue;">**{SSO Profile Name}**</mark>
>
>     <figure><img src="/files/npDVLXjjjmhuHaigOsPH" alt=""><figcaption></figcaption></figure>
> * SSO 프로파일의 Account와 Role에 의해 AWS CLI 명령 실행 <mark style="color:blue;">**(aws s3 ls)**</mark>
>   * 명령어 : aws s3 ls --profile <mark style="color:blue;">**{SSO Profile Name}**</mark>
>
>     <figure><img src="/files/OPba5QgVTjDj4HsUc1LD" alt=""><figcaption></figcaption></figure>

### 2.3 참고 사항

{% stepper %}
{% step %}

### AWS CLI 명령어 실행할 때마다 계속 <mark style="color:orange;">"SSO 프로파일 옵션"(--profile)</mark>을 뒤에 붙여 주어야 하나요?

> * 정확히 어떤 Account의 역할을 통해 AWS CLI 명령어을 실행하는지 확인을 위해 옵션을 사용하는 것이 좋지만, **많은 명령어 실행 작업과 고정된 Account의 역할을 사용한다면&#x20;**<mark style="color:blue;">**기본 SSO 프로파일로 설정하여 옵션을 제거**</mark>**하여 AWS CLI 명령을 실행 할 수 있습니다.**
>   * 1번 방법 : 현재 Shell(PowerShell / CMD)에 기본값 구성 <mark style="color:orange;">**(다른 Shell은 적용 안됨)**</mark>
>     * Windows 명령어: set AWS\_PROFILE=<mark style="color:blue;">**{SSO Profile Name}**</mark>
>     * Mac OS  / Linux  명령어 : export AWS\_PROFILE=<mark style="color:blue;">**{SSO Profile Name}**</mark>
>
>       <figure><img src="/files/mTNQPcCqTkEsqAJXFobl" alt=""><figcaption></figcaption></figure>
>   * 2번 방법 : AWS CLI의 Config를 통한 기본 프로파일 구성
>     * Path : C:\Users\\<mark style="color:blue;">**{사용자}**</mark>\\.aws
>     * File : config
>
>       <figure><img src="/files/tbUcs9Jt83HfR5ka3JDM" alt=""><figcaption></figcaption></figure>
>     * Config 수정
>       * 아래와 같이 기본 값으로 구성할 <mark style="color:blue;">"SSO 프로파일"에 대해</mark> <mark style="color:blue;"></mark><mark style="color:blue;">**복사 후**</mark> "SSO 프로파일" <mark style="color:blue;">이름을 "</mark><mark style="color:blue;">**default**</mark><mark style="color:blue;">" 로 변경</mark>합니다.
>
>         <figure><img src="/files/Kmqe5KTO94RNvyAyNQlt" alt=""><figcaption></figcaption></figure>
>       * "default" 변경 됨에 따라 SSO 프로필 옵션이 자동으로 적용되어 AWS CLI 명령어 실행이 가능합니다. <mark style="color:orange;">**(새로운 Shell을 실행하여도 "SSO 프로파일" 옵션이 계속 고정 적용 됨)**</mark>
>
>         <figure><img src="/files/ox5ze4YjpcZR6odICI7f" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

### AWS CLI에 SSO 구성 삭제 하는 방법은 없나요?

> * "C:\Users\\<mark style="color:blue;">**{사용자}**</mark>\\.aws" 경로에 있는 모든 파일을 삭제 후 "aws configure" 통해 다시 인증 구성을 하시면 됩니다. <mark style="color:red;">**(빨간 박스 항목 전부 삭제)**</mark>
>
>   <figure><img src="/files/R0u52Ks8yjNzTLaM08xI" alt=""><figcaption></figcaption></figure>

{% endstep %}

{% step %}

### SSO 인증한 임시 Access Key에 대한 세션은 어떻게 관리되나요?

> * Okta SSO 인증 정보는 "\~.aws\cli\cache" 경로에 json 파일로 생성됩니다.
>
>   <figure><img src="/files/uH1NIm7YD9RoK0V77Ury" alt=""><figcaption></figcaption></figure>
> * 인증 완료되고 임시 AccessKey의 만료시간은 1시간이며, 이는 <mark style="color:blue;">**AWS IAM Identity Center에서 구성한 권한 세트의 세션 시간을 기준으로 설정**</mark>됩니다.>   \
>   이는 AWS IAM Identity Center에서 구성한 Okta IDP 정보만 인증 요건으로 처리되며, Okta의 정책 세션 시간으로 결정되지 않습니다.
>
>   <figure><img src="/files/j5fkU8u9pc3MdPQybfZM" alt=""><figcaption></figcaption></figure>

{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zerotrust.goorm.cloud/okta/management/app-integraiton/app-integration-guide/amazon-web-service/aws-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
