From e1e5df6b408a2c4f2ed63254046e33b7ab09a103 Mon Sep 17 00:00:00 2001 From: Marcelo Politzer Date: Thu, 7 Jul 2022 16:16:15 -0300 Subject: [PATCH] Add dapp user --- CHANGELOG.md | 1 + configs/default-buildroot-config | 2 +- configs/lp64d-buildroot-config | 2 +- configs/min-buildroot-config | 2 +- external/users.txt | 1 + skel/sbin/init | 20 ++++++++++++++++++-- 6 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 external/users.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ddeaea..35f6030 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Remove dehash tools - Updated toolchain version to v0.11.0 +- Create a dapp user and set it as the default ## [0.13.0] - 2022-07-22 ### Changed diff --git a/configs/default-buildroot-config b/configs/default-buildroot-config index f81de18..d00ea1c 100644 --- a/configs/default-buildroot-config +++ b/configs/default-buildroot-config @@ -394,7 +394,7 @@ BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin" BR2_GENERATE_LOCALE="" # BR2_SYSTEM_ENABLE_NLS is not set # BR2_TARGET_TZ_INFO is not set -BR2_ROOTFS_USERS_TABLES="" +BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL_CARTESI_PATH)/users.txt" BR2_ROOTFS_OVERLAY="skel" BR2_ROOTFS_PRE_BUILD_SCRIPT="" BR2_ROOTFS_POST_BUILD_SCRIPT="" diff --git a/configs/lp64d-buildroot-config b/configs/lp64d-buildroot-config index 04e3920..1bbc51c 100644 --- a/configs/lp64d-buildroot-config +++ b/configs/lp64d-buildroot-config @@ -399,7 +399,7 @@ BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin" BR2_GENERATE_LOCALE="" # BR2_SYSTEM_ENABLE_NLS is not set # BR2_TARGET_TZ_INFO is not set -BR2_ROOTFS_USERS_TABLES="" +BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL_CARTESI_PATH)/users.txt" BR2_ROOTFS_OVERLAY="skel" BR2_ROOTFS_PRE_BUILD_SCRIPT="" BR2_ROOTFS_POST_BUILD_SCRIPT="" diff --git a/configs/min-buildroot-config b/configs/min-buildroot-config index 2de0f16..118fda3 100644 --- a/configs/min-buildroot-config +++ b/configs/min-buildroot-config @@ -394,7 +394,7 @@ BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin" BR2_GENERATE_LOCALE="" # BR2_SYSTEM_ENABLE_NLS is not set # BR2_TARGET_TZ_INFO is not set -BR2_ROOTFS_USERS_TABLES="" +BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL_CARTESI_PATH)/users.txt" BR2_ROOTFS_OVERLAY="skel" BR2_ROOTFS_PRE_BUILD_SCRIPT="" BR2_ROOTFS_POST_BUILD_SCRIPT="" diff --git a/external/users.txt b/external/users.txt new file mode 100644 index 0000000..a9400aa --- /dev/null +++ b/external/users.txt @@ -0,0 +1 @@ +dapp 1000 dapp 1000 = /home/dapp /bin/sh - dapp user diff --git a/skel/sbin/init b/skel/sbin/init index 3475cc0..bcedcd8 100755 --- a/skel/sbin/init +++ b/skel/sbin/init @@ -41,12 +41,28 @@ done /sbin/ifconfig lo 127.0.0.1 if [ -n "$*" ]; then - export HOME=/ + if [ -c /dev/rollup ]; then + chown root:dapp /dev/rollup + chmod 660 /dev/rollup + fi + + if [ -c /dev/yield ]; then + chown root:dapp /dev/yield + chmod 660 /dev/yield + fi + export PS1='\h:\w # ' if [ -f "$DEFAULT_ENV_FILE" ]; then source $DEFAULT_ENV_FILE fi - setsid cttyhack /bin/sh -c "$*" + if [ "$single" == "yes" ]; then + export HOME=/ + setsid cttyhack /bin/sh -c "$*" + else + export HOME=/home/dapp/ + cd $HOME + setsid cttyhack /bin/su -p dapp -s /bin/sh -c "$*" + fi else echo "Nothing to do." fi