Skip to content

Commit 5420fb0

Browse files
committed
support: simplify, user must use sudo for full logs
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 39429f7 commit 5420fb0

File tree

2 files changed

+53
-40
lines changed

2 files changed

+53
-40
lines changed

doc/support.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ provides a convenient way to collect comprehensive system diagnostics.
55
This command gathers configuration files, logs, network state, and other
66
system information into a single compressed archive.
77

8+
> [!NOTE]
9+
> The `support collect` command should be run with `sudo` to collect
10+
> complete system information (kernel logs, hardware details, etc.).
11+
> Use the `--unprivileged` option to run as a regular user in degraded
12+
> data collection mode.
13+
814
## Collecting Support Data
915

1016
To collect support data and save it to a file:
1117

1218
```bash
13-
admin@host:~$ support collect > support-data.tar.gz
14-
(admin@host) Password: ***********
19+
admin@host:~$ sudo support collect > support-data.tar.gz
1520
Starting support data collection from host...
21+
Collecting to: /var/lib/support
1622
This may take up to a minute. Please wait...
1723
Tailing /var/log/messages for 30 seconds (please wait)...
1824
Log tail complete.
@@ -24,7 +30,7 @@ admin@host:~$ ls -l support-data.tar.gz
2430
The command can also be run remotely via SSH from your workstation:
2531

2632
```bash
27-
$ ssh admin@host support collect > support-data.tar.gz
33+
$ ssh admin@host 'sudo support collect' > support-data.tar.gz
2834
...
2935
```
3036

@@ -38,8 +44,9 @@ For secure transmission of support data, the archive can be encrypted
3844
with GPG using a password:
3945

4046
```bash
41-
admin@host:~$ support collect -p mypassword > support-data.tar.gz.gpg
47+
admin@host:~$ sudo support collect -p mypassword > support-data.tar.gz.gpg
4248
Starting support data collection from host...
49+
Collecting to: /var/lib/support
4350
This may take up to a minute. Please wait...
4451
...
4552
Collection complete. Creating archive...
@@ -52,8 +59,8 @@ but the local ssh client may then echo the password.
5259

