Ownership & Conflicts
What Labelgate will and won't touch on Cloudflare, and how to fix a conflict.
Labelgate only changes or deletes Cloudflare resources it created itself. Anything you made by hand stays untouched.
What Labelgate touches
| Labelgate will | Labelgate won't |
|---|---|
| Create DNS records, tunnel rules and Access applications and policies for your labels | Take over a record, rule or application you created by hand |
| Update and delete the resources it created | Edit or delete anything it did not create |
| Add its own rules to a tunnel | Change your own tunnel rules, the catch-all rule or the tunnel's global settings |
| Add its tag to an Access application it created | Change an Access policy it did not create, even one with the same name |
Labelgate recognises its own resources like this:
- DNS records: the comment starts with
labelgate:<instance ID>. Text from acommentlabel is added after it. - Access applications: they carry the tag
labelgate-<instance ID>. - Tunnel rules and Access policies: Labelgate remembers them in its database.
Do not remove the marker or the tag by hand. If you do, Labelgate stops managing that resource and leaves it where it is.
Instance ID
Each Labelgate installation has a short random instance ID, for example a1b2c3d4. It is created on first start, saved in the database and printed in the startup log. Two installations can share one Cloudflare account because each one only touches resources with its own ID.
You never need to set it, unless you lose the database.
Existing records are never taken over
If a hostname in your labels already exists on Cloudflare, and Labelgate did not create it, Labelgate leaves it alone. The service shows this error in the dashboard and the logs:
conflict: existing record not owned by labelgateLabelgate checks again on every sync, so the error goes away once you fix it.
How to fix it
Pick one:
- Let Labelgate manage it. Delete the existing record, Access application or tunnel rule in the Cloudflare dashboard. Labelgate creates its own on the next sync.
- Keep yours. Remove the label, or change it to a hostname that is free.
- Hand a DNS record over without deleting it. Set the record's comment to
labelgate:<instance ID>in the Cloudflare dashboard. On the next sync Labelgate takes the record over and updates it to match your labels. ForMX,SRV,TXTandCAArecords the content must also match.
When two services want the same hostname
The service that had the hostname first keeps it. The newcomer gets an error and changes nothing on Cloudflare:
conflict: the A record app.example.com is already managed by container webapp service web on the main instance; remove the duplicate label from one of the containersA few more rules:
- One hostname belongs to one host: the main host or one agent. Other hosts get
conflict: hostname app.example.com is already managed by agent edge1. - One hostname is either DNS or tunnel, not both. A DNS service and a tunnel service on the same hostname are a conflict.
- Containers on the same host may share a hostname if they use different record types or paths.
To move a hostname to another host, remove it from the old host first. With the default cleanup, the old host gives it up once its records are deleted, about 30 minutes later (sync.remove_delay).
Your own tunnel rules
You can keep managing some tunnel rules by hand. Labelgate only adds and removes its own rules. It keeps:
- your manual rules;
- the catch-all rule (if there is none, Labelgate adds
http_status:404); - the tunnel's global settings.
If one of your manual rules uses the same hostname as a label, that label gets a conflict error and your rule stays as it is.
Access applications and policies
- Labelgate creates one Access policy per hostname and keeps it in sync with your labels. Remove an e-mail from the label, and that person loses access on the next sync.
- It adds its tag next to any tags already on the application.
- It never reads, changes or deletes policies it did not create.
Cleanup
-
When a container stops or its labels go away, Labelgate deletes the container's resources 30 minutes later (
sync.remove_delay,LABELGATE_SYNC_REMOVE_DELAY). If the container comes back sooner, nothing is deleted. -
To keep a service's resources on Cloudflare, set
cleanup: "false"on it:labelgate.dns.web.cleanup: "false" -
Resources of an offline agent are kept for 24 hours first (
sync.agent_grace,LABELGATE_SYNC_AGENT_GRACE). -
Cleanup only ever deletes resources Labelgate created.
If you lose the database
Without its database, Labelgate starts with a new instance ID. Its old DNS records then look like someone else's, and you get conflicts.
To fix it, find the old ID in the comment of one of your records (labelgate:a1b2c3d4 ...). Set it before starting Labelgate:
LABELGATE_INSTANCE_ID=a1b2c3d4Labelgate then takes its DNS records and Access applications back. Tunnel rules and Access policies cannot be recovered this way. Delete the old ones in the Cloudflare dashboard.
To avoid this, back up the data folder (/app/config in the container).