first commit
This commit is contained in:
73
oauth2/oauth2.tf
Normal file
73
oauth2/oauth2.tf
Normal file
@@ -0,0 +1,73 @@
|
||||
resource "kubectl_manifest" "oauth2-secret" {
|
||||
ignore_fields = ["metadata.annotations"]
|
||||
yaml_body = <<-EOF
|
||||
apiVersion: "secretgenerator.mittwald.de/v1alpha1"
|
||||
kind: "StringSecret"
|
||||
metadata:
|
||||
name: "${var.component}-${var.instance}-id"
|
||||
namespace: "${var.namespace}"
|
||||
labels: ${jsonencode(var.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
|
||||
}
|
||||
}
|
||||
|
||||
data "authentik_certificate_key_pair" "ca" {
|
||||
name = "authentik Self-signed Certificate"
|
||||
}
|
||||
|
||||
data "authentik_scope_mapping" "oauth2" {
|
||||
managed_list = [
|
||||
"goauthentik.io/providers/oauth2/scope-email",
|
||||
"goauthentik.io/providers/oauth2/scope-openid",
|
||||
"goauthentik.io/providers/oauth2/scope-profile"
|
||||
]
|
||||
}
|
||||
data "authentik_flow" "default-authorization-flow" {
|
||||
slug = "default-provider-authorization-implicit-consent"
|
||||
}
|
||||
data "authentik_flow" "default-authentication-flow" {
|
||||
slug = "default-authentication-flow"
|
||||
}
|
||||
|
||||
resource "authentik_provider_oauth2" "oauth2" {
|
||||
name = "${var.component}-${var.instance}"
|
||||
client_id = data.kubernetes_secret_v1.oauth2-client-id.data["client-id"]
|
||||
authentication_flow = data.authentik_flow.default-authentication-flow.id
|
||||
authorization_flow = data.authentik_flow.default-authorization-flow.id
|
||||
client_type = "confidential"
|
||||
sub_mode = "user_username"
|
||||
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}"
|
||||
]
|
||||
}
|
||||
|
||||
resource "kubernetes_secret_v1" "oauth2-client-secret" {
|
||||
metadata {
|
||||
name = "${var.component}-${var.instance}-secret"
|
||||
namespace = var.namespace
|
||||
labels = var.labels
|
||||
}
|
||||
data = {
|
||||
client-secret = authentik_provider_oauth2.oauth2.client_secret
|
||||
}
|
||||
}
|
||||
|
||||
data "kubernetes_ingress_v1" "authentik" {
|
||||
metadata {
|
||||
name = "authentik"
|
||||
namespace = "${var.domain}-auth"
|
||||
}
|
||||
}
|
||||
7
oauth2/outputs.tf
Normal file
7
oauth2/outputs.tf
Normal file
@@ -0,0 +1,7 @@
|
||||
output "provider-id" {
|
||||
value = authentik_provider_oauth2.oauth2.id
|
||||
}
|
||||
|
||||
output "sso_configuration_url" {
|
||||
value = "https://${data.kubernetes_ingress_v1.authentik.spec[0].rule[0].host}/application/o/${var.component}-${var.instance}"
|
||||
}
|
||||
17
oauth2/providers.tf
Normal file
17
oauth2/providers.tf
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.20.0"
|
||||
}
|
||||
kubectl = {
|
||||
source = "gavinbunney/kubectl"
|
||||
version = "~> 1.14.0"
|
||||
}
|
||||
authentik = {
|
||||
source = "goauthentik/authentik"
|
||||
version = "~> 2023.5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
22
oauth2/variables.tf
Normal file
22
oauth2/variables.tf
Normal file
@@ -0,0 +1,22 @@
|
||||
variable "component" {
|
||||
type = string
|
||||
}
|
||||
variable "instance" {
|
||||
type = string
|
||||
}
|
||||
variable "namespace" {
|
||||
type = string
|
||||
}
|
||||
variable "domain" {
|
||||
type = string
|
||||
}
|
||||
variable "labels" {
|
||||
type = map(string)
|
||||
}
|
||||
variable "dns_name" {
|
||||
type = string
|
||||
}
|
||||
variable "redirect_path" {
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
Reference in New Issue
Block a user