Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
chore(readme): update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
macadock committed Oct 4, 2024
1 parent 34385e4 commit 4bbd676
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
INFRA_DIR: 'infra'
TF_VAR_USERNAME: ${{ secrets.USERNAME }}
TF_VAR_PASSWORD: ${{ secrets.PASSWORD }}
TF_VAR_HOSTNAME: ${{ secrets.HOSTNAME }}
TF_VAR_CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
TF_VAR_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
TF_VAR_CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }}
Expand Down
61 changes: 53 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
```
npm install
npm run dev
```

```
npm run deploy
```
# DDNS Update

This worker is responsible for updating the IP address of a Cloudflare domain.

## Requirements

- Cloudflare account
- Existing custom domain on Cloudflare with A record

## Setup

1. Create a Cloudflare account.
2. Add a custom domain to Cloudflare.
3. Create a Cloudflare API token with the following permissions:
- Zone - Read
- DNS - Edit
- Workers - Edit
4. Create a Terraform state bucket called ```terraform-ddns-update``` using Cloudflare R2.
5. Create a Cloudflare API token with the following permissions:
- Read/Write objects
- Only applied for ```terraform-ddns-update``` bucket
6. Define username and password for basic authentication.
- You can use the website https://generate-secret.vercel.app/32 to generate random strings.
7. Deploy the worker
8. Make requests to the worker

## How to use

Make a GET request to the worker on ```/update-domain``` with the following headers and query parameters:

- Header:
- ```Authorization: Basic base64(username:password)```
- Be sure to encode the username and password using base64.
- You can use the native node function ```btoa(`${username}:${password}`)``` to encode the username and password.

- Query parameters:
- ```domain```: The domain to update
- ```ip```: The IP address to update

## Terraform

Worker environment variables:
- `HOSTNAME`: The hostname where the worker is deployed.
- `CLOUDFLARE_ACCOUNT_ID`: The Cloudflare account ID.
- `CLOUDFLARE_API_TOKEN`: The Cloudflare API token.
- `CLOUDFLARE_ZONE_ID`: The Cloudflare zone ID.
- `USERNAME`: The username for basic authentication.
- `PASSWORD`: The password for basic authentication.

Terraform state bucket:
- `AWS_ACCESS_KEY_ID`: The AWS access key ID.
- `AWS_SECRET_ACCESS_KEY`: The AWS secret access key.
- `AWS_ENDPOINT_URL_S3`: The AWS endpoint URL.
2 changes: 1 addition & 1 deletion infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "cloudflare_workers_script" "ddns-update-worker" {

resource "cloudflare_workers_domain" "sonaura-worker-domain" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
hostname = "domain.barriere.me"
hostname = var.HOSTNAME
service = cloudflare_workers_script.ddns-update-worker.name
zone_id = var.CLOUDFLARE_ZONE_ID
}
4 changes: 4 additions & 0 deletions infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ variable "USERNAME" {

variable "PASSWORD" {
type = string
}

variable "HOSTNAME" {
type = string
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const app = new Hono<{ Bindings: CloudflareBindings }>();

app.get("/update-domain", async (c) => {
try {
const token = c.req.header("authorization");
const token = c.req.header("Authorization");

if (!token) {
return c.json({ error: "Missing token" }, { status: 401 });
Expand Down

0 comments on commit 4bbd676

Please sign in to comment.