generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Eli 546/create hashing secrets #479
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a7b6d36
ELI 546 - Create hashing secrets in aws secret manager
Karthikeyannhs 9f488bc
ELI 546 - added initial secrets, added kms encryptions
Karthikeyannhs 6252050
ELI 546 - adding string secret
Karthikeyannhs b72c226
ELI 546 - secret manager access to Lambda Role
Karthikeyannhs 2cc40fd
ELI 546 - checkov suppressions
Karthikeyannhs b079096
ELI 546 - checkov suppressions
Karthikeyannhs e5e35bc
ELI 546 - firehose checkov suppressions
Karthikeyannhs fe2a886
ELI 546 -add more permissions in permission boundary
Karthikeyannhs 95045b2
ELI 546 - ignore secret changes
Karthikeyannhs 0383a12
ELI 546 - adding permissions to the role
Karthikeyannhs 1ee0f8b
ELI 546 - adding permissions to the role - fix
Karthikeyannhs 8c20259
ELI 546 - adding permissions to the role - fix
Karthikeyannhs bcee215
ELI 546 - adding permissions to the role - fix
Karthikeyannhs d200816
ELI 546 - adding permissions to the role - fix
Karthikeyannhs b4c6e02
ELI 546 - adding permissions to the role - fix
Karthikeyannhs 9e2cb9a
ELI 546 - adding permissions to the role - fix
Karthikeyannhs 475f4d1
ELI 546 - adding permissions to the role - fix
Karthikeyannhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| data "aws_caller_identity" "current" {} |
This file contains hidden or 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 @@ | ||
| ../_shared/default_variables.tf |
This file contains hidden or 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,59 @@ | ||
| # KMS CMK to encrypt/decrypt secrets | ||
| resource "aws_kms_key" "secrets_cmk" { | ||
| #checkov:skip=CKV_AWS_111: Root user needs full KMS key management | ||
| #checkov:skip=CKV_AWS_356: Root user needs full KMS key management | ||
| #checkov:skip=CKV_AWS_109: Root user needs full KMS key management | ||
| description = "CMK for Secrets Manager - ${var.project_name}-${var.environment}" | ||
| enable_key_rotation = true | ||
| deletion_window_in_days = 30 | ||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| # Allow your account root full control | ||
| { | ||
| Sid = "AllowAccountAdminsFullAccess" | ||
| Effect = "Allow" | ||
| Principal = { AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" } | ||
| Action = "kms:*" | ||
| Resource = "*" | ||
| }, | ||
| # Allow Secrets Manager service to use the key | ||
| { | ||
| Sid = "AllowSecretsManagerServiceUse" | ||
| Effect = "Allow" | ||
| Principal = { Service = "secretsmanager.amazonaws.com" } | ||
| Action = [ | ||
| "kms:Encrypt", | ||
| "kms:Decrypt", | ||
| "kms:GenerateDataKey", | ||
| "kms:GenerateDataKeyWithoutPlaintext", | ||
| "kms:DescribeKey" | ||
| ] | ||
| Resource = "*" | ||
| }, | ||
| # Allow external role to decrypt for reading the secret | ||
| { | ||
| Sid = "AllowExternalRoleDecrypt" | ||
| Effect = "Allow" | ||
| Principal = { AWS = var.external_write_access_role_arn } | ||
| Action = [ | ||
| "kms:Decrypt", | ||
| "kms:DescribeKey" | ||
| ] | ||
| Resource = "*" | ||
| }, | ||
| # Allow Lambda role to decrypt for reading the secret | ||
| { | ||
| Sid = "AllowLambdaRoleDecrypt" | ||
| Effect = "Allow" | ||
| Principal = { AWS = var.eligibility_lambda_role_arn } | ||
| Action = [ | ||
| "kms:Decrypt", | ||
| "kms:DescribeKey" | ||
| ] | ||
| Resource = "*" | ||
| } | ||
| ] | ||
| }) | ||
| tags = var.tags | ||
| } |
This file contains hidden or 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,52 @@ | ||
| # Secret definition in your account | ||
| resource "aws_secretsmanager_secret" "hashing_secret" { | ||
| #checkov:skip=CKV2_AWS_57: Secret rotations are handled manually | ||
| name = "${var.project_name}-${var.environment}/hashing_secret" | ||
| description = "cross account hashing secrets" | ||
| kms_key_id = aws_kms_key.secrets_cmk.arn | ||
| tags = { | ||
| Environment = var.environment | ||
| ManagedBy = "terraform" | ||
| } | ||
| } | ||
|
|
||
| # Initial secrets | ||
| resource "aws_secretsmanager_secret_version" "hashing_secrets_test" { | ||
Karthikeyannhs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| secret_id = aws_secretsmanager_secret.hashing_secret.id | ||
| secret_string = "initial_secret" | ||
| lifecycle { | ||
| ignore_changes = [secret_string] | ||
| } | ||
| } | ||
|
|
||
| # Resource-based policy attached to the secret | ||
| resource "aws_secretsmanager_secret_policy" "hashing_secret_policy" { | ||
| secret_arn = aws_secretsmanager_secret.hashing_secret.arn | ||
|
|
||
| policy = jsonencode({ | ||
| Version = "2012-10-17", | ||
| Statement = [ | ||
| { | ||
| Sid = "CrossAccountAccess", | ||
| Effect = "Allow", | ||
| Principal = { AWS = var.external_write_access_role_arn }, | ||
| Action = [ | ||
| "secretsmanager:GetSecretValue", | ||
| "secretsmanager:DescribeSecret" | ||
| ], | ||
| Resource = "*" | ||
| }, | ||
| { | ||
| Sid = "LambdaAccess", | ||
| Effect = "Allow", | ||
| Principal = { AWS = var.eligibility_lambda_role_arn }, | ||
| Action = [ | ||
| "secretsmanager:GetSecretValue", | ||
| "secretsmanager:DescribeSecret" | ||
| ], | ||
| Resource = "*" | ||
| } | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
This file contains hidden or 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,9 @@ | ||
| variable "external_write_access_role_arn" { | ||
| description = "Arn of the external write access role to provide secret manager access" | ||
| type = string | ||
| } | ||
|
|
||
| variable "eligibility_lambda_role_arn" { | ||
| description = "Arn of the lambda role to provide secret manager access" | ||
| type = string | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| module "secrets_manager" { | ||
| source = "../../modules/secrets_manager" | ||
| count = length(aws_iam_role.write_access_role) | ||
| external_write_access_role_arn = aws_iam_role.write_access_role[count.index].arn | ||
| environment = var.environment | ||
| stack_name = local.stack_name | ||
| workspace = terraform.workspace | ||
| eligibility_lambda_role_arn = aws_iam_role.eligibility_lambda_role.arn | ||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.