Skip to contentSkip to conversation

PAM support in Busybox if linux-pam is built

PATCH New Dmitry 2 participants 9 messages Sep 4, 2012 – Sep 5, 2012

lore
Share & tools
lore

Dmitry

author
#0 lore raw

PATCH 1/2 PAM support in Busybox if linux-pam is built

---
 package/busybox/Config.in  |   11 +++++++++++
 package/busybox/busybox.mk |   12 ++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
package/busybox/Config.in +11 -0
index dedcf18..2a9cbf1 100644
@@ -62,6 +62,17 @@ config BR2_PACKAGE_BUSYBOX_WATCHDOG
 	  Install the watchdog daemon startup script,
 	  that just start at the boot the busybox watchdog daemon.
 
+config BR2_PACKAGE_BUSYBOX_PAM
+	bool "Enable PAM support in Busybox"
+	default n
+	depends on BR2_PACKAGE_LINUX_PAM
+	help
+	  If this item is selected, Busybox login will use the PAM stack
+	  for local logins. Local logins with null password are allowed
+	  for users with records in /etc/passwd ("default" and "root").
+	  The default PAM configuration file requires user accounts with
+	  nonzero length passwords.
+
 if BR2_PACKAGE_BUSYBOX_WATCHDOG
 
 config BR2_PACKAGE_BUSYBOX_WATCHDOG_PERIOD
package/busybox/busybox.mk +12 -0
index 33f8633..21942c6 100644
@@ -164,6 +164,17 @@ define BUSYBOX_INSTALL_WATCHDOG_SCRIPT
 endef
 endif
 
+ifeq ($(BR2_PACKAGE_BUSYBOX_PAM),y)
+BUSYBOX_DEPENDENCIES += linux-pam
+define BUSYBOX_ENABLE_PAM
+	$(call KCONFIG_ENABLE_OPT,CONFIG_PAM,$(BUSYBOX_BUILD_CONFIG))
+endef
+else
+define BUSYBOX_ENABLE_PAM
+	$(call KCONFIG_DISABLE_OPT,CONFIG_PAM,$(BUSYBOX_BUILD_CONFIG))
+endef
+endif
+
 # We do this here to avoid busting a modified .config in configure
 BUSYBOX_POST_EXTRACT_HOOKS += BUSYBOX_COPY_CONFIG
 
@@ -179,6 +190,7 @@ define BUSYBOX_CONFIGURE_CMDS
 	$(BUSYBOX_DISABLE_MMU_APPLETS)
 	$(BUSYBOX_SET_INIT)
 	$(BUSYBOX_SET_WATCHDOG)
+	$(BUSYBOX_ENABLE_PAM)
 	@yes "" | $(MAKE) ARCH=$(KERNEL_ARCH) CROSS_COMPILE="$(TARGET_CROSS)" \
 		-C $(@D) oldconfig
 endef
Signature · 1 line
1.7.2.5
author
#1 lore raw

PATCH 2/2 Provide PAM default configuration files when building linux-pam package

---
 package/linux-pam/default      |    8 ++++++++
 package/linux-pam/linux-pam.mk |    7 +++++++
 package/linux-pam/login        |    9 +++++++++
 3 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 package/linux-pam/default
 create mode 100644 package/linux-pam/login
package/linux-pam/default new file +8 -0
new file mode 100644
index 0000000..0bd5ba0
@@ -0,0 +1,8 @@
+#
+# default; standard UN*X access
+#
+auth     required       pam_unix.so
+account  required       pam_unix.so
+password required       pam_unix.so
+session  required       pam_unix.so
+
package/linux-pam/linux-pam.mk +7 -0
index 48cb073..2807bc1 100644
@@ -24,4 +24,11 @@ ifeq ($(BR2_PACKAGE_LIBINTL),y)
 	LINUX_PAM_MAKE_OPT += LIBS=-lintl
 endif
 
+define LINUX_PAM_CONFFILES
+	$(INSTALL) -D -m 0644 package/linux-pam/default $(TARGET_DIR)/etc/pam.d/default
+	$(INSTALL) -D -m 0644 package/linux-pam/login $(TARGET_DIR)/etc/pam.d/login
+endef
+
+LINUX_PAM_POST_INSTALL_TARGET_HOOKS += LINUX_PAM_CONFFILES
+
 $(eval $(autotools-package))
