Skip to content

Commit 3f0400e

Browse files
rpoluriRaj Polurimassdosage
authored
Optional customer_principal and producer_iamroles in apiary managed bucket policies. (#159)
* optional customer account and producer iam roles * fix sns policy * update changelog * Update CHANGELOG.md Co-authored-by: Adrian Woodhead <awoodhead@expediagroup.com> Co-authored-by: Raj Poluri <rpoluri@expediagroup.com> Co-authored-by: Adrian Woodhead <awoodhead@expediagroup.com>
1 parent f4f8ae9 commit 3f0400e

6 files changed

Lines changed: 17 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6+
## [6.2.1] - 2020-05-27
7+
### Changed
8+
- Optional `customer_principal` and `producer_iamroles` in Apiary managed bucket policies.
9+
610
## [6.2.0] - 2020-05-11
711
### Added
812
- Variable to deny IAM roles access to Apiary managed S3 buckets.

VARIABLES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| Name | Description | Type | Default | Required |
66
|------|-------------|:----:|:-----:|:-----:|
77
| apiary_assume_roles | List of maps - each map describes an IAM role that can be assumed in this account to write data into the configured list of schemas. See section [`apiary_assume_roles`](#apiary_assume_roles) for more info. | list(map) | - | no |
8-
| apiary_customer_accounts | AWS account IDs for clients of this Metastore. | list | - | yes |
8+
| apiary_customer_accounts | AWS account IDs for clients of this Metastore. | list | - | no |
99
| apiary_database_name | Database name to create in RDS for Apiary. | string | `apiary` | no |
1010
| apiary_deny_roles | AWS IAM roles denied access to Apiary managed S3 buckets. | list | - | yes |
1111
| apiary_domain_name | Apiary domain name for Route 53. | string | `` | no |

s3.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ data "template_file" "bucket_policy" {
1717
vars = {
1818
#if apiary_shared_schemas is empty or contains current schema, allow customer accounts to access this bucket.
1919
customer_principal = "${length(var.apiary_shared_schemas) == 0 || contains(var.apiary_shared_schemas, each.key) ?
20-
join("\",\"", formatlist("arn:aws:iam::%s:root", var.apiary_customer_accounts)) :
21-
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"}"
20+
join("\",\"", formatlist("arn:aws:iam::%s:root", var.apiary_customer_accounts)) : ""}"
2221

2322
bucket_name = each.value["data_bucket"]
24-
producer_iamroles = "${replace(lookup(var.apiary_producer_iamroles, each.key, "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"), ",", "\",\"")}"
23+
producer_iamroles = replace(lookup(var.apiary_producer_iamroles, each.key, ""), ",", "\",\"")
2524
deny_iamroles = join("\",\"", var.apiary_deny_iamroles)
2625
}
2726
}

sns.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ resource "aws_sns_topic" "apiary_metadata_events" {
1212
count = var.enable_metadata_events ? 1 : 0
1313
name = "${local.instance_alias}-metadata-events"
1414

15-
policy = <<POLICY
15+
policy = length(var.apiary_customer_accounts) == 0 ? null : <<POLICY
1616
{
1717
"Version":"2012-10-17",
1818
"Statement":[{
1919
"Effect": "Allow",
2020
"Principal": {
21-
"AWS": [ "${join("\",\"", formatlist("arn:aws:iam::%s:root",var.apiary_customer_accounts))}" ]
21+
"AWS": [ "${join("\",\"", formatlist("arn:aws:iam::%s:root", var.apiary_customer_accounts))}" ]
2222
},
2323
"Action": [ "SNS:Subscribe", "SNS:Receive" ],
2424
"Resource": "arn:aws:sns:*:*:${local.instance_alias}-metadata-events"
@@ -31,7 +31,7 @@ resource "aws_sns_topic" "apiary_data_events" {
3131
for_each = var.enable_data_events ? {
3232
for schema in local.schemas_info : "${schema["schema_name"]}" => schema if lookup(schema, "enable_data_events_sqs", "0") == "0"
3333
} : {}
34-
name = "${local.instance_alias}-${each.value["resource_suffix"]}-data-events"
34+
name = "${local.instance_alias}-${each.value["resource_suffix"]}-data-events"
3535

3636
policy = <<POLICY
3737
{
@@ -51,7 +51,7 @@ POLICY
5151

5252
resource "aws_sqs_queue" "apiary_data_event_queue" {
5353
count = local.create_sqs_data_event_queue ? 1 : 0
54-
name = "${local.instance_alias}-data-event-queue"
54+
name = "${local.instance_alias}-data-event-queue"
5555

5656
policy = <<POLICY
5757
{

templates/apiary_bucket_policy.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"Version": "2012-10-17",
33
"Id": "MyPolicyID",
44
"Statement": [
5+
%{if customer_principal != ""}
56
{
67
"Sid": "Apiary customer account permissions",
78
"Effect": "Allow",
@@ -18,6 +19,7 @@
1819
"arn:aws:s3:::${bucket_name}/*"
1920
]
2021
},
22+
%{endif}
2123
%{if deny_iamroles != ""}
2224
{
2325
"Sid": "Local role deny permissions",
@@ -32,6 +34,7 @@
3234
}
3335
},
3436
%{endif}
37+
%{if producer_iamroles != ""}
3538
{
3639
"Sid": "Apiary producer iamrole permissions",
3740
"Effect": "Allow",
@@ -68,6 +71,7 @@
6871
"StringNotEquals": {"s3:x-amz-acl":"bucket-owner-full-control"}
6972
}
7073
},
74+
%{endif}
7175
{
7276
"Sid": "DenyUnSecureCommunications",
7377
"Effect": "Deny",

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ variable "external_database_host" {
9292

9393
variable "apiary_customer_accounts" {
9494
description = "AWS account IDs for clients of this Metastore."
95-
type = list(any)
95+
type = list(string)
96+
default = []
9697
}
9798

9899
variable "apiary_deny_iamroles" {

0 commit comments

Comments
 (0)