Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare API Client

#authored-by-ai #claude-3-7-sonnet

#autonomous-ai #cursor

SPDX-License-Identifier: MIT

This account was created and is owned by a real human, however, be advised that THIS REPO WAS AUTONOMOUSLY PUBLISHED BY AN AI via execution of ./01_create_github_repo.sh --personal --public

Overview

This repository contains a collection of Python scripts for interacting with the Cloudflare API to manage DNS records. It focuses particularly on automating the addition and verification of Microsoft 365 MX records, which are required for properly configuring email services with Microsoft 365.

Key Features

  • Add Microsoft 365 MX records to Cloudflare-managed domains
  • Verify successful MX record creation and propagation
  • Automatically extract the current Microsoft 365 MX record format from official documentation
  • Comprehensive verification against both Cloudflare API and Google DNS

Scripts

Setup and Requirements

  • 01_create_github_repo.sh - Creates and initializes the GitHub repository
  • 02_create_venv.sh - Sets up a Python virtual environment for the project
  • 03_requirements.txt - Lists Python package dependencies
  • 04_load_requirements.sh - Installs the required dependencies

DNS Management Scripts

  • 05_add_M365_mx_record.py - Adds a Microsoft 365 MX record to a specified domain using the Cloudflare API
  • 06_verify_M365_mx_record.py - Verifies that the MX record was successfully added and has propagated to public DNS
  • 07_add_M365_txt_verification_record.py - Adds the Microsoft 365 TXT domain verification record using the Cloudflare API. It reads the necessary record details from the output file (03.output.powershell.output.txt) generated by the ms_graph_ps repository.
  • 08_verify_M365_txt_verification_record.py - Verifies that the TXT verification record was successfully added and has propagated to public DNS, using the same input file as script 07 to determine the expected value.
  • 09_process_M365_dns_records.py - Processes Microsoft 365 DNS records from the PowerShell output and compares them to existing Cloudflare records, offering options to add/update each record interactively.
  • 10_add_dns_record.py - Adds a DNS record to Cloudflare with special handling for SRV records and other record types.
  • 11_verify_add_dns_record.py - Verifies that a DNS record was correctly added by checking both Cloudflare and public DNS.
  • 12_delete_dns_record.py - Deletes a DNS record from Cloudflare.
  • 13_verify_delete_dns_record.py - Verifies that a DNS record was successfully deleted from Cloudflare.
  • 14_review_dns_records.py - Interactive tool to review all DNS records in a Cloudflare zone, with options to verify or delete each record.

Vercel and General CNAME/A Record Scripts

  • 15_configure_vercel_web_deployment.py - Configures the necessary A record (pointing to 76.76.21.21) for a Vercel web deployment on the root domain.
    • Usage: ./15_configure_vercel_web_deployment.py yourdomain.com [--debug]
  • 16_verify_vercel_web_propagation.py - Verifies that the Vercel A record has propagated to public DNS (Google, Cloudflare, Quad9) and optionally checks against the Cloudflare API.
    • Reads record ID from 15.output.record_id.txt for API check.
    • Usage: ./16_verify_vercel_web_propagation.py <zone_domain>
  • 17_add_domain_cname.py - Adds a general CNAME record to the specified domain.
    • Usage: ./17_add_domain_cname.py <zone_domain> <cname_name> <cname_target> [--debug] (e.g., ./17_add_domain_cname.py example.com www target.example.com)
  • 18_verify_cname_propagation.py - Verifies that a CNAME record has propagated to public DNS (Google, Cloudflare, Quad9) and optionally checks against the Cloudflare API.
    • Reads record details from 17.output.record_details.json.
    • Usage: ./18_verify_cname_propagation.py <zone_domain>

Usage

Environment Setup

  1. Clone this repository
  2. Run ./02_create_venv.sh to create the Python virtual environment
  3. Run ./04_load_requirements.sh to install dependencies
  4. Create a .env file in your home directory with the following content:
    CLOUDFLARE_API_TOKEN=your_api_token_here
    CLOUDFLARE_ZONE_ID=your_zone_id_here
    

Workflow for Adding and Verifying a Domain with Microsoft 365

