Skip to content

Commit f0fb734

Browse files
author
Abhishek Mishra
committed
!Documentation: describe build-time passwd generation workflow.
Document the new mkpasswd-based password generation system and its integration with the build process. Changes: * Add comprehensive mkpasswd tool documentation to components/tools * Update SIM board docs to explain generated passwd workflow * Update ESP32-C3-legacy board docs for passwd generation * Update RX65N board docs with credential handling guidance * Document how to configure and use BOARD_ETC_ROMFS_PASSWD_* options * Explain security benefits of build-time generation vs static files * Update all doc examples from default username "admin" to "root" BREAKING CHANGE: Boards using static /etc/passwd files in ETC_ROMFS must migrate to the new build-time generation workflow documented in Documentation/components/tools/index.rst. The old static passwd files are no longer present in migrated boards; boards that relied on them will fail to build until credentials are configured via Kconfig. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
1 parent 8744e5e commit f0fb734

4 files changed

Lines changed: 167 additions & 39 deletions

File tree

Documentation/components/tools/index.rst

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,113 @@ and host C programs that are important parts of the NuttX build system:
1111
:glob:
1212

1313
./*
14+
15+
.. _mkpasswd_autogen:
16+
17+
mkpasswd — Build-time ``/etc/passwd`` Generation
18+
-------------------------------------------------
19+
20+
``tools/mkpasswd`` is a C host tool (compiled from ``tools/mkpasswd.c``) that
21+
generates a single ``/etc/passwd`` entry at build time. It is invoked
22+
automatically by the ROMFS build step when
23+
``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y`` is set.
24+
25+
Why build-time generation?
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
28+
Shipping a hard-coded default password in firmware is a well-known security
29+
weakness (CWE-798). By generating the ``/etc/passwd`` entry from a
30+
user-supplied plaintext password at build time, each firmware image carries
31+
unique credentials. The build will fail if the password is left empty,
32+
preventing accidental deployments with no credentials.
33+
34+
For improved baseline security, the configured password must be at least
35+
8 characters long.
36+
37+
How it works
38+
~~~~~~~~~~~~
39+
40+
1. The host tool reads the plaintext password from
41+
``CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD``.
42+
2. The password is hashed using the Tiny Encryption Algorithm (TEA) — the
43+
same implementation used at runtime in
44+
``libs/libc/misc/lib_tea_encrypt.c`` — with custom base64 encoding
45+
matching ``apps/fsutils/passwd/passwd_encrypt.c``.
46+
3. The resulting hashed entry is written to
47+
``etctmp/<mountpoint>/passwd`` and then embedded into the ROMFS image.
48+
4. The **plaintext password is never stored in the firmware image**.
49+
50+
Kconfig options
51+
~~~~~~~~~~~~~~~
52+
53+
Enable the feature and configure credentials via ``make menuconfig``:
54+
55+
.. code:: kconfig
56+
57+
CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y
58+
CONFIG_NSH_CONSOLE_LOGIN=y # required to enforce login prompt
59+
CONFIG_BOARD_ETC_ROMFS_PASSWD_USER="root" # default: root
60+
CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD="<secret>" # required, min length 8
61+
CONFIG_BOARD_ETC_ROMFS_PASSWD_UID=0
62+
CONFIG_BOARD_ETC_ROMFS_PASSWD_GID=0
63+
CONFIG_BOARD_ETC_ROMFS_PASSWD_HOME="/"
64+
65+
The TEA encryption keys can be changed from their defaults via
66+
``CONFIG_FSUTILS_PASSWD_KEY1..4``.
67+
68+
``/etc/passwd`` file format
69+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
70+
71+
.. code:: text
72+
73+
user:x:uid:gid:home
74+
75+
Where:
76+
77+
* ``user`` — user name
78+
* ``x`` — TEA-hashed, base64-encoded password
79+
* ``uid`` — numeric user ID
80+
* ``gid`` — numeric group ID
81+
* ``home`` — login directory
82+
83+
Verifying the generated entry
84+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85+
86+
After enabling ``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE`` and setting a
87+
password, rebuild and verify:
88+
89+
1. **Configure and build**:
90+
91+
.. code:: console
92+
93+
$ make menuconfig # enable BOARD_ETC_ROMFS_PASSWD_ENABLE and set password
94+
$ make
95+
96+
2. **Inspect the generated passwd line** (written to the board build tree):
97+
98+
.. code:: console
99+
100+
$ cat boards/<arch>/<chip>/<board>/src/etctmp/etc/passwd
101+
root:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
102+
103+
3. **Verify the plaintext is absent from firmware**:
104+
105+
.. code:: console
106+
107+
$ grep <your-password> boards/<arch>/<chip>/<board>/src/etctmp.c
108+
# must print nothing
109+
110+
Notes on ``savedefconfig``
111+
~~~~~~~~~~~~~~~~~~~~~~~~~~
112+
113+
To avoid leaking credentials into board defconfigs, ``make savedefconfig``
114+
does not save the following options in the generated defconfig:
115+
116+
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD``
117+
* ``CONFIG_FSUTILS_PASSWD_KEY1``
118+
* ``CONFIG_FSUTILS_PASSWD_KEY2``
119+
* ``CONFIG_FSUTILS_PASSWD_KEY3``
120+
* ``CONFIG_FSUTILS_PASSWD_KEY4``
121+
122+
If you need these values for local development, add them manually to your
123+
local defconfig after running ``make savedefconfig``.

Documentation/platforms/renesas/rx65n/boards/rx65n-grrose/index.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,21 +491,21 @@ mounted at /etc and will look like this at run-time:
491491
nsh>
492492
493493
``/etc/init.d/rc.sysinit`` is system init script; ``/etc/init.d/rcS`` is the
494-
start-up script; ``/etc/passwd`` is a the password file. It supports a single
495-
user:
494+
start-up script; ``/etc/passwd`` is the password file.
496495

497-
.. code:: text
496+
The ``/etc/passwd`` file is auto-generated at build time when
497+
``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE`` is set. Enable the option and set
498+
credentials via ``make menuconfig``:
498499

499-
USERNAME: admin
500-
PASSWORD: Administrator
500+
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y``
501+
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_USER`` (default: ``root``)
502+
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD`` (required, build fails if empty)
501503

502-
nsh> cat /etc/passwd
503-
admin:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
504+
The password is hashed with TEA at build time by the host tool
505+
``tools/mkpasswd``; the plaintext is **not** stored in the firmware.
504506

505-
The encrypted passwords in the provided passwd file are only valid if the TEA
506-
key is set to: 012345678 9abcdef0 012345678 9abcdef0. Changes to either the key
507-
or the password word will require regeneration of the ``nsh_romfimg.h`` header
508-
file.
507+
For the full description of the mechanism, TEA key configuration, file format,
508+
and verification steps, see :ref:`mkpasswd_autogen`.
509509

510510
The format of the password file is:
511511

Documentation/platforms/risc-v/esp32c3-legacy/boards/esp32c3-legacy-devkit/ROMFS.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ README
99
that will be mounted at /etc and will look like this at run-time:
1010

1111
NuttShell (NSH) NuttX-10.1.0-RC1
12-
MOTD: username=admin password=Administrator
12+
NuttX login. Configure credentials via make menuconfig.
1313
nsh> ls -Rl /etc
1414
/etc:
1515
dr-xr-xr-x 0 .
@@ -23,18 +23,22 @@ README
2323
nsh>
2424

2525
/etc/init.d/rc.sysinit is system init script; /etc/init.d/rcS is the start-up
26-
script; /etc/passwd is a the password file. It supports a single user:
26+
script; /etc/passwd is the password file.
2727

28-
USERNAME: admin
29-
PASSWORD: Administrator
28+
The /etc/passwd file is auto-generated at build time when
29+
CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE is set. To configure the root user and
30+
password, run 'make menuconfig' and set:
3031

31-
nsh> cat /etc/passwd
32-
admin:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
32+
CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y
33+
CONFIG_BOARD_ETC_ROMFS_PASSWD_USER (default: root)
34+
CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD (required, build fails if empty)
3335

34-
The encrypted passwords in the provided passwd file are only valid if the
35-
TEA key is set to: 012345678 9abcdef0 012345678 9abcdef0. Changes to either
36-
the key or the password word will require regeneration of the nsh_romfimg.h
37-
header file.
36+
The password is hashed with TEA at build time by the host tool
37+
tools/mkpasswd; the plaintext is NOT stored in the firmware image.
38+
39+
For the full description of the mechanism, TEA key configuration, file
40+
format, and verification steps, see Documentation/components/tools/index.rst
41+
(mkpasswd section).
3842

3943
The format of the password file is:
4044

Documentation/platforms/sim/sim/boards/sim/index.rst

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,13 +1903,13 @@ This is a configuration with login password protection for NSH.
19031903

19041904
.. note::
19051905

1906-
This config has password protection enabled. The login info is:
1906+
This config has password protection enabled. The default login info is:
19071907

1908-
* USERNAME: admin
1908+
* USERNAME: root
19091909
* PASSWORD: Administrator
19101910

1911-
The encrypted password is retained in ``/etc/passwd``. I am sure that you
1912-
will find this annoying. You can disable the password protection by
1911+
The encrypted password is retained in ``/etc/passwd``.
1912+
You can disable the password protection by
19131913
de-selecting ``CONFIG_NSH_CONSOLE_LOGIN=y``.
19141914

19151915
can
@@ -2021,24 +2021,23 @@ mounted at ``/etc`` and will look like this at run-time:
20212021
nsh>
20222022
20232023
``/etc/init.d/rc.sysinit`` is system init script; ``/etc/init.d/rcS`` is the
2024-
start-up script; ``/etc/passwd`` is a the password file. It supports a single
2025-
user:
2024+
start-up script; ``/etc/passwd`` is the password file.
20262025

2027-
.. code:: text
2028-
2029-
USERNAME: admin
2030-
PASSWORD: Administrator
2031-
2032-
.. code:: console
2026+
The ``/etc/passwd`` file is auto-generated at build time when
2027+
``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE`` is set. Enable the option and set
2028+
credentials via ``make menuconfig``:
20332029

2034-
nsh> cat /etc/passwd
2035-
admin:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
2030+
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y``
2031+
* ``CONFIG_NSH_CONSOLE_LOGIN=y`` (required, otherwise login is not enforced)
2032+
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_USER`` (default: ``root``)
2033+
* ``CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD`` (required, build fails if empty or shorter than 8 characters)
20362034

2037-
The encrypted passwords in the provided passwd file are only valid if the
2038-
TEA key is set to: 012345678 9abcdef0 012345678 9abcdef0.
2035+
The password is hashed with TEA at build time by the host tool
2036+
``tools/mkpasswd``; the plaintext is **not** stored in the firmware.
20392037

2040-
Changes to either the key or the password word will require regeneration of the
2041-
``nsh_romfimg.h`` header file.
2038+
For the full description of the build-time password generation mechanism,
2039+
TEA key configuration, file format, and verification steps, see
2040+
:ref:`mkpasswd_autogen`.
20422041

20432042
The format of the password file is:
20442043

@@ -2054,6 +2053,21 @@ Where:
20542053
* gid: Group ID (0 for now)
20552054
* home: Login directory (/ for now)
20562055

2056+
For configuration, verification steps, and TEA key details, see
2057+
:ref:`mkpasswd_autogen`.
2058+
2059+
Login test inside the simulator
2060+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2061+
2062+
.. code:: console
2063+
2064+
$ ./nuttx
2065+
NuttShell (NSH) NuttX-<version>
2066+
nsh login: root
2067+
Password:
2068+
User Logged-in!
2069+
nsh>
2070+
20572071
``/etc/group`` is a group file. It is not currently used.
20582072

20592073
.. code:: console

0 commit comments

Comments
 (0)