Redshift監査ログ設定の確認

Redshiftの監査ログを適切な保存先へエクスポートしてください。

説明

Redshift の接続やユーザーの操作を長期にわたって調査するには、監査ログを S3 または CloudWatch Logs に転送します。

想定される影響

外部に保存しない場合、データベースの保存期間を過ぎた接続や管理操作の記録を調べにくくなります。

対処方法

aws_redshift_logging にクラスターと配信先を指定します。cloudwatch では log_exports でログの種類を選びます。SQL 操作も記録するにはクラスターの enable_user_activity_logging を有効にします。connectionlog なら新しい接続など、選択した種類の記録が届くか確認し、閲覧権限と保存期間を設定してください。

例

例では既存のクラスターに S3 配信を追加します。バケットと配信ポリシーを用意し、互換性のあるノードタイプとクラスタータイプを変数で指定します。本番では例のパスワードを管理された認証情報に置き換え、Terraform の状態ファイルを保護してください。

変更前

hcl
resource "aws_redshift_cluster" "example" {
  cluster_identifier = "tf-redshift-cluster"
  database_name      = "mydb"
  master_username    = "foo"
  master_password    = "Mustbe8characters"
  node_type          = var.redshift_node_type
  cluster_type       = var.redshift_cluster_type
}

変更後

hcl
resource "aws_redshift_cluster" "example" {
  cluster_identifier = "tf-redshift-cluster"
  database_name      = "mydb"
  master_username    = "foo"
  master_password    = "Mustbe8characters"
  node_type          = var.redshift_node_type
  cluster_type       = var.redshift_cluster_type
}

resource "aws_redshift_logging" "example" {
  cluster_identifier   = aws_redshift_cluster.example.id
  log_destination_type = "s3"
  bucket_name          = aws_s3_bucket.logs.id
}

参考資料