Skip to content

Commit 4da8c49

Browse files
Hiran Adikariclaude
andcommitted
feat(identity): add pluggable IdP modules for Rancher OIDC federation
Introduces a two-tier module pattern under modules/identity/: providers/asgardeo/ — creates asgardeo_application, outputs standardized OIDC interface (client_id, client_secret, issuer_url, auth_endpoint, token_endpoint, jwks_url) providers/azure-ad/ — usable stub: computes Azure AD v2.0 OIDC endpoints from tenant_id; accepts manual client credentials until azuread_application resources are implemented rancher-oidc/ — IdP-agnostic: consumes the standardized interface and creates rancher2_auth_config_generic_oidc Swapping identity providers requires changing only the idp module source; the rancher-oidc module and all downstream config remain unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 687a055 commit 4da8c49

12 files changed

Lines changed: 349 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
locals {
2+
base_url = "https://api.asgardeo.io/t/${var.org_name}"
3+
issuer_url = "${local.base_url}/oauth2/token"
4+
auth_endpoint = "${local.base_url}/oauth2/authorize"
5+
token_endpoint = "${local.base_url}/oauth2/token"
6+
jwks_url = "${local.base_url}/oauth2/jwks"
7+
discovery_url = "${local.base_url}/oauth2/token/.well-known/openid-configuration"
8+
}
9+
10+
resource "asgardeo_application" "this" {
11+
name = var.app_name
12+
description = var.description
13+
access_url = var.access_url
14+
15+
oidc {
16+
grant_types = ["authorization_code", "refresh_token"]
17+
callback_urls = var.callback_urls
18+
allowed_origins = var.allowed_origins
19+
logout_redirect_urls = var.logout_redirect_urls
20+
21+
pkce {
22+
mandatory = false
23+
support_plain_transform_algorithm = false
24+
}
25+
26+
access_token {
27+
type = "JWT"
28+
user_access_token_expiry_seconds = 3600
29+
}
30+
31+
refresh_token {
32+
expiry_seconds = 86400
33+
renew_refresh_token = true
34+
}
35+
}
36+
37+
advanced {
38+
skip_login_consent = var.skip_consent
39+
skip_logout_consent = var.skip_consent
40+
}
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ── Standardized OIDC interface (shared by all provider modules) ──────────────
2+
3+
output "client_id" {
4+
value = asgardeo_application.this.client_id
5+
description = "OAuth2 client ID generated by Asgardeo."
6+
}
7+
8+
output "client_secret" {
9+
value = asgardeo_application.this.client_secret
10+
description = "OAuth2 client secret generated by Asgardeo."
11+
sensitive = true
12+
}
13+
14+
output "issuer_url" {
15+
value = local.issuer_url
16+
description = "OIDC issuer URL (token endpoint used as issuer for Rancher compatibility)."
17+
}
18+
19+
output "auth_endpoint" {
20+
value = local.auth_endpoint
21+
description = "OAuth2 authorization endpoint."
22+
}
23+
24+
output "token_endpoint" {
25+
value = local.token_endpoint
26+
description = "OAuth2 token endpoint."
27+
}
28+
29+
output "jwks_url" {
30+
value = local.jwks_url
31+
description = "JSON Web Key Set URL for token signature verification."
32+
}
33+
34+
# ── Asgardeo-specific outputs ─────────────────────────────────────────────────
35+
36+
output "application_id" {
37+
value = asgardeo_application.this.id
38+
description = "Asgardeo internal application ID."
39+
}
40+
41+
output "discovery_url" {
42+
value = local.discovery_url
43+
description = "OIDC well-known discovery URL for manual verification."
44+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
variable "org_name" {
2+
type = string
3+
description = "Asgardeo organisation name (the subdomain of your Asgardeo tenant)."
4+
}
5+
6+
variable "app_name" {
7+
type = string
8+
description = "Display name for the OIDC application in Asgardeo."
9+
}
10+
11+
variable "description" {
12+
type = string
13+
description = "Human-readable description of the application."
14+
default = "Managed by Terraform."
15+
}
16+
17+
variable "access_url" {
18+
type = string
19+
description = "URL users are redirected to after authentication (e.g. https://app.example.com/dashboard)."
20+
}
21+
22+
variable "callback_urls" {
23+
type = list(string)
24+
description = "OAuth2 redirect URIs that Asgardeo will accept after authentication."
25+
}
26+
27+
variable "allowed_origins" {
28+
type = list(string)
29+
description = "Origins permitted to make CORS requests to the Asgardeo token endpoint."
30+
}
31+
32+
variable "logout_redirect_urls" {
33+
type = list(string)
34+
description = "URLs to redirect to after logout."
35+
}
36+
37+
variable "skip_consent" {
38+
type = bool
39+
description = "Skip login and logout consent screens for seamless SSO."
40+
default = true
41+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_providers {
3+
asgardeo = {
4+
source = "asgardeo/asgardeo"
5+
# Version constraint is informational while dev_overrides is active.
6+
# Remove once the provider is published to the Terraform Registry.
7+
version = "~> 0.1"
8+
}
9+
}
10+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# ── Azure AD OIDC endpoints (computed from tenant_id) ────────────────────────
2+
locals {
3+
base_url = "https://login.microsoftonline.com/${var.tenant_id}/v2.0"
4+
issuer_url = local.base_url
5+
auth_endpoint = "https://login.microsoftonline.com/${var.tenant_id}/oauth2/v2.0/authorize"
6+
token_endpoint = "https://login.microsoftonline.com/${var.tenant_id}/oauth2/v2.0/token"
7+
jwks_url = "https://login.microsoftonline.com/${var.tenant_id}/discovery/v2.0/keys"
8+
discovery_url = "${local.base_url}/.well-known/openid-configuration"
9+
}
10+
11+
# ── TODO: Automated app registration ─────────────────────────────────────────
12+
# The resources below are not yet implemented. The module currently operates
13+
# in "bring your own app" mode: create the app registration in the Azure portal
14+
# (or via az CLI) and pass client_id / client_secret as variables.
15+
#
16+
# When implementing, add:
17+
#
18+
# resource "azuread_application" "this" {
19+
# display_name = var.app_name
20+
# web {
21+
# redirect_uris = var.callback_urls
22+
# implicit_grant { access_token_issuance_enabled = false }
23+
# }
24+
# required_resource_access { ... }
25+
# }
26+
#
27+
# resource "azuread_service_principal" "this" {
28+
# client_id = azuread_application.this.client_id
29+
# }
30+
#
31+
# resource "azuread_application_password" "this" {
32+
# application_id = azuread_application.this.id
33+
# }
34+
#
35+
# Then remove var.client_id / var.client_secret and source them from the
36+
# resources instead.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# ── Standardized OIDC interface (shared by all provider modules) ──────────────
2+
3+
output "client_id" {
4+
value = var.client_id
5+
description = "OAuth2 client ID."
6+
}
7+
8+
output "client_secret" {
9+
value = var.client_secret
10+
description = "OAuth2 client secret."
11+
sensitive = true
12+
}
13+
14+
output "issuer_url" {
15+
value = local.issuer_url
16+
description = "OIDC issuer URL (https://login.microsoftonline.com/{tenant}/v2.0)."
17+
}
18+
19+
output "auth_endpoint" {
20+
value = local.auth_endpoint
21+
description = "OAuth2 authorization endpoint."
22+
}
23+
24+
output "token_endpoint" {
25+
value = local.token_endpoint
26+
description = "OAuth2 token endpoint."
27+
}
28+
29+
output "jwks_url" {
30+
value = local.jwks_url
31+
description = "JSON Web Key Set URL."
32+
}
33+
34+
# ── Azure AD-specific outputs ─────────────────────────────────────────────────
35+
36+
output "discovery_url" {
37+
value = local.discovery_url
38+
description = "OIDC well-known discovery URL."
39+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
variable "tenant_id" {
2+
type = string
3+
description = "Azure AD tenant ID (Directory ID). Used to construct OIDC endpoints."
4+
}
5+
6+
# ── Manual credentials (until azuread_application is implemented) ─────────────
7+
8+
variable "client_id" {
9+
type = string
10+
description = "Client ID of the Azure AD app registration. Create manually in the Azure portal until automated app registration is implemented."
11+
}
12+
13+
variable "client_secret" {
14+
type = string
15+
description = "Client secret of the Azure AD app registration."
16+
sensitive = true
17+
}
18+
19+
# ── Future: passed to azuread_application once implemented ───────────────────
20+
21+
variable "app_name" {
22+
type = string
23+
description = "Display name for the Azure AD application (used when automated registration is implemented)."
24+
default = ""
25+
}
26+
27+
variable "callback_urls" {
28+
type = list(string)
29+
description = "OAuth2 redirect URIs (used when automated registration is implemented)."
30+
default = []
31+
}
32+
33+
variable "allowed_origins" {
34+
type = list(string)
35+
description = "CORS allowed origins (used when automated registration is implemented)."
36+
default = []
37+
}
38+
39+
variable "logout_redirect_urls" {
40+
type = list(string)
41+
description = "Post-logout redirect URIs (used when automated registration is implemented)."
42+
default = []
43+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_providers {
3+
# hashicorp/azuread ~> 2.0 will be required once app registration
4+
# resources are implemented. No provider needed for the current
5+
# "bring your own app" mode.
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "rancher2_auth_config_generic_oidc" "this" {
2+
client_id = var.client_id
3+
client_secret = var.client_secret
4+
issuer = var.issuer_url
5+
rancher_url = var.rancher_callback_url
6+
auth_endpoint = var.auth_endpoint
7+
token_endpoint = var.token_endpoint
8+
jwks_url = var.jwks_url
9+
scopes = var.scopes
10+
group_search_enabled = var.group_search_enabled
11+
access_mode = var.access_mode
12+
enabled = var.enabled
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "auth_config_id" {
2+
value = rancher2_auth_config_generic_oidc.this.id
3+
description = "Rancher auth config resource ID."
4+
}

0 commit comments

Comments
 (0)