From: Reza Arbab <arbab@linux.ibm.com>
To: buildroot@buildroot.org
Cc: Laurent Vivier <laurent@vivier.eu>, Joel Stanley <joel@jms.id.au>
Subject: [Buildroot] [PATCH v3 7/8] package/petitboot: enable user separation
Date: Mon, 9 Oct 2023 10:17:28 -0500 [thread overview]
Message-ID: <20231009151729.2223963-8-arbab@linux.ibm.com> (raw)
In-Reply-To: <20231009151729.2223963-1-arbab@linux.ibm.com>
Run the petitboot UI as an unprivileged user. This requires using the
agetty package instead of the busybox getty utility, running the initial
pb-console helper at user login rather than directly.
If sudo is installed, with a sudoers policy allowing petituser to
perform sudo with no password (or a blank password), the "drop to shell"
feature of petitboot will automatically become a root shell.
Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
package/petitboot/Config.in | 1 +
package/petitboot/S15pb-discover | 4 +++-
package/petitboot/pb-console | 6 ++++--
package/petitboot/petitboot.mk | 12 ++++++++++++
package/petitboot/shell_config | 24 ++++++++++++++++++++++++
package/petitboot/shell_profile | 2 ++
6 files changed, 46 insertions(+), 3 deletions(-)
create mode 100644 package/petitboot/shell_config
create mode 100644 package/petitboot/shell_profile
diff --git a/package/petitboot/Config.in b/package/petitboot/Config.in
index 5f1d91e77ecb..0f965e71e628 100644
--- a/package/petitboot/Config.in
+++ b/package/petitboot/Config.in
@@ -16,6 +16,7 @@ config BR2_PACKAGE_PETITBOOT
select BR2_PACKAGE_KEXEC_LITE if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
select BR2_PACKAGE_NVME if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
select BR2_PACKAGE_POWERPC_UTILS if ( BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le )
+ select BR2_PACKAGE_UTIL_LINUX_AGETTY
help
Petitboot is a small kexec-based bootloader
diff --git a/package/petitboot/S15pb-discover b/package/petitboot/S15pb-discover
index 71ab62d99859..a37e33521f1a 100644
--- a/package/petitboot/S15pb-discover
+++ b/package/petitboot/S15pb-discover
@@ -12,7 +12,9 @@ fi
start() {
printf 'Starting %s: ' "$DAEMON"
- mkdir -p /var/log/petitboot
+ # shellcheck disable=SC2174 # only apply -m to deepest dir
+ mkdir -p -m 0775 /var/log/petitboot
+ chown root:petitgroup /var/log/petitboot
# shellcheck disable=SC2086 # we need the word splitting
start-stop-daemon -S -q -b -m -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
diff --git a/package/petitboot/pb-console b/package/petitboot/pb-console
index 407ff3b30232..eea40163d02f 100644
--- a/package/petitboot/pb-console
+++ b/package/petitboot/pb-console
@@ -3,14 +3,16 @@
DAEMON="pb-console"
PB_CONSOLE_PORT=${2:-"console"}
-PB_CONSOLE_ARGS="--getty --detach -- -n -i 0 $PB_CONSOLE_PORT linux"
+PB_CONSOLE_ARGS="--getty=/sbin/agetty --detach -- -a petituser -n -i $PB_CONSOLE_PORT linux"
# shellcheck source=/dev/null
[ -r "/etc/default/petitboot" ] && . "/etc/default/petitboot"
start() {
printf 'Starting %s on %s: ' "$DAEMON" "$PB_CONSOLE_PORT"
- mkdir -p /var/log/petitboot
+ # shellcheck disable=SC2174 # only apply -m to deepest dir
+ mkdir -p -m 0775 /var/log/petitboot
+ chown root:petitgroup /var/log/petitboot
# shellcheck disable=SC2086 # we need the word splitting
start-stop-daemon -S -q -x "/usr/libexec/petitboot/$DAEMON" \
diff --git a/package/petitboot/petitboot.mk b/package/petitboot/petitboot.mk
index ff87f3498734..5b517eb3b1a6 100644
--- a/package/petitboot/petitboot.mk
+++ b/package/petitboot/petitboot.mk
@@ -71,6 +71,10 @@ define PETITBOOT_POST_INSTALL
$(TARGET_DIR)/usr/sbin/kexec-restart
$(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/pb-console \
$(TARGET_DIR)/etc/init.d/pb-console
+ $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/shell_config \
+ $(TARGET_DIR)/home/petituser/.shrc
+ $(INSTALL) -D -m 0755 $(PETITBOOT_PKGDIR)/shell_profile \
+ $(TARGET_DIR)/home/petituser/.profile
mkdir -p $(TARGET_DIR)/etc/udev/rules.d
(for port in $(PETITBOOT_GETTY_PORT); do \
@@ -84,4 +88,12 @@ endef
PETITBOOT_POST_INSTALL_TARGET_HOOKS += PETITBOOT_POST_INSTALL
+define PETITBOOT_USERS
+ petituser -1 petitgroup -1 * /home/petituser /bin/sh - petitboot user
+endef
+
+define PETITBOOT_PERMISSIONS
+ /var/petitboot d 775 root petitgroup - - - - -
+endef
+
$(eval $(autotools-package))
diff --git a/package/petitboot/shell_config b/package/petitboot/shell_config
new file mode 100644
index 000000000000..b10b95baae6c
--- /dev/null
+++ b/package/petitboot/shell_config
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+try_sudo() {
+ [ -x "$(command -v sudo)" ] || return
+ sudo -K
+ echo | sudo -S /bin/true >/dev/null 2>&1 || return
+
+ echo "No password required, running as root."
+ sudo -i
+ sudo -K
+ exit
+}
+
+reset
+
+echo "Exiting petitboot. Type 'exit' to return."
+echo "You may run 'pb-sos' to gather diagnostic data."
+
+if [ "$(id -u)" != "0" ]; then
+ try_sudo
+ export PS1='$ '
+else
+ export PS1='# '
+fi
diff --git a/package/petitboot/shell_profile b/package/petitboot/shell_profile
new file mode 100644
index 000000000000..1ca5e6364dba
--- /dev/null
+++ b/package/petitboot/shell_profile
@@ -0,0 +1,2 @@
+export ENV="/home/petituser/.shrc"
+exec /usr/libexec/petitboot/pb-console
--
2.39.3
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2023-10-09 15:19 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-09 15:17 [Buildroot] [PATCH v3 0/8] package/petitboot: misc fixes/enhancement Reza Arbab
2023-10-09 15:17 ` [Buildroot] [PATCH v3 1/8] package/petitboot: fix menu comment Reza Arbab
2023-11-09 16:59 ` Peter Korsgaard
2023-10-09 15:17 ` [Buildroot] [PATCH v3 2/8] package/petitboot: fix pb-discover pidfile creation Reza Arbab
2023-10-09 15:17 ` [Buildroot] [PATCH v3 3/8] package/petitboot: use default logfile dir Reza Arbab
2023-11-09 16:59 ` Peter Korsgaard
2023-10-09 15:17 ` [Buildroot] [PATCH v3 4/8] package/petitboot: prefer kexec-lite on powerpc Reza Arbab
2023-11-05 17:40 ` Arnout Vandecappelle via buildroot
2023-10-09 15:17 ` [Buildroot] [PATCH v3 5/8] package/petitboot: fix shutdown Reza Arbab
2023-11-05 17:57 ` Arnout Vandecappelle via buildroot
2023-11-09 16:13 ` Reza Arbab
2023-10-09 15:17 ` [Buildroot] [PATCH v3 6/8] package/petitboot: run petitboot UI on consoles Reza Arbab
2023-11-05 18:06 ` Arnout Vandecappelle via buildroot
2023-10-09 15:17 ` Reza Arbab [this message]
2023-11-05 18:26 ` [Buildroot] [PATCH v3 7/8] package/petitboot: enable user separation Arnout Vandecappelle via buildroot
2023-11-09 16:16 ` Reza Arbab
2023-11-10 9:01 ` Arnout Vandecappelle via buildroot
2023-11-14 15:25 ` Reza Arbab
2023-10-09 15:17 ` [Buildroot] [PATCH v3 8/8] package/petitboot: prefer UTF-8 support Reza Arbab
2023-11-05 18:30 ` Arnout Vandecappelle via buildroot
2023-11-09 16:17 ` Reza Arbab
2023-11-05 18:31 ` [Buildroot] [PATCH v3 0/8] package/petitboot: misc fixes/enhancement Arnout Vandecappelle via buildroot
2023-11-09 16:19 ` Reza Arbab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231009151729.2223963-8-arbab@linux.ibm.com \
--to=arbab@linux.ibm.com \
--cc=buildroot@buildroot.org \
--cc=joel@jms.id.au \
--cc=laurent@vivier.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.