-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlog_bucket.tf
More file actions
80 lines (64 loc) · 1.89 KB
/
Copy pathlog_bucket.tf
File metadata and controls
80 lines (64 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
data "aws_canonical_user_id" "log_bucket_owner_account" {}
resource "aws_s3_bucket" "log_bucket" {
bucket = var.log_bucket_name
lifecycle {
prevent_destroy = true
}
}
resource "aws_s3_bucket_server_side_encryption_configuration" "log_bucket" {
bucket = aws_s3_bucket.log_bucket.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
data "aws_iam_policy_document" "dandiset_log_bucket_policy" {
statement {
sid = "S3ServerAccessLogsPolicy"
effect = "Allow"
resources = ["${aws_s3_bucket.log_bucket.arn}/*"]
actions = ["s3:PutObject"]
condition {
test = "StringEquals"
variable = "aws:SourceAccount"
values = [data.aws_caller_identity.current.account_id]
}
condition {
test = "ArnLike"
variable = "aws:SourceArn"
values = [aws_s3_bucket.dandiset_bucket.arn]
}
principals {
type = "Service"
identifiers = ["logging.s3.amazonaws.com"]
}
}
}
resource "aws_s3_bucket_policy" "dandiset_log_bucket_policy" {
provider = aws
bucket = aws_s3_bucket.log_bucket.id
policy = data.aws_iam_policy_document.dandiset_log_bucket_policy.json
}
data "aws_iam_policy_document" "dandiset_log_bucket_owner" {
version = "2008-10-17"
// TODO: gate behind a "cross account" flag, since this is technically only
// needed for sponsored log bucket.
statement {
resources = [
"${aws_s3_bucket.log_bucket.arn}",
"${aws_s3_bucket.log_bucket.arn}/*",
]
actions = [
"s3:GetObject",
"s3:ListBucket",
]
}
}
resource "aws_iam_user_policy" "dandiset_log_bucket_owner" {
// The Heroku IAM user will always be in the project account
provider = aws.project
name = "${var.log_bucket_name}-ownership-policy"
user = var.heroku_user.user_name
policy = data.aws_iam_policy_document.dandiset_log_bucket_owner.json
}