Pull request for branch yem-package-create-user
Hello All!
Here is a series that allows packages to create users.
Packages that install daemons may well want to run those daemons as non-root users to avoid security issues. Currently, there are two users of choice to run 'generic' daemons: root or daemon (although there are a few dedicated users to run a few services: mail, sshd, ftp...).
This series builds upon both the package infrastrucutre to define the user(s) a package may want to create, and the filesystem infrastructure to actually generate these users, and chown their ${HOME}s.
Documentation is updated accordingly.
As a proof of concept, the package tvheadend has been updated to use a dedicated user to run its daemon as (call me stubborn! ;-] ).
Changes v8 -> v9:
- rebased on master for Peter
Changes v7 -> v8:
- rebased on master, fixed conflicts in docs/manual
Changes v6 -> v7:
- rebased onto the 'next' branch for Peter
Changes v5 -> v6: (All after suggestions by Arnout)
- clean up awk invocations
- ensure users with an explicit uid are created before users with a computed uid
- ditto for groups/gid
- cleanup group-addign function
- fix password encoding method
- cleanup /etc/shadow fields
- fix typos
Changes v4 -> v5:
- rebased ontop master after Developer's Day comments and upstreaming
Changes v3 -> v4:
- use the configured password encryption scheme
- some tweaks and typo-fixes to the documentation
Changes v2 -> v3:
- clarify password prefixes (Samuel)
- move makeuser syntax doc to its own file (Samuel)
- use awk instead of sed to parse /etc/passwd et al. (Cam, Thomas)
- sanitise use of grep (Cam)
- enhancements and fixes to makuser syntax doc (Cam)
Changes v1 -> v2:
- drop the gshadow patch (Thomas, Peter)
- tvheadend user is now part of the video secondary group
The following changes since commit 7219dfa275abaf332cb3828be381436147f41f04:
nitrogen6x: get rid of ext2 rev 1 notice now we can create it directly instead (2013-04-12 15:02:18 +0200)
are available in the git repository at:
git://gitorious.org/buildroot/buildroot.git yem-package-create-user
Yann E. MORIN (2):
packages: add ability for packages to create users package/tvheadend: use a non-root user to run the daemon
docs/manual/adding-packages-generic.txt | 16 +- docs/manual/appendix.txt | 1 + docs/manual/makeusers-syntax.txt | 87 +++++++ fs/common.mk | 3 + package/pkg-generic.mk | 1 + package/tvheadend/etc.default.tvheadend | 5 +- package/tvheadend/tvheadend.mk | 10 +- support/scripts/mkusers | 409 +++++++++++++++++++++++++++++++ 8 files changed, 525 insertions(+), 7 deletions(-) create mode 100644 docs/manual/makeusers-syntax.txt create mode 100755 support/scripts/mkusers
Regards,
Yann E. MORIN
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 1/2 packages: add ability for packages to create users
Packages that install daemons may need those daemons to run as a non-root, or an otherwise non-system (eg. 'daemon'), user.
Add infrastructure for packages to create users, by declaring the FOO_USERS variable that contain a makedev-syntax-like description of the user(s) to add.
--- docs/manual/adding-packages-generic.txt | 16 +- docs/manual/appendix.txt | 1 + docs/manual/makeusers-syntax.txt | 87 +++++++ fs/common.mk | 3 + package/pkg-generic.mk | 1 + support/scripts/mkusers | 409 +++++++++++++++++++++++++++++++ 6 files changed, 515 insertions(+), 2 deletions(-) create mode 100644 docs/manual/makeusers-syntax.txt create mode 100755 support/scripts/mkusers
docs/manual/adding-packages-generic.txt +14 -2
@@ -53,7 +53,11 @@ system is based on hand-written Makefiles or shell scripts. 36: /bin/foo f 4755 0 0 - - - - - 37: endef 38: -39: $(eval $(generic-package)) +39: define LIBFOO_USERS +40: foo -1 libfoo -1 * - - - LibFoo daemon +41: endef +42: +43: $(eval $(generic-package)) -------------------------------- The Makefile begins on line 7 to 11 with metadata information: the
@@ -140,7 +144,10 @@ On line 31..33, we define a device-node file used by this package On line 35..37, we define the permissions to set to specific files installed by this package (+LIBFOO_PERMISSIONS+). -Finally, on line 39, we call the +generic-package+ function, which +On lines 39..41, we define a user that is used by this package (eg. +to run a daemon as non-root) (+LIBFOO_USERS+). + +Finally, on line 43, we call the +generic-package+ function, which generates, according to the variables defined previously, all the Makefile code necessary to make your package working.
@@ -307,6 +314,11 @@ information is (assuming the package name is +libfoo+) : You can find some documentation for this syntax in the xref:makedev-syntax[]. This variable is optional. +* +LIBFOO_USERS+ lists the users to create for this package, if it installs + a program you want to run as a specific user (eg. as a daemon, or as a + cron-job). The syntax is similar in spirit to the makedevs one, and is + described in the xref:makeuser-syntax[]. This variable is optional. + * +LIBFOO_LICENSE+ defines the license (or licenses) under which the package is released. This name will appear in the manifest file produced by +make legal-info+.
docs/manual/appendix.txt +1 -0
@@ -5,6 +5,7 @@ Appendix ======== include::makedev-syntax.txt[] +include::makeusers-syntax.txt[] [[package-list]] Available packages
docs/manual/makeusers-syntax.txt new file +87 -0
87 lines not on this page · raw message
fs/common.mk +3 -0
@@ -35,6 +35,7 @@ FAKEROOT_SCRIPT = $(BUILD_DIR)/_fakeroot.fs FULL_DEVICE_TABLE = $(BUILD_DIR)/_device_table.txt ROOTFS_DEVICE_TABLES = $(call qstrip,$(BR2_ROOTFS_DEVICE_TABLE) \ $(BR2_ROOTFS_STATIC_DEVICE_TABLE)) +USERS_TABLE = $(BUILD_DIR)/_users_table.txt define ROOTFS_TARGET_INTERNAL
@@ -55,6 +56,8 @@ endif printf '$$(subst $$(sep),\n,$$(PACKAGES_PERMISSIONS_TABLE))' >> $$(FULL_DEVICE_TABLE) echo "$$(HOST_DIR)/usr/bin/makedevs -d $$(FULL_DEVICE_TABLE) $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT) endif + printf '$(subst $(sep),\n,$(PACKAGES_USERS))' > $(USERS_TABLE) + $(TOPDIR)/support/scripts/mkusers $(USERS_TABLE) $(TARGET_DIR) >> $(FAKEROOT_SCRIPT) echo "$$(ROOTFS_$(2)_CMD)" >> $$(FAKEROOT_SCRIPT) chmod a+x $$(FAKEROOT_SCRIPT) $$(HOST_DIR)/usr/bin/fakeroot -- $$(FAKEROOT_SCRIPT)
package/pkg-generic.mk +1 -0
@@ -529,6 +529,7 @@ ifeq ($$($$($(2)_KCONFIG_VAR)),y) TARGETS += $(1) PACKAGES_PERMISSIONS_TABLE += $$($(2)_PERMISSIONS)$$(sep) PACKAGES_DEVICES_TABLE += $$($(2)_DEVICES)$$(sep) +PACKAGES_USERS += $$($(2)_USERS)$$(sep) ifeq ($$($(2)_SITE_METHOD),svn) DL_TOOLS_DEPENDENCIES += svn
support/scripts/mkusers new file +409 -0
409 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH 2/2 package/tvheadend: use a non-root user to run the daemon
In reply to Yann E. MORIN--- package/tvheadend/etc.default.tvheadend | 5 ++--- package/tvheadend/tvheadend.mk | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-)
package/tvheadend/etc.default.tvheadend +2 -3
@@ -1,6 +1,5 @@ -# Once we have a real user, we'll use it -TVH_USER=root -TVH_GROUP=root +TVH_USER=tvheadend +TVH_GROUP=tvheadend #TVH_ADAPTERS= #TVH_HTTP_PORT=9981 #TVH_HTSP_PORT=9982
package/tvheadend/tvheadend.mk +8 -2
@@ -26,9 +26,11 @@ TVHEADEND_DEPENDENCIES += dvb-apps # To run tvheadend, we need: # - a startup script, and its config file # - a default DB with a tvheadend admin +# - a non-root user to run as define TVHEADEND_INSTALL_DB - $(INSTALL) -D package/tvheadend/accesscontrol.1 \ - $(TARGET_DIR)/root/.hts/tvheadend/accesscontrol/1 + $(INSTALL) -D -m 0600 package/tvheadend/accesscontrol.1 \ + $(TARGET_DIR)/home/tvheadend/.hts/tvheadend/accesscontrol/1 + chmod -R go-rwx $(TARGET_DIR)/home/tvheadend endef TVHEADEND_POST_INSTALL_TARGET_HOOKS = TVHEADEND_INSTALL_DB
@@ -37,6 +39,10 @@ define TVHEADEND_INSTALL_INIT_SYSV $(INSTALL) -D package/tvheadend/S99tvheadend $(TARGET_DIR)/etc/init.d/S99tvheadend endef +define TVHEADEND_USERS +tvheadend -1 tvheadend -1 * /home/tvheadend - video TVHeadend daemon +endef + #---------------------------------------------------------------------------- # tvheadend is not an autotools-based package, but it is possible to # call its ./configure script as if it were an autotools one.
Signature · 1 line
1.7.2.5
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Yann" == Yann E MORIN <[email protected]> writes:
Yann> Hello All!
Yann> Here is a series that allows packages to create users.
Yann> Packages that install daemons may well want to run those daemons as Yann> non-root users to avoid security issues. Currently, there are two users Yann> of choice to run 'generic' daemons: root or daemon (although there are Yann> a few dedicated users to run a few services: mail, sshd, ftp...).
Yann> This series builds upon both the package infrastrucutre to define the Yann> user(s) a package may want to create, and the filesystem infrastructure Yann> to actually generate these users, and chown their ${HOME}s.
Yann> Documentation is updated accordingly.
Yann> As a proof of concept, the package tvheadend has been updated to use Yann> a dedicated user to run its daemon as (call me stubborn! ;-] ).
Committed series, thanks!
Signature · 1 line
Bye, Peter Korsgaard