Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## [0.3.2] - 2026-11-24

### Fixed

- **Package upgrades restart the services:** upgrading the `ziti-ssh-host` or `ziti-ssh-ca` package now restarts the
service if it is running (`systemctl try-restart`; fresh installs and stopped services are left alone). Before,
the old daemon kept running after an upgrade until it was restarted — Ubuntu's `needrestart` usually did that, but
RHEL-family systems and Debian without `needrestart` kept the previous version, including after upgrading to 0.3.0
for its security fixes. Upgrading to this release restarts the services; a host that was upgraded earlier and not
restarted since may still run its previous version — see `docs/provisioning.md` → Upgrading.

## [0.3.1] - 2026-11-24

Fixes from an end-to-end test of 0.3.0 on Ubuntu 24.04, Ubuntu 26.04 and RHEL 10.
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ ziti-ssh/
│ ├── mfa/ # MFA TOTP prompt (terminal, hidden, bounded attempts)
│ ├── oidc/ # OIDC authorization code flow (PKCE, loopback callback); flow_test.go: fake IdP
│ └── ratelimit/ # Per-identity token-bucket rate limiter
├── packaging/ # nfpm configs, postinstall/preremove/postremove scripts, systemd units
├── packaging/ # nfpm configs, postinstall/preremove/postremove scripts (try-restart on upgrade; scripts_test.go runs them against stubs), systemd units
├── scripts/
│ ├── build-packages.sh # Builds deb and/or rpm packages into dist/ (FORMAT=deb,rpm ARCHS=amd64,arm64)
│ ├── docker-build-packages.sh
Expand Down
2 changes: 1 addition & 1 deletion docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ curl -sSL https://get.netfoundry.io/linux-install.bash | sudo bash -s ziti-ssh
curl -sSL https://get.netfoundry.io/linux-install.bash | sudo bash -s ziti-scp
```

The install script configures the repository and installs the latest stable package. Subsequent upgrades are handled by the system package manager (`apt upgrade` / `yum update`).
The install script configures the repository and installs the latest stable package. Subsequent upgrades are handled by the system package manager (`apt upgrade` / `yum update`); see [Upgrading](provisioning.md#upgrading) for restarting the services.

### Verifying packages

Expand Down
14 changes: 14 additions & 0 deletions docs/provisioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,20 @@ go build -o /usr/local/bin/ziti-scp ./cmd/ziti-scp

---

## Upgrading

Upgrade with the system package manager (`apt-get install --only-upgrade ziti-ssh-host`, `dnf upgrade ziti-ssh-host`, and likewise for `ziti-ssh-ca`). Upgrading `ziti-ssh-host` or `ziti-ssh-ca` to 0.3.2 or later restarts the service if it is running (`systemctl try-restart`, run by the new package's install script), so the new version takes effect at once; a stopped service stays stopped. A restart of `ziti-ssh-host` stops new connections and gives open sessions up to 30 seconds to finish before closing them ([Graceful shutdown](operations.md#graceful-shutdown)), so upgrade hosts when that is acceptable.

**Hosts upgraded to 0.3.1 or earlier:** upgrades to those versions did not restart the service, so the version that was running before may still be running. Ubuntu's `needrestart` usually restarted it during `apt upgrade`; on RHEL-family systems, and on Debian without `needrestart`, it did not. To check, look at the running process's executable: `(deleted)` means it is the replaced binary. Then restart the service (or upgrade to 0.3.2+, which restarts it):

```sh
sudo readlink /proc/$(systemctl show -p MainPID --value ziti-ssh-host)/exe # or ziti-ssh-ca
# /usr/bin/ziti-ssh-host (deleted) -> still the previous version
sudo systemctl restart ziti-ssh-host
```

---

## Uninstalling

Packages install binaries to `/usr/bin` (earlier releases used `/usr/local/bin`; upgrading moves them automatically).
Expand Down
24 changes: 23 additions & 1 deletion packaging/scripts/postinstall-ziti-ssh-ca.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ CONF_DIR="${ZITI_SSH_CA_CONF_DIR:-/etc/ziti-ssh-ca}"
DROPIN_DIR="${ZITI_SSH_CA_DROPIN_DIR:-/etc/systemd/system/ziti-ssh-ca.service.d}"
DROPIN_FILE="${DROPIN_DIR}/10-controller-user.conf"
DROPIN_MARKER="# Managed by the ziti-ssh-ca package"
SYSTEMD_DIR="${ZITI_SSH_SYSTEMD_DIR:-/run/systemd/system}"

# is_upgrade reports whether this run upgrades an installed package:
# deb postinst "configure <old-version>", rpm %post with $1 >= 2. Fresh
# installs, reconfigures without an old version and dpkg abort-* calls are not.
is_upgrade() {
case "${1:-}" in
configure) [ -n "${2:-}" ] ;;
[2-9] | [1-9][0-9]*) true ;;
*) false ;;
esac
}

if [ ! -f "${CONF_DIR}/env" ]; then
cat > "${CONF_DIR}/env" <<'ENVEOF'
Expand Down Expand Up @@ -131,6 +143,16 @@ User=ziti. If the controller runs as a different user, run:
EOF
fi

if [ -d /run/systemd/system ]; then
if [ -d "${SYSTEMD_DIR}" ]; then
systemctl daemon-reload || true
# On upgrade, restart the service if it is running so the new binary takes
# effect (try-restart leaves a stopped service stopped). Without this, the
# old daemon keeps running until the next restart or reboot.
if is_upgrade "$@"; then
if systemctl try-restart ziti-ssh-ca.service; then
echo "ziti-ssh-ca: restarted ziti-ssh-ca.service (if it was running) to use the new version" >&2
else
echo "ziti-ssh-ca: warning: could not restart ziti-ssh-ca.service; run: systemctl restart ziti-ssh-ca.service" >&2
fi
fi
fi
33 changes: 29 additions & 4 deletions packaging/scripts/postinstall-ziti-ssh-host.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/bin/sh
set -e

if [ ! -f /etc/ziti-ssh-host/env ]; then
cat > /etc/ziti-ssh-host/env <<'ENVEOF'
# Paths (overridable only to allow testing this script outside a real install).
CONF_DIR="${ZITI_SSH_HOST_CONF_DIR:-/etc/ziti-ssh-host}"
SYSTEMD_DIR="${ZITI_SSH_SYSTEMD_DIR:-/run/systemd/system}"

# is_upgrade reports whether this run upgrades an installed package:
# deb postinst "configure <old-version>", rpm %post with $1 >= 2. Fresh
# installs, reconfigures without an old version and dpkg abort-* calls are not.
is_upgrade() {
case "${1:-}" in
configure) [ -n "${2:-}" ] ;;
[2-9] | [1-9][0-9]*) true ;;
*) false ;;
esac
}

if [ ! -f "${CONF_DIR}/env" ]; then
cat > "${CONF_DIR}/env" <<'ENVEOF'
# ziti-ssh-host environment configuration
# Uncomment and set these variables before starting the service.

Expand Down Expand Up @@ -60,7 +75,7 @@ if [ ! -f /etc/ziti-ssh-host/env ]; then
# RESTRICT_GROUPS: true = config may grant only groups listed in ALLOW_GROUPS.
#ZITI_RESTRICT_GROUPS=false
ENVEOF
chmod 640 /etc/ziti-ssh-host/env
chmod 640 "${CONF_DIR}/env"
fi

# Accounts in this group may only log in with a CA certificate (the sshd
Expand All @@ -70,6 +85,16 @@ if command -v groupadd >/dev/null 2>&1; then
groupadd -f --system ziti-ssh-managed
fi

if [ -d /run/systemd/system ]; then
if [ -d "${SYSTEMD_DIR}" ]; then
systemctl daemon-reload || true
# On upgrade, restart the service if it is running so the new binary takes
# effect (try-restart leaves a stopped service stopped). Without this, the
# old daemon keeps running until the next restart or reboot.
if is_upgrade "$@"; then
if systemctl try-restart ziti-ssh-host.service; then
echo "ziti-ssh-host: restarted ziti-ssh-host.service (if it was running) to use the new version" >&2
else
echo "ziti-ssh-host: warning: could not restart ziti-ssh-host.service; run: systemctl restart ziti-ssh-host.service" >&2
fi
fi
fi
119 changes: 119 additions & 0 deletions packaging/scripts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
Copyright NetFoundry Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package packaging holds the nfpm package definitions and their install
// scripts; this test runs the scripts against stub system commands.
package packaging

import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)

// stubs writes fake system commands that log their arguments to log.
func stubs(t *testing.T, log string) string {
t.Helper()
dir := t.TempDir()
logger := "#!/bin/sh\necho \"$(basename \"$0\") $*\" >> " + log + "\n"
for name, body := range map[string]string{
"systemctl": logger + "exit 0\n",
"groupadd": logger + "exit 0\n",
"pgrep": "#!/bin/sh\nexit 1\n", // no controller process
"chown": logger + "exit 0\n",
} {
if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o755); err != nil {
t.Fatal(err)
}
}
return dir
}

// The postinstall scripts restart a running service on upgrade only:
// deb "configure <old-version>" or rpm "$1 >= 2".
func TestPostinstallRestartsOnUpgradeOnly(t *testing.T) {
cases := []struct {
args []string
restart bool
}{
{[]string{"configure", ""}, false}, // deb fresh install
{[]string{"configure"}, false}, // deb, no old version
{[]string{"configure", "0.3.0-1"}, true}, // deb upgrade
{[]string{"abort-upgrade", "0.3.1-1"}, false},
{[]string{"1"}, false}, // rpm fresh install
{[]string{"2"}, true}, // rpm upgrade
{[]string{"12"}, true}, // rpm, several versions installed
}
for _, pkg := range []struct{ script, unit, confEnv string }{
{"scripts/postinstall-ziti-ssh-host.sh", "ziti-ssh-host.service", "ZITI_SSH_HOST_CONF_DIR"},
{"scripts/postinstall-ziti-ssh-ca.sh", "ziti-ssh-ca.service", "ZITI_SSH_CA_CONF_DIR"},
} {
for _, c := range cases {
name := filepath.Base(pkg.script) + " " + strings.Join(c.args, " ")
t.Run(name, func(t *testing.T) {
tmp := t.TempDir()
log := filepath.Join(tmp, "calls.log")
conf := filepath.Join(tmp, "conf")
systemd := filepath.Join(tmp, "systemd")
for _, d := range []string{conf, systemd} {
if err := os.MkdirAll(d, 0o755); err != nil {
t.Fatal(err)
}
}
cmd := exec.Command("sh", append([]string{pkg.script}, c.args...)...)
cmd.Env = []string{
"PATH=" + stubs(t, log) + ":/usr/bin:/bin",
pkg.confEnv + "=" + conf,
"ZITI_SSH_CA_DROPIN_DIR=" + filepath.Join(tmp, "dropin"),
"ZITI_SSH_SYSTEMD_DIR=" + systemd,
}
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("script failed: %v\n%s", err, out)
}
calls, _ := os.ReadFile(log)
if !strings.Contains(string(calls), "systemctl daemon-reload") {
t.Errorf("no daemon-reload; calls:\n%s", calls)
}
restarted := strings.Contains(string(calls), "systemctl try-restart "+pkg.unit)
if restarted != c.restart {
t.Errorf("try-restart called = %v, want %v; calls:\n%s", restarted, c.restart, calls)
}
if _, err := os.Stat(filepath.Join(conf, "env")); err != nil {
t.Errorf("env file not created: %v", err)
}
})
}
}
}

// Without systemd (containers, chroots) nothing is reloaded or restarted.
func TestPostinstallWithoutSystemd(t *testing.T) {
tmp := t.TempDir()
log := filepath.Join(tmp, "calls.log")
cmd := exec.Command("sh", "scripts/postinstall-ziti-ssh-host.sh", "2")
cmd.Env = []string{
"PATH=" + stubs(t, log) + ":/usr/bin:/bin",
"ZITI_SSH_HOST_CONF_DIR=" + tmp,
"ZITI_SSH_SYSTEMD_DIR=" + filepath.Join(tmp, "absent"),
}
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("script failed: %v\n%s", err, out)
}
if calls, _ := os.ReadFile(log); strings.Contains(string(calls), "systemctl") {
t.Errorf("systemctl called without systemd:\n%s", calls)
}
}