cloudflare / cloudflare/cloudflared

🐛Ingress rules ignored when using systemd

Open
#1,031 1 comment 1 reaction 0 assignees View on GitHub
Priority: Normal Type: Bug
Dominant language
Go
Stars
15.6k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
I have followed the official docs on setting up a tunnel from linux (ubuntu 22.04) and it works when I run the tunnel manually using `cloudflared tunnel run mytunnel`. However, when setting it up as service with systemd using `cloudflared service install` the tunnel doesnt work.

**To Reproduce**
Steps to reproduce the behavior:
```bash
# Add cloudflare gpg key
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

# Add this repo to your apt repositories
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared jammy main' | sudo tee /etc/apt/sources.list.d/cloudflared.list

# install cloudflared
sudo apt-get update && sudo apt-get install cloudflared

# Create user to run cloudflared
sudo useradd -r -m cloudflared
sudo usermod -a -G cloudflared myuser

sudo -H -u cloudflared bash -c 'cloudflared tunnel login'
sudo -H -u cloudflared bash -c 'cloudflared tunnel create mytunnel'
tunnel_id=$(sudo -u cloudflared cloudflared tunnel list | tail -n 1 | cut -c1-36)

echo "tunnel: ${tunnel_id}
credentials-file: /home/cloudflared/.cloudflared/${tunnel_id}.json
ingress:
- hostname: mytunnel.mydomain.com
service: http://localhost:8000
- service: http_status:404
" > /home/cloudflared/.cloudflared/config.yml

sudo -H -u cloudflared bash -c 'cloudflared tunnel route dns mytunnel mytunnel.mydomain.com'

sudo -H -u cloudflared bash -c 'sudo cloudflared service install $(cloudflared tunnel token mytunnel)'
sudo systemctl start cloudflared
sudo systemctl enable cloudflared
```

**Expected behavior**
Able to access what I have exposed on port 8000 over the web

**Environment and versions**
- OS: Linux Ubuntu 22.04

**Logs and errors**
```
Jul 23 20:41:08 box cloudflared[34826]: 2023-07-23T18:41:08Z WRN No ingress rules were defined in provided config (if any) nor from the cli, cloudflared will return 503 for all incoming HTTP requests
```
**Additional context**
It seems that `cloudflared service install` doesnt define a user for the systemd service. Thus the service is run as root, and this might break the search path for the config file, which in my case is sitting with my service user in `/home/cloudflared/.cloudflared/config.yml`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.