LoginSignup
14
6

More than 3 years have passed since last update.

RDS for PostgreSQLで監査ログをCloudWatchLogsに出力する

Posted at

pgauditの有効化

1. RDSに接続する

下記コマンドを実行する

psql -U [ユーザ名] -h [RDSのエンドポイント] -d [DB名]

2. pgauditが利用するDBロールを作成する

下記コマンドを実行する

=> CREATE ROLE rds_pgaudit;

3. RDSのパラメータグループを変更する

AWS管理コンソールから RDS > パラメータグループ > 設定するインスタンスのパラメータグループ で変更する
下記は 必須

パラメータ名
pgaudit.role rds_pgaudit
shared_preload_libraries pgaudit

下記は 任意

パラメータ名 許可される値 説明
pgaudit.log_level debug5, debug4, debug3, debug2, debug1, info, notice, warning, log(デフォルト) ログレベル
pgaudit.log ddl, function, misc, read, role, write, none(デフォルト), all, -ddl, -function, -misc, -read, -role, -write 監査ログの種類

4. RDSを再起動して、変更したパラメータを反映する

5. RDSに再接続する

下記コマンドを実行する

psql -U [ユーザ名] -h [RDSのエンドポイント] -d [DB名]

6. 再起動後、pgauditがロードされていることを確認する

下記の内容であればOK

=> SHOW shared_preload_libraries;
 shared_preload_libraries 
--------------------------
 rdsutils,pgaudit
(1 row)

7. pgauditの拡張機能を有効化する。

下記コマンドを実行する

=> CREATE EXTENSION pgaudit;

8. pgauditに作成したロールがアタッチされているか確認する。

下記の内容であればOK

=> SHOW pgaudit.role;
 pgaudit.role 
--------------
 rds_pgaudit

CloudWatchLogsへのログ出力

1. ログのエクスポートで Postgresql log にチェックを入れる

AWS管理コンソールから DBインスタンスの[ログのエクスポート]の設定を変更する

aws_rds_postgresqllog_export_cloudwatchlogs.png

2. ログが CloudWatchLogs に出力されていることを確認する

AWS管理コンソールから CloudWatch > ロググループ で確認する

出力先ロググループ名 /aws/Instance/{DBインスタンス名}/postgresql

参考

pgaudit 拡張機能の使用
Aurora PostgreSQLにて監査ログを取得する

14
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
6