🔐 Contributor Guide: Adding Entra ID OAuth2 Support for a Web Service

This guide explains how a contributor can add Entra ID OAuth2 authentication to an existing web service that sits behind the repository’s reverse‑proxy setup.


🧩 Background

The roles/global/defaults/main/vault.yml vault file defines the service‑principal credentials used to configure Microsoft Entra ID. This service principal has permissions to create and manage Azure AD applications and generate client secrets:

The target web service must already have an entry under rproxy_setup_sites in inventory/ansible/group_vars/all/main.yml for the inventory where the host is defined.


🛠️ Ansible Requirements


🔄 High‑Level Flow


🧭 Step‑by‑Step Instructions

1. Update the Web Service Host Inventory File

① Add the [oauth2_rproxy] group

Define the reverse‑proxy host (e.g., rproxy-0).
The deploy_oauth2_proxy.yml playbook runs on this host.

[oauth2_rproxy]
rproxy-0

② Add the [python] group

This group ensures Python is installed on the reverse‑proxy host.

[python]
rproxy-0

③ Update the rproxy_setup_sites entry

Locate the service’s entry in group_vars/all/main.yml and ensure it includes the required OAuth2 keys:

rproxy_setup_sites:
  - server_name: code.refol.us

    # OAuth2 integration variables
    use_oauth2: true
    oauth2_provider: "entra-id"
    oauth2_scope: "openid profile email"
    oauth2_cookie_secret: "base64-random-32-bytes"
    oauth2_client_id: ""
    oauth2_callback_url: "https://code.refol.us/oauth2/callback"
    oauth2_client_secret: ""
    oauth2_email_domains: "*"

Notes


▶️ Running the OAuth2 Deployment Playbook

Execute the playbook:

ansible-playbook -k -i inventory/ansible/inventory.ini playbooks/oauth2_proxy/deploy_oauth2_proxy.yml

This playbook:


🔑 Notes on Secret Creation and Azure Modules

az login --service-principal \
  --username <client_id> \
  --password <client_secret> \
  --tenant <tenant_id>

📝 Processing Notes