Skip to content

fix: preserve Linux service credentials after partial installation failures - #1787

Open
OgShadoww wants to merge 1 commit into
cloudflare:masterfrom
OgShadoww:fix/linux-service-install-1774
Open

OgShadoww wants to merge 1 commit into
cloudflare:masterfrom
OgShadoww:fix/linux-service-install-1774

Conversation

@OgShadoww

Copy link
Copy Markdown

Summary

Related to #1774.

Fix credential cleanup during Linux service installation when the installation fails after creating a service definition.

Previously, cloudflared service install could fail during systemd startup and remove /etc/cloudflared/token, even though the service remained installed and enabled. Subsequent service restarts would then fail because the token file was missing.

Changes

  • Preserve newly created credentials when a service definition exists or its state cannot be determined.
  • Remove newly created credentials only when installation fails before the service definition is created.
  • Prevent overwriting existing token files, including symlinks, using exclusive file creation (O_CREATE | O_EXCL) with 0600 permissions.
  • Reject repeated installations before modifying existing service credentials.
  • Add testable installation helpers and regression coverage for partial failures across Linux service managers.

Testing

Validated on Linux ARM64 using Go 1.27.3:

  • go test -mod=readonly -count=1 -v ./cmd/cloudflared — passed
  • go test -mod=readonly -race -count=1 ./cmd/cloudflared — passed
  • make fmt-check lint — passed
  • go vet — passed
  • git diff --check — passed

Added six test functions covering 29 cases, including startup failures, partial service installations, existing credentials, symlinks, file permissions, and SysV/OpenRC service definitions.

The complete test suite is not fully green. An unrelated TLS curve test also fails on unchanged HEAD, and intermittent network test failures were observed. No actual systemd service startup was performed.

Scope

This fixes the credential-loss consequence of #1774, but does not address the original systemd startup timeout. The existing Type=notify and TimeoutStartSec=15 settings remain unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant