Skip to content

Commit

Permalink
Add slack cognito client (#100)
Browse files Browse the repository at this point in the history
* Add slack cognito client

* fix outputs

* add slack client id to authz service

* changeset
  • Loading branch information
JoshuaWilkes authored Mar 18, 2024
1 parent 95aa468 commit 5618d75
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-suns-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@common-fate/terraform-aws-common-fate-deployment": minor
---

Add a slack cognito client to enable delegated slack based access requests to be attributed correctly to Slack as an origin
6 changes: 4 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ module "control_plane" {
subnet_ids = local.private_subnet_ids
vpc_id = local.vpc_id
ecs_cluster_id = local.ecs_cluster_id
auth_authority_url = module.cognito.auth_authority_url
database_host = module.control_plane_db.endpoint
database_user = module.control_plane_db.username
alb_listener_arn = module.alb.listener_arn
sqs_queue_name = module.events.sqs_queue_name
auth_issuer = module.cognito.auth_issuer
control_plane_service_client_id = module.cognito.control_plane_service_client_id
control_plane_service_client_secret = module.cognito.control_plane_service_client_secret
slack_service_client_id = module.cognito.slack_service_client_id
slack_service_client_secret = module.cognito.slack_service_client_secret
oidc_slack_issuer = module.cognito.auth_issuer
licence_key_ps_arn = var.licence_key_ps_arn
log_level = var.control_plane_log_level
grant_assume_on_role_arns = var.control_plane_grant_assume_on_role_arns
Expand Down Expand Up @@ -188,7 +190,6 @@ module "access_handler" {
release_tag = var.release_tag
subnet_ids = local.private_subnet_ids
vpc_id = local.vpc_id
auth_authority_url = module.cognito.auth_authority_url
ecs_cluster_id = local.ecs_cluster_id
alb_listener_arn = module.alb.listener_arn
auth_issuer = module.cognito.auth_issuer
Expand Down Expand Up @@ -223,6 +224,7 @@ module "authz" {
oidc_access_handler_service_client_id = module.cognito.access_handler_service_client_id
oidc_control_plane_client_id = module.cognito.control_plane_service_client_id
oidc_provisioner_service_client_id = module.cognito.provisioner_client_id
oidc_slack_service_client_id = module.cognito.slack_service_client_id
alb_security_group_id = module.alb.alb_security_group_id
additional_cors_allowed_origins = var.additional_cors_allowed_origins
}
Expand Down
4 changes: 0 additions & 4 deletions modules/access/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ resource "aws_ecs_task_definition" "access_handler_task" {
containerPort = 9090,
}],
environment = [
{
name = "CF_OIDC_AUTHORITY_URL",
value = var.auth_authority_url
},
{
name = "CF_EVENT_BRIDGE_ARN",
value = var.eventbus_arn
Expand Down
4 changes: 0 additions & 4 deletions modules/access/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ variable "app_url" {
}
}

variable "auth_authority_url" {
description = "Specifies the URL used for authentication."
type = string
}

variable "ecs_cluster_id" {
description = "Identifies the Amazon Elastic Container Service (ECS) cluster for deployment."
Expand Down
4 changes: 4 additions & 0 deletions modules/authz/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ resource "aws_ecs_task_definition" "authz_task" {
name = "CF_OIDC_PROVISIONER_SERVICE_CLIENT_ID",
value = var.oidc_provisioner_service_client_id
},
{
name = "CF_OIDC_SLACK_SERVICE_CLIENT_ID",
value = var.oidc_slack_service_client_id
},


],
Expand Down
4 changes: 4 additions & 0 deletions modules/authz/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ variable "oidc_provisioner_service_client_id" {
description = "Provisioner Service Account OIDC Client ID"
type = string
}
variable "oidc_slack_service_client_id" {
description = "Slack Service Account OIDC Client ID"
type = string
}

variable "log_level" {
description = "Log level for ECS service"
Expand Down
17 changes: 17 additions & 0 deletions modules/cognito/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ resource "aws_cognito_user_pool_client" "control_plane_service_client" {
generate_secret = true
}

resource "aws_cognito_user_pool_client" "slack_service_client" {
name = "${var.namespace}-${var.stage}-slack-client"
user_pool_id = aws_cognito_user_pool.cognito_user_pool.id

explicit_auth_flows = [
"ALLOW_USER_SRP_AUTH",
"ALLOW_REFRESH_TOKEN_AUTH"
]

access_token_validity = 8
allowed_oauth_flows = ["client_credentials"]
allowed_oauth_scopes = aws_cognito_resource_server.resource_server.scope_identifiers
allowed_oauth_flows_user_pool_client = true
generate_secret = true
}



resource "aws_cognito_user_pool_client" "access_handler_service_client" {
name = "${var.namespace}-${var.stage}-access-handler-client"
Expand Down
10 changes: 10 additions & 0 deletions modules/cognito/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ output "identity_provider_name" {
description = "The name of the Cognito identity provider"
value = local.identity_provider_name
}

output "slack_service_client_id" {
description = "The client ID for the slack service."
value = aws_cognito_user_pool_client.slack_service_client.id
}

output "slack_service_client_secret" {
description = "The client secret for the slack service."
value = aws_cognito_user_pool_client.slack_service_client.client_secret
}
21 changes: 12 additions & 9 deletions modules/controlplane/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,6 @@ locals {
name = "CF_SCIM_SOURCE",
value = var.scim_source
},
{
name = "CF_OIDC_AUTHORITY_URL",
value = var.auth_authority_url
},
// used for client credentials
{
name = "CF_CONTROL_PLANE_SERVICE_OIDC_ISSUER",
value = var.auth_issuer
},
// used for auth middleware
{
name = "CF_OIDC_TRUSTED_ISSUER_COGNITO",
Expand Down Expand Up @@ -398,6 +389,18 @@ locals {
name = "CF_CONTROL_PLANE_SERVICE_OIDC_ISSUER",
value = var.oidc_control_plane_issuer
},
{
name = "CF_SLACK_SERVICE_OIDC_CLIENT_ID",
value = var.slack_service_client_id
},
{
name = "CF_SLACK_SERVICE_OIDC_CLIENT_SECRET",
value = var.slack_service_client_secret
},
{
name = "CF_SLACK_SERVICE_OIDC_ISSUER",
value = var.oidc_slack_issuer
},
{ name = "CF_CORS_ALLOWED_ORIGINS"
value = join(",", concat([var.app_url], var.additional_cors_allowed_origins))
},
Expand Down
20 changes: 14 additions & 6 deletions modules/controlplane/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ variable "ecs_cluster_id" {
type = string
}

variable "auth_authority_url" {
description = "Specifies the URL used for authentication."
type = string
}

variable "auth_issuer" {
description = "Specifies the issuer for authentication."
type = string
Expand All @@ -135,11 +130,24 @@ variable "control_plane_service_client_secret" {
type = string
sensitive = true
}

variable "oidc_control_plane_issuer" {
description = "OIDC issuer for the Control Plane service"
type = string
}
variable "slack_service_client_id" {
description = "Specifies the client ID for the slack service."
type = string
}

variable "slack_service_client_secret" {
description = "Specifies the client secret for the slack service."
type = string
sensitive = true
}
variable "oidc_slack_issuer" {
description = "OIDC issuer for the Slack service"
type = string
}

variable "alb_listener_arn" {
description = "Specifies the Amazon Load Balancer (ALB) listener ARN."
Expand Down

0 comments on commit 5618d75

Please sign in to comment.