system: allow/disallow root login, accept encoded passwords
PATCH v6 1/1 system: allow/disallow root login, accept encoded passwords
From: Lorenzo Catucci <[email protected]>
Currently, there is only two possibilities regarding the root account:
- it is enabled with no password (the default)
- it is enabled, using a clear-text, user-provided password
This is deemed insufficient in many cases, especially when the .config file has to be published (e.g. for the GPL compliance, or any other reason.).
Fix that in two ways:
- add a bolean option that allows/disallows root login altogether,
which defaults to 'y' to keep backward compatibility;
- accept already-encoded passwords, which we recognise as starting
with either of $1$, $5$ or $6$ (resp. for md5, sha256 or sha512).
[yann.morin.1998 at free.fr:
- don't add a choice to select between clear-text/encoded password,
use a single prompt;
- differentiate in the password hook itself;
- rewrite parts of the help entry;
- rewrite and expand the commit log
]
---
Notes:
Lorenzo, I did not add your Acked-by tag, since there was some changes prompted by Arnout; I however kept your Tested-by since the logic is still the same. Feel free to review this iteration again. Thanks! :-)
---
Chanages v5 -> v6:
- use simpler $(filter) (Arnout)
- fix default value (Arnout)
- expand help about doubling $s (Arnout)
Changes v4 -> v5:
- use makefile syntax instead of shell (Thomas)
- typoes (Thomas)
- fix up the commit log (it never was possible to disable root login)
--- system/Config.in | 30 +++++++++++++++++++++--------- system/system.mk | 22 ++++++++++++++++------ 2 files changed, 37 insertions(+), 15 deletions(-)
system/Config.in +21 -9
@@ -176,26 +176,38 @@ endif if BR2_ROOTFS_SKELETON_DEFAULT +config BR2_TARGET_ENABLE_ROOT_LOGIN + bool "Enable root login" + default y + help + Enable root login password + config BR2_TARGET_GENERIC_ROOT_PASSWD string "Root password" default "" + depends on BR2_TARGET_ENABLE_ROOT_LOGIN help - Set the initial root password (in clear). It will be md5-encrypted. + Set the initial root password. If set to empty (the default), then no root password will be set, and root will need no password to log in. - WARNING! WARNING! - Although pretty strong, MD5 is now an old hash function, and - suffers from some weaknesses, which makes it susceptible to attacks. - It is showing its age, so this root password should not be trusted - to properly secure any product that can be shipped to the wide, - hostile world. + If the password starts with any of $1$, $5$ or $6$, it is considered + to be already crypt-encoded with respectively md5, sha256 or sha512. + Any other value is taken to be a clear-text value, and is crypt-encoded + as per the "Passwords encoding" scheme, above. + + Note: "$" signs in the hashed password must be doubled. For example, + if the hashed password is "$1$longsalt$v35DIIeMo4yUfI23yditq0", + then you must enter it as "$$1$$longsalt$$v35DIIeMo4yUfI23yditq0" + (this is necessary otherwise make would attempt to interpret the $ + as a variable expansion). WARNING! WARNING! - The password appears in clear in the .config file, and may appear + The password appears as-is in the .config file, and may appear in the build log! Avoid using a valuable password if either the - .config file or the build log may be distributed! + .config file or the build log may be distributed, or at the + very least use a strong cryptographic hash for your password! choice bool "/bin/sh"
system/system.mk +16 -6
@@ -34,7 +34,7 @@ endef TARGET_FINALIZE_HOOKS += SYSTEM_ISSUE endif -ifneq ($(TARGET_GENERIC_ROOT_PASSWD),) +ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y) PACKAGES += host-mkpasswd endif
@@ -69,12 +69,22 @@ TARGET_FINALIZE_HOOKS += SET_NETWORK ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y) -define SYSTEM_ROOT_PASSWD - [ -n "$(TARGET_GENERIC_ROOT_PASSWD)" ] && \ - TARGET_GENERIC_ROOT_PASSWD_HASH=$$($(MKPASSWD) -m "$(TARGET_GENERIC_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)"); \ - $(SED) "s,^root:[^:]*:,root:$$TARGET_GENERIC_ROOT_PASSWD_HASH:," $(TARGET_DIR)/etc/shadow +ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y) +ifeq ($(TARGET_GENERIC_ROOT_PASSWD),) +SYSTEM_ROOT_PASSWORD = +else ifneq ($(filter $$1$$% $$5$$% $$6$$%,$(TARGET_GENERIC_ROOT_PASSWD)),) +SYSTEM_ROOT_PASSWORD = $(TARGET_GENERIC_ROOT_PASSWD) +else +SYSTEM_ROOT_PASSWORD = $(shell $(MKPASSWD) -m "$(TARGET_GENERIC_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)") +endif +else # !BR2_TARGET_ENABLE_ROOT_LOGIN +SYSTEM_ROOT_PASSWORD = * +endif + +define SYSTEM_SET_ROOT_PASSWD + $(SED) 's,^root:[^:]*:,root:$(SYSTEM_ROOT_PASSWORD):,' $(TARGET_DIR)/etc/shadow endef -TARGET_FINALIZE_HOOKS += SYSTEM_ROOT_PASSWD +TARGET_FINALIZE_HOOKS += SYSTEM_SET_ROOT_PASSWD ifeq ($(BR2_SYSTEM_BIN_SH_NONE),y) define SYSTEM_BIN_SH
Signature · 1 line
1.9.1
PATCH v6 1/1 system: allow/disallow root login, accept encoded passwords
Quoted 3 lines · Yann E. MORIN
From: Lorenzo Catucci <[email protected]>
Currently, there is only two possibilities regarding the root account:
are
Quoted 10 lines
- it is enabled with no password (the default)
- it is enabled, using a clear-text, user-provided passwordThis is deemed insufficient in many cases, especially when the .config file has to be published (e.g. for the GPL compliance, or any other reason.).
Fix that in two ways:
- add a bolean option that allows/disallows root login altogether,
boolean
Quoted 9 lines
which defaults to 'y' to keep backward compatibility;- accept already-encoded passwords, which we recognise as starting
with either of $1$, $5$ or $6$ (resp. for md5, sha256 or sha512).Signed-off-by Lorenzo M. Catucci <[email protected]>[yann.morin.1998 at free.fr:
- don't add a choice to select between clear-text/encoded password,use a single prompt;
Quoted 8 lines
- differentiate in the password hook itself;
- rewrite parts of the help entry;
- rewrite and expand the commit log
]Signed-off-by Yann E. MORIN <[email protected]>Cc Thomas Petazzoni <[email protected]>Cc Arnout Vandecappelle <[email protected]>Tested-by "Lorenzo M. Catucci" <[email protected]>
A few more optional suggestions below.
Quoted 27 lines
---
Notes:
Lorenzo, I did not add your Acked-by tag, since there was some changes prompted by Arnout; I however kept your Tested-by since the logic is still the same. Feel free to review this iteration again. Thanks! :-)---
Chanages v5 -> v6:
- use simpler $(filter) (Arnout)
- fix default value (Arnout)
- expand help about doubling $s (Arnout)Changes v4 -> v5:
- use makefile syntax instead of shell (Thomas)
- typoes (Thomas)
- fix up the commit log (it never was possible to disable root login)--- system/Config.in | 30 +++++++++++++++++++++--------- system/system.mk | 22 ++++++++++++++++------ 2 files changed, 37 insertions(+), 15 deletions(-)system/Config.in +0
-0
system/Config.in endif · line 183
Quoted 8 lines
system/Config.in +5
-0@@ -176,26 +176,38 @@ endif if BR2_ROOTFS_SKELETON_DEFAULT +config BR2_TARGET_ENABLE_ROOT_LOGIN + bool "Enable root login" + default y + help + Enable root login password
Perhaps more explicitly: "If not enabled, root login is still possible with
e.g. an authorized ssh key".
Quoted 56 lines
system/Config.in +16
-9+ config BR2_TARGET_GENERIC_ROOT_PASSWD string "Root password" default "" + depends on BR2_TARGET_ENABLE_ROOT_LOGIN help - Set the initial root password (in clear). It will be md5-encrypted. + Set the initial root password. If set to empty (the default), then no root password will be set, and root will need no password to log in. - WARNING! WARNING! - Although pretty strong, MD5 is now an old hash function, and - suffers from some weaknesses, which makes it susceptible to attacks. - It is showing its age, so this root password should not be trusted - to properly secure any product that can be shipped to the wide, - hostile world. + If the password starts with any of $1$, $5$ or $6$, it is considered + to be already crypt-encoded with respectively md5, sha256 or sha512. + Any other value is taken to be a clear-text value, and is crypt-encoded + as per the "Passwords encoding" scheme, above. + + Note: "$" signs in the hashed password must be doubled. For example, + if the hashed password is "$1$longsalt$v35DIIeMo4yUfI23yditq0", + then you must enter it as "$$1$$longsalt$$v35DIIeMo4yUfI23yditq0" + (this is necessary otherwise make would attempt to interpret the $ + as a variable expansion). WARNING! WARNING! - The password appears in clear in the .config file, and may appear + The password appears as-is in the .config file, and may appear in the build log! Avoid using a valuable password if either the - .config file or the build log may be distributed! + .config file or the build log may be distributed, or at the + very least use a strong cryptographic hash for your password! choice bool "/bin/sh"system/system.mk +1
-1@@ -34,7 +34,7 @@ endef TARGET_FINALIZE_HOOKS += SYSTEM_ISSUE endif -ifneq ($(TARGET_GENERIC_ROOT_PASSWD),) +ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y) PACKAGES += host-mkpasswd endif@@ -69,12 +69,22 @@ TARGET_FINALIZE_HOOKS += SET_NETWORK ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y)
system/system.mk TARGET_FINALIZE_HOOKS += SET_NETWORK · line 77
Quoted 10 lines
system/system.mk +6
-4-define SYSTEM_ROOT_PASSWD - [ -n "$(TARGET_GENERIC_ROOT_PASSWD)" ] && \ - TARGET_GENERIC_ROOT_PASSWD_HASH=$$($(MKPASSWD) -m "$(TARGET_GENERIC_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)"); \ - $(SED) "s,^root:[^:]*:,root:$$TARGET_GENERIC_ROOT_PASSWD_HASH:," $(TARGET_DIR)/etc/shadow +ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y) +ifeq ($(TARGET_GENERIC_ROOT_PASSWD),) +SYSTEM_ROOT_PASSWORD = +else ifneq ($(filter $$1$$% $$5$$% $$6$$%,$(TARGET_GENERIC_ROOT_PASSWD)),) +SYSTEM_ROOT_PASSWORD = $(TARGET_GENERIC_ROOT_PASSWD) +else
Perhaps the PACKAGES += host-mkpasswd should move here?
Perhaps add a comment:
# This variable will only be evaluated in the finalize stage, so we can be sure
# that host-mkpasswd has already been built.
Regards,
Arnout
Quoted 15 lines
system/system.mk +9
-1+SYSTEM_ROOT_PASSWORD = $(shell $(MKPASSWD) -m "$(TARGET_GENERIC_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)") +endif +else # !BR2_TARGET_ENABLE_ROOT_LOGIN +SYSTEM_ROOT_PASSWORD = * +endif + +define SYSTEM_SET_ROOT_PASSWD + $(SED) 's,^root:[^:]*:,root:$(SYSTEM_ROOT_PASSWORD):,' $(TARGET_DIR)/etc/shadow endef -TARGET_FINALIZE_HOOKS += SYSTEM_ROOT_PASSWD +TARGET_FINALIZE_HOOKS += SYSTEM_SET_ROOT_PASSWD ifeq ($(BR2_SYSTEM_BIN_SH_NONE),y) define SYSTEM_BIN_SH
Signature · 6 lines
Arnout Vandecappelle arnout at mind be Senior Embedded Software Architect +32-16-286500 Essensium/Mind http://www.mind.be G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle GPG fingerprint: 7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
PATCH v6 1/1 system: allow/disallow root login, accept encoded passwords
In reply to Yann E. MORINYann,
I've had to insert the following fixup patch to import your v6 into master:
system/system.mk +1 -1
@@ -35,7 +35,7 @@ TARGET_FINALIZE_HOOKS += SYSTEM_ISSUE endif ifneq ($(TARGET_GENERIC_ROOT_PASSWD),) -TARGETS += host-mkpasswd +PACKAGES += host-mkpasswd endif define SET_NETWORK_LOCALHOST
While I concur with Arnout's call for moving that line just before the $(shell $(MKPASSWD) call, I can confirm both
As for Arnout's suggestion about "config BR2_TARGET_ENABLE_ROOT_LOGIN", I'd replace the "Enable root login password" with "Enable console interactive root login", and then go on to explain there can be other login means like authorized ssh keys or sudo.
Thank you very much, yours
lorenzo
Quoted 146 lines · Yann E. MORIN
From: Lorenzo Catucci <[email protected]>
Currently, there is only two possibilities regarding the root account:
- it is enabled with no password (the default)
- it is enabled, using a clear-text, user-provided passwordThis is deemed insufficient in many cases, especially when the .config file has to be published (e.g. for the GPL compliance, or any other reason.).
Fix that in two ways:
- add a bolean option that allows/disallows root login altogether,
which defaults to 'y' to keep backward compatibility;- accept already-encoded passwords, which we recognise as starting
with either of $1$, $5$ or $6$ (resp. for md5, sha256 or sha512).Signed-off-by Lorenzo M. Catucci <[email protected]>[yann.morin.1998 at free.fr:
- don't add a choice to select between clear-text/encoded password,use a single prompt;- differentiate in the password hook itself;
- rewrite parts of the help entry;
- rewrite and expand the commit log
]Signed-off-by Yann E. MORIN <[email protected]>Cc Thomas Petazzoni <[email protected]>Cc Arnout Vandecappelle <[email protected]>Tested-by "Lorenzo M. Catucci" <[email protected]>---
Notes:
Lorenzo, I did not add your Acked-by tag, since there was some changes prompted by Arnout; I however kept your Tested-by since the logic is still the same. Feel free to review this iteration again. Thanks! :-)---
Chanages v5 -> v6:
- use simpler $(filter) (Arnout)
- fix default value (Arnout)
- expand help about doubling $s (Arnout)Changes v4 -> v5:
- use makefile syntax instead of shell (Thomas)
- typoes (Thomas)
- fix up the commit log (it never was possible to disable root login)--- system/Config.in | 30 +++++++++++++++++++++--------- system/system.mk | 22 ++++++++++++++++------ 2 files changed, 37 insertions(+), 15 deletions(-)system/Config.in +21
-9@@ -176,26 +176,38 @@ endif if BR2_ROOTFS_SKELETON_DEFAULT +config BR2_TARGET_ENABLE_ROOT_LOGIN + bool "Enable root login" + default y + help + Enable root login password + config BR2_TARGET_GENERIC_ROOT_PASSWD string "Root password" default "" + depends on BR2_TARGET_ENABLE_ROOT_LOGIN help - Set the initial root password (in clear). It will be md5-encrypted. + Set the initial root password. If set to empty (the default), then no root password will be set, and root will need no password to log in. - WARNING! WARNING! - Although pretty strong, MD5 is now an old hash function, and - suffers from some weaknesses, which makes it susceptible to attacks. - It is showing its age, so this root password should not be trusted - to properly secure any product that can be shipped to the wide, - hostile world. + If the password starts with any of $1$, $5$ or $6$, it is considered + to be already crypt-encoded with respectively md5, sha256 or sha512. + Any other value is taken to be a clear-text value, and is crypt-encoded + as per the "Passwords encoding" scheme, above. + + Note: "$" signs in the hashed password must be doubled. For example, + if the hashed password is "$1$longsalt$v35DIIeMo4yUfI23yditq0", + then you must enter it as "$$1$$longsalt$$v35DIIeMo4yUfI23yditq0" + (this is necessary otherwise make would attempt to interpret the $ + as a variable expansion). WARNING! WARNING! - The password appears in clear in the .config file, and may appear + The password appears as-is in the .config file, and may appear in the build log! Avoid using a valuable password if either the - .config file or the build log may be distributed! + .config file or the build log may be distributed, or at the + very least use a strong cryptographic hash for your password! choice bool "/bin/sh"system/system.mk +16
-6@@ -34,7 +34,7 @@ endef TARGET_FINALIZE_HOOKS += SYSTEM_ISSUE endif -ifneq ($(TARGET_GENERIC_ROOT_PASSWD),) +ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y) PACKAGES += host-mkpasswd endif@@ -69,12 +69,22 @@ TARGET_FINALIZE_HOOKS += SET_NETWORK ifeq ($(BR2_ROOTFS_SKELETON_DEFAULT),y) -define SYSTEM_ROOT_PASSWD - [ -n "$(TARGET_GENERIC_ROOT_PASSWD)" ] && \ - TARGET_GENERIC_ROOT_PASSWD_HASH=$$($(MKPASSWD) -m "$(TARGET_GENERIC_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)"); \ - $(SED) "s,^root:[^:]*:,root:$$TARGET_GENERIC_ROOT_PASSWD_HASH:," $(TARGET_DIR)/etc/shadow +ifeq ($(BR2_TARGET_ENABLE_ROOT_LOGIN),y) +ifeq ($(TARGET_GENERIC_ROOT_PASSWD),) +SYSTEM_ROOT_PASSWORD = +else ifneq ($(filter $$1$$% $$5$$% $$6$$%,$(TARGET_GENERIC_ROOT_PASSWD)),) +SYSTEM_ROOT_PASSWORD = $(TARGET_GENERIC_ROOT_PASSWD) +else +SYSTEM_ROOT_PASSWORD = $(shell $(MKPASSWD) -m "$(TARGET_GENERIC_PASSWD_METHOD)" "$(TARGET_GENERIC_ROOT_PASSWD)") +endif +else # !BR2_TARGET_ENABLE_ROOT_LOGIN +SYSTEM_ROOT_PASSWORD = * +endif + +define SYSTEM_SET_ROOT_PASSWD + $(SED) 's,^root:[^:]*:,root:$(SYSTEM_ROOT_PASSWORD):,' $(TARGET_DIR)/etc/shadow endef -TARGET_FINALIZE_HOOKS += SYSTEM_ROOT_PASSWD +TARGET_FINALIZE_HOOKS += SYSTEM_SET_ROOT_PASSWD ifeq ($(BR2_SYSTEM_BIN_SH_NONE),y) define SYSTEM_BIN_SH
Signature · 6 lines
+-------------------------+----------------------------------------------+ | Lorenzo M. Catucci | Centro di Calcolo e Documentazione | | catucci at ccd.uniroma2.it | Universit? degli Studi di Roma "Tor Vergata" | | | Via O. Raimondo 18 ** I-00173 ROMA ** ITALY | | Tel. +39 06 7259 2255 | Fax. +39 06 7259 2125 | +-------------------------+----------------------------------------------+
PATCH v6 1/1 system: allow/disallow root login, accept encoded passwords
Lorenzo, All,
On 2015-05-03 13:57 +0200, Lorenzo M. Catucci spake thusly:
Quoted 9 lines
Yann,
I've had to insert the following fixup patch to import your v6 into master:
system/system.mk +0
-0
system/system.mk TARGET_FINALIZE_HOOKS += SYSTEM_ISSUE · line 38
Quoted 5 lines
system/system.mk +1
-1@@ -35,7 +35,7 @@ TARGET_FINALIZE_HOOKS += SYSTEM_ISSUE endif ifneq ($(TARGET_GENERIC_ROOT_PASSWD),) -TARGETS += host-mkpasswd +PACKAGES += host-mkpasswd
I don't understand: this is already th4e case in the v6 I sent:
https://patchwork.ozlabs.org/patch/467351/
Quoted 7 lines
system/system.mk +0
-0endif define SET_NETWORK_LOCALHOSTWhile I concur with Arnout's call for moving that line just before the $(shell $(MKPASSWD) call, I can confirm both
OK, I'll move it.
Quoted 7 lines
As for Arnout's suggestion about "config
BR2_TARGET_ENABLE_ROOT_LOGIN", I'd replace the "Enable root login password" with "Enable console interactive root login", and then go on to explain there can be other login means like authorized ssh keys or sudo.
Well, it's not only console, it can also be via ssh.
I've changed the boolean prompt to:
bool "Enable root login with password"
and the help text to:
Allow root to log in with a password.
If not enabled, root will not be able to log in with a password. However, if you have an ssh server and you add an ssh key, you can still allow root to log in. Alternatively, you can use sudo to become root.
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. | '------------------------------^-------^------------------^--------------------'