본문 바로가기

AWS/Database

AWS RDS SSL/TLS 인증서 교체 ( CA ) 문제점 ( 2015 -> 2019 )

관련 AWS Blog : https://aws.amazon.com/ko/blogs/database/amazon-rds-customers-update-your-ssl-tls-certificates-by-february-5-2020/

 

AWS RDS 인증서 만료 timeline

관련 Blog를 맨 앞으로 빼 놓은 이유는 AWS가 발생시킨 이벤트라서 그렇습니다.

 

많은 분들이 아시는 내용이겠지만 간단히 정리하자면,

1. 2020년 1월 14일 이후에 생성된 새로운 인스턴스들은 2019 CA로 적용됩니다. 이전까지 생성된 건 2015 CA 입니다.(default)

2. 2020년 2월 4일, 이때까지 CA 인증서를 갱신하지 않았다면 강제로 적용되기 시작하는 시점입니다.

3. 2020년 3월 5일, update 최종 기한입니다. 만약 CA를 어떤 식으로든 적용시키지 않았다면 connection이 맺어지지 않습니다.

 

여기에는 많은 용어들이 나오는데요. CA Cert, SSL, TLS, Client Key, Server Key 등등등..

 

보안 기능이 강화되고 중요해지면서 나온 개념입니다. 요새는 SSL(Secure Socket Layer)를 많이 알고 계실 텐데요. 사용기한이 있는 CA Certification에 있는 인증서를 가지고 인증을 받고 사용하게 됩니다. 서명도 받아야 하고 public key를 가지고 로그인도 해야 합니다.

 

도메인 같은 경우에도 인증서를 주기적으로 갱신해줘야 합니다. 사용기한이 있으니까요.

 

지금 발생한 이슈도 동일하게 CA Certification이 ca-2015에서 ca-2019로 바뀌게 된 것이죠.

 

DB 같은 경우에는 어떻게 connection을 맺게 될까요?? 또, 왜 필요할까요??

 

우선 필요한 이유는 packet capture를 하게 되면 모든 정보를 알게 됩니다. password, query 내용, query 결과 등이 그대로 패킷에 나오게 되는데 보안상 매우 위험하다고 볼 수 있습니다.

 

MySQL

- https://dev.mysql.com/doc/refman/5.6/en/using-encrypted-connections.html#using-encrypted-connections-server-side-startup-configuration

- https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_have_ssl

- have-ssl, ssl-ca, ssl-cert, ssl-key 를 설정해주면 됩니다.

 

PostgreSQL

- https://www.postgresql.org/docs/9.6/ssl-tcp.html

- MySQL과 비슷하게 ca, cert, key file 세개가 필요하고 ssl을 on 해줘야 합니다.(postgresql.conf)

- 추가적으로 postgresql에는 pg_hba.conf에 host, hostssl, hostnossl 세가지가 존재하는데, hostssl인 경우에는 ssl을 사용해야만 접속 가능합니다.

- RDS PostgreSQL의 경우에는 pg_hba.conf가 없기 때문에 별도의 parameter가 존재하는데요. rds.force_ssl 이라는 파라미터를 통해 ssl을 이용해서 접근하도록 강제로 박아넣을 수 있슴다! postgresql 9.6 이전에는 static이고 9.6이상은 dynamic이므로 참고 부탁드려욥

 

그렇다면 CA인증서 갱신은 어떻게 할 수 있을까요?

1. RDS탭에서 modify를 하고 reboot을 진행한다.(Aurora의 경우 failover가 발생하지 않고 reboot만 발생합니다.)

2. AWS CLI를 사용한다.(--no-certificate-rotation-restart, --apply-immediately), https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-instance.html

 

블로그에 나와 있듯이 --no-certificate-rotation-restart 를 사용하게 되면 reboot이 발생하지 않고 바로 CA인증서가 갱신됩니다.

 

다만! 중요한 점은 교체됐다고 해서 ca-2019를 사용할수는 없고 ca-2015로만 여전히 접속이 가능합니다.

그 이유는 reboot을 하지 않아서라고 볼 수 있습니다. show variables와 pg_settings를 봐도 명시가 되어 있지 않지만 서버 startup시, CA인증서를 가져오기 때문으로 보입니다. 

 

아래의 정보는 Postgresql RDS와 MySQL Aurora에 접근 했을 때 test한 화면입니다. --no-reboot 옵션을 사용해서 인증서를 교체했지만 실제로 reboot 하기 전엔 2019 인증서로 들어갈 수 없는 걸 볼 수 있습니다.

 

PostgreSQL

eddie@localhost:~$ psql "host=###host###.ap-northeast-2.rds.amazonaws.com sslmode=verify-full sslrootcert=rds-2015.pem dbname=choong user=eddie"
Password:
psql (9.5.19, server 10.9)
WARNING: psql major version 9.5, server major version 10.
         Some psql features might not work.
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
​
[eddie-test][eddie] 01-16,11:27:08 [choong] > \q

eddie@localhost:~$ psql "host=###host###.ap-northeast-2.rds.amazonaws.com sslmode=verify-full sslrootcert=rds-2019.pem dbname=choong user=eddie"
psql: SSL error: certificate verify failed

MySQL

eddie@localhost:~$ mysql -ueddie -p -h ###host###.ap-northeast-2.rds.amazonaws.com --ssl-ca=rds-2015.pem
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10892510
Server version: 5.7.12-log MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

eddie@localhost:~$ mysql -ueddie -p -h ###host###.ap-northeast-2.rds.amazonaws.com --ssl-ca=rds-2019.pem
Enter password:
ERROR 2026 (HY000): SSL connection error: error:00000001:lib(0):func(0):reason(1)

 

 

https://docs.aws.amazon.com/ko_kr/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html 에서 ROOT 인증서를 받을 수 있습니다.

 

따라서 ssl만 이용해서 접속을하게끔 해놓으셨다면 반드시 리붓을 해야하며, 만약 하지 않는 다면 3월 5일에 대박 장애를 맞이 할 수 있습니다.