Skip to content

Commit c8dea83

Browse files
authored
Merge pull request #633 from NHSDigital/feature/add-signing-resources
Feature/add signing resources
2 parents 83f6d2b + 17c63ba commit c8dea83

5 files changed

Lines changed: 112 additions & 0 deletions

File tree

infrastructure/modules/lambda/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ output "aws_lambda_invoke_arn" {
1616
output "lambda_cmk_arn" {
1717
value = aws_kms_key.lambda_cmk.arn
1818
}
19+
20+
output "lambda_signing_profile_name" {
21+
value = aws_signer_signing_profile.lambda_signing.name
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "aws_signer_signing_profile" "lambda_signing" {
2+
name = "${terraform.workspace == "default" ? "" : "${terraform.workspace}"}EligibilityApiLambdaSigningProfile"
3+
#aws signer is strict with names, does not like hyphens or underscores
4+
5+
platform_id = "AWSLambda-SHA384-ECDSA"
6+
7+
signature_validity_period {
8+
value = 365
9+
type = "DAYS"
10+
}
11+
}
12+
13+
resource "aws_lambda_code_signing_config" "signing_config" {
14+
allowed_publishers {
15+
signing_profile_version_arns = [
16+
aws_signer_signing_profile.lambda_signing.version_arn
17+
]
18+
}
19+
20+
policies {
21+
untrusted_artifact_on_deployment = "Enforce"
22+
}
23+
24+
description = "Only allow Lambda bundles signed by our trusted signer profile"
25+
}

infrastructure/stacks/api-layer/lambda.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ module "eligibility_signposting_lambda_function" {
3535
api_domain_name = local.api_domain_name
3636
}
3737

38+
39+
# Needed by github workflows to sign the lambda artifacts
40+
output "signing_profile_name" {
41+
value = module.eligibility_signposting_lambda_function.lambda_signing_profile_name
42+
}
43+
3844
# -----------------------------------------------------------------------------
3945
# Secret rotation lambdas
4046
# -----------------------------------------------------------------------------

infrastructure/stacks/iams-developer-roles/github_actions_policies.tf

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,76 @@ resource "aws_iam_policy" "cloudwatch_management" {
809809
tags = merge(local.tags, { Name = "cloudwatch-management" })
810810
}
811811

812+
resource "aws_iam_policy" "code_signing_management" {
813+
#checkov:skip=CKV_AWS_290: Actions require wildcard resource for Lambda code signing configs and Signer jobs
814+
#checkov:skip=CKV_AWS_235: Actions require wildcard resource for Lambda code signing configs and Signer jobs
815+
#checkov:skip=CKV_AWS_355: Actions require wildcard resource for Lambda code signing configs and Signer jobs
816+
name = "code-signing-management"
817+
description = "Allow GitHub Actions to manage Lambda code signing and start Signer jobs"
818+
path = "/service-policies/"
819+
820+
policy = jsonencode({
821+
Version = "2012-10-17",
822+
Statement = [
823+
{
824+
Sid = "LambdaCodeSigningConfigManagement",
825+
Effect = "Allow",
826+
Action = [
827+
"lambda:CreateCodeSigningConfig",
828+
"lambda:UpdateCodeSigningConfig",
829+
"lambda:DeleteCodeSigningConfig",
830+
"lambda:GetCodeSigningConfig",
831+
"lambda:ListCodeSigningConfigs",
832+
"lambda:GetFunctionCodeSigningConfig",
833+
"lambda:ListTags"
834+
],
835+
Resource = "*"
836+
},
837+
{
838+
Sid = "LambdaFunctionSigningManagement",
839+
Effect = "Allow",
840+
Action = [
841+
"lambda:DeleteFunctionCodeSigningConfig",
842+
"lambda:PutFunctionCodeSigningConfig"
843+
],
844+
Resource = "arn:aws:lambda:*:${data.aws_caller_identity.current.account_id}:function:eligibility_signposting_api"
845+
},
846+
{
847+
Sid = "SignerProfileManagement"
848+
Effect = "Allow"
849+
Action = [
850+
"signer:GetSigningProfile",
851+
"signer:TagResource",
852+
"signer:UntagResource",
853+
"signer:ListTagsForResource"
854+
]
855+
Resource = local.lambda_signing_profile_arn
856+
},
857+
{
858+
Sid = "SignerProfileCreateAndList"
859+
Effect = "Allow"
860+
Action = [
861+
"signer:PutSigningProfile",
862+
"signer:ListSigningProfiles"
863+
]
864+
Resource = "*"
865+
},
866+
{
867+
Sid = "SignerJobUsage",
868+
Effect = "Allow",
869+
Action = [
870+
"signer:StartSigningJob",
871+
"signer:DescribeSigningJob",
872+
"signer:ListSigningJobs"
873+
],
874+
Resource = "*"
875+
},
876+
]
877+
})
878+
879+
tags = merge(local.tags, { Name = "code-signing-management" })
880+
}
881+
812882
# Attach the policies to the role
813883
resource "aws_iam_role_policy_attachment" "terraform_state" {
814884
role = aws_iam_role.github_actions.name
@@ -859,3 +929,8 @@ resource "aws_iam_role_policy_attachment" "kinesis_management_attach" {
859929
role = aws_iam_role.github_actions.name
860930
policy_arn = aws_iam_policy.kinesis_management.arn
861931
}
932+
933+
resource "aws_iam_role_policy_attachment" "code_signing_management" {
934+
role = aws_iam_role.github_actions.name
935+
policy_arn = aws_iam_policy.code_signing_management.arn
936+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
locals {
22
stack_name = "iams-developer-roles"
3+
lambda_signing_profile_name = "${terraform.workspace == "default" ? "" : "${terraform.workspace}"}EligibilityApiLambdaSigningProfile"
4+
lambda_signing_profile_arn = "arn:aws:signer:${var.default_aws_region}:${data.aws_caller_identity.current.account_id}:/signing-profiles/${local.lambda_signing_profile_name}"
35
}

0 commit comments

Comments
 (0)