Home Backup Pulls Failed for 37 Days After an ISP Move to CGNAT
A third backup copy is there for the day the first two disappear together, but it only has value if new files actually reach it, not when a job reports that it ran. And "the source is empty" and "cannot access the source" must not be written out as the same message.
1-minute summary
- Symptom / problem
- The home backup job reports the source as empty, although the source has files every night
- Who should read
- People pulling backups home over SSH with a key restricted by from=
- Fix in short
- The from= in authorized_keys pins the old IP range, but the ISP moved the line behind CGNAT. Find the real range with RDAP, then check the ACL mask that removes list permission on the folder
The system owner happened to ask me whether the backups pulled by the computer at home were still working. I opened the home daemon's logs. It ran every day, never crashed, and raised no alerts. At a glance, everything looked normal. But when I checked the date of the last file it had successfully pulled, it was from 37 days earlier. Throughout that month and more, the source produced backups every night, the home machine connected out every night, and every night it came back empty-handed without telling anyone.
The IP addresses, IP ranges, usernames, hostnames, and paths in this article are all examples (I use reserved testing ranges in place of the real IP ranges). The log messages, diagnostic sequence, and figures are real.
A three-part system, and the question of whether it still works
This backup system has three parts. First, the web host writes daily backups to an NFS share on the backup host. Second, the backup host runs vzdump on the entire VM every Sunday. Third, a Windows machine at home runs a daemon that uses rclone and rsync over SSH to pull files from the backup host on a schedule: daily at 03:00 and weekly on Sundays at 04:00, using a read-only user I call backupreader in this article. I covered the background of the first two parts in Rebuilding DirectAdmin Backups with NFS and POSIX ACL.
The third part uses pull, not push. The home machine initiates the connection to the backup host, and the server restricts this key to connections from the home connection's IP range. That restriction was the first layer of the problem.
The home logs said the source was empty
The daemon recorded the same two lines every day.
Source /mnt/backup/daily/Monday/ is empty - skipping
No vzdump file found in /mnt/backup/dump/
My first conclusion on reading them was that the source was not producing backups, because the log explicitly said the source was empty. So I checked the backup host first, which was the wrong guess. Everything at the source was normal.
# บนโฮสต์สำรอง: ของรายวันล่าสุด และ vzdump ล่าสุด
for d in /mnt/backup/daily/*/; do
printf '%-10s %3s ไฟล์ %s\n' "$(basename "$d")" "$(ls -1 "$d" | wc -l)" "$(du -sh "$d" | cut -f1)"
done
ls -lh --time-style=long-iso /mnt/backup/dump/ | tail -3
All the daily files were there, 22 to 42 files a day, totaling 49 to 119 GB per day. The latest vzdump was 174 GB and had run on schedule. The source was not empty. What was empty was what the home machine could see. So the problem had to be in the pull, not at the source or the destination.
This daemon lists the source folder over SSH. When it could not connect, the list command returned an empty result, and the code interpreted that as no files to pull. It politely skipped the job, treating it as no error and sending no alert. This was the gap that kept it silent for 37 days. An authentication failure was converted into a normal status from the very first line.
Layer one: the key was valid, but not from a permitted host
The answer was in the backup host's sshd logs, and it was clear enough to need no interpretation.
grep 'backupreader' /var/log/auth.log | tail -2
# Authentication tried for backupreader with correct key but not from a permitted host
# (host=198.19.77.236, ip=198.19.77.236, required=198.18.0.0/16)
The key was valid, but it was rejected because of where it came from. The line for this key in backupreader's authorized_keys read from="198.18.0.0/16" ssh-ed25519 ..., the old /16 range within which the home's outbound IP had always rotated. Then the ISP moved the home connection behind CGNAT, and the outbound IP jumped to another block it had never used before. Nothing on the home machine had changed. The key had not changed. The server had not changed. What changed was the route in between, without anyone being notified.
The client only saw that the connection failed. The message giving the actual reason was only on the server, which is consistent with sshd's security principle of not telling outsiders why they were rejected. But it also means that if I only check the machine doing the pulling, I will never see the words not from a permitted host.
Do not guess a new /16: find the actual IP ranges with RDAP
I nearly made another mistake here. My first suggestion was to add the entire /16 containing the new IP. It was the same kind of guess that had led to this failure. The owner told me to first look up which ranges the ISP actually used when rotating IPs for this connection.
The method was to collect every outbound IP this connection had used that I could find. I also pulled historical login logs from the web host, then queried RDAP for each IP to find its allocation.
# IP ที่เคยเห็นจากสายที่บ้าน (ตัวอย่าง) -> ช่วงที่ registry จัดสรรไว้จริง
for ip in 198.19.77.236 198.19.140.12 198.18.70.5 198.18.210.9; do
curl -s "https://rdap.apnic.net/ip/$ip" \
| jq -r '"\(.startAddress) - \(.endAddress) \(.name)"'
done
The results give a start and end address, which Python's standard library can convert directly to CIDR. There is no need to count the bits by hand.
import ipaddress
ranges = [('198.19.0.0', '198.19.127.255'),
('198.19.128.0', '198.19.191.255'),
('198.18.64.0', '198.18.127.255'),
('198.18.208.0', '198.18.223.255')]
for a, b in ranges:
for net in ipaddress.summarize_address_range(ipaddress.ip_address(a), ipaddress.ip_address(b)):
print(f'{str(net):<18} {net.num_addresses:>6} IP')
# 198.19.0.0/17 32768 IP <- ช่วง CGNAT ปัจจุบัน
# 198.19.128.0/18 16384 IP
# 198.18.64.0/18 16384 IP
# 198.18.208.0/20 4096 IP
I found 4 ranges: one /17, the CGNAT range the connection currently used, two /18 ranges, and one /20 range. All belonged to the same ISP's fibre service, and all were narrower than the /16 I had been about to guess and add.
Add the /16 containing the new IP
Quick, and it fixes today's symptom, but it also allows addresses unrelated to this connection, with no way to know whether it covers the range the ISP will rotate to next. When the IP jumps again, the same silent failure returns.
Use the actual allocations from RDAP
This gives the boundaries the registry actually allocated to the ISP for that service, covering every range the connection has used. Each range is narrower than /16 and comes with an allocation name, so I can trace why it was added.
Add them in two places: from= and the CrowdSec whitelist
These IP ranges need to go in two places. The first is what actually blocked access this time. from= accepts multiple comma-separated ranges on one line.
# ~backupreader/.ssh/authorized_keys (บรรทัดเดียว)
from="198.19.0.0/17,198.19.128.0/18,198.18.64.0/18,198.18.208.0/20" ssh-ed25519 AAAA...<PUBLIC_KEY> backup-pull
The second is CrowdSec on the backup host, because connecting and being rejected repeatedly every night is behavior an intrusion prevention system could see as password guessing. I put the whitelist in its own separate file under /etc/crowdsec/parsers/s02-enrich/ instead of editing an existing file, because this machine has a service that periodically writes a whitelist from DDNS to its own file. If I added the ranges to that file, they would be overwritten on the next run.
# /etc/crowdsec/parsers/s02-enrich/home-isp-ranges.yaml
name: local/home-isp-ranges
description: "ช่วง IP ขาออกของสายที่บ้าน ตาม allocation จาก RDAP"
whitelist:
reason: "home backup puller"
cidr:
- "198.19.0.0/17"
- "198.19.128.0/18"
- "198.18.64.0/18"
- "198.18.208.0/20"
systemctl reload crowdsec
cscli parsers list | grep home-isp-ranges
There is a question to answer here: if a DDNS-based whitelist already existed, why did it not help? The answer is that behind CGNAT, the DDNS name and the actual outbound IP no longer refer to the same address. The DDNS name points to the address reported by the home router, while the server sees the address of the ISP's NAT device that the connection is assigned to use at that moment. So the mechanism tracking the home's IP by name had been tracking the wrong address since the connection was moved.
Restricting a key by IP range can greatly limit the damage if the key leaks. I still use it. But the home connection's IP range is the ISP's decision, and it can change without notice. A check like this needs an alert that measures the result at the destination. Otherwise, when the ISP changes something, the system will be just as secure but have no backups.
Layer two: an ACL mask removed list permission from one folder
Once I fixed from=, SSH worked. I still did not trust it until I could actually pull files, so I tested from the home machine with the actual user, going through all 6 daily folders one by one.
# รันจากเครื่องที่บ้าน ด้วย key และ user ตัวเดียวกับที่ daemon ใช้
for d in Monday Tuesday Wednesday Thursday Friday Saturday; do
n=$(ssh -o BatchMode=yes [email protected] "ls -A /mnt/backup/daily/$d | wc -l" 2>&1)
echo "$d: $n"
done
# Monday ถึง Friday: ได้จำนวนไฟล์กลับมาครบทั้ง 5 โฟลเดอร์
# Saturday: ls: cannot open directory '/mnt/backup/daily/Saturday': Permission denied
5 folders passed. Saturday could not be listed. If I had stopped once SSH connected, this layer would have become the next silent gap. getfacl showed the cause.
getfacl /mnt/backup/daily/Saturday
# user::rwx
# user:backupreader:r-x #effective:--x
# group::rwx #effective:--x
# mask::--x
# other::--x
stat -c '%a %U %n' /mnt/backup/daily/*/
# 771 ... Monday (และวันอื่นอีก 4 โฟลเดอร์)
# 711 ... Saturday (owner คนละตัวกับวันอื่น)
The entry for backupreader still had the full r-x, but the mask was only --x. The effective permissions for every entry other than the owner are the entry AND the mask, leaving --x: permission to enter the folder, but not to list it. The cause was that the Saturday folder had been recreated with mode 0711 and a different owner from the other days, which used 0771. On a file with an ACL, the group bits in the mode are the mask itself. So mode 0711 also sets the mask to --x.
| Folder | mode | Reader's ACL entry | mask | Effective permissions |
|---|---|---|---|---|
| Other 5 daily folders | 0771 | r-x | rwx | r-x can enter and list |
| Saturday | 0711 | r-x | --x | --x can enter, cannot list |
setfacl -m m::r-x /mnt/backup/daily/Saturday # หรือ chmod g+rx ซึ่งให้ผลเดียวกันกับ mask
getfacl /mnt/backup/daily/Saturday | grep -E 'backupreader|mask'
# user:backupreader:r-x
# mask::r-x
After the fix, I tested all 6 days again, and they all passed. What gives me pause is that the existing cron health check did not catch this, because it only checked the ACL on the top-level folder, and only for the user that writes the backups. It did not look inside the daily folders or check the reader's permissions at all.
Gaps to close
These are recommendations; I have not implemented all of them yet. But all three come from gaps I actually found during this work. First, the pulling side must distinguish "authentication failed" from "source is empty" and treat both as errors.
out=$(ssh -o BatchMode=yes -o ConnectTimeout=20 [email protected] \
"ls -A /mnt/backup/daily/$DAY" 2>&1); rc=$?
if [ $rc -ne 0 ]; then
echo "[ERR] เข้าต้นทางไม่ได้ rc=$rc: $out"; exit 2 # auth ล้ม / สิทธิ์ไม่พอ / ต่อไม่ติด
fi
if [ -z "$out" ]; then
echo "[ERR] ต้นทางว่างจริง: $DAY"; exit 3 # ก็ยังเป็น error ไม่ใช่ skip
fi
Second, measure the destination, not whether the job ran. Alert when the age of the latest file at home exceeds the acceptable number of days.
# รันบนเครื่องที่บ้านหลังรอบดึงรายวัน
$limitDays = 2
$newest = Get-ChildItem 'E:\backup\daily' -Recurse -File |
Sort-Object LastWriteTime -Descending | Select-Object -First 1
$age = if ($newest) { ((Get-Date) - $newest.LastWriteTime).TotalDays } else { 9999 }
if ($age -gt $limitDays) {
Write-Output ("[ERR] ไฟล์ล่าสุดอายุ {0:N1} วัน เกิน {1} วัน" -f $age, $limitDays)
exit 1
}
Write-Output ("[OK] ไฟล์ล่าสุดอายุ {0:N1} วัน" -f $age)
Third, test permissions as the actual reader user, from the actual destination machine, not as root on the source machine. root can always read every folder, so checking as root will never reveal a mask that removes someone else's permissions.
- When backup pulls go silent, read the server's sshd logs first. Look for
not from a permitted host. The client will never report this reason. - Collect the outbound IPs the connection has used from historical logs, then query RDAP for the actual allocations. Do not guess a /16.
- Add the resulting ranges to
from=and to the intrusion prevention system's whitelist in a separate file. Do not overwrite a file maintained by another service. - Test actual pulls as the reader user, from the destination machine, for every folder. Do more than just establish an SSH connection.
- For any folder that cannot be listed, check the
maskingetfaclbefore the user's entry. - Set an alert based on the age of the latest file at the destination, and make the pulling side treat both inaccessible and empty sources as errors.
For all 37 days, every number the system monitored was normal. The jobs ran, the source had files, and the top-level ACL was correct. The only wrong number was the age of the latest file on the home machine, which nobody was measuring. If there had been an alert for an age exceeding 2 days, this would have been resolved on the third day.
To sum up, this system had all its protective checks in place, and every one worked correctly. from= correctly rejected an unknown source. The ACL mask correctly followed the configured mode. What was missing was the other side of those checks: something to report whether the things that should get through were still getting through. I described a similar case on the upload path to object storage in Backups Ran Successfully Every Night, but There Were No Offsite Copies for 3 Weeks. That time it was a token and swallowed errors; this time it was IP ranges and a mask. But the lesson is the same: let the destination be the judge. If you use from= with a home connection, feel free to open your sshd logs today. If I have left anything out or made any typos, I will come back and fix them later.
Want us to set this up?
Get help with server setup, configuration, migration, or troubleshooting. Save time for the work that matters.
Hit something like this? Stuck somewhere?
Come trade notes on the LinuxThai board



Comments 0
No comments yet — be the first