package/linux-pam/login new file +9 -0
new file mode 100644
index 0000000..d65a9d4
@@ -0,0 +1,9 @@
+#
+# login: allow local logins to users with entries in /etc/passwd and
+# /etc/shadow even with null password
+#
+auth      required       pam_unix.so nullok
+account   required       pam_unix.so nullok
+password  required       pam_unix.so nullok
+session   required       pam_unix.so nullok
+
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH 2/2 Provide PAM default configuration files when building linux-pam package

Dmitry, All,

Quoted 5 lines · On Tuesday 04 September 2012 05:28:42 Dmitry wrote:
---
 package/linux-pam/default      |    8 ++++++++
 package/linux-pam/linux-pam.mk |    7 +++++++
 package/linux-pam/login        |    9 +++++++++

I think that this patch, which adds the default files, should come _before_ the busybox patch. If only the busybox patch were to be applied, then PAM would not be useable as it would lack those files.

In the current order, iIt would also break 'bisectability'.

Quoted 10 lines
 3 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 package/linux-pam/default
 create mode 100644 package/linux-pam/login
package/linux-pam/default new file +0 -0
new file mode 100644
index 0000000..0bd5ba0

package/linux-pam/default line 8

Quoted 8 lines
package/linux-pam/default new file +8 -0
@@ -0,0 +1,8 @@
+#
+# default; standard UN*X access
+#
+auth     required       pam_unix.so
+account  required       pam_unix.so
+password required       pam_unix.so
+session  required       pam_unix.so
+

I am not a PAM expert, so I can't say whether these settings are correct, enough, or whatever. I'd trust close to anybody on this subject. ;-)

package/linux-pam/linux-pam.mk ifeq ($(BR2_PACKAGE_LIBINTL),y) · line 29

Quoted 11 lines
package/linux-pam/linux-pam.mk +3 -0
index 48cb073..2807bc1 100644
@@ -24,4 +24,11 @@ ifeq ($(BR2_PACKAGE_LIBINTL),y)
 	LINUX_PAM_MAKE_OPT += LIBS=-lintl
 endif
 
+define LINUX_PAM_CONFFILES
+	$(INSTALL) -D -m 0644 package/linux-pam/default $(TARGET_DIR)/etc/pam.d/default
+	$(INSTALL) -D -m 0644 package/linux-pam/login $(TARGET_DIR)/etc/pam.d/login

I'd use:

    $(INSTALL) -D -m 0644 $(@D)/default $(TARGET_DIR)/etc/pam.d/default

Also, shouldn't these files get special permission (ie. redable only by root, or stuff like that)? If so, then use:
LINUX_PAM_PERMISSIONS = .....

Quoted 11 lines
package/linux-pam/linux-pam.mk +4 -0
+endef
+
+LINUX_PAM_POST_INSTALL_TARGET_HOOKS += LINUX_PAM_CONFFILES
+
 $(eval $(autotools-package))
package/linux-pam/login new file +0 -0
new file mode 100644
index 0000000..d65a9d4

package/linux-pam/login line 8

Quoted 8 lines
package/linux-pam/login new file +8 -0
@@ -0,0 +1,9 @@
+#
+# login: allow local logins to users with entries in /etc/passwd and
+# /etc/shadow even with null password
+#
+auth      required       pam_unix.so nullok
+account   required       pam_unix.so nullok
+password  required       pam_unix.so nullok
+session   required       pam_unix.so nullok

Ditto, I'm not a PAM expert...

Although I doubt I'd like a system where null passwords are OK... :-/ At the risk of adding to the option maze, I'd suggest at least adding a config knob to enable that. For example:

config BR2_PACKAGE_LINUX_PAM_NULL_PASSWD_OK
bool "Allow null passwords"
help
Allow local logins to users with entries in /etc/passwd and /etc/shadow even with null password.

And only add the "nullok" if that option is set.

If that's not OK to add such an option, then I'd say we should remove the "nullok" stuff, and leave it to a local post-build script that tweaks this file if the user really wants to allow local null-password logins.

IMNSHO, the defaut should be a secure system.

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.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

PATCH 2/2 Provide PAM default configuration files when building linux-pam package

Yann,

Thanks for your comments. Replies below.

Quoted 10 lines · Yann E. MORIN
Quoted 4 lines
---
 package/linux-pam/default      |    8 ++++++++
 package/linux-pam/linux-pam.mk |    7 +++++++
 package/linux-pam/login        |    9 +++++++++

I think that this patch, which adds the default files, should come _before_ the busybox patch. If only the busybox patch were to be applied, then PAM would not be useable as it would lack those files.

In the current order, iIt would also break 'bisectability'.

This patch was a "reasonable compromise" to have a somewhat working system emulating PAM-less behavior when PAM is enabled in login and no proper PAM configs are provided.
I think that in a real project, a post-build filesystem fix should replace these files with something more sensible (like mine does). Regarding ordering, I'll try to switch the order.

Quoted 11 lines

package/linux-pam/default line 8

Quoted 8 lines
package/linux-pam/default new file +8 -0
+#
+# default; standard UN*X access
+#
+auth     required       pam_unix.so
+account  required       pam_unix.so
+password required       pam_unix.so
+session  required       pam_unix.so
+

I am not a PAM expert, so I can't say whether these settings are correct, enough, or whatever. I'd trust close to anybody on this subject. ;-)

This is an example from PAM documentation: in all entries standard Unix files (passwd/shadow) are checked, and null passwords are not allowed.

Quoted 6 lines

package/linux-pam/linux-pam.mk ifeq ($(BR2_PACKAGE_LIBINTL),y) · line 29

Quoted 3 lines
package/linux-pam/linux-pam.mk +3 -0
+define LINUX_PAM_CONFFILES
+     $(INSTALL) -D -m 0644 package/linux-pam/default $(TARGET_DIR)/etc/pam.d/default
+     $(INSTALL) -D -m 0644 package/linux-pam/login $(TARGET_DIR)/etc/pam.d/login

I'd use:

    $(INSTALL) -D -m 0644 $(@D)/default $(TARGET_DIR)/etc/pam.d/default

But $(@D) is the build directory, while the files are part of Buildroot package rather than PAM itself. $(@D) is to my understanding output/build/linux-pam-x.y.z

Quoted 4 lines

Also, shouldn't these files get special permission (ie. redable only by root, or stuff like that)? If so, then use:
LINUX_PAM_PERMISSIONS = .....

Not sure if that's needed: they do not have anything secret, just nobody other than root can change them.

Quoted 9 lines

package/linux-pam/login line 8

Quoted 7 lines
package/linux-pam/login new file +7 -0
+# login: allow local logins to users with entries in /etc/passwd and
+# /etc/shadow even with null password
+#
+auth      required       pam_unix.so nullok
+account   required       pam_unix.so nullok
+password  required       pam_unix.so nullok
+session   required       pam_unix.so nullok

Ditto, I'm not a PAM expert...

Neither am I... Just porting.

Quoted 2 lines

Although I doubt I'd like a system where null passwords are OK... :-/

PAM-less mode allows this: the above config applies to local logins only via busybox login.

Quoted 10 lines

At the risk of adding to the option maze, I'd suggest at least adding a config knob to enable that. For example:

config BR2_PACKAGE_LINUX_PAM_NULL_PASSWD_OK
bool "Allow null passwords"
help
Allow local logins to users with entries in /etc/passwd and /etc/shadow even with null password.

And only add the "nullok" if that option is set.

I'm afraid this is too much. And it should be provided for the PAM-less config as well.

One who wants to use PAM will likely design a proper authentication scheme and provide their own better PAM configs.

Quoted 6 lines

If that's not OK to add such an option, then I'd say we should remove the "nullok" stuff, and leave it to a local post-build script that tweaks this file if the user really wants to allow local null-password logins.

IMNSHO, the defaut should be a secure system.

But it is not by default: root can login w/o password

http://git.buildroot.net/buildroot/tree/fs/skeleton/etc/shadow

this is /etc/shadow from buildroot git which is installed by default:
am I correct?

Thanks.

Signature · 3 lines
Dmitry Golubovsky

Anywhere on the Web
#4 lore raw

PATCH 2/2 Provide PAM default configuration files when building linux-pam package

Dmitry, All,

Quoted 5 lines · On Tuesday 04 September 2012 19:33:08 Dmitry Golubovsky wrote:
Quoted 4 lines · Yann E. MORIN

I think that this patch, which adds the default files, should come _before_ the busybox patch. If only the busybox patch were to be applied, then PAM would not be useable as it would lack those files.

Quoted 7 lines
Quoted 1 line

In the current order, iIt would also break 'bisectability'.

This patch was a "reasonable compromise" to have a somewhat working system emulating PAM-less behavior when PAM is enabled in login and no proper PAM configs are provided.
I think that in a real project, a post-build filesystem fix should replace these files with something more sensible (like mine does).

Ah, OK I get it. With these two files, even if no PAM configuration is provided by other means, it would behave as if PAM was not enabled. Right?

Quoted 1 line

Regarding ordering, I'll try to switch the order.

Yes, because without this patch, if linux-pam is enabled, and PAM is enabled in busybox (which is possible with the previous patch), what would be the behaviour?

I guess that, without its config files, PAM would not allow anything, right?

