

# RDS 프록시에 대한 표준 IAM 인증에서 엔드 투 엔드 IAM 인증으로 전환
<a name="rds-proxy-iam-migration"></a>

 현재 클라이언트가 IAM을 사용하여 프록시에 인증하지만 프록시가 보안 암호를 사용하여 데이터베이스에 연결하는 RDS 프록시에 표준 IAM 인증을 사용하는 경우, 클라이언트-프록시 연결과 프록시-데이터베이스 연결이 모두 IAM 인증을 사용하는 엔드 투 엔드 IAM 인증으로 마이그레이션할 수 있습니다.

**엔드 투 엔드 IAM 인증으로 이동**

1. **RDS 프록시 IAM 역할 권한 업데이트**

   Secrets Manager와 `rds:db-connect` 권한을 모두 포함하는 업데이트된 프록시 권한 정책을 생성합니다.

   ```
   # Create updated proxy permission policy
   cat > updated-proxy-policy.json ≪ EOF
   ```

   ```
   {
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Sid": "GetSecretsValue",
         "Action": [
           "secretsmanager:GetSecretValue"
         ],
         "Effect": "Allow",
         "Resource": [
           "arn:aws:secretsmanager:us-east-1:123456789012:secret:secretName-1234f"
         ]
       },
       {
         "Sid": "RdsDBConnect",
         "Action": [
           "rds-db:connect"
         ],
         "Effect": "Allow",
         "Resource": [
           "arn:aws:rds-db:us-east-1:123456789012:dbuser:cluster-ABCDEFGHIJKL01234/jane_doe"
         ]
       }
     ]
   }
   ```

   역할 정책 프록시를 업데이트합니다.

   ```
   aws iam put-role-policy \
               --role-name RDSProxyRole \
               --policy-name UpdatedProxyPermissions \
               --policy-document file://updated-proxy-policy.json
   ```

1. 엔드 투 엔드 IAM 인증을 활성화하도록 RDS 프록시 수정

   ```
   aws rds modify-db-proxy \
     --db-proxy-name my-database-proxy \
     --default-auth-scheme IAM_AUTH \
     --region us-east-1
   ```

   마이그레이션 중에 가동 중지 시간이 발생하지 않도록 계속하기 전에 RDS 프록시 상태가 **사용 가능**이고 `DefaultAuthScheme`이 `IAM_AUTH`인지 확인합니다.

   ```
   aws rds describe-db-proxies --db-proxy-name my-database-proxy --region us-east-1
   ```

   예상 결과:

   ```
   {
     "DBProxies": [
       {
         "DBProxyName": "my-database-proxy",
         "DBProxyArn": "arn:aws:rds:us-east-1:123456789012:db-proxy:prx-0123456789abcdef",
         "Status": "available",
         ...
         "DefaultAuthScheme": "IAM_AUTH"
       }
     ]
   }
   ```

1. 데이터베이스에서 IAM 인증 활성화

   ```
   aws rds modify-db-cluster \
     --db-cluster-identifier my-database-cluster \
     --enable-iam-database-authentication \
     --region us-east-1
   ```

1. IAM 인증을 위한 데이터베이스 사용자 구성

   Aurora PostgreSQL의 경우:

   ```
   GRANT rds_iam TO jane_doe;
   ```

   Aurora MySQL의 경우:

   ```
   ALTER USER 'jane_doe' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
   ALTER USER 'jane_doe'@'%' REQUIRE SSL;
   ```

1. 클라이언트 애플리케이션 코드는 변경할 필요가 없습니다. 연결 프로세스는 동일하게 유지됩니다.

   Aurora PostgreSQL의 경우:

   ```
   # Generate authentication token
   export PGPASSWORD=$(aws rds generate-db-auth-token \
     --hostname my-database-proxy.proxy-ABCDEFGHIJKL01234.us-east-1.rds.amazonaws.com \
     --port 5432 \
     --username jane_doe \
     --region us-east-1)
   
   # Connect to database through proxy
   psql "host=my-database-proxy.proxy-ABCDEFGHIJKL01234.us-east-1.rds.amazonaws.com port=5432 user=jane_doe dbname=postgres password=$PGPASSWORD sslmode=require sslrootcert=us-east-1-bundle.pem"
   ```

   Aurora MySQL의 경우:

   ```
   # Generate authentication token
   export MYSQL_PWD=$(aws rds generate-db-auth-token \
     --hostname my-database-proxy.proxy-ABCDEFGHIJKL01234.us-east-1.rds.amazonaws.com \
     --port 3306 \
     --username jane_doe \
     --region us-east-1)
   
   # Connect to database through proxy
   mysql -h my-database-proxy.proxy-ABCDEFGHIJKL01234.us-east-1.rds.amazonaws.com \
     -P 3306 \
     -u jane_doe \
     --ssl-ca=us-east-1-bundle.pem \
     --enable-cleartext-plugin
   ```