Files
terraform-cloudflare-tunnel…/Access_Controls-Service_Auth-Service_Tokens.tf
hcornet 04e0f318f4
Terraform Apply / Terraform Apply (push) Failing after 20s
Update 31-07-2026
2026-07-31 09:50:42 +02:00

49 lines
2.0 KiB
Terraform

# =============================================================================
# CLOUDFLARE : Access Controls : Service Auth : Service Tokens
# =============================================================================
# BRIQUE SERVICE TOKENS : accès machine-to-machine (sans utilisateur).
#
# Cas d'usage : une CI, une sonde de supervision ou un script doit appeler
# une application protégée par Access. Pas d'humain pour s'authentifier via
# l'IdP -> on émet un service token (paire Client ID / Client Secret) que la
# machine présente en en-têtes HTTP :
# CF-Access-Client-Id: <client_id>
# CF-Access-Client-Secret: <client_secret>
#
# La politique associée utilise decision = "non_identity" : c'est la décision
# dédiée aux authentifications par service token.
#
# ACTIONS EXTERNES (voir ACTIONS_EXTERNES.md) :
# - Récupérer les credentials : terraform output -raw service_token_gitea_ci_id
# et terraform output -raw service_token_gitea_ci_secret
# - Les stocker comme secrets dans Gitea (et idéalement dans Vault)
# - Le token expire (duration ci-dessous) : anticiper la rotation
# =============================================================================
#======================================================
# Service token pour la CI Gitea
#======================================================
resource "cloudflare_zero_trust_access_service_token" "gitea_ci" {
account_id = local.cloudflare_account_id
name = "Gitea CI"
duration = "8760h" # 1 an
}
#======================================================
# Politique réutilisable : accepter ce service token
#======================================================
resource "cloudflare_zero_trust_access_policy" "allow_service_token_gitea_ci" {
account_id = local.cloudflare_account_id
name = "Allow service token Gitea CI"
decision = "non_identity"
session_duration = "24h"
include = [{
service_token = {
token_id = cloudflare_zero_trust_access_service_token.gitea_ci.id
}
}]
}