-
Notifications
You must be signed in to change notification settings - Fork 2
CCM-12939 event audit pipeline #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bc20664
bd295ce
93c640e
b2dda3a
065ae92
0d248b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| resource "aws_glue_catalog_database" "supplier" { | ||
| name = "${local.csi}-supplier" | ||
| description = "Glue catalog database for Suppliers API" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| resource "aws_glue_crawler" "event_crawler" { | ||
| count = local.event_cache_bucket_name != null ? 1 : 0 | ||
| name = "${local.csi}-audit-event-crawler" | ||
| database_name = aws_glue_catalog_database.supplier.name | ||
| role = aws_iam_role.glue_role.arn | ||
|
|
||
| table_prefix = "" | ||
| s3_target { | ||
| path = "s3://${local.event_cache_bucket_name}/" | ||
| } | ||
|
|
||
| s3_target { | ||
| path = "s3://${local.eventsub_event_cache_bucket_name}/" | ||
| } | ||
|
|
||
| schedule = "cron(0 * * * ? *)" | ||
| recrawl_policy { | ||
| recrawl_behavior = "CRAWL_NEW_FOLDERS_ONLY" | ||
| } | ||
|
|
||
| schema_change_policy { | ||
| delete_behavior = "LOG" | ||
| update_behavior = "LOG" | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| resource "aws_iam_role" "glue_role" { | ||
| name = "${local.csi}-glue-role" | ||
| assume_role_policy = data.aws_iam_policy_document.glue_assume_role.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "glue_assume_role" { | ||
| statement { | ||
| sid = "AllowGlueServiceAssumeRole" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["glue.amazonaws.com"] | ||
| } | ||
|
|
||
| actions = [ | ||
| "sts:AssumeRole", | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_iam_policy" "glue_service_policy" { | ||
| name = "${local.csi}-glue-service-policy" | ||
| description = "Policy for ${local.csi} Glue Service Role" | ||
| policy = data.aws_iam_policy_document.glue_service_policy.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "glue_service_policy" { | ||
| statement { | ||
| sid = "AllowGlueLogging" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "logs:CreateLogGroup", | ||
| "logs:CreateLogStream", | ||
| "logs:PutLogEvents" | ||
| ] | ||
| resources = ["arn:aws:logs:*:*:*"] | ||
| } | ||
|
|
||
| statement { | ||
| sid = "AllowListBucketAndGetLocation" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "s3:ListBucket", | ||
| "s3:GetBucketLocation" | ||
| ] | ||
|
|
||
| resources = [ | ||
| "arn:aws:s3:::${local.event_cache_bucket_name}", | ||
| "arn:aws:s3:::${local.eventsub_event_cache_bucket_name}" | ||
| ] | ||
| } | ||
| statement { | ||
| sid = "AllowS3Access" | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "s3:GetObject", | ||
| "s3:GetObjectVersion", | ||
| "s3:PutObject", | ||
| "s3:DeleteObject" | ||
| ] | ||
| resources = [ | ||
| "arn:aws:s3:::${local.event_cache_bucket_name}/*", | ||
| "arn:aws:s3:::${local.eventsub_event_cache_bucket_name}/*" | ||
| ] | ||
| } | ||
| statement { | ||
| sid = "GlueCatalogAccess" | ||
| effect = "Allow" | ||
| actions = [ | ||
| "glue:GetDatabase", | ||
| "glue:GetDatabases", | ||
| "glue:GetTable", | ||
| "glue:GetTables", | ||
| "glue:CreateTable", | ||
| "glue:UpdateTable", | ||
| "glue:CreatePartition", | ||
| "glue:BatchCreatePartition", | ||
| "glue:GetPartition", | ||
| "glue:BatchGetPartition", | ||
| "glue:UpdatePartition" | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
| statement { | ||
| sid = "S3TempAndGlueETL" | ||
| effect = "Allow" | ||
| actions = [ | ||
| "s3:PutObject", | ||
| "s3:GetObject" | ||
| ] | ||
| resources = [ | ||
| "arn:aws:s3:::aws-glue-*", | ||
| "arn:aws:s3:::aws-glue-*/*" | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy_attachment" "gllue_attach_policy" { | ||
| role = aws_iam_role.glue_role.name | ||
| policy_arn = aws_iam_policy.glue_service_policy.arn | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| resource "aws_s3_bucket_policy" "eventcache" { | ||
| count = local.event_cache_bucket_name != null ? 1 : 0 | ||
| bucket = local.event_cache_bucket_name | ||
| policy = data.aws_iam_policy_document.eventcache[0].json | ||
|
|
||
| depends_on = [module.eventpub] | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "eventcache" { | ||
| count = local.event_cache_bucket_name != null ? 1 : 0 | ||
| statement { | ||
| sid = "AllowGlueListBucketAndGetLocation" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "AWS" | ||
| identifiers = [aws_iam_role.glue_role.arn] | ||
| } | ||
|
|
||
| actions = [ | ||
| "s3:ListBucket", | ||
| "s3:GetBucketLocation" | ||
| ] | ||
|
|
||
| resources = [ | ||
| "arn:aws:s3:::${local.csi_global}-eventcache" | ||
| ] | ||
| } | ||
|
|
||
| # Object-level permissions: Get/Put/Delete objects | ||
| statement { | ||
| sid = "AllowGlueObjectAccess" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "AWS" | ||
| identifiers = [aws_iam_role.glue_role.arn] | ||
| } | ||
|
|
||
| actions = [ | ||
| "s3:GetObject", | ||
| "s3:GetObjectVersion", | ||
| "s3:PutObject", | ||
| "s3:DeleteObject" | ||
| ] | ||
|
|
||
| resources = [ | ||
| "arn:aws:s3:::${local.csi_global}-eventcache/*" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| resource "aws_s3_bucket" "event_reporting" { | ||
| bucket = "${local.csi_global}-event-reporting" | ||
|
|
||
| tags = merge(local.default_tags, { "Enable-Backup" = var.enable_backups }, { "Enable-S3-Continuous-Backup" = var.enable_backups }) | ||
| } | ||
| resource "aws_s3_bucket_ownership_controls" "event_reporting" { | ||
| bucket = aws_s3_bucket.event_reporting.id | ||
|
|
||
| rule { | ||
| object_ownership = "BucketOwnerPreferred" | ||
| } | ||
| } | ||
| resource "aws_s3_bucket_versioning" "event_reporting" { | ||
| bucket = aws_s3_bucket.event_reporting.id | ||
|
|
||
| versioning_configuration { | ||
| status = "Enabled" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| resource "aws_kinesis_firehose_delivery_stream" "main" { | ||
| resource "aws_kinesis_firehose_delivery_stream" "eventsub" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to be a little careful about renaming things, since Terraform's default behaviour is to tear down the old resource and create the new one. That could be disruptive now that we have real data going through production. It might be safer to add a |
||
| count = var.enable_event_cache ? 1 : 0 | ||
|
|
||
| name = local.csi | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about where this change came from - it matches a change on an unmerged branch of mine, but I'm not sure it's needed on this branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may have just been me trying to get things to appear in the correct place.
I'll remove it from here and check everything works