If so, then the default files should come _before_ they are required.

Quoted 12 lines
Quoted 11 lines

package/linux-pam/default line 8

Quoted 8 lines
package/linux-pam/default new file +8 -0
+#
+# default; standard UN*X access
+#
+auth     required       pam_unix.so
+account  required       pam_unix.so
+password required       pam_unix.so
+session  required       pam_unix.so
+

I am not a PAM expert, so I can't say whether these settings are correct, enough, or whatever. I'd trust close to anybody on this subject. ;-)

Quoted 1 line

This is an example from PAM documentation:

OK, good! :-)

Quoted 10 lines
Quoted 6 lines

package/linux-pam/linux-pam.mk ifeq ($(BR2_PACKAGE_LIBINTL),y) · line 29

Quoted 3 lines
package/linux-pam/linux-pam.mk +3 -0
+define LINUX_PAM_CONFFILES
+     $(INSTALL) -D -m 0644 package/linux-pam/default $(TARGET_DIR)/etc/pam.d/default
+     $(INSTALL) -D -m 0644 package/linux-pam/login $(TARGET_DIR)/etc/pam.d/login

I'd use:

    $(INSTALL) -D -m 0644 $(@D)/default $(TARGET_DIR)/etc/pam.d/default

But $(@D) is the build directory, while the files are part of Buildroot package rather than PAM itself. $(@D) is to my understanding output/build/linux-pam-x.y.z

Gah, my bad...
This morning's cafeine dose is no longer having any effect... :-(

Quoted 6 lines
Quoted 3 lines

Also, shouldn't these files get special permission (ie. redable only by root, or stuff like that)? If so, then use:
LINUX_PAM_PERMISSIONS = .....

Not sure if that's needed: they do not have anything secret, just nobody other than root can change them.

OK, I just checked on my distro, and indeed there're world-readable. /etc/shadow is not, however, and that was what I probably was thinking about (damn lack of cafeine is kicking again...)

Quoted 2 lines
Quoted 2 lines

At the risk of adding to the option maze, I'd suggest at least adding a config knob to enable that. For example:

[--SNIP--]

Quoted 2 lines

I'm afraid this is too much. And it should be provided for the PAM-less config as well.

Yep.

Quoted 2 lines

One who wants to use PAM will likely design a proper authentication scheme and provide their own better PAM configs.

Granted.

Quoted 2 lines
Quoted 1 line

IMNSHO, the defaut should be a secure system.

But it is not by default: root can login w/o password

Yep again, indeed.

If you resubmit with the ordering reversed, you can add my:

    Acked-by: "Yann E. MORIN" <[email protected]>

for this patch (I'll review the other later).

Thanks for bearing with me. ;-)

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.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH 2/2 Provide PAM default configuration files when building linux-pam package

Yann,

Quoted 8 lines · Yann E. MORIN
Quoted 5 lines

This patch was a "reasonable compromise" to have a somewhat working system emulating PAM-less behavior when PAM is enabled in login and no proper PAM configs are provided.
I think that in a real project, a post-build filesystem fix should replace these files with something more sensible (like mine does).

Ah, OK I get it. With these two files, even if no PAM configuration is provided by other means, it would behave as if PAM was not enabled. Right?

Correct: local logins via busybox login (or whatever calls pam_start with "login" as program name) will be possible for "default" and "root" (but not any other config) even if /etc/shadow has null passwords. At least in my tests it worked so.

Quoted 2 lines

I guess that, without its config files, PAM would not allow anything, right?

Correct.

Quoted 3 lines

If so, then the default files should come _before_ they are required.

Yes, this is reasonable.

Quoted 3 lines

Thanks for bearing with me. ;-)

That's fine: thanks for your comments.

I'll see if there are any more comments on these patches and will try to reorder and resubmit them later tonight.

Signature · 3 lines
Dmitry Golubovsky

Anywhere on the Web
#6 lore raw

PATCH 1/2 PAM support in Busybox if linux-pam is built

In reply to Dmitry

Dmitry, All,

Quoted 17 lines · On Tuesday 04 September 2012 05:28:41 Dmitry wrote:
---
 package/busybox/Config.in  |   11 +++++++++++
 package/busybox/busybox.mk |   12 ++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
package/busybox/Config.in +3 -0
index dedcf18..2a9cbf1 100644
@@ -62,6 +62,17 @@ config BR2_PACKAGE_BUSYBOX_WATCHDOG
 	  Install the watchdog daemon startup script,
 	  that just start at the boot the busybox watchdog daemon.
 
