bbconfigbuild/configfragments.py: run discover_fragments() only once when enabling them
PATCH 1/6 bbconfigbuild/configfragments.py: run discover_fragments() only once when enabling them
From: Alexander Kanavin <[email protected]>
--- meta/lib/bbconfigbuild/configfragments.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
meta/lib/bbconfigbuild/configfragments.py +4 -3
@@ -97,8 +97,8 @@ class ConfigFragmentsPlugin(LayerPlugin): print_fragment(f, args.verbose, is_enabled=False) print('') - def fragment_exists(self, fragmentname): - for layername, layerdata in self.discover_fragments().items(): + def fragment_exists(self, fragmentname, fragments): + for layername, layerdata in fragments.items(): for f in layerdata['fragments']: if f['name'] == fragmentname: return True
@@ -136,8 +136,9 @@ class ConfigFragmentsPlugin(LayerPlugin): enabled_fragments.append(f) return " ".join(enabled_fragments), None, 0, True + fragments = self.discover_fragments() for f in args.fragmentname: - if not self.fragment_exists(f) and not self.builtin_fragment_exists(f): + if not self.fragment_exists(f, fragments) and not self.builtin_fragment_exists(f): raise Exception("Fragment {} does not exist; use 'list-fragments' to see the full list.".format(f)) self.create_conf(args.confpath)
Signature · 1 line
2.39.5
PATCH 2/6 bbconfigbuild/configfragments.py: replace fragment_exists() with a more generic get_fragment()
From: Alexander Kanavin <[email protected]>
This can be used to get fragment information by its name (or None, if there's no fragment), rather than just check for its existence.
--- meta/lib/bbconfigbuild/configfragments.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
meta/lib/bbconfigbuild/configfragments.py +4 -4
@@ -97,12 +97,12 @@ class ConfigFragmentsPlugin(LayerPlugin): print_fragment(f, args.verbose, is_enabled=False) print('') - def fragment_exists(self, fragmentname, fragments): + def get_fragment(self, fragmentname, fragments): for layername, layerdata in fragments.items(): for f in layerdata['fragments']: if f['name'] == fragmentname: - return True - return False + return f + return None def fragment_prefix(self, fragmentname): return fragmentname.split("/",1)[0]
@@ -138,7 +138,7 @@ class ConfigFragmentsPlugin(LayerPlugin): fragments = self.discover_fragments() for f in args.fragmentname: - if not self.fragment_exists(f, fragments) and not self.builtin_fragment_exists(f): + if not self.get_fragment(f, fragments) and not self.builtin_fragment_exists(f): raise Exception("Fragment {} does not exist; use 'list-fragments' to see the full list.".format(f)) self.create_conf(args.confpath)
Signature · 1 line
2.39.5
PATCH 3/6 bbconfigbuild/configfragments.py: print fragment descriptions when enabling them
In reply to Alexander KanavinFrom: Alexander Kanavin <[email protected]>
Such descriptions can contain useful or important information, and users may not see that otherwise at all. To reduce clutter in CI outputs or similar scenarios, -q option suppresses that printing.
--- meta/lib/bbconfigbuild/configfragments.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
meta/lib/bbconfigbuild/configfragments.py +6 -1
@@ -144,7 +144,11 @@ class ConfigFragmentsPlugin(LayerPlugin): self.create_conf(args.confpath) modified = bb.utils.edit_metadata_file(args.confpath, ["OE_FRAGMENTS"], enable_helper) if modified: - print("Fragment {} added to {}.".format(", ".join(args.fragmentname), args.confpath)) + for f in args.fragmentname: + print("Fragment {} added to {}.".format(f, args.confpath)) + f_info = self.get_fragment(f, fragments) + if f_info and not args.quiet: + print('\nFragment summary: {}\n\nFragment description:\n{}\n'.format(f_info['summary'],f_info['description'])) def do_disable_fragment(self, args): """ Disable a fragment in the local build configuration """
@@ -193,6 +197,7 @@ class ConfigFragmentsPlugin(LayerPlugin): parser_enable_fragment = self.add_command(sp, 'enable-fragment', self.do_enable_fragment, parserecipes=False) parser_enable_fragment.add_argument("--confpath", default=default_confpath, help='Configuration file which contains a list of enabled fragments (default is {}).'.format(default_confpath)) + parser_list_fragments.add_argument('--quiet', '-q', action='store_true', help='Do not print descriptions of the newly enabled fragments') parser_enable_fragment.add_argument('fragmentname', help='The name of the fragment (use list-fragments to see them)', nargs='+') parser_disable_fragment = self.add_command(sp, 'disable-fragment', self.do_disable_fragment, parserecipes=False)
Signature · 1 line
2.39.5
PATCH 4/6 fragments: add a 'root-login-without-password' fragment
In reply to Alexander KanavinFrom: Alexander Kanavin <[email protected]>
Please see this for background/some discussion:
https://lists.openembedded.org/g/openembedded-architecture/topic/115913545
Care should be taken to not enable this by default, and especially not for production images. Poky and oe-core default templates did it, and it was not a good starting point. Hopefully the fragment name, and the description that users will see when enabling the fragment will provide enough warning.
--- .../fragments/yocto/root-login-without-password.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 meta/conf/fragments/yocto/root-login-without-password.conf
meta/conf/fragments/yocto/root-login-without-password.conf new file +10 -0
@@ -0,0 +1,10 @@ +BB_CONF_FRAGMENT_SUMMARY = "Log in as root without password on serial console and over ssh (use with caution)." +BB_CONF_FRAGMENT_DESCRIPTION = "By default images are built such that root login is disabled \ +(which is the preferred, secure default). However, for testing and development purposes it can \ +be beneficial to be able to log in as root, both on serial console and over ssh connections, \ +which is what this fragment enables. Use with great cauion, and ideally only in tightly \ +controlled local builds and CI testing environments, and never in artefacts that are deployed \ +into products. \ +" + +EXTRA_IMAGE_FEATURES += "allow-empty-password empty-root-password allow-root-login"
Signature · 1 line
2.39.5
Re: [OE-core] [PATCH 4/6] fragments: add a 'root-login-without-password' fragment
Hello,
Quoted 26 lines · Alexander Kanavin via lists.openembedded.org
From: Alexander Kanavin <[email protected]>
Please see this for background/some discussion:
https://lists.openembedded.org/g/openembedded-architecture/topic/115913545Care should be taken to not enable this by default, and especially not for production images. Poky and oe-core default templates did it, and it was not a good starting point. Hopefully the fragment name, and the description that users will see when enabling the fragment will provide enough warning.
Signed-off-by Alexander Kanavin <[email protected]>--- .../fragments/yocto/root-login-without-password.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644
meta/conf/fragments/yocto/root-login-without-password.confmeta/conf/fragments/yocto/root-login-without-password.conf new file +1
-0@@ -0,0 +1,10 @@ +BB_CONF_FRAGMENT_SUMMARY = "Log in as root without password on serialconsole and over ssh (use with caution)."
Quoted 8 lines
+BB_CONF_FRAGMENT_DESCRIPTION = "By default images are built such that root login is disabled \
+(which is the preferred, secure default). However, for testing and development purposes it can \
+be beneficial to be able to log in as root, both on serial console and over ssh connections, \
+which is what this fragment enables. Use with great cauion, and ideally only in tightly \
Small typo au "caution" here
+controlled local builds and CI testing environments, and never in
Quoted 21 lines
artefacts that are deployed \
meta/conf/fragments/yocto/root-login-without-password.conf new file +4
-0+into products. \ +" + +EXTRA_IMAGE_FEATURES += "allow-empty-password empty-root-passwordallow-root-login"
--
2.39.5-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#225452):
https://lists.openembedded.org/g/openembedded-core/message/225452
Mute This Topic: https://lists.openembedded.org/mt/116010925/4316185
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
PATCH 5/6 testimage.bbclass: check that root-login-without-password image features are present
In reply to Alexander KanavinFrom: Alexander Kanavin <[email protected]>
More or less all of testimage relies on logging in as root, without password, both on console and over ssh. Previously this was enabled by default in poky and core, but now that it isn't, testimage will error out on timeouts in both console and ssh login attempts. This commit adds an earlier check and provides a hint to the users about what they should do.
--- meta/classes-recipe/testimage.bbclass | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
meta/classes-recipe/testimage.bbclass +11 -1
@@ -131,12 +131,22 @@ do_testimage[depends] += "${TESTIMAGEDEPENDS}" do_testimage[lockfiles] += "${TESTIMAGELOCK}" def testimage_sanity(d): - if (d.getVar('TEST_TARGET') == 'simpleremote' + test_target = d.getVar('TEST_TARGET') + if (test_target == 'simpleremote' and (not d.getVar('TEST_TARGET_IP') or not d.getVar('TEST_SERVER_IP'))): bb.fatal('When TEST_TARGET is set to "simpleremote" ' 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.') + image_features = d.getVar('IMAGE_FEATURES') + needed_features = "allow-empty-password empty-root-password allow-root-login" + present_features = set(image_features.split()) & set(needed_features.split()) + if (test_target in ('simpleremote', 'qemu') + and (len(present_features) < len(needed_features.split()))): + bb.fatal("When TEST_TARGET is '{}', IMAGE_FEATURES need to include '{}', and they are currently set to '{}'. This can be done for all images in a local build by running\n\nbitbake-config-build enable-fragment core/yocto/root-login-without-password\n\nand rebuilding the image-under-test." + .format(test_target, needed_features, image_features)) + + def get_testimage_configuration(d, test_type, machine): import platform from oeqa.utils.metadata import get_layers
Signature · 1 line
2.39.5
PATCH 6/6 rootfs-postcommands.bbclass: add a note to the login banner when root-without-password logins are enabled
In reply to Alexander KanavinFrom: Alexander Kanavin <[email protected]>
When enabled, users will see:
===
Poky (Yocto Project Reference Distro) 5.2.99+snapshot-1dac0d15f2d979128cb449b59bf5fd69b4ba5084 qemux86-64 ttyS0
Type 'root' to login with superuser privileges (no password will be asked).
qemux86-64 login:
===
--- meta/classes-recipe/rootfs-postcommands.bbclass | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
meta/classes-recipe/rootfs-postcommands.bbclass +8 -1
@@ -5,7 +5,7 @@ # # Zap the root password if empty-root-password feature is not enabled -ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "empty-root-password", "", "zap_empty_root_password ",d)}' +ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "empty-root-password", "add_empty_root_password_note", "zap_empty_root_password ",d)}' # Allow dropbear/openssh to accept logins from accounts with an empty password string if allow-empty-password is enabled ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "allow-empty-password", "ssh_allow_empty_password ", "",d)}'
@@ -255,6 +255,13 @@ zap_empty_root_password () { fi } +# +# This function adds a note to the login banner that the system is configured for root logins without password +# +add_empty_root_password_note () { + echo "Type 'root' to login with superuser privileges (no password will be asked).\n" >> ${IMAGE_ROOTFS}/etc/issue +} + # # allow dropbear/openssh to accept logins from accounts with an empty password string #
Signature · 1 line
2.39.5