-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgithub_actions_policies.tf
More file actions
160 lines (136 loc) · 4.15 KB
/
github_actions_policies.tf
File metadata and controls
160 lines (136 loc) · 4.15 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Terraform State Management Policy
resource "aws_iam_policy" "terraform_state" {
name = "terraform-state-management"
description = "Policy granting access to S3 bucket for Terraform state"
path = "/service-policies/"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
Resource = [
"${local.terraform_state_bucket_arn}",
"${local.terraform_state_bucket_arn}/*"
]
}
]
})
tags = merge(
local.tags,
{
Name = "terraform-state-management"
}
)
}
# API Infrastructure Management Policy
resource "aws_iam_policy" "api_infrastructure" {
#checkov:skip=CKV_AWS_287 Ensure IAM policies does not allow credentials exposure
#checkov:skip=CKV_AWS_355 Ensure no IAM policies documents allow "*" as a statement's resource for restrictable actions
#checkov:skip=CKV_AWS_288 Ensure IAM policies does not allow data exfiltration
#checkov:skip=CKV_AWS_289 Ensure IAM policies does not allow permissions management / resource exposure without constraints
#checkov:skip=CKV_AWS_286 Ensure IAM policies does not allow privilege escalation
#checkov:skip=CKV_AWS_290 Ensure IAM policies does not allow write access without constraints
name = "api-infrastructure-management"
description = "Policy granting permissions to manage API infrastructure"
path = "/service-policies/"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
# Lambda permissions
"lambda:*",
# DynamoDB permissions
"dynamodb:*",
# API Gateway permissions
"apigateway:*",
# S3 permissions
"s3:*",
# KMS permissions
"kms:List*",
"kms:Describe*",
"kms:GetKeyPolicy*",
"kms:GetKeyRotationStatus",
"kms:Decrypt*",
"kms:DeleteAlias",
"kms:UpdateKeyDescription",
"kms:CreateGrant",
"kms:CreateAlias",
# Cloudwatch permissions
"logs:Describe*",
"logs:ListTagsForResource",
#EC2 permissions
"ec2:Describe*",
"ec2:CreateTags",
# IAM permissions (scoped to resources with specific path prefix)
"iam:Get*",
"iam:GetPolicy*",
"iam:GetRole*",
"iam:List*",
"iam:Create*",
"iam:Update*",
"iam:Delete*",
"iam:PutRolePermissionsBoundary",
"iam:PutRolePolicy",
# ssm
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:DescribeParameters",
"ssm:ListTagsForResource",
# acm
"acm:ListCertificates",
"acm:DescribeCertificate",
"acm:GetCertificate",
"acm:ListTagsForCertificate",
],
Resource = "*"
}
]
})
tags = merge(
local.tags,
{
Name = "api-infrastructure-management"
}
)
}
# Assume role policy document for GitHub Actions
data "aws_iam_policy_document" "github_actions_assume_role" {
statement {
sid = "OidcAssumeRoleWithWebIdentity"
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [
aws_iam_openid_connect_provider.github.arn
]
}
condition {
test = "StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = ["repo:${var.github_org}/${var.github_repo}:*"]
}
condition {
test = "StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}
}
}
# Attach the policies to the role
resource "aws_iam_role_policy_attachment" "terraform_state" {
role = aws_iam_role.github_actions.name
policy_arn = aws_iam_policy.terraform_state.arn
}
resource "aws_iam_role_policy_attachment" "api_infrastructure" {
role = aws_iam_role.github_actions.name
policy_arn = aws_iam_policy.api_infrastructure.arn
}