+config BR2_PACKAGE_BUSYBOX_PAM
+	bool "Enable PAM support in Busybox"
+	default n

package/busybox/Config.in config BR2_PACKAGE_BUSYBOX_WATCHDOG · line 77

Quoted 10 lines
package/busybox/Config.in +7 -0
+	depends on BR2_PACKAGE_LINUX_PAM
+	help
+	  If this item is selected, Busybox login will use the PAM stack
+	  for local logins.
 
        Local logins with null password are allowed
+	  for users with records in /etc/passwd ("default" and "root").
 
+	  The default PAM configuration file requires user accounts with
+	  nonzero length passwords.

These two sentences tend to contradict each other. What about:

The default PAM configuration in buildroot allows local users (those with records in /etc/passwd and /etc/shadow) with null passwords to log in.

Then the second sentence can go away, because the PAM config files patch will come before that patch. ;-]

If you can come with another formulation that is not contradictory, that is fine by me, too. ;-)

Quoted 8 lines
package/busybox/Config.in +0 -0
 if BR2_PACKAGE_BUSYBOX_WATCHDOG
 
 config BR2_PACKAGE_BUSYBOX_WATCHDOG_PERIOD
package/busybox/busybox.mk +0 -0
index 33f8633..21942c6 100644

package/busybox/busybox.mk define BUSYBOX_INSTALL_WATCHDOG_SCRIPT · line 169

Quoted 6 lines
package/busybox/busybox.mk +3 -0
@@ -164,6 +164,17 @@ define BUSYBOX_INSTALL_WATCHDOG_SCRIPT
 endef
 endif
 
+ifeq ($(BR2_PACKAGE_BUSYBOX_PAM),y)
+BUSYBOX_DEPENDENCIES += linux-pam
+define BUSYBOX_ENABLE_PAM

To be more in line with other options, I'd suggest this be BUSYBOX_SET_PAM (we already have a bunch of BUSYBOX_SET_XXX, although there are variations). But I have no strong objection to keeping ENABLE.

Otherwise, LGTM. When you resubmit (with at least the help clarification):

    Acked-by: "Yann E. MORIN" <[email protected]>

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.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

PATCH 1/2 PAM support in Busybox if linux-pam is built

Yann,

Quoted 7 lines · Yann E. MORIN

package/busybox/Config.in config BR2_PACKAGE_BUSYBOX_WATCHDOG · line 74

Quoted 5 lines

Local logins with null password are allowed

package/busybox/Config.in +3 -0
+       for users with records in /etc/passwd ("default" and "root").
 
+       The default PAM configuration file requires user accounts with
+       nonzero length passwords.

These two sentences tend to contradict each other. What about:

No, they do not contradict each other because they are about two different files (which may be not so clear as it is written - but I tried to keep the text short).

The first sentence is about /etc/pam.d/login.

The second is about /etc/pam.d/default (which means any program that calls pam_start with arbitrary program name and no match in PAM configs uses /etc/pam.d/default).

Quoted 4 lines

To be more in line with other options, I'd suggest this be BUSYBOX_SET_PAM (we already have a bunch of BUSYBOX_SET_XXX, although there are variations). But I have no strong objection to keeping ENABLE.

I see a whole variety of names:

define BUSYBOX_CONFIGURE_CMDS

	$(BUSYBOX_SET_LARGEFILE)
	$(BUSYBOX_SET_IPV6)
	$(BUSYBOX_SET_RPC)
	$(BUSYBOX_PREFER_STATIC)
	$(BUSYBOX_SET_MDEV)
	$(BUSYBOX_NETKITBASE)
	$(BUSYBOX_NETKITTELNET)
	$(BUSYBOX_INTERNAL_SHADOW_PASSWORDS)
	$(BUSYBOX_DISABLE_MMU_APPLETS)
	$(BUSYBOX_SET_INIT)
	$(BUSYBOX_SET_WATCHDOG)

and there is "DISABLE" ;)

I'd keep "ENABLE".

Thanks.

Signature · 3 lines
Dmitry Golubovsky

Anywhere on the Web
#8 lore raw

PATCH 1/2 PAM support in Busybox if linux-pam is built

In reply to Yann E. MORIN

Yann,

Quoted 2 lines · Yann E. MORIN

Otherwise, LGTM. When you resubmit (with at least the help clarification):

    Acked-by: "Yann E. MORIN" <[email protected]>

OK, the patches have been reordered, the help message has been expanded to mention both files, and where they come form, and that users are advised to supply their own PAM config.

Thanks.

Signature · 3 lines
Dmitry Golubovsky

Anywhere on the Web