-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support new GitHub bot deployment #15
Changes from 18 commits
2e72689
d1d4d35
687c51f
695aef0
4f62c8e
fdafa31
14b09e1
6cb7f4d
fda3e7c
a86a981
393253e
a9f24df
a67a435
731e6d9
8b25bc1
5ccf235
57a1d15
c933e4a
527636b
ceec324
50392e1
605cc6a
23d9a4d
be0a379
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ override.tf.json | |
*_override.tf | ||
*_override.tf.json | ||
.terraformrc | ||
terraform.rc | ||
terraform.rc | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
## [3.0.0] - 2024-06-03 | ||
|
||
### Added | ||
|
||
- Support to GitHub bot 2.x deployment integration | ||
- Enable running multiple bot instances of the same type in a single region | ||
- Enable setting a custom pattern for all the resources created by the module | ||
- Enable setting a path to the lambda source code (Zip file) | ||
|
||
### Changed | ||
|
||
- Lambdas runtime upgraded to node20.x | ||
|
||
## [2.1.0] - 2023-08-16 | ||
|
||
### Added | ||
|
||
- Support hardening & engines flag | ||
|
||
## [2.0.0] - 2023-06-18 | ||
|
||
### Changed | ||
|
||
- GitLab's integration infrastructure is now based on multiple lambda functions to make sure the response is being sent to GitLab in less than 10 seconds | ||
|
||
## [1.1.1] - 2023-05-31 | ||
|
||
### Added | ||
|
||
- Option to pull the secrets required for the GitLab bot to accessed from AWS secrets manager | ||
|
||
## [1.1.0] - 2022-12-11 | ||
|
||
### Changed | ||
|
||
- New versions of GitLab and TFC using new Spectral severities | ||
|
||
## [1.0.2] - 2022-10-23 | ||
|
||
### Added | ||
|
||
- Support for Jira integration | ||
- Support for GitLab integration | ||
|
||
## [1.0.1] - 2022-10-05 | ||
|
||
### Changed | ||
|
||
- Bots are now downloading the latest Spectral scanner version instead of accessing the scanner through a lambda layer | ||
|
||
## [1.0.0] - 2022-09-11 | ||
|
||
### Added | ||
|
||
- Added support for Terraform cloud integration |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,42 +6,60 @@ Terraform configuration used to create the required AWS resources for integratin | |
|
||
## Requirements | ||
|
||
| Name | Version | | ||
| ----------- | ----------- | | ||
| [terraform](https://www.terraform.io/downloads) | >= 1.3.0 | | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.26.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
| ----------- | ----------- | | ||
| [aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) | >= 4.37.0 | | ||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.26.0 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | n/a | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_api_gateway"></a> [api\_gateway](#module\_api\_gateway) | ./modules/api_gateway | n/a | | ||
| <a name="module_backend_lambda_function"></a> [backend\_lambda\_function](#module\_backend\_lambda\_function) | ./modules/lambda | n/a | | ||
| <a name="module_frontend_lambda_function"></a> [frontend\_lambda\_function](#module\_frontend\_lambda\_function) | ./modules/lambda | n/a | | ||
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | ./modules/lambda | n/a | | ||
| <a name="module_lambda_role"></a> [lambda\_role](#module\_lambda\_role) | ./modules/role | n/a | | ||
| <a name="module_secrets_manager"></a> [secrets\_manager](#module\_secrets\_manager) | ./modules/secrets_manager | n/a | | ||
|
||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
| ----------- | ----------- | ----------- | ----------- | ----------- | | ||
| `environment` | The target environment name for deployment | `string` | `prod` | No | | ||
| `integration_type` | Spectral integration type (A unique phrase describing the integration) - Available values: `terraform`, `jira` and `gitlab` | `string` | N/A | Yes | | ||
| [`env_vars`](#env_vars) | Extendable object contains all required environment variables required for the integration. | `map(string)` | N/A | No | | ||
| [`global_tags`](#global_tags) | Tags to be applied on every newly created resource. | `map(string)` | ```{ BusinessUnit = "Spectral" }``` | No | | ||
| [`tags`](#tags) | Tags to be applied on concrete resources | `map(map(string))` | ```{ iam = { } lambda = { } api_gateway = { } }``` | No | | ||
| `lambda_enable_logs` | Specifies if Lambda should have CloudWatch a dedicated logs group. | `bool` | `false` | No | | ||
| `lambda_logs_retention_in_days` | Specifies the number of days you want to retain log events in the specified log group. | `number` | `30` | No | | ||
| `lambda_function_timeout` | Amount of time your Lambda Function has to run in seconds. | `number` | 300 | No | | ||
| `lambda_function_memory_size` | Amount of memory in MB your Lambda Function can use at runtime. | `number` | 1024 | No | | ||
| `lambda_publish` | Whether to publish creation/change as new Lambda Function Version. | `bool` | `false` | No | | ||
| `store_secret_in_secrets_manager` | Whether to store secrets values on a vault (currently supporting AWS secrets manager on GitLab integration). | `bool` | `false` | No | | ||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_backend_lambda_source_code_path"></a> [backend\_lambda\_source\_code\_path](#input\_backend\_lambda\_source\_code\_path) | Path to the lambda source code zip file of the backend lambda | `string` | `null` | no | | ||
| <a name="input_env_vars"></a> [env\_vars](#input\_env\_vars) | Extendable object contains all required environment variables required for the integration. | `map(string)` | <pre>{<br> "CHECK_POLICY": "Fail on errors only",<br> "SPECTRAL_DSN": ""<br>}</pre> | no | | ||
| <a name="input_environment"></a> [environment](#input\_environment) | The target environment name for deployment. | `string` | `"prod"` | no | | ||
| <a name="input_frontend_lambda_source_code_path"></a> [frontend\_lambda\_source\_code\_path](#input\_frontend\_lambda\_source\_code\_path) | Path to the lambda source code zip file of the frontend lambda | `string` | `null` | no | | ||
| <a name="input_gateway_api_integration_timeout_milliseconds"></a> [gateway\_api\_integration\_timeout\_milliseconds](#input\_gateway\_api\_integration\_timeout\_milliseconds) | Timeout for the API Gateway to wait for lambda response | `number` | `29000` | no | | ||
| <a name="input_global_tags"></a> [global\_tags](#input\_global\_tags) | A list of tags to apply on all newly created resources. | `map(string)` | <pre>{<br> "BusinessUnit": "Spectral"<br>}</pre> | no | | ||
| <a name="input_integration_type"></a> [integration\_type](#input\_integration\_type) | Spectral integration type (A unique phrase describing the integration) - Available values: `github`, `terraform`, `jira` and `gitlab` | `string` | n/a | yes | | ||
| <a name="input_lambda_enable_logs"></a> [lambda\_enable\_logs](#input\_lambda\_enable\_logs) | Specifies if Lambda should have CloudWatch a dedicated logs group. | `bool` | `false` | no | | ||
| <a name="input_lambda_function_memory_size"></a> [lambda\_function\_memory\_size](#input\_lambda\_function\_memory\_size) | Amount of memory in MB your Lambda Function can use at runtime. Defaults to 1024. | `number` | `1024` | no | | ||
| <a name="input_lambda_function_timeout"></a> [lambda\_function\_timeout](#input\_lambda\_function\_timeout) | Amount of time your Lambda Function has to run in seconds. | `number` | `300` | no | | ||
| <a name="input_lambda_logs_retention_in_days"></a> [lambda\_logs\_retention\_in\_days](#input\_lambda\_logs\_retention\_in\_days) | Specifies the number of days you want to retain log events in the specified log group. | `number` | `30` | no | | ||
| <a name="input_lambda_publish"></a> [lambda\_publish](#input\_lambda\_publish) | Whether to publish creation/change as new Lambda Function Version. | `bool` | `false` | no | | ||
| <a name="input_lambda_source_code_path"></a> [lambda\_source\_code\_path](#input\_lambda\_source\_code\_path) | Path to the lambda source code zip file | `string` | `null` | no | | ||
| <a name="input_resource_name_common_part"></a> [resource\_name\_common\_part](#input\_resource\_name\_common\_part) | A common part for all resources created under the stack | `string` | `null` | no | | ||
| <a name="input_secrets_names"></a> [secrets\_names](#input\_secrets\_names) | Names of secrets to create | `list(string)` | `null` | no | | ||
| <a name="input_store_secret_in_secrets_manager"></a> [store\_secret\_in\_secrets\_manager](#input\_store\_secret\_in\_secrets\_manager) | Whether to store your secrets in secrets manager, default is false | `bool` | `false` | no | | ||
| <a name="input_tags"></a> [tags](#input\_tags) | A collection of tags grouped by key representing it's target resource. | `map(map(string))` | <pre>{<br> "api_gateway": {},<br> "iam": {},<br> "lambda": {}<br>}</pre> | no | | ||
|
||
### env_vars | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section is partially relevant to the bots. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The env vars are not detailed in this section, this just shows how to set variables and redirects the users to the docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is the var that is mandatory, in a different but, there is more mandatory env var. i just say to refer to our docs and remote this section |
||
|
||
In some integrations, Spectral requires some extra environment variables besides the default ones. | ||
Those extra variables should be added to the `env_vars` map in addition to `SPECTRAL_DSN` which is mandatory. | ||
|
||
Please refer to our docs / source pages to view the extra environment variables needed for the integration. | ||
In some integrations, Spectral requires some environment variables besides the default ones. | ||
Those variables should be added to the `env_vars`. | ||
|
||
##### SPECTRAL_DSN (mandatory) | ||
Please refer to our [docs](https://guides.spectralops.io/docs/welcome-to-checkpoint-cloudguard-guides) / source pages to view the extra environment variables needed for the integration. | ||
|
||
Your SpectralOps identifier, retrieved from your SpectralOps account. | ||
|
||
### global_tags | ||
|
||
|
@@ -142,13 +160,19 @@ module "spectral_lambda_integration" { | |
|
||
### This module has the following outputs | ||
|
||
1. `rest_api_id` - The ID of the REST API. | ||
2. `rest_api_url` - The URL for accessing the lambda through the ApiGateway. | ||
3. `rest_api_arn` - Amazon Resource Name (ARN) identifying your Rest API. | ||
4. `rest_api_execution_arn` - The execution ARN part to be used in lambda_permission's source_arn, not concatenated to other allowed API resources. | ||
5. `rest_api_lambda_execution_arn` - The execution ARN part to be used in lambda_permission's source_arn, concatenated with allowed API resources (method & path). | ||
6. `lambda_function_arn` - Amazon Resource Name (ARN) identifying your Lambda Function. | ||
7. `lambda_function_name` - The name of the lambda function. | ||
8. `lambda_iam_role_arn` - Amazon Resource Name (ARN) specifying the role. | ||
9. `lambda_iam_role_name` - Name of the role. | ||
10. `secrets_arns` - Arns of created secrets in secrets manager. | ||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_lambda_function_arn"></a> [lambda\_function\_arn](#output\_lambda\_function\_arn) | Amazon Resource Name (ARN) identifying your Lambda Function | | ||
| <a name="output_lambda_function_name"></a> [lambda\_function\_name](#output\_lambda\_function\_name) | The name of the lambda function | | ||
| <a name="output_lambda_iam_role_arn"></a> [lambda\_iam\_role\_arn](#output\_lambda\_iam\_role\_arn) | Amazon Resource Name (ARN) specifying the role | | ||
| <a name="output_lambda_iam_role_name"></a> [lambda\_iam\_role\_name](#output\_lambda\_iam\_role\_name) | Name of the role | | ||
| <a name="output_rest_api_arn"></a> [rest\_api\_arn](#output\_rest\_api\_arn) | Amazon Resource Name (ARN) identifying your Rest API | | ||
| <a name="output_rest_api_execution_arn"></a> [rest\_api\_execution\_arn](#output\_rest\_api\_execution\_arn) | The execution ARN part to be used in lambda\_permission's source\_arn, not concatenated to other allowed API resources | | ||
| <a name="output_rest_api_id"></a> [rest\_api\_id](#output\_rest\_api\_id) | The ID of the REST API | | ||
| <a name="output_rest_api_lambda_execution_arn"></a> [rest\_api\_lambda\_execution\_arn](#output\_rest\_api\_lambda\_execution\_arn) | The execution ARN part to be used in lambda\_permission's source\_arn, concatenated with allowed API resources (method & path) | | ||
| <a name="output_rest_api_url"></a> [rest\_api\_url](#output\_rest\_api\_url) | The URL for accessing the lambda through the ApiGateway | | ||
| <a name="output_secrets_arns"></a> [secrets\_arns](#output\_secrets\_arns) | Arns of created secrets in secrets manager | | ||
|
||
## Support | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a changelog file that lists versions, describes the changes, and breaks changes per version is essential, and can avoid a lot of questions. |
||
|
||
For GitHub deployment - only bot version 2.x is supported |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module "spectral_lambda_integration" { | ||
source = "github.com/SpectralOps/spectral-terraform-lambda-integration" | ||
|
||
integration_type = "github" | ||
lambda_enable_logs = true | ||
|
||
# Use this attributes to deploy specific version of the bot | ||
frontend_lambda_source_code_path = "./source-code/github/github-frontend.zip" | ||
backend_lambda_source_code_path = "./source-code/github/github-backend.zip" | ||
|
||
env_vars = { | ||
# Required environment variables | ||
SPECTRAL_DSN = "MySpectralDSN" | ||
CHECK_POLICY = "Fail on any issue" # (Fail on any issue / Fail on warnings and above / Fail on errors only / Always Pass) | ||
GITHUB_APP_ID = "MyGitHubAppId" | ||
GITHUB_WEBHOOK_SECRET = "MyGitHubWebhookSecret" | ||
GITHUB_PRIVATE_KEY = "MyGitHubPrivateKey" | ||
# Optional environment variables | ||
SECRETS_VAULT = "aws_secrets_manager" | ||
VAULT_KEY_SPECTRAL_DSN = "Spectral_Dsn-..." | ||
VAULT_KEY_GITHUB_WEBHOOK_SECRET = "Spectral_GithubBot_WebhookSecret-..." | ||
VAULT_KEY_GITHUB_PRIVATE_KEY = "Spectral_GithubBot_PrivateKey-..." | ||
GITHUB_SHOULD_POST_REVIEW_COMMENTS = false | ||
GITHUB_SHOULD_SKIP_CHECK = false | ||
S3_BLACK_LIST_OBJECT_KEY = "The S3 object key of your blacklist flie" | ||
S3_BLACK_LIST_BUCKET_NAME = "The S3 bucket name that holds your blacklist file" | ||
SHOULD_SKIP_INGEST = false | ||
STRICT_MODE = false | ||
SPECTRAL_TAGS = "iac,base,audit" | ||
HOME = "/tmp" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
locals { | ||
resource_name_pattern = "spectral-${var.integration_type}-integration-${var.environment}" | ||
single_lambda_integration = contains(["jira", "terraform"], var.integration_type) ? true : false | ||
multiple_lambda_integration = contains(["gitlab"], var.integration_type) ? true : false | ||
api_triggered_function_arn = local.single_lambda_integration ? module.lambda_function[0].lambda_function_arn : module.frontend_lambda_function[0].lambda_function_arn | ||
resource_name_pattern = coalesce(var.resource_name_common_part, "spectral-${var.integration_type}-integration-${var.environment}-${random_string.random_resource_name_suffix.id}") | ||
single_lambda_integration = contains(["jira", "terraform"], var.integration_type) ? true : false | ||
multiple_lambda_integration = contains(["gitlab", "github"], var.integration_type) ? true : false | ||
api_triggered_function_arn = local.single_lambda_integration ? module.lambda_function[0].lambda_function_arn : module.frontend_lambda_function[0].lambda_function_arn | ||
frontend_lambda_handler = contains(["github"], var.integration_type) ? "index.handler" : "frontend.app" | ||
backend_lambda_handler = contains(["github"], var.integration_type) ? "index.handler" : "backend.app" | ||
shared_default_secrets_names = ["Spectral_Dsn"] | ||
default_secrets_names = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct |
||
"github" = coalesce(var.secrets_names, concat(local.shared_default_secrets_names, ["Spectral_GithubBot_PrivateKey", "Spectral_GithubBot_WebhookSecret"])), | ||
"gitlab" = coalesce(var.secrets_names, concat(local.shared_default_secrets_names, ["Spectral_GitlabBot_GitlabToken", "Spectral_GitlabBot_WebhookSecret"])) | ||
} | ||
# Please do not change or replace the 'frontend' suffix since there a logic in the bot based in it | ||
api_triggered_function_name = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ variable "tags" { | |
|
||
variable "integration_type" { | ||
type = string | ||
description = "Spectral integration type (A unique phrase describing the integration) - Available values: `terraform`." | ||
description = "Spectral integration type (A unique phrase describing the integration) - Available values: `github`, `terraform`, `jira` and `gitlab`" | ||
} | ||
|
||
variable "timeout" { | ||
|
@@ -71,16 +71,16 @@ variable "secrets_arns" { | |
default = [] | ||
} | ||
|
||
variable "store_secret_in_secrets_manager" { | ||
description = "Whether to store your secrets in secrets manager, default is false" | ||
type = bool | ||
} | ||
|
||
variable "lambda_source_code_filename" { | ||
type = string | ||
description = "The lambda source code filename" | ||
} | ||
|
||
variable "lambda_source_code_path" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use terraform-docs to generate the readme file for the lambda module. |
||
type = string | ||
description = "The lambda source code path" | ||
} | ||
|
||
variable "role_arn" { | ||
type = string | ||
description = "The lambda source code filename" | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,8 @@ | ||
locals { | ||
secrets_arns = concat( | ||
try(module.gitlab[0].secrets_arns, []), | ||
[aws_secretsmanager_secret.spectral_dsn.arn] | ||
) | ||
secrets_arns = [for secret in aws_secretsmanager_secret.general_secret : secret.arn] | ||
} | ||
|
||
resource "aws_secretsmanager_secret" "spectral_dsn" { | ||
name = "Spectral_Dsn" | ||
} | ||
|
||
module "gitlab" { | ||
count = var.integration_type == "gitlab" ? 1 : 0 | ||
source = "./gitlab" | ||
resource "aws_secretsmanager_secret" "general_secret" { | ||
count = length(var.secrets_names) | ||
name = var.secrets_names[count.index] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
variable "integration_type" { | ||
description = "Integration type to create secrets for" | ||
type = string | ||
} | ||
|
||
variable "secrets_names" { | ||
description = "Names of secrets to create" | ||
type = list(string) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some missing fields in the documentation. check out this tool https://terraform-docs.io/ it can help you to manage it
lambda_source_code_path
frontend_lambda_source_code_path
backend_lambda_source_code_path
lambda_logs_retention_in_days
lambda_enable_logs
resource_name_common_part
secrets_names
gateway_api_integration_timeout_milliseconds