Skip to content

Commit fc203b3

Browse files
authored
Mode auth implementation into a module (#182)
* move auth into module for better portability to allow spining up multiple auth setup in one cluster * fixup! move auth into module for better portability * move user-auth to terraform-aws-zero * fixup! move user-auth to terraform-aws-zero * remove auth-domain from user-auth currently all the auth requests are going through oathkeeper using the api ingress to route to the kratos service * customizable list of whitelisted return urls * add cookie signing secret key * fixup! add cookie signing secret key * fixup! fixup! add cookie signing secret key * fixup! fixup! fixup! add cookie signing secret key * fixup! fixup! fixup! fixup! add cookie signing secret key * fixup! fixup! fixup! fixup! fixup! add cookie signing secret key * fixup! fixup! fixup! fixup! fixup! fixup! add cookie signing secret key
1 parent e6e1af3 commit fc203b3

16 files changed

Lines changed: 73 additions & 673 deletions

File tree

.github/workflows/terraform.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: hashicorp/setup-terraform@v1
16-
with:
17-
terraform_version: 0.13.5
18-
1916
- name: Install Zero
2017
id: install_zero
2118
run: |

templates/kubernetes/terraform/environments/prod/main.tf

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,23 @@ module "kubernetes" {
7575
]
7676

7777
domain_name = local.domain_name
78-
auth_enabled = <% if eq (index .Params `userAuth`) "yes" %>true<% else %>false<% end %>
79-
auth_domain = "auth.${local.domain_name}"
80-
backend_service_domain = "<% index .Params `productionBackendSubdomain` %>${local.domain_name}"
81-
frontend_service_domain = "<% index .Params `productionFrontendSubdomain` %>${local.domain_name}"
82-
# This domain or address must be verified by the mail provider (Sendgrid, SES, etc.)
83-
user_auth_mail_from_address = "noreply@${local.domain_name}"
84-
78+
<% if eq (index .Params `userAuth`) "yes" %>user_auth = [
79+
{
80+
name = local.project
81+
auth_namespace = "user-auth"
82+
frontend_service_domain = "<% index .Params `productionFrontendSubdomain` %>.${local.domain_name}"
83+
backend_service_domain = "<% index .Params `productionBackendSubdomain` %>.${local.domain_name}"
84+
whitelisted_return_urls = ["https://<% index .Params `productionFrontendSubdomain` %>.${local.domain_name}"]
85+
jwks_secret_name = "${local.project}-${local.environment}-oathkeeper-jwks-${local.random_seed}"
86+
# This domain or address must be verified by the mail provider (Sendgrid, SES, etc.)
87+
user_auth_mail_from_address = "noreply@${local.domain_name}"
88+
cookie_sigining_secret_key = "${local.project}-${local.environment}-${local.random_seed}"
89+
}
90+
## User auth: Kratos requires database and a secret (as: `user_auth[0].name`)
91+
## Oathkeeper requires a private key (as `user_auth[0].jwks_secret_name`)
92+
## per environment one of each (database/database secret/private key) is created in the pre-k8s step
93+
## If you need to add another user-auth instance you will have to create another set of these resources
94+
]<% end %>
8595
notification_service_enabled = <%if eq (index .Params `notificationServiceEnabled`) "yes" %>true<% else %>false<% end %>
8696
notification_service_highly_available = true
8797

templates/kubernetes/terraform/environments/stage/main.tf

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,23 @@ module "kubernetes" {
7474
]
7575

7676
domain_name = local.domain_name
77-
auth_enabled = <% if eq (index .Params `userAuth`) "yes" %>true<% else %>false<% end %>
78-
auth_domain = "auth.${local.domain_name}"
79-
backend_service_domain = "<% index .Params `stagingBackendSubdomain` %>${local.domain_name}"
80-
frontend_service_domain = "<% index .Params `stagingFrontendSubdomain` %>${local.domain_name}"
81-
# This domain or address must be verified by the mail provider (Sendgrid, SES, etc.)
82-
user_auth_mail_from_address = "noreply@${local.domain_name}"
83-
77+
<% if eq (index .Params `userAuth`) "yes" %>user_auth = [
78+
{
79+
name = local.project
80+
auth_namespace = "user-auth"
81+
frontend_service_domain = "<% index .Params `stagingFrontendSubdomain` %>.${local.domain_name}"
82+
backend_service_domain = "<% index .Params `stagingBackendSubdomain` %>.${local.domain_name}"
83+
whitelisted_return_urls = ["https://<% index .Params `stagingFrontendSubdomain` %>.${local.domain_name}"]
84+
jwks_secret_name = "${local.project}-${local.environment}-oathkeeper-jwks-${local.random_seed}"
85+
# This domain or address must be verified by the mail provider (Sendgrid, SES, etc.)
86+
user_auth_mail_from_address = "noreply@${local.domain_name}"
87+
cookie_sigining_secret_key = "${local.project}-${local.environment}-${local.random_seed}"
88+
}
89+
## User auth: Kratos requires database and a secret (as: `user_auth[0].name`)
90+
## Oathkeeper requires a private key (as `user_auth[0].jwks_secret_name`)
91+
## per environment one of each (database/database secret/private key) is created in the pre-k8s step
92+
## If you need to add another user-auth instance you will have to create another set of these resources
93+
]<% end %>
8494
notification_service_enabled = <%if eq (index .Params `notificationServiceEnabled`) "yes" %>true<% else %>false<% end %>
8595
notification_service_highly_available = false
8696

templates/kubernetes/terraform/modules/kubernetes/cert_manager.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ resource "null_resource" "cert_manager_dns_issuer" {
126126
# Create a role using oidc to map service accounts
127127
module "iam_assumable_role_cert_manager" {
128128
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
129-
version = "~> v2.14.0"
129+
version = "~> v3.12.0"
130130
create_role = true
131131
role_name = "${var.project}-k8s-${var.environment}-cert-manager"
132132
provider_url = replace(data.aws_eks_cluster.cluster.identity.0.oidc.0.issuer, "https://", "")

templates/kubernetes/terraform/modules/kubernetes/cluster_autoscaler.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ resource "helm_release" "cluster_autoscaler" {
3737
# Create a role using oidc to map service accounts
3838
module "iam_assumable_role_cluster_autoscaler" {
3939
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
40-
version = "~> v2.14.0"
40+
version = "~> v3.12.0"
4141
create_role = true
4242
role_name = "${var.project}-k8s-${var.environment}-cluster-autoscaler"
4343
provider_url = replace(data.aws_eks_cluster.cluster.identity.0.oidc.0.issuer, "https://", "")

templates/kubernetes/terraform/modules/kubernetes/external_dns.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Create a role using oidc to map service accounts
22
module "iam_assumable_role_external_dns" {
33
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
4-
version = "~> v2.14.0"
4+
version = "~> v3.12.0"
55
create_role = true
66
role_name = "${var.project}-k8s-${var.environment}-external-dns"
77
provider_url = replace(data.aws_eks_cluster.cluster.identity.0.oidc.0.issuer, "https://", "")

templates/kubernetes/terraform/modules/kubernetes/files/kratos-values.yml

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)