-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkali_iam.tf
69 lines (55 loc) · 2.17 KB
/
kali_iam.tf
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
# Create the IAM instance profile for the Kali EC2 server instance
# The instance profile to be used
resource "aws_iam_instance_profile" "kali" {
provider = aws.provisionassessment
name = "kali_instance_profile_${terraform.workspace}"
role = aws_iam_role.kali_instance_role.name
}
# The instance role
resource "aws_iam_role" "kali_instance_role" {
provider = aws.provisionassessment
assume_role_policy = data.aws_iam_policy_document.ec2_service_assume_role_doc.json
name = "kali_instance_role_${terraform.workspace}"
}
resource "aws_iam_role_policy" "kali_assume_delegated_role_policy" {
provider = aws.provisionassessment
name = "kali_assume_delegated_role_policy"
policy = data.aws_iam_policy_document.kali_assume_delegated_role_policy_doc.json
role = aws_iam_role.kali_instance_role.id
}
# Attach the CloudWatch Agent policy to this role as well
resource "aws_iam_role_policy_attachment" "cloudwatch_agent_policy_attachment_kali" {
provider = aws.provisionassessment
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
role = aws_iam_role.kali_instance_role.id
}
# Attach the SSM Agent policy to this role as well
resource "aws_iam_role_policy_attachment" "ssm_agent_policy_attachment_kali" {
provider = aws.provisionassessment
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
role = aws_iam_role.kali_instance_role.id
}
# Attach a policy that allows the Kali instances to mount and write to
# the EFS
resource "aws_iam_role_policy_attachment" "efs_mount_policy_attachment_kali" {
provider = aws.provisionassessment
policy_arn = aws_iam_policy.efs_mount_policy.arn
role = aws_iam_role.kali_instance_role.id
}
################################
# Define the role policies below
################################
# Allow the Kali instance to assume the necessary roles to perform its
# function.
data "aws_iam_policy_document" "kali_assume_delegated_role_policy_doc" {
statement {
actions = [
"sts:AssumeRole",
"sts:TagSession",
]
effect = "Allow"
resources = [
data.terraform_remote_state.sharedservices.outputs.assessment_findings_write_role.arn,
]
}
}