Compare commits
3 Commits
0.1.0
...
159b576b24
| Author | SHA1 | Date | |
|---|---|---|---|
| 159b576b24 | |||
| 1c42b356c1 | |||
| 6ea3cfc0bf |
@@ -4,29 +4,9 @@ locals {
|
||||
"app.kubernetes.io/component" = "authentik-oauth2"
|
||||
})
|
||||
}
|
||||
resource "kubectl_manifest" "oauth2-secret" {
|
||||
ignore_fields = ["metadata.annotations"]
|
||||
yaml_body = <<-EOF
|
||||
apiVersion: "secretgenerator.mittwald.de/v1alpha1"
|
||||
kind: "StringSecret"
|
||||
metadata:
|
||||
name: "${local.app_slug}-id"
|
||||
namespace: "${var.namespace}"
|
||||
labels: ${jsonencode(local.oauth2_labels)}
|
||||
spec:
|
||||
forceRegenerate: false
|
||||
fields:
|
||||
- fieldName: "client-id"
|
||||
length: "32"
|
||||
EOF
|
||||
}
|
||||
data "kubernetes_secret_v1" "oauth2-client-id" {
|
||||
depends_on = [kubectl_manifest.oauth2-secret]
|
||||
metadata {
|
||||
name = kubectl_manifest.oauth2-secret.name
|
||||
namespace = var.namespace
|
||||
labels = local.oauth2_labels
|
||||
}
|
||||
resource "random_password" "client_id" {
|
||||
length = 32
|
||||
special = false
|
||||
}
|
||||
|
||||
data "authentik_certificate_key_pair" "ca" {
|
||||
@@ -49,7 +29,7 @@ data "authentik_flow" "default-authentication-flow" {
|
||||
|
||||
resource "authentik_provider_oauth2" "oauth2" {
|
||||
name = "${local.app_slug}"
|
||||
client_id = data.kubernetes_secret_v1.oauth2-client-id.data["client-id"]
|
||||
client_id = random_password.client_id.result
|
||||
authentication_flow = data.authentik_flow.default-authentication-flow.id
|
||||
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
||||
client_type = "confidential"
|
||||
@@ -57,10 +37,21 @@ resource "authentik_provider_oauth2" "oauth2" {
|
||||
signing_key = data.authentik_certificate_key_pair.ca.id
|
||||
property_mappings = data.authentik_scope_mapping.oauth2.ids
|
||||
redirect_uris = [
|
||||
"https://${var.dns_name}/${var.redirect_path}"
|
||||
"https://${var.redirect_path!=""?"${var.dns_name}/${var.redirect_path}":"${var.dns_name}"}"
|
||||
]
|
||||
}
|
||||
|
||||
resource "kubernetes_secret_v1" "oauth2-client-id" {
|
||||
metadata {
|
||||
name = "${local.app_slug}-id"
|
||||
namespace = var.namespace
|
||||
labels = local.oauth2_labels
|
||||
}
|
||||
data = {
|
||||
client-id = random_password.client_id.result
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_secret_v1" "oauth2-client-secret" {
|
||||
metadata {
|
||||
name = "${local.app_slug}-secret"
|
||||
@@ -68,6 +59,7 @@ resource "kubernetes_secret_v1" "oauth2-client-secret" {
|
||||
labels = local.oauth2_labels
|
||||
}
|
||||
data = {
|
||||
client-id = random_password.client_id.result
|
||||
client-secret = authentik_provider_oauth2.oauth2.client_secret
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ output "sso_token_url" {
|
||||
value = "https://${data.kubernetes_ingress_v1.authentik.spec[0].rule[0].host}/application/o/token/"
|
||||
}
|
||||
output "client_id" {
|
||||
value = data.kubernetes_secret_v1.oauth2-client-id.data["client-id"]
|
||||
value = random_password.client_id.result
|
||||
}
|
||||
output "client_secret" {
|
||||
value = data.kubernetes_secret_v1.oauth2-client-secret.data["client-secret"]
|
||||
value = authentik_provider_oauth2.oauth2.client_secret
|
||||
}
|
||||
|
||||
output "secret_client_id_name" {
|
||||
value = kubectl_manifest.oauth2-secret.name
|
||||
value = kubernetes_secret_v1.oauth2-client-secret.metadata[0].name
|
||||
}
|
||||
output "secret_client_secret_name" {
|
||||
value = kubernetes_secret_v1.oauth2-client-secret.metadata[0].name
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
locals {
|
||||
selector = var.selector==null?var.labels:var.selector
|
||||
app_slug = "${var.instance}${var.component==""?"":"-"}${var.component}"
|
||||
cluster_ports = var.svc_type == "ClusterIP" ? [for idx, target in var.targets : {
|
||||
"name" = target
|
||||
@@ -35,7 +36,7 @@ locals {
|
||||
"ClusterIP" = {
|
||||
type = "ClusterIP"
|
||||
ports = local.cluster_ports
|
||||
selector = var.labels
|
||||
selector = local.selector
|
||||
},
|
||||
"ExternalName" = {
|
||||
type = "ExternalName"
|
||||
@@ -44,12 +45,12 @@ locals {
|
||||
},
|
||||
"NodePort" = {
|
||||
type = "NodePort"
|
||||
selector = var.labels
|
||||
selector = local.selector
|
||||
ports = local.node_ports
|
||||
},
|
||||
"LoadBalancer" = {
|
||||
type = "LoadBalancer"
|
||||
selector = var.labels
|
||||
selector = local.selector
|
||||
ports = local.lb_ports
|
||||
externalTrafficPolicy = var.lb_policy
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ variable "namespace" {
|
||||
variable "labels" {
|
||||
type = map(string)
|
||||
}
|
||||
variable "selector" {
|
||||
type = map(string)
|
||||
default = null
|
||||
}
|
||||
variable "annotations" {
|
||||
type = map(string)
|
||||
default = {}
|
||||
|
||||
Reference in New Issue
Block a user