generated from NHSDigital/nhs-notify-repository-template
-
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
Open
nhsd-david-wass
wants to merge
9
commits into
main
Choose a base branch
from
feature/CCM-12939-Event-Audit-Pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bc20664
workflow
nhsd-david-wass bd295ce
Enable firehose
nhsd-david-wass 93c640e
Status updates for sub
nhsd-david-wass b2dda3a
override fast-xml-parser
nhsd-david-wass 065ae92
add bucket to eventsub outputs
nhsd-david-wass 0d248b4
add schedule
nhsd-david-wass d1b5b36
review changes
nhsd-david-wass 2f2bc2c
CVE-2026-25547
nhsd-david-wass 69659e8
moved eventsub s3 policy documents
nhsd-david-wass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
infrastructure/terraform/components/api/glue_catalog_database_supplier.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
26 changes: 26 additions & 0 deletions
26
infrastructure/terraform/components/api/glue_crawler_event_crawler.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
|
|
||
| } |
105 changes: 105 additions & 0 deletions
105
infrastructure/terraform/components/api/iam_role_glue.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
infrastructure/terraform/components/api/s3_bucket_policy_eventcache.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/*" | ||
| ] | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
infrastructure/terraform/components/api/s3_event_reporting.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
isn't eventcache bucket created via the shared module? I think that module creats a bucket policy already, you can pass additional statements to this var:
policy_documentsThere 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.
But, this eventcache bucket is created by the eventpub module which itself is a shared module, how do I specify the policy_documents in this case