-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added support for Code Signing Configuration (#351)
Co-authored-by: Bryant Biggs <[email protected]> Co-authored-by: Anton Babenko <[email protected]>
- Loading branch information
1 parent
62cdf74
commit dd40178
Showing
12 changed files
with
281 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# AWS Lambda Code Signing example | ||
|
||
Configuration in this directory creates AWS Lambda Function deployed with code signing profile and signed code. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_lambda"></a> [lambda](#module\_lambda) | ../../ | n/a | | ||
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_lambda_code_signing_config.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_code_signing_config) | resource | | ||
| [aws_s3_object.unsigned](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource | | ||
| [aws_signer_signing_job.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/signer_signing_job) | resource | | ||
| [aws_signer_signing_profile.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/signer_signing_profile) | resource | | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_lambda_function_arn"></a> [lambda\_function\_arn](#output\_lambda\_function\_arn) | The ARN of the Lambda Function | | ||
| <a name="output_lambda_function_invoke_arn"></a> [lambda\_function\_invoke\_arn](#output\_lambda\_function\_invoke\_arn) | The Invoke ARN of the Lambda Function | | ||
| <a name="output_lambda_function_signing_job_arn"></a> [lambda\_function\_signing\_job\_arn](#output\_lambda\_function\_signing\_job\_arn) | ARN of the signing job | | ||
| <a name="output_lambda_function_signing_profile_version_arn"></a> [lambda\_function\_signing\_profile\_version\_arn](#output\_lambda\_function\_signing\_profile\_version\_arn) | ARN of the signing profile version | | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
|
||
# Make it faster by skipping something | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
} | ||
|
||
################################################################################ | ||
# Lambda Function | ||
################################################################################ | ||
|
||
module "lambda" { | ||
source = "../../" | ||
|
||
function_name = random_pet.this.id | ||
handler = "index.lambda_handler" | ||
runtime = "python3.8" | ||
code_signing_config_arn = aws_lambda_code_signing_config.this.arn | ||
create_package = false | ||
|
||
s3_existing_package = { | ||
bucket = aws_signer_signing_job.this.signed_object[0].s3[0].bucket | ||
key = aws_signer_signing_job.this.signed_object[0].s3[0].key | ||
} | ||
} | ||
|
||
################################################################################ | ||
# Lambda Code Signing | ||
################################################################################ | ||
|
||
resource "aws_s3_object" "unsigned" { | ||
bucket = module.s3_bucket.s3_bucket_id | ||
key = "unsigned/existing_package.zip" | ||
source = "${path.module}/../fixtures/python3.8-zip/existing_package.zip" | ||
|
||
# Making sure that S3 versioning configuration is propagated properly | ||
depends_on = [ | ||
module.s3_bucket | ||
] | ||
} | ||
|
||
resource "aws_signer_signing_profile" "this" { | ||
platform_id = "AWSLambda-SHA384-ECDSA" | ||
# invalid value for name (must be alphanumeric with max length of 64 characters) | ||
name = replace(random_pet.this.id, "-", "") | ||
|
||
signature_validity_period { | ||
value = 3 | ||
type = "MONTHS" | ||
} | ||
} | ||
|
||
resource "aws_signer_signing_job" "this" { | ||
profile_name = aws_signer_signing_profile.this.name | ||
|
||
source { | ||
s3 { | ||
bucket = module.s3_bucket.s3_bucket_id | ||
key = aws_s3_object.unsigned.id | ||
version = aws_s3_object.unsigned.version_id | ||
} | ||
} | ||
|
||
destination { | ||
s3 { | ||
bucket = module.s3_bucket.s3_bucket_id | ||
prefix = "signed/" | ||
} | ||
} | ||
|
||
ignore_signing_job_failure = true | ||
} | ||
|
||
resource "aws_lambda_code_signing_config" "this" { | ||
allowed_publishers { | ||
signing_profile_version_arns = [aws_signer_signing_profile.this.version_arn] | ||
} | ||
|
||
policies { | ||
untrusted_artifact_on_deployment = "Enforce" | ||
} | ||
} | ||
|
||
################################################################################ | ||
# Supporting Resources | ||
################################################################################ | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
module "s3_bucket" { | ||
source = "terraform-aws-modules/s3-bucket/aws" | ||
version = "~> 3.0" | ||
|
||
bucket_prefix = "${random_pet.this.id}-" | ||
force_destroy = true | ||
|
||
# S3 bucket-level Public Access Block configuration | ||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
|
||
versioning = { | ||
enabled = true | ||
} | ||
|
||
server_side_encryption_configuration = { | ||
rule = { | ||
apply_server_side_encryption_by_default = { | ||
sse_algorithm = "AES256" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "lambda_function_signing_job_arn" { | ||
description = "ARN of the signing job" | ||
value = module.lambda.lambda_function_signing_job_arn | ||
} | ||
|
||
output "lambda_function_signing_profile_version_arn" { | ||
description = "ARN of the signing profile version" | ||
value = module.lambda.lambda_function_signing_profile_version_arn | ||
} | ||
|
||
output "lambda_function_arn" { | ||
description = "The ARN of the Lambda Function" | ||
value = module.lambda.lambda_function_arn | ||
} | ||
|
||
output "lambda_function_invoke_arn" { | ||
description = "The Invoke ARN of the Lambda Function" | ||
value = module.lambda.lambda_function_invoke_arn | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 4.9" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.