-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GOVSI-680: Provision KMS key and creds for account mgmt app
- Provision a KMS CMK for account management - Generate a random client ID - Add client to DynamoDB table with placeholder for public key (workaround until hashicorp/terraform-provider-aws#20595 is resolved) - Output details so they can be injected into the account management PaaS app
- Loading branch information
1 parent
f4fc020
commit 38fd04d
Showing
6 changed files
with
154 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.0 | ||
1.0.4 |
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,55 @@ | ||
resource "random_string" "account_management_client_id" { | ||
lower = true | ||
upper = true | ||
special = false | ||
number = true | ||
length = 32 | ||
} | ||
|
||
data "aws_kms_public_key" "account_management_jwt_key" { | ||
depends_on = [aws_kms_key.account_management_jwt_key] | ||
key_id = aws_kms_key.account_management_jwt_key.arn | ||
} | ||
|
||
resource "aws_dynamodb_table_item" "account_management_client" { | ||
table_name = aws_dynamodb_table.client_registry_table.name | ||
hash_key = aws_dynamodb_table.client_registry_table.hash_key | ||
|
||
item = jsonencode({ | ||
ClientID = { | ||
S = random_string.account_management_client_id.result | ||
} | ||
ClientName = { | ||
S = "${var.environment}-account-managment" | ||
} | ||
Contacts = { | ||
L = [] | ||
} | ||
PostLogoutRedirectUrls = { | ||
L = [] | ||
} | ||
RedirectUrls = { | ||
L = [ | ||
{ | ||
S = "https://account-management.${var.environment}.${var.service_domain_name}/auth/callback" | ||
} | ||
] | ||
} | ||
Scopes = { | ||
L = [ | ||
{ | ||
S = "openid" | ||
}, | ||
{ | ||
S = "phone" | ||
}, | ||
{ | ||
S = "email" | ||
}, | ||
] | ||
} | ||
PublicKey = { | ||
S = "paste me manually until Terraform provider bug is fixed" | ||
} | ||
}) | ||
} |
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,72 @@ | ||
resource "aws_kms_key" "account_management_jwt_key" { | ||
description = "KMS key for Account Management JWT Authentication (${var.environment})" | ||
deletion_window_in_days = 30 | ||
key_usage = "SIGN_VERIFY" | ||
customer_master_key_spec = "RSA_2048" | ||
} | ||
|
||
resource "aws_kms_alias" "account_management_jwt_alias" { | ||
name = "alias/${var.environment}-account-management-jwt-key-alias" | ||
target_key_id = aws_kms_key.account_management_jwt_key.key_id | ||
} | ||
|
||
data "aws_iam_policy_document" "account_management_jwt_kms_policy_document" { | ||
count = var.use_localstack ? 0 : 1 | ||
statement { | ||
sid = "AllowAccessToKmsSigningKey" | ||
effect = "Allow" | ||
|
||
actions = [ | ||
"kms:Sign", | ||
"kms:GetPublicKey", | ||
] | ||
resources = [ | ||
aws_kms_key.account_management_jwt_key.arn, | ||
] | ||
} | ||
} | ||
|
||
resource "aws_iam_policy" "account_management_jwt_lambda_kms_policy" { | ||
count = var.use_localstack ? 0 : 1 | ||
name = "${var.environment}-account-managment-jwt-kms-policy" | ||
path = "/" | ||
description = "IAM policy for managing KMS connection for account management application" | ||
|
||
policy = data.aws_iam_policy_document.account_management_jwt_kms_policy_document[0].json | ||
} | ||
|
||
resource "aws_iam_user" "account_management_app" { | ||
name = "${var.environment}-account-managment-application" | ||
} | ||
|
||
resource "aws_iam_access_key" "account_management_app_access_keys" { | ||
user = aws_iam_user.account_management_app.name | ||
} | ||
|
||
data "aws_iam_policy_document" "account_management_app_role_assume_policy" { | ||
version = "2012-10-17" | ||
|
||
statement { | ||
effect = "Allow" | ||
principals { | ||
identifiers = [ | ||
aws_iam_user.account_management_app.arn | ||
] | ||
type = "AWS" | ||
} | ||
|
||
actions = [ | ||
"sts:AssumeRole" | ||
] | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "account_management_app_role" { | ||
assume_role_policy = data.aws_iam_policy_document.account_management_app_role_assume_policy.json | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "account_management_app_kms" { | ||
count = var.use_localstack ? 0 : 1 | ||
role = aws_iam_role.account_management_app_role.name | ||
policy_arn = aws_iam_policy.account_management_jwt_lambda_kms_policy[0].arn | ||
} |
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