Skip to content

Commit c641e29

Browse files
devaladeclaude
andcommitted
fix(harden): fix 6 bugs in harden command and gum_confirm
- SSH port change now updates local shipnode.conf, not the remote file - Remove `local` keyword inside remote heredoc (not valid outside a function) - Fix UFW port-check regex to correctly match existing rules - Fix SSH uncomment sed to handle `# Key` with space after hash - Remove --no-limit from gum_confirm to prevent multi-select on yes/no - Remove redundant 2>&1 after &>/dev/null in fail2ban status check Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c65aeab commit c641e29

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to ShipNode will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.4.11] - 2026-05-11
9+
10+
### Fixed
11+
- **harden**: SSH port change now updates local `shipnode.conf` instead of the remote file, so subsequent commands use the correct port
12+
- **harden**: Removed `local` keyword inside remote heredoc in `install_configure_fail2ban` (caused `bash: local: can only be used in a function` error)
13+
- **harden**: Fixed UFW duplicate-rule check regex to correctly match existing port rules
14+
- **harden**: SSH uncomment `sed` now handles commented keys with a space after `#` (e.g. `# PasswordAuthentication`)
15+
- **prompts**: Removed `--no-limit` from `gum_confirm` to prevent multi-select on yes/no prompts
16+
- **prompts**: Removed redundant `2>&1` after `&>/dev/null` in fail2ban status check
17+
818
## [1.4.0] - 2026-05-10
919

1020
### Added

lib/commands/harden.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ apply_ssh_config() {
5151
local value="$2"
5252
remote_exec bash << EOF
5353
# Uncomment if the key is commented out
54-
sudo sed -i "s/^#\(${key}[[:space:]]\)/\1/" /etc/ssh/sshd_config
54+
sudo sed -i "s/^#[[:space:]]*\(${key}[[:space:]]\)/\1/" /etc/ssh/sshd_config
5555
# Check if the configuration already exists
5656
if grep -qE "^${key}[[:space:]]" /etc/ssh/sshd_config; then
5757
# Update existing line
@@ -140,7 +140,7 @@ apply_firewall_rules() {
140140
\$SUDO ufw default allow outgoing 2>/dev/null || true
141141
142142
# Allow SSH (only if not already allowed)
143-
if ! \$SUDO ufw status | grep -qE "^\[?${ssh_port}\]"; then
143+
if ! \$SUDO ufw status | grep -qE "${ssh_port}/tcp"; then
144144
\$SUDO ufw allow ${ssh_port}/tcp
145145
fi
146146
@@ -161,7 +161,7 @@ EOF
161161
check_fail2ban() {
162162
remote_exec bash << 'EOF'
163163
if command -v fail2ban-server &> /dev/null; then
164-
if systemctl is-active fail2ban &> /dev/null 2>&1; then
164+
if systemctl is-active fail2ban &>/dev/null; then
165165
echo "ACTIVE"
166166
else
167167
echo "INSTALLED_INACTIVE"
@@ -199,7 +199,7 @@ install_configure_fail2ban() {
199199
fi
200200
201201
# Determine log path based on distro
202-
local log_path="/var/log/auth.log"
202+
log_path="/var/log/auth.log"
203203
if [ -f "/var/log/secure" ]; then
204204
log_path="/var/log/secure"
205205
fi
@@ -333,7 +333,7 @@ cmd_harden() {
333333
apply_ssh_config "Port" "$new_port"
334334
SSH_PORT="$new_port"
335335
# Persist SSH_PORT to shipnode.conf on the server
336-
remote_exec "sed -i 's/^SSH_PORT=.*/SSH_PORT=${new_port}/' ${REMOTE_PATH}/shipnode.conf" 2>/dev/null || true
336+
sed -i "s/^SSH_PORT=.*/SSH_PORT=${new_port}/" shipnode.conf 2>/dev/null || true
337337
((changes_made++))
338338
success "SSH port configured: $new_port"
339339
echo ""

lib/core.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BLUE='\033[0;34m'
1010
NC='\033[0m' # No Color
1111

1212
# ShipNode version
13-
VERSION="1.4.10"
13+
VERSION="1.4.11"
1414

1515
# SSH multiplexing for connection reuse
1616
SSH_CONTROL_PATH="/tmp/shipnode-ssh-%r@%h:%p"

lib/prompts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ gum_confirm() {
143143
if [ "$USE_GUM" = true ] && [ -t 0 ]; then
144144
if [ "$default" = "y" ]; then
145145
local choice
146-
choice=$(printf 'Yes\nNo' | gum choose --header "$message" --default "Yes" --no-limit 2>/dev/null || echo "No")
146+
choice=$(printf 'Yes\nNo' | gum choose --header "$message" --default "Yes" 2>/dev/null || echo "No")
147147
[ "$choice" = "Yes" ] && return 0 || return 1
148148
else
149149
local choice
150-
choice=$(printf 'Yes\nNo' | gum choose --header "$message" --default "No" --no-limit 2>/dev/null || echo "No")
150+
choice=$(printf 'Yes\nNo' | gum choose --header "$message" --default "No" 2>/dev/null || echo "No")
151151
[ "$choice" = "Yes" ] && return 0 || return 1
152152
fi
153153
else

0 commit comments

Comments
 (0)