5360
> [!TIP]
5461
> To hide the encryption password for an SSH session, the script supports
55-
> reading from stdin:
56-
> `echo "$MYSECRET" | ssh user@device support collect -p >
62+
> reading from stdin:
63+
> `echo "$MYSECRET" | ssh user@device 'sudo support collect -p' >
5764
> file.tar.gz.gpg`
5865
5966
After transferring the resulting file to your workstation, decrypt it

src/bin/support

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,12 @@ cmd_collect()
9696
;;
9797
*)
9898
echo "Error: Unknown option '$1'" >&2
99-
echo "Usage: $prognm collect [--log-sec|-s N] [--password|-p PASSWORD]" >&2
99+
echo "Usage: $prognm collect [-s N] [-p PASSWORD]" >&2
100100
exit 1
101101
;;
102102
esac
103103
done
104104

105-
# Determine if we need sudo and if it's available
106-
SUDO=""
107-
if [ "$(id -u)" -ne 0 ]; then
108-
if command -v sudo >/dev/null 2>&1; then
109-
SUDO="sudo"
110-
fi
111-
fi
112-
113105
# If WORK_DIR not set globally, try /var/lib/support first (more space,
114106
# persistent across user sessions). Fall back to $HOME if we can't create/write there
115107
if [ -z "$WORK_DIR" ]; then
@@ -120,15 +112,12 @@ cmd_collect()
120112
# Doesn't exist, try to create it
121113
if mkdir -p /var/lib/support 2>/dev/null; then
122114
WORK_DIR="/var/lib/support"
123-
elif [ -n "$SUDO" ] && $SUDO mkdir -p /var/lib/support 2>/dev/null && \
124-
$SUDO chown "$(id -u):$(id -g)" /var/lib/support 2>/dev/null; then
125-
WORK_DIR="/var/lib/support"
126115
fi
127116
elif [ -d /var/lib/support ]; then
128-
# Exists but not writable, try to fix permissions with sudo
117+
# Exists but not writable, try to fix permissions (requires root)
129118
# Try chmod first (might just be permission issue), then chown if needed
130-
if $SUDO chmod 755 /var/lib/support 2>/dev/null && \
131-
$SUDO chown "$(id -u):$(id -g)" /var/lib/support 2>/dev/null; then
119+
if chmod 755 /var/lib/support 2>/dev/null && \
120+
chown "$(id -u):$(id -g)" /var/lib/support 2>/dev/null; then
132121
# Verify it's actually writable now
133122
if [ -w /var/lib/support ] 2>/dev/null; then
134123
WORK_DIR="/var/lib/support"
@@ -272,7 +261,7 @@ cmd_collect()
272261
fi
273262

274263
# Kernel and system state
275-
collect system/dmesg.txt ${SUDO} dmesg
264+
collect system/dmesg.txt dmesg
276265
collect system/free.txt free -h
277266
collect system/stat.txt cat /proc/stat
278267
collect system/softirqs.txt cat /proc/softirqs
@@ -316,10 +305,10 @@ cmd_collect()
316305
ip -o link show | grep 'link/ether' | awk -F': ' '{print $2}' > "${COLLECT_DIR}/.iface-list" 2>> "${EXEC_LOG}"
317306
if [ -s "${COLLECT_DIR}/.iface-list" ]; then
318307
while IFS= read -r iface; do
319-
# ethtool typically needs root/sudo
320-
collect "network/ethtool/${iface}.txt" ${SUDO} ethtool "$iface"
321-
collect "network/ethtool/stats-${iface}.txt" ${SUDO} ethtool -S "$iface"
322-
collect "network/ethtool/module-${iface}.txt" ${SUDO} ethtool -m "$iface"
308+
# ethtool typically needs root
309+
collect "network/ethtool/${iface}.txt" ethtool "$iface"
310+
collect "network/ethtool/stats-${iface}.txt" ethtool -S "$iface"
311+
collect "network/ethtool/module-${iface}.txt" ethtool -m "$iface"
323312
done < "${COLLECT_DIR}/.iface-list"
324313
fi
325314
rm -f "${COLLECT_DIR}/.iface-list"
@@ -332,7 +321,7 @@ cmd_collect()
332321

333322
# Firewall rules
334323
if command -v nft >/dev/null 2>&1; then
335-
collect network/nftables.txt ${SUDO} nft list ruleset
324+
collect network/nftables.txt nft list ruleset
336325
fi
337326

338327
# FRR routing information
@@ -548,7 +537,10 @@ usage()
548537
{
549538
echo "Usage: $prognm [global-options] <command> [options]"
550539
echo ""
540+
echo "Note: Run with 'sudo' for complete data collection (dmesg, ethtool, etc.)"
541+
echo ""
551542
echo "Global options:"
543+
echo " -u, --unprivileged Allow running without root (some data will be missing)"
552544
echo " -w, --work-dir PATH Use PATH as working directory for collection/cleanup"
553545
echo " (default: /var/lib/support with fallback to \$HOME)"
554546
echo ""
@@ -568,23 +560,29 @@ usage()
568560
echo " -d, --days N Remove directories older than N days (default: 7)"
569561
echo ""
570562
echo "Examples:"
571-
echo " $prognm collect > support-data.tar.gz"
572-
echo " $prognm collect -p > support-data.tar.gz.gpg"
573-
echo " $prognm collect --password mypass > support-data.tar.gz.gpg"
574-
echo " $prognm --work-dir /tmp/ram collect > support-data.tar.gz"
575-
echo " ssh user@device $prognm collect > support-data.tar.gz"
576-
echo " $prognm clean --dry-run"
577-
echo " $prognm clean --days 30"
578-
echo " $prognm --work-dir /tmp/ram clean"
563+
echo " sudo $prognm collect > support-data.tar.gz"
564+
echo " sudo $prognm collect -p > support-data.tar.gz.gpg"
565+
echo " sudo $prognm collect --password mypass > support-data.tar.gz.gpg"
566+
echo " sudo $prognm --work-dir /tmp/ram collect > support-data.tar.gz"
567+
echo " ssh user@device 'sudo $prognm collect' > support-data.tar.gz"
568+
echo " $prognm -u collect > support-data.tar.gz (degraded)"
569+
echo " sudo $prognm clean --dry-run"
570+
echo " sudo $prognm clean --days 30"
571+
echo " sudo $prognm --work-dir /tmp/ram clean"
579572
exit 1
580573
}
581574

582575
# Main command dispatcher
583576
# Parse global options first
584577
WORK_DIR=""
578+
ALLOW_UNPRIVILEGED=0
585579

586580
while [ $# -gt 0 ]; do
587581
case "$1" in
582+
-u|--unprivileged)
583+
ALLOW_UNPRIVILEGED=1
584+
shift
585+
;;
588586
-w|--work-dir)
589587
if [ -z "$2" ]; then
590588
echo "Error: --work-dir requires a path argument" >&2
@@ -612,11 +610,19 @@ command="$1"
612610
shift
613611

614612
case "$command" in
615-
collect)
616-
cmd_collect "$@"
617-
;;
618-
clean)
619-
cmd_clean "$@"
613+
collect|clean)
614+
# Check if running as root (uid 0)
615+
if [ "$(id -u)" -ne 0 ] && [ "$ALLOW_UNPRIVILEGED" -eq 0 ]; then
616+
echo "Error: This command should be run with 'sudo' for complete data collection." >&2
617+
echo " Use -u/--unprivileged to run as a regular user in degraded mode." >&2
618+
exit 1
619+
fi
620+
621+
if [ "$command" = "collect" ]; then
622+
cmd_collect "$@"
623+
else
624+
cmd_clean "$@"
625+
fi
620626
;;
621627
help|--help|-h)
622628
usage

0 commit comments

Comments
 (0)