Skip to content

Commit a8f9eea

Browse files
authored
CCM-9703: sftp vpc config (#441)
1 parent c33efac commit a8f9eea

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

infrastructure/terraform/components/acct/security_group_allow_sftp_egress.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,25 @@ resource "aws_security_group" "allow_sftp_egress" {
77
Name = "${local.csi}-sftp-egress"
88
}
99
}
10+
11+
#trivy:ignore:aws-ec2-no-public-egress-sgr
12+
resource "aws_security_group_rule" "allow_sftp_egress_ssh" {
13+
description = "Allow SFTP egress within VPC on port 22"
14+
type = "egress"
15+
from_port = 22
16+
to_port = 22
17+
protocol = "tcp"
18+
cidr_blocks = ["0.0.0.0/0"]
19+
security_group_id = aws_security_group.allow_sftp_egress.id
20+
}
21+
22+
#trivy:ignore:aws-ec2-no-public-egress-sgr
23+
resource "aws_security_group_rule" "allow_sftp_egress_https" {
24+
description = "Allow SFTP egress within VPC on port 443"
25+
type = "egress"
26+
from_port = 443
27+
to_port = 443
28+
protocol = "tcp"
29+
cidr_blocks = ["0.0.0.0/0"]
30+
security_group_id = aws_security_group.allow_sftp_egress.id
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
data "aws_vpc" "account_vpc" {
2+
tags = {
3+
Component = "acct"
4+
}
5+
}
6+
7+
data "aws_subnets" "account_vpc_private_subnets" {
8+
filter {
9+
name = "vpc-id"
10+
values = [data.aws_vpc.account_vpc.id]
11+
}
12+
13+
tags = {
14+
Subnet = "Private"
15+
}
16+
}
17+
18+
data "aws_security_group" "account_vpc_sg_allow_sftp_egress" {
19+
vpc_id = data.aws_vpc.account_vpc.id
20+
21+
tags = {
22+
Name = "${data.aws_vpc.account_vpc.tags["Project"]}-${data.aws_vpc.account_vpc.tags["Environment"]}-acct-sftp-egress"
23+
}
24+
}

infrastructure/terraform/modules/backend-api/module_lambda_send_letter_proof.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ module "lambda_send_letter_proof" {
3232
maximum_concurrency = 5
3333
}
3434
}
35+
36+
vpc = {
37+
id = data.aws_vpc.account_vpc.id
38+
cidr_block = data.aws_vpc.account_vpc.cidr_block
39+
subnet_ids = data.aws_subnets.account_vpc_private_subnets.ids
40+
security_group_ids = [data.aws_security_group.account_vpc_sg_allow_sftp_egress.id]
41+
}
3542
}
3643

3744
data "aws_iam_policy_document" "send_letter_proof" {

infrastructure/terraform/modules/backend-api/module_lambda_sftp_poll.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ module "lambda_sftp_poll" {
2222

2323
timeout = 60 * 10
2424
memory_size = 2048
25+
26+
vpc = {
27+
id = data.aws_vpc.account_vpc.id
28+
cidr_block = data.aws_vpc.account_vpc.cidr_block
29+
subnet_ids = data.aws_subnets.account_vpc_private_subnets.ids
30+
security_group_ids = [data.aws_security_group.account_vpc_sg_allow_sftp_egress.id]
31+
}
2532
}
2633

2734
data "aws_iam_policy_document" "sftp_poll" {

infrastructure/terraform/modules/lambda-function/iam_role_lambda_execution_role.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ resource "aws_iam_role_policy_attachment" "lambda_execution" {
1414
policy_arn = aws_iam_policy.lambda_execution_policy.arn
1515
}
1616

17+
resource "aws_iam_role_policy_attachment" "lambda_function_vpc" {
18+
count = var.vpc == null ? 0 : 1
19+
role = aws_iam_role.lambda_execution_role.name
20+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
21+
}
22+
1723
data "aws_iam_policy_document" "lambda_service_trust_policy" {
1824
statement {
1925
sid = "LambdaAssumeRole"

0 commit comments

Comments
 (0)