|
| 1 | +--- |
| 2 | +title: Automate DNSLink updates with GitHub Actions |
| 3 | +description: Guide on how to use the DNSLink Action to automatically update DNS records when deploying static sites to IPFS. |
| 4 | +--- |
| 5 | + |
| 6 | +# Automate DNSLink updates with GitHub Actions |
| 7 | + |
| 8 | +This guide explains how to automatically update [DNSLink](../../concepts/dnslink.md) records when you deploy your site to IPFS. By the end, your DNS will automatically point to the latest CID whenever you push to your repository. |
| 9 | + |
| 10 | +DNSLink lets users access your IPFS-hosted content through a human-readable domain name like `docs.ipfs.tech` instead of a CID like `bafybeic...`. When combined with [ipshipyard/ipfs-deploy-action](./deploy-github-action.md), you get a complete CI/CD pipeline for IPFS websites. |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +Before you begin, make sure you have: |
| 15 | + |
| 16 | +1. Your site deployed to IPFS with a CID (see [Deploy static apps to IPFS with GitHub Actions](./deploy-github-action.md)) |
| 17 | +2. A domain name with DNS managed by [Cloudflare](https://www.cloudflare.com/), [DNSimple](https://dnsimple.com/), or [Gandi](https://www.gandi.net/en/domain/dns) |
| 18 | +3. A GitHub repository with Actions enabled |
| 19 | + |
| 20 | +## Security Considerations |
| 21 | + |
| 22 | +::: warning API Token Security |
| 23 | +DNS API tokens are sensitive credentials. A compromised token could allow attackers to modify your DNS records, potentially redirecting your domain to malicious content. |
| 24 | + |
| 25 | +For open source projects that accept pull requests from forks, use the [two-workflow pattern](#two-workflow-pattern-for-open-source-projects) to ensure fork code never has access to your DNS credentials. |
| 26 | +::: |
| 27 | + |
| 28 | +## Step 1: Configure DNS Provider |
| 29 | + |
| 30 | +### Option A: Cloudflare (recommended) |
| 31 | + |
| 32 | +1. Log into the [Cloudflare dashboard](https://dash.cloudflare.com/) and select your domain |
| 33 | +2. Go to the **Overview** tab and scroll down to find your **Zone ID** ([detailed instructions](https://github.com/ipshipyard/dnslink-action#finding-your-zone-id)) |
| 34 | +3. Go to **My Profile** > **API Tokens** > **Create Token** ([detailed instructions](https://github.com/ipshipyard/dnslink-action#creating-an-api-token)) |
| 35 | +4. Create a custom token with these permissions: |
| 36 | + - Zone > DNS > Edit |
| 37 | + - Scope the token to your specific zone |
| 38 | +5. Add both values as [GitHub secrets](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions): |
| 39 | + - `CF_ZONE_ID`: Your Zone ID |
| 40 | + - `CF_AUTH_TOKEN`: Your API token |
| 41 | + |
| 42 | +For a visual walkthrough, see the [Cloudflare video tutorial](https://github.com/ipshipyard/dnslink-action#cloudflare-video-tutorial). |
| 43 | + |
| 44 | +### Option B: DNSimple |
| 45 | + |
| 46 | +1. Log into DNSimple and go to **Account** > **Access Tokens** |
| 47 | +2. Create a new API token |
| 48 | +3. Add it as a GitHub secret named `DNSIMPLE_TOKEN` |
| 49 | + |
| 50 | +### Option C: Gandi |
| 51 | + |
| 52 | +1. Log into [Gandi](https://www.gandi.net/) and go to **Account** > **Security** > **Personal Access Tokens** |
| 53 | +2. Create a new token with DNS management permissions |
| 54 | +3. Add it as a GitHub secret named `GANDI_TOKEN` |
| 55 | + |
| 56 | +## Step 2: Add DNSLink Action to Your Workflow |
| 57 | + |
| 58 | +Add [ipshipyard/dnslink-action](https://github.com/ipshipyard/dnslink-action) to your workflow after deploying to IPFS. The action takes the CID from [ipshipyard/ipfs-deploy-action](https://github.com/ipshipyard/ipfs-deploy-action) and updates your DNS record. |
| 59 | + |
| 60 | +For complete workflow examples, see: |
| 61 | + |
| 62 | +- [Simple workflow (no fork PRs)](https://github.com/ipshipyard/ipfs-deploy-action#simple-workflow-no-fork-prs) - single workflow for repositories that don't accept external contributions |
| 63 | +- [Dual workflows (with fork PRs)](https://github.com/ipshipyard/ipfs-deploy-action#dual-workflows-with-fork-prs) - secure pattern for open source projects |
| 64 | + |
| 65 | +For DNS provider-specific configuration, see the [ipshipyard/dnslink-action README](https://github.com/ipshipyard/dnslink-action#usage). |
| 66 | + |
| 67 | +## Step 3: Verify the DNSLink Record |
| 68 | + |
| 69 | +After the workflow runs, verify the DNSLink record: |
| 70 | + |
| 71 | +```bash |
| 72 | +dig +short TXT _dnslink.yourdomain.com |
| 73 | +``` |
| 74 | + |
| 75 | +You should see output like: |
| 76 | + |
| 77 | +``` |
| 78 | +"dnslink=/ipfs/bafybeic..." |
| 79 | +``` |
| 80 | + |
| 81 | +## Two-Workflow Pattern for Open Source Projects |
| 82 | + |
| 83 | +For repositories that accept pull requests from forks, use a two-workflow pattern to keep secrets secure. This is critical because **pull requests from forks can contain malicious code that could exfiltrate your secrets**. |
| 84 | + |
| 85 | +The solution is to separate building (which runs untrusted code) from deploying (which uses secrets): |
| 86 | + |
| 87 | +1. **Build workflow**: Runs on PR events, builds the site, uploads artifact. No secrets. |
| 88 | +2. **Deploy workflow**: Triggered by `workflow_run` event after build succeeds. Has access to secrets but only runs trusted action code, not fork code. |
| 89 | + |
| 90 | +For complete workflow examples, see: |
| 91 | + |
| 92 | +- [ipshipyard/ipfs-deploy-action: Dual workflows with fork PRs](https://github.com/ipshipyard/ipfs-deploy-action#dual-workflows-with-fork-prs) |
| 93 | +- [ipshipyard/dnslink-action: Dual workflows for secure fork PRs](https://github.com/ipshipyard/dnslink-action#dual-workflows-for-secure-fork-prs) |
| 94 | + |
| 95 | +## Security: Sandboxed DNS Zone |
| 96 | + |
| 97 | +For additional security, use a sandboxed DNS zone to limit what the CI API token can modify. This way, if the token is compromised, attackers can only modify TXT records on a dedicated zone, not your main domain's DNS records (like A, MX, or NS records). |
| 98 | + |
| 99 | +### How it works |
| 100 | + |
| 101 | +Instead of giving CI direct access to your domain's DNS: |
| 102 | + |
| 103 | +1. Create a dedicated zone for DNSLink records (e.g., `dnslinks.example.com`) |
| 104 | +2. Create an API token scoped only to that zone |
| 105 | +3. On your main domain, add a CNAME record pointing `_dnslink.yourdomain.com` to `_dnslink.yourdomain.dnslinks.example.com` |
| 106 | +4. The action updates the TXT record on the sandboxed zone |
| 107 | + |
| 108 | +For detailed setup instructions, see the [ipshipyard/dnslink-action security documentation](https://github.com/ipshipyard/dnslink-action#security-sandboxed-dnslink-domain). |
| 109 | + |
| 110 | +## HTTP Hosting |
| 111 | + |
| 112 | +DNSLink maps a domain name to a CID, so IPFS gateways can serve your content. You also need HTTP hosting for users who access your site directly via `https://yourdomain.com`. |
| 113 | + |
| 114 | +You have two options: |
| 115 | + |
| 116 | +1. **Self-hosted**: Run your own Kubo + Caddy setup that resolves DNSLink and serves content over HTTPS. See [Setup a DNSLink Gateway](./dnslink-gateway.md). |
| 117 | + |
| 118 | +2. **Third-party hosting**: Deploy to [GitHub Pages](https://pages.github.com/), [Cloudflare Pages](https://pages.cloudflare.com/), or [Netlify](https://www.netlify.com/). These handle HTTP hosting independently, while DNSLink provides IPFS access for users with local nodes or gateways. |
| 119 | + |
| 120 | +## Troubleshooting |
| 121 | + |
| 122 | +1. **DNSLink not updating** |
| 123 | + - Verify your API token has DNS edit permissions |
| 124 | + - Check that `dnslink_domain` matches your DNS setup |
| 125 | + - Review the GitHub Actions logs for error messages |
| 126 | + |
| 127 | +2. **DNS propagation delays** |
| 128 | + - DNS changes can take time to propagate |
| 129 | + - Use `dig` to check the authoritative nameserver directly |
| 130 | + |
| 131 | +3. **CNAME not resolving** |
| 132 | + - Ensure the CNAME target includes the full domain name |
| 133 | + - Verify both zones are properly configured |
| 134 | + |
| 135 | +## Getting Help |
| 136 | + |
| 137 | +If you encounter issues: |
| 138 | + |
| 139 | +1. Check the GitHub Actions run logs for detailed error messages |
| 140 | +2. Review the [ipshipyard/dnslink-action README](https://github.com/ipshipyard/dnslink-action) for updates |
| 141 | +3. Open an issue in the [action's repository](https://github.com/ipshipyard/dnslink-action/issues/new) |
0 commit comments