Skip to content
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

feat(terraform): add and use kubernetes-secrets module #583

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 18 additions & 54 deletions terraform/authentik/applications.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
data "kubernetes_secret" "grafana" {
metadata {
name = "grafana-secret"
namespace = "monitoring"
module "secrets" {
source = "../kubernetes/secrets"

secrets = {
gitea = { namespace = "default", name = "gitea-oauth-secret" }
gitops = { namespace = "flux-system", name = "oidc-auth" }
grafana = { namespace = "monitoring", name = "grafana-secret" }
minio = { namespace = "default", name = "minio" }
nextcloud = { namespace = "default", name = "nextcloud-secret" }
pgadmin = { namespace = "database", name = "pgadmin" }
workflows = { namespace = "argo", name = "argo-server-sso" }
}
}

Expand All @@ -14,17 +21,10 @@ module "oauth2-grafana" {
auth_groups = [authentik_group.infra.id, authentik_group.admins.id]
authorization_flow = data.authentik_flow.default-authorization-flow.id
client_id = "grafana"
client_secret = data.kubernetes_secret.grafana.data["GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET"]
client_secret = module.secrets.data.grafana["GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET"]
redirect_uris = ["https://grafana.18b.haus/login/generic_oauth"]
}

data "kubernetes_secret" "gitops" {
metadata {
name = "oidc-auth"
namespace = "flux-system"
}
}

module "oauth2-gitops" {
source = "./modules/oauth2-application"
name = "GitOps"
Expand All @@ -34,17 +34,10 @@ module "oauth2-gitops" {
auth_groups = [authentik_group.infra.id, authentik_group.admins.id]
authorization_flow = data.authentik_flow.default-authorization-flow.id
client_id = "gitops"
client_secret = data.kubernetes_secret.gitops.data["clientSecret"]
client_secret = module.secrets.data.gitops["clientSecret"]
redirect_uris = ["https://gitops.18b.haus/oauth2/callback"]
}

data "kubernetes_secret" "minio" {
metadata {
name = "minio"
namespace = "default"
}
}

module "oauth2-minio" {
source = "./modules/oauth2-application"
name = "MinIO"
Expand All @@ -54,18 +47,11 @@ module "oauth2-minio" {
auth_groups = [authentik_group.infra.id, authentik_group.admins.id]
authorization_flow = data.authentik_flow.default-authorization-flow.id
client_id = "minio"
client_secret = data.kubernetes_secret.minio.data["MINIO_IDENTITY_OPENID_CLIENT_SECRET"]
client_secret = module.secrets.data.minio["MINIO_IDENTITY_OPENID_CLIENT_SECRET"]
redirect_uris = ["https://minio.18b.haus/oauth_callback"]
additional_property_mappings = [authentik_scope_mapping.openid-minio.id]
}

data "kubernetes_secret" "nextcloud" {
metadata {
name = "nextcloud-secret"
namespace = "default"
}
}

module "oauth2-nextcloud" {
source = "./modules/oauth2-application"
name = "Nextcloud"
Expand All @@ -75,7 +61,7 @@ module "oauth2-nextcloud" {
auth_groups = [authentik_group.nextcloud.id, authentik_group.admins.id]
authorization_flow = data.authentik_flow.default-authorization-flow.id
client_id = "nextcloud"
client_secret = data.kubernetes_secret.nextcloud.data["OIDC_CLIENT_SECRET"]
client_secret = module.secrets.data.nextcloud["OIDC_CLIENT_SECRET"]
redirect_uris = ["https://cloud.18b.haus/apps/oidc_login/oidc"]
additional_property_mappings = [authentik_scope_mapping.openid-nextcloud.id]
}
Expand All @@ -99,13 +85,6 @@ module "oauth2-proxmox" {
]
}

data "kubernetes_secret" "pgadmin" {
metadata {
name = "pgadmin"
namespace = "database"
}
}

module "oauth2-pgadmin" {
source = "./modules/oauth2-application"
name = "pgAdmin"
Expand All @@ -115,18 +94,10 @@ module "oauth2-pgadmin" {
auth_groups = [authentik_group.infra.id, authentik_group.admins.id]
authorization_flow = data.authentik_flow.default-authorization-flow.id
client_id = "pgadmin"
client_secret = data.kubernetes_secret.pgadmin.data["OAUTH2_CLIENT_SECRET"]
client_secret = module.secrets.data.pgadmin["OAUTH2_CLIENT_SECRET"]
redirect_uris = ["https://pgadmin.18b.haus/oauth2/authorize"]
}


data "kubernetes_secret" "workflows" {
metadata {
name = "argo-server-sso"
namespace = "argo"
}
}

module "oauth2-workflows" {
source = "./modules/oauth2-application"
name = "Argo Workflows"
Expand All @@ -137,17 +108,10 @@ module "oauth2-workflows" {
auth_groups = [authentik_group.infra.id, authentik_group.admins.id]
authorization_flow = data.authentik_flow.default-authorization-flow.id
client_id = "workflows"
client_secret = data.kubernetes_secret.workflows.data["client-secret"]
client_secret = module.secrets.data.workflows["client-secret"]
redirect_uris = ["https://workflows.18b.haus/oauth2/callback"]
}

data "kubernetes_secret" "gitea" {
metadata {
name = "gitea-oauth-secret"
namespace = "default"
}
}

module "oauth2-gitea" {
source = "./modules/oauth2-application"
name = "Gitea"
Expand All @@ -158,7 +122,7 @@ module "oauth2-gitea" {
auth_groups = [authentik_group.users.id, authentik_group.admins.id]
authorization_flow = data.authentik_flow.default-authorization-flow.id
client_id = "gitea"
client_secret = data.kubernetes_secret.gitea.data["secret"]
client_secret = module.secrets.data.gitea["secret"]
redirect_uris = ["https://git.18b.haus/user/oauth2/Authentik/callback"]
}

Expand Down
4 changes: 0 additions & 4 deletions terraform/authentik/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ terraform {
source = "goauthentik/authentik"
version = "2024.2.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.27.0"
}
}
}
22 changes: 22 additions & 0 deletions terraform/kubernetes/secrets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
variable "secrets" {
default = {}
description = "Map of arbitrary names to Kubernetes secret references"
type = map(object({
namespace = string
name = string
}))
}

data "kubernetes_secret" "all" {
for_each = var.secrets

metadata {
name = each.value.name
namespace = each.value.namespace
}
}

output "data" {
description = "Map of names uses as keys in the `secrets` variable to the referenced secret's data"
value = { for name, secret in data.kubernetes_secret.all : name => secret.data }
}
8 changes: 8 additions & 0 deletions terraform/kubernetes/secrets/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.27.0"
}
}
}
39 changes: 11 additions & 28 deletions terraform/minio/main.tf
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
data "kubernetes_secret" "argo-workflows" {
metadata {
name = "argo-minio-credentials"
namespace = "argo"
}
}

data "kubernetes_secret" "cloudnative-pg" {
metadata {
name = "cloudnative-pg"
namespace = "database"
}
}

data "kubernetes_secret" "cluster-secrets" {
metadata {
name = "cluster-secrets"
namespace = "flux-system"
}
}
module "secrets" {
source = "../kubernetes/secrets"

data "kubernetes_secret" "gitea" {
metadata {
name = "gitea-secret"
namespace = "default"
secrets = {
argo-workflows = { namespace = "argo", name = "argo-minio-credentials" }
cloudnative-pg = { namespace = "database", name = "cloudnative-pg" }
cluster-secrets = { namespace = "flux-system", name = "cluster-secrets" }
gitea = { namespace = "default", name = "gitea-secret" }
}
}

locals {
buckets = {
argo-workflow-artifacts = data.kubernetes_secret.argo-workflows.data["secret-access-key"]
cloudnative-pg = data.kubernetes_secret.cloudnative-pg.data["aws-secret-access-key"]
gitea = data.kubernetes_secret.gitea.data["minio-secret-access-key"]
volsync = data.kubernetes_secret.cluster-secrets.data["SECRET_VOLSYNC_MINIO_SECRET_ACCESS_KEY"]
argo-workflow-artifacts = module.secrets.data.argo-workflows["secret-access-key"]
cloudnative-pg = module.secrets.data.cloudnative-pg["aws-secret-access-key"]
gitea = module.secrets.data.gitea["minio-secret-access-key"]
volsync = module.secrets.data.cluster-secrets["SECRET_VOLSYNC_MINIO_SECRET_ACCESS_KEY"]
}
}

Expand Down
4 changes: 0 additions & 4 deletions terraform/minio/versions.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.27.0"
}
minio = {
source = "aminueza/minio"
version = "2.2.0"
Expand Down