This repository works in conjunction with the ms_graph_ps repository. The recommended workflow involves steps from both repositories:

  1. Add M365 MX Record (using this cloudflare_api_client repo):

    • Activate the virtual environment: source ./cloudflare_api_client-venv/bin/activate
    • Run ./05_add_M365_mx_record.py yourdomain.com.
    • This adds the primary mail exchange record required by Microsoft 365 to your Cloudflare DNS.
  2. Verify MX Record Propagation:

    • Run ./06_verify_M365_mx_record.py yourdomain.com.
    • This checks Cloudflare and public DNS to ensure the MX record is correctly set up. Wait a few minutes if verification fails initially, as DNS propagation takes time.
  3. Add Domain & Get TXT Record (using ms_graph_ps):

    • Go to your local clone of the ms_graph_ps repository (cd ../ms_graph_ps).
    • Run ./03_powershell_add_domain.sh yourdomain.com.
    • This script interacts with Microsoft Graph to add the domain to your M365 tenant and generates the required TXT verification record details in ../ms_graph_ps/03.output.powershell.output.txt.
  4. Add TXT Record to Cloudflare (using this cloudflare_api_client repo):

    • Navigate back to this cloudflare_api_client directory (cd ../cloudflare_api_client).
    • Ensure the virtual environment is active: source ./cloudflare_api_client-venv/bin/activate
    • Run ./07_add_M365_txt_verification_record.py yourdomain.com.
    • This script reads the TXT record details from the output file created in step 3 and adds the record to your Cloudflare DNS zone.
  5. Verify TXT Record Propagation:

    • Run ./08_verify_M365_txt_verification_record.py yourdomain.com.
    • This script checks both Cloudflare and public DNS (Google) to confirm the TXT record is correctly set up and visible. Wait a few minutes if verification fails initially.
  6. Trigger M365 Verification (using ms_graph_ps):

    • Once script 08 shows success (especially via Google DNS), go back to your local clone of the ms_graph_ps repository (cd ../ms_graph_ps).
    • Run ./04_powershell_confirm_domain.sh yourdomain.com.
    • This script uses Confirm-MgDomain to tell Microsoft 365 to check for the TXT record and complete the domain verification.
  7. Get M365 Service Records (using ms_graph_ps):

    • After step 6 successfully confirms the domain, run ./05_powershell_show_domain_svc_recs.sh yourdomain.com.
    • This script retrieves the additional DNS records (CNAMEs for Autodiscover/Intune/etc., SRV records for Teams/Skype) needed for full M365 service functionality and saves them to ../ms_graph_ps/05.output.powershell.ouput.txt.
  8. Add Service Records to Cloudflare (using this cloudflare_api_client repo):

    • Navigate back to this cloudflare_api_client directory (cd ../cloudflare_api_client).
    • Ensure the virtual environment is active: source ./cloudflare_api_client-venv/bin/activate
    • Run ./09_process_M365_dns_records.py yourdomain.com.
    • This script automatically:
      • Cleans and processes the Microsoft 365 DNS records from ../ms_graph_ps/05.output.powershell.output.txt
      • Compares each record with existing records in your Cloudflare zone
      • Prompts you to add or update each record interactively
      • Uses scripts 10-13 to add, delete, and verify records as needed
    • Alternatively, you can use ./14_review_dns_records.py yourdomain.com to review existing records in your Cloudflare zone.

Adding an MX Record for Microsoft 365

./05_add_M365_mx_record.py yourdomain.com

This will:

  1. Fetch the current MX record format from Microsoft's documentation
  2. Create the correct MX record for your domain in Cloudflare
  3. Return a success message with the API response

Verifying MX Record Creation and Propagation

./06_verify_M365_mx_record.py yourdomain.com

This will:

  1. Check the Cloudflare API to verify the record was created correctly
  2. Check Google DNS (8.8.8.8) to verify the record has propagated to public DNS
  3. Provide a detailed verification summary

Features

  • Resilient to Format Changes: Automatically extracts the current Microsoft 365 MX record format from official documentation rather than hardcoding it
  • Dual Verification: Checks both Cloudflare configuration and public DNS propagation
  • Detailed Feedback: Provides comprehensive output on verification status
  • API Token Security: Uses environment variables for secure credential management

Requirements

  • Python 3.6+
  • Cloudflare API Token with DNS edit permissions
  • Cloudflare Zone ID for your domain

Support

Please note that this repository is maintained primarily by autonomous AI agents. There is no guarantee that the human developer that created and owns this account will review your issues or pull requests.

An AI agent may review submitted issues and pull requests. However, there is no guarantee that the AI will choose to address them, nor that any AI-driven changes will be satisfactory.

The AI first screens all submissions for malicious intent or content. Malicious issues or pull requests will be reported to the various warranted channels.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages