Skip to content
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

feat: grant cross-account access to Superset #25

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions terragrunt/aws/buckets/athena.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,33 @@ module "athena_bucket" {
versioning = {
enabled = true
}
}

resource "aws_s3_bucket_policy" "athena_bucket" {
bucket = module.athena_bucket.s3_bucket_id
policy = data.aws_iam_policy_document.athena_bucket.json
}

data "aws_iam_policy_document" "athena_bucket" {
statement {
sid = "SupersetReadWrite"
effect = "Allow"
principals {
type = "AWS"
identifiers = [
var.superset_iam_role_arn
]
}
actions = [
"s3:AbortMultipartUpload",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject"
]
resources = [
module.athena_bucket.s3_bucket_arn,
"${module.athena_bucket.s3_bucket_arn}/*"
]
}
}
27 changes: 27 additions & 0 deletions terragrunt/aws/buckets/curated.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,30 @@ module "curated_bucket" {
enabled = true
}
}

resource "aws_s3_bucket_policy" "curated_bucket" {
bucket = module.curated_bucket.s3_bucket_id
policy = data.aws_iam_policy_document.curated_bucket.json
}

data "aws_iam_policy_document" "curated_bucket" {
statement {
sid = "SupersetRead"
effect = "Allow"
principals {
type = "AWS"
identifiers = [
var.superset_iam_role_arn
]
}
actions = [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
]
resources = [
module.curated_bucket.s3_bucket_arn,
"${module.curated_bucket.s3_bucket_arn}/*"
]
}
}
27 changes: 27 additions & 0 deletions terragrunt/aws/buckets/transformed.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,30 @@ module "transformed_bucket" {
enabled = true
}
}

resource "aws_s3_bucket_policy" "transformed_bucket" {
bucket = module.transformed_bucket.s3_bucket_id
policy = data.aws_iam_policy_document.transformed_bucket.json
}

data "aws_iam_policy_document" "transformed_bucket" {
statement {
sid = "SupersetRead"
effect = "Allow"
principals {
type = "AWS"
identifiers = [
var.superset_iam_role_arn
]
}
actions = [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
]
resources = [
module.transformed_bucket.s3_bucket_arn,
"${module.transformed_bucket.s3_bucket_arn}/*"
]
}
}
31 changes: 31 additions & 0 deletions terragrunt/aws/glue/iam.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
#
# Resource policy for the Glue Data Catalog
#
resource "aws_glue_resource_policy" "cross_account_access" {
policy = data.aws_iam_policy_document.cross_account_access.json
}

data "aws_iam_policy_document" "cross_account_access" {
statement {
sid = "SupersetReadAccess"
principals {
type = "AWS"
identifiers = [
var.superset_iam_role_arn
]
}
actions = [
"glue:BatchGetPartition",
"glue:GetDatabase",
"glue:GetDatabases",
"glue:GetPartition",
"glue:GetPartitions",
"glue:GetTable",
"glue:GetTables",
"glue:GetTableVersion",
"glue:GetTableVersions"
]
resources = ["arn:aws:glue:${var.region}:${var.account_id}:*"]
}
}

#
# Glue crawler role
#
Expand Down
5 changes: 5 additions & 0 deletions terragrunt/env/common/common_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ variable "region" {
description = "(Required) The region to build infra in"
type = string
}

variable "superset_iam_role_arn" {
description = "(Required) The ARN of the IAM role that Superset uses to access the Glue catalog"
type = string
}
9 changes: 5 additions & 4 deletions terragrunt/env/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ locals {
}

inputs = {
account_id = "${local.vars.inputs.account_id}"
billing_tag_value = "${local.vars.inputs.billing_tag_value}"
env = "${local.vars.inputs.env}"
region = "ca-central-1"
account_id = "${local.vars.inputs.account_id}"
billing_tag_value = "${local.vars.inputs.billing_tag_value}"
env = "${local.vars.inputs.env}"
region = "ca-central-1"
superset_iam_role_arn = "arn:aws:iam::066023111852:role/SupersetAthenaRead"
}

remote_state {
Expand Down
Loading