11# Trust policy document
22data "aws_iam_policy_document" "terraform_developer_assume_role" {
33 statement {
4- effect = " Allow"
4+ effect = " Allow"
55 actions = [" sts:AssumeRole" ]
66
77 principals {
8- type = " AWS"
8+ type = " AWS"
99 identifiers = [" arn:aws:iam::${ data . aws_caller_identity . current . account_id } :root" ]
1010 }
1111
@@ -19,15 +19,9 @@ data "aws_iam_policy_document" "terraform_developer_assume_role" {
1919 }
2020}
2121
22- # Policy document for terraform access
23- # ARN(s) will need adding once they are in place / additional policies
24- # created in the main api stack and this removed
22+ # Policy document for basic developer read only permissions
2523data "aws_iam_policy_document" "terraform_developer_policy" {
26- # checkov:skip=CKV_AWS_356 Data source IAM policy document allows all resources with restricted actions
27- # checkov:skip=CKV_AWS_356 Ensure IAM policies does not allow data exfiltration
28- # checkov:skip=CKV_AWS_109 Ensure IAM policies does not allow permissions management / resource exposure without constraints
29- # checkov:skip=CKV_AWS_108 Ensure IAM policies does not allow data exfiltration
30- # checkov:skip=CKV_AWS_111 Ensure IAM policies does not allow write access without constraints
24+
3125 # S3 bucket for Terraform state
3226 dynamic "statement" {
3327 for_each = var. environment != " prod" ? [1 ] : []
@@ -69,7 +63,9 @@ data "aws_iam_policy_document" "terraform_developer_policy" {
6963 " dynamodb:DescribeTable" ,
7064 " dynamodb:ListTables" ,
7165 ]
72- resources = [" *" ]
66+ resources = [
67+ " arn:aws:dynamodb:*:${ data . aws_caller_identity . current . account_id } :table:*eligibility_datastore"
68+ ]
7369 }
7470 }
7571
@@ -79,9 +75,6 @@ data "aws_iam_policy_document" "terraform_developer_policy" {
7975 content {
8076 effect = " Allow"
8177 actions = [
82- " dynamodb:CreateTable" ,
83- " dynamodb:UpdateTable" ,
84- " dynamodb:UpdateTableReplicaAutoScaling" ,
8578 " dynamodb:DescribeTable" ,
8679 " dynamodb:ListTables" ,
8780 " dynamodb:Query" ,
@@ -91,7 +84,9 @@ data "aws_iam_policy_document" "terraform_developer_policy" {
9184 " dynamodb:UpdateItem" ,
9285 " dynamodb:DeleteItem"
9386 ]
94- resources = [" *" ]
87+ resources = [
88+ " arn:aws:dynamodb:*:${ data . aws_caller_identity . current . account_id } :table:*eligibility_datastore"
89+ ]
9590 }
9691 }
9792
@@ -105,7 +100,9 @@ data "aws_iam_policy_document" "terraform_developer_policy" {
105100 " lambda:List*" ,
106101 " lambda:Get*" ,
107102 ]
108- resources = [" *" ]
103+ resources = [
104+ " arn:aws:lambda:*:${ data . aws_caller_identity . current . account_id } :function:*eligibility_signposting_api"
105+ ]
109106 }
110107 }
111108
@@ -115,53 +112,28 @@ data "aws_iam_policy_document" "terraform_developer_policy" {
115112 content {
116113 effect = " Allow"
117114 actions = [
118- " lambda:*"
115+ " lambda:InvokeFunction" ,
116+ " lambda:List*" ,
117+ " lambda:Get*" ,
118+ ]
119+ resources = [
120+ " arn:aws:lambda:*:${ data . aws_caller_identity . current . account_id } :function:*eligibility_signposting_api"
119121 ]
120- resources = [" *" ]
121122 }
122123 }
123124
124- # CloudWatch and logging permissions
125- statement {
126- effect = " Allow"
127- actions = [
128- " logs:*" ,
129- " cloudtrail:*" ,
130- " cloudwatch:*"
131- ]
132- resources = [" *" ]
133- }
134125
135126 # IAM permissions (restricted)
136127 statement {
137128 effect = " Allow"
138129 actions = [
139- " iam:Get*" ,
140130 " iam:List*" ,
141- " iam:PassRole"
142- ]
143- resources = [" *" ]
144- }
145-
146- # KMS permissions
147- statement {
148- effect = " Allow"
149- actions = [
150- " kms:Describe*" ,
151- " kms:List*" ,
152- " kms:Get*"
153131 ]
154- resources = [" *" ]
155- }
156-
157- # SSM permissions
158- statement {
159- effect = " Allow"
160- actions = [
161- " ssm:GetParameter*" ,
162- " ssm:PutParameter"
132+ resources = [
133+ " arn:aws:iam::*:role/eligibility_lambda-role*" ,
134+ " arn:aws:iam::*:role/*-api-gateway-*-role" ,
135+ " arn:aws:iam::*:role/eligibility-signposting-api-*-external-write-role"
163136 ]
164- resources = [" *" ]
165137 }
166138
167139 # S3 permissions for application buckets
@@ -170,33 +142,13 @@ data "aws_iam_policy_document" "terraform_developer_policy" {
170142 actions = [
171143 " s3:List*" ,
172144 " s3:Get*" ,
173- " s3:Put*" ,
174- " s3:CreateBucket" ,
175- " s3:DeleteObject"
176145 ]
177- resources = [" *" ]
178- }
179-
180- # API Gateway permissions
181- statement {
182- effect = " Allow"
183- actions = [
184- " apigateway:*"
185- ]
186- resources = [" *" ]
187- }
188-
189- # Read-only permissions for broader resources
190- statement {
191- effect = " Allow"
192- actions = [
193- " ec2:Describe*" ,
194- " iam:Get*" ,
195- " iam:List*" ,
196- " s3:List*" ,
197- " kms:List*"
146+ resources = [
147+ " arn:aws:s3:::*eligibility-signposting-${ var . environment } -eli-rules" ,
148+ " arn:aws:s3:::*eligibility-signposting-${ var . environment } -eli-rules/*" ,
149+ " arn:aws:s3:::*eligibility-signposting-${ var . environment } -eli-audit" ,
150+ " arn:aws:s3:::*eligibility-signposting-${ var . environment } -eli-audit/*" ,
198151 ]
199- resources = [" *" ]
200152 }
201153}
202154
@@ -212,3 +164,5 @@ resource "aws_iam_role_policy_attachment" "terraform_developer_attachment" {
212164 role = aws_iam_role. terraform_developer . name
213165 policy_arn = aws_iam_policy. terraform_developer_policy . arn
214166}
167+
168+ data "aws_region" "current" {}
0 commit comments