bitbake-worker: skipping disable network when unprivileged userns is restricted
PATCH 1/1 bitbake-worker: skipping disable network when unprivileged userns is restricted
From: Chen Qi <[email protected]>
From ubuntu24.04, apparmor is enabled by default, and unprivileged userns is restricted, which causes following error when bitbake-worker try to disable network:
Traceback (most recent call last):
File "/poky/bitbake/bin/bitbake-worker", line 278, in child
bb.utils.disable_network(uid, gid)
File "/poky/bitbake/lib/bb/utils.py", line 1696, in disable_network
with open("/proc/self/uid_map", "w") as f:PermissionError: [Errno 1] Operation not permitted
Like what we have done for non local uid, skip disable network in above condition to avoid have to disable profile unprivileged_userns for the host or have to config a profile per project
[1] https://lists.yoctoproject.org/g/yocto/topic/workaround_for_uid_map_error/106192359
--- bitbake/bin/bitbake-worker | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
bitbake/bin/bitbake-worker +12 -3
@@ -272,12 +272,21 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): bb.utils.set_process_name("%s:%s" % (the_data.getVar("PN"), taskname.replace("do_", ""))) + def skip_disable_network(taskname, uid): + if not bb.utils.is_local_uid(uid): + logger.debug("Skipping disable network for %s since %s is not a local uid." % (taskname, uid)) + return True + if os.path.exists("/proc/sys/kernel/apparmor_restrict_unprivileged_userns"): + with open("/proc/sys/kernel/apparmor_restrict_unprivileged_userns") as f: + if f.readline().strip() == "1": + logger.debug("Skipping disable network since sys.kernel.apparmor_restrict_unprivileged_userns is 1") + return True + return False + if not bb.utils.to_boolean(the_data.getVarFlag(taskname, 'network')): - if bb.utils.is_local_uid(uid): + if not skip_disable_network(taskname, uid): logger.debug("Attempting to disable network for %s" % taskname) bb.utils.disable_network(uid, gid) - else: - logger.debug("Skipping disable network for %s since %s is not a local uid." % (taskname, uid)) # exported_vars() returns a generator which *cannot* be passed to os.environ.update() # successfully. We also need to unset anything from the environment which shouldn't be there
Signature · 1 line
2.25.1
Should we rather direct users to disable the apparmor restriction? I don't think an important QA constraint in the bitbake build process should be automatically disabled this way.
Wasn't there also an upstream discussion/ticket with ubuntu? I'd rather have this resolved upstream. Disabling the network check instead isn't going to help that.
Alex
Quoted 66 lines · Changqing Li via lists.openembedded.org
From: Chen Qi <[email protected]>
From ubuntu24.04, apparmor is enabled by default, and unprivileged userns is restricted, which causes following error when bitbake-worker try to disable network:
Traceback (most recent call last):
File "/poky/bitbake/bin/bitbake-worker", line 278, in child
bb.utils.disable_network(uid, gid)
File "/poky/bitbake/lib/bb/utils.py", line 1696, indisable_networkwith open("/proc/self/uid_map", "w") as f:PermissionError: [Errno 1] Operation not permitted
Like what we have done for non local uid, skip disable network in above condition to avoid have to disable profile
unprivileged_usernsfor the host or have to config a profile per project[1] https://lists.yoctoproject.org/g/yocto/topic/workaround_for_uid_map_error/106192359
Signed-off-by Chen Qi <[email protected]>Signed-off-by Changqing Li <[email protected]>--- bitbake/bin/bitbake-worker | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)bitbake/bin/bitbake-worker +12
-4@@ -272,12 +272,21 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): bb.utils.set_process_name("%s:%s" % (the_data.getVar("PN"), taskname.replace("do_", ""))) + def skip_disable_network(taskname, uid): + if not bb.utils.is_local_uid(uid): + logger.debug("Skipping disable network for %s since %s is not a local uid." % (taskname, uid)) + return True + if os.path.exists("/proc/sys/kernel/apparmor_restrict_unprivileged_userns"): + with open("/proc/sys/kernel/apparmor_restrict_unprivileged_userns") as f: + if f.readline().strip() == "1": + logger.debug("Skipping disable network since sys.kernel.apparmor_restrict_unprivileged_userns is 1") + return True + return False + if not bb.utils.to_boolean(the_data.getVarFlag(taskname, 'network')): - if bb.utils.is_local_uid(uid): + if not skip_disable_network(taskname, uid): logger.debug("Attempting to disable network for %s" % taskname) bb.utils.disable_network(uid, gid) - else: - logger.debug("Skipping disable network for %s since %s is not a local uid." % (taskname, uid)) # exported_vars() returns a generator which *cannot* be passed to os.environ.update() # successfully. We also need to unset anything from the environment which shouldn't be there --2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16397): https://lists.openembedded.org/g/bitbake-devel/message/16397
Mute This Topic: https://lists.openembedded.org/mt/107099079/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Quoted 1 line · Alexander Kanavin
Should we rather direct users to disable the apparmor restriction?
How about an extra patch for the env init script to warn users about this situation?
There have already been some check there. e.g.,
py_v38_check=$(python3 -c 'import sys; print(sys.version_info >= (3,8,0))')
Quoted 3 lines
I
don't think an important QA constraint in the bitbake build process should be automatically disabled this way.
It's a best-to-have feature. It's not 100% necessary to have an image built out. There's already a is_local_uid check that skips network disabling.
Quoted 2 lines
Wasn't there also an upstream discussion/ticket with ubuntu? I'd rather have this resolved upstream.
Frankly I'm not very optimistic about Ubuntu solving this problem. We're on our own.
Quoted 2 lines
Disabling the network check
instead isn't going to help that.
Hopefully we can lower the barrier for people to use Yocto if possible, even if they use Ubuntu24 and know little about apparmor.
P.S.
This problem has reported to Ubuntu for 4 months. It was discussed on the Yocto mailing list. People seem to be waiting for Ubuntu. I'm not very optimistic about getting a solution from Ubuntu.
Regards,
Qi
Quoted 70 lines
Alex
Quoted 65 lines · Changqing Li via lists.openembedded.org
From: Chen Qi <[email protected]>
From ubuntu24.04, apparmor is enabled by default, and unprivileged
userns is restricted, which causes following error when bitbake-worker try to disable network:
Traceback (most recent call last):
File "/poky/bitbake/bin/bitbake-worker", line 278, in child
bb.utils.disable_network(uid, gid)
File "/poky/bitbake/lib/bb/utils.py", line 1696, indisable_networkwith open("/proc/self/uid_map", "w") as f:PermissionError: [Errno 1] Operation not permitted
Like what we have done for non local uid, skip disable network in above condition to avoid have to disable profile
unprivileged_usernsfor the host or have to config a profile per project[1] https://lists.yoctoproject.org/g/yocto/topic/workaround_for_uid_map_error/106192359
Signed-off-by Chen Qi <[email protected]>Signed-off-by Changqing Li <[email protected]>--- bitbake/bin/bitbake-worker | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)bitbake/bin/bitbake-worker +12
-4@@ -272,12 +272,21 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): bb.utils.set_process_name("%s:%s" % (the_data.getVar("PN"), taskname.replace("do_", ""))) + def skip_disable_network(taskname, uid): + if not bb.utils.is_local_uid(uid): + logger.debug("Skipping disable network for %s since %s is not a local uid." % (taskname, uid)) + return True + if os.path.exists("/proc/sys/kernel/apparmor_restrict_unprivileged_userns"): + with open("/proc/sys/kernel/apparmor_restrict_unprivileged_userns") as f: + if f.readline().strip() == "1": + logger.debug("Skipping disable network since sys.kernel.apparmor_restrict_unprivileged_userns is 1") + return True + return False + if not bb.utils.to_boolean(the_data.getVarFlag(taskname, 'network')): - if bb.utils.is_local_uid(uid): + if not skip_disable_network(taskname, uid): logger.debug("Attempting to disable network for %s" % taskname) bb.utils.disable_network(uid, gid) - else: - logger.debug("Skipping disable network for %s since %s is not a local uid." % (taskname, uid)) # exported_vars() returns a generator which *cannot* be passed to os.environ.update() # successfully. We also need to unset anything from the environment which shouldn't be there --2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16397): https://lists.openembedded.org/g/bitbake-devel/message/16397
Mute This Topic: https://lists.openembedded.org/mt/107099079/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Quoted 3 lines · ChenQi
This problem has reported to Ubuntu for 4 months. It was discussed on the Yocto mailing list. People seem to be waiting for Ubuntu. I'm not very optimistic about getting a solution from Ubuntu.
I do not agree. The last comment (#10, added two weeks ago) in
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2056555 shows how to create an apparmor profile specifically for bitbake, so once this is added to apparmor upstream and makes its way into Ubuntu the problem will be solved. At that point the forced network disabling will become unnecessary and damaging. Ubuntu release notes imply they've done it for things like Chrome and Discord, but they expect more to be added:
Alex
Quoted 16 lines · Alexander Kanavin
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 3 lines · ChenQi
This problem has reported to Ubuntu for 4 months. It was discussed on the Yocto mailing list. People seem to be waiting for Ubuntu. I'm not very optimistic about getting a solution from Ubuntu.
I do not agree. The last comment (#10, added two weeks ago) in
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2056555 shows how to create an apparmor profile specifically for bitbake, so once this is added to apparmor upstream and makes its way into Ubuntu the problem will be solved. At that point the forced network disabling will become unnecessary and damaging. Ubuntu release notes imply they've done it for things like Chrome and Discord, but they expect more to be added:
Quoted 1 line
I think applications like Chrome, thunderbird etc are commonly used applications by user, so they are might in
ubuntu's package repo, so they will support it and add profile for it by default. But for bitbake, it is mostly
for developer and and not support by ubuntu. And considering there might be many other softwares meet this issue,
so I am not optimistic that ubuntu will add default profile for all these softwares. so maybe we are still on our own.
One option is using this patch, so users don't have to struggle on this problem, don't need sudo, don't need an apparmor profile etc,
but have the side effect that skip disable network, we need to balance which to choose.
One option is document or notice message in oe-init-build-env, suggest user to disable unprivileged_userns or write a profile for bitbake.
Regards
Changqing
Quoted 2 lines
Alex
Quoted 18 lines · Changqing Li via lists.openembedded.org
Quoted 14 lines · Alexander Kanavin
Quoted 5 lines · ChenQi
This problem has reported to Ubuntu for 4 months. It was discussed on the Yocto mailing list. People seem to be waiting for Ubuntu. I'm not very optimistic about getting a solution from Ubuntu.
I do not agree. The last comment (#10, added two weeks ago) inhttps://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2056555 shows how to create an apparmor profile specifically for bitbake, so once this is added to apparmor upstream and makes its way into Ubuntu the problem will be solved. At that point the forced network disabling will become unnecessary and damaging. Ubuntu release notes imply they've done it for things like Chrome and Discord, but they expect more to be added:
Quoted 7 lines
I think applications like Chrome, thunderbird etc are commonly used applications by user, so they are might in ubuntu's package repo, so they will support it and add profile for it by default. But for bitbake, it is mostly for developer and and not support by ubuntu. And considering there might be many other softwares meet this issue, so I am not optimistic that ubuntu will add default profile for all these softwares. so maybe we are still on our own. One option is using this patch, so users don't have to struggle on this problem, don't need sudo, don't need an apparmor profile etc, but have the side effect that skip disable network, we need to balance which to choose.
One option is document or notice message in oe-init-build-env, suggest user to disableunprivileged_usernsor write a profile for bitbake.
I do not want to just stop disabling the network silently so the patch as written isn't an option.
I'm also not keen to make oe-init-build-env too complex, it is meant to be just enough to get us into bitbake, nothing more. Adding sanity checks there is the wrong place. This could happen in the normal sanity.bbclass code but we need to make sure it triggers when a user upgrades their existing distro.
I think we should open a new ticket with ubuntu specifically about adding a profile for bitbake and see if we can get a definitive answer on whether we can add a profile for it or not. I'd suggest a new ticket so we don't get confused with the comments in the one linked above.
Cheers,
Richard
Quoted 36 lines · Richard Purdie
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 16 lines · Changqing Li via lists.openembedded.org
Quoted 13 lines · Alexander Kanavin
Quoted 4 lines · ChenQi
This problem has reported to Ubuntu for 4 months. It was discussed on the Yocto mailing list. People seem to be waiting for Ubuntu. I'm not very optimistic about getting a solution from Ubuntu.
I do not agree. The last comment (#10, added two weeks ago) inhttps://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2056555 shows how to create an apparmor profile specifically for bitbake, so once this is added to apparmor upstream and makes its way into Ubuntu the problem will be solved. At that point the forced network disabling will become unnecessary and damaging. Ubuntu release notes imply they've done it for things like Chrome and Discord, but they expect more to be added:
Quoted 7 lines
I think applications like Chrome, thunderbird etc are commonly used applications by user, so they are might in ubuntu's package repo, so they will support it and add profile for it by default. But for bitbake, it is mostly for developer and and not support by ubuntu. And considering there might be many other softwares meet this issue, so I am not optimistic that ubuntu will add default profile for all these softwares. so maybe we are still on our own. One option is using this patch, so users don't have to struggle on this problem, don't need sudo, don't need an apparmor profile etc, but have the side effect that skip disable network, we need to balance which to choose.
One option is document or notice message in oe-init-build-env, suggest user to disableunprivileged_usernsor write a profile for bitbake.I do not want to just stop disabling the network silently so the patch as written isn't an option.
I'm also not keen to make oe-init-build-env too complex, it is meant to be just enough to get us into bitbake, nothing more. Adding sanity checks there is the wrong place. This could happen in the normal sanity.bbclass code but we need to make sure it triggers when a user upgrades their existing distro.
Quoted 4 lines
I think we should open a new ticket with ubuntu specifically about adding a profile for bitbake and see if we can get a definitive answer on whether we can add a profile for it or not. I'd suggest a new ticket so we don't get confused with the comments in the one linked above.
file a new ticket https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2072615
let's wait to see if the recommended profile can be acceptted.
Regards
Changqing
Quoted 7 lines
Cheers,
Richard
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 39 lines · Changqing Li via lists.openembedded.org
Quoted 36 lines · Richard Purdie
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 16 lines · Changqing Li via lists.openembedded.org
Quoted 13 lines · Alexander Kanavin
Quoted 4 lines · ChenQi
This problem has reported to Ubuntu for 4 months. It was discussed on the Yocto mailing list. People seem to be waiting for Ubuntu. I'm not very optimistic about getting a solution from Ubuntu.
I do not agree. The last comment (#10, added two weeks ago) inhttps://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2056555 shows how to create an apparmor profile specifically for bitbake, so once this is added to apparmor upstream and makes its way into Ubuntu the problem will be solved. At that point the forced network disabling will become unnecessary and damaging. Ubuntu release notes imply they've done it for things like Chrome and Discord, but they expect more to be added:
Quoted 7 lines
I think applications like Chrome, thunderbird etc are commonly used applications by user, so they are might in ubuntu's package repo, so they will support it and add profile for it by default. But for bitbake, it is mostly for developer and and not support by ubuntu. And considering there might be many other softwares meet this issue, so I am not optimistic that ubuntu will add default profile for all these softwares. so maybe we are still on our own. One option is using this patch, so users don't have to struggle on this problem, don't need sudo, don't need an apparmor profile etc, but have the side effect that skip disable network, we need to balance which to choose.
One option is document or notice message in oe-init-build-env, suggest user to disableunprivileged_usernsor write a profile for bitbake.I do not want to just stop disabling the network silently so the patch as written isn't an option.
I'm also not keen to make oe-init-build-env too complex, it is meant to be just enough to get us into bitbake, nothing more. Adding sanity checks there is the wrong place. This could happen in the normal sanity.bbclass code but we need to make sure it triggers when a user upgrades their existing distro.
Quoted 9 lines
Quoted 4 lines
I think we should open a new ticket with ubuntu specifically about adding a profile for bitbake and see if we can get a definitive answer on whether we can add a profile for it or not. I'd suggest a new ticket so we don't get confused with the comments in the one linked above.
file a new ticket https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2072615
let's wait to see if the recommended profile can be acceptted.
Hi,
The request is rejected as following comments:
Unfortunately, as John has stated in this comment:
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2063976/comments/3 <https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2063976/comments/3>
We are not able to ship a profile for bitbake running in a writable location of an unprivileged user because it could be used to bypass the restriction.
Regards
Changqing
Quoted 19 lines
Regards
Changqing
Quoted 6 lines
Cheers,
Richard
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16414):https://lists.openembedded.org/g/bitbake-devel/message/16414 Mute This Topic:https://lists.openembedded.org/mt/107099079/3616873
Group Owner:[email protected] Unsubscribe:https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Quoted 10 lines · Changqing Li via lists.openembedded.org
The request is rejected as following comments:
Unfortunately, as John has stated in this comment:
https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2063976/commen
ts/3
We are not able to ship a profile for bitbake running in a writable location of an unprivileged user because it could be used to bypass the restriction.
Sad but I can see why.
In that case we should put a sanity check into sanity.bbclass to detect the permissions issue and point the user at docs on how to make things work if the issue is present.
Cheers,
Richard
Quoted 5 lines · Changqing Li
I think applications like Chrome, thunderbird etc are commonly used applications by user, so they are might in ubuntu's package repo, so they will support it and add profile for it by default. But for bitbake, it is mostly for developer and and not support by ubuntu. And considering there might be many other softwares meet this issue, so I am not optimistic that ubuntu will add default profile for all these softwares. so maybe we are still on our own. One option is using this patch, so users don't have to struggle on this problem, don't need sudo, don't need an apparmor profile etc,
Yes. Things will 'just work' on the surface. But you would also be doing those users a disservice by quietly disabling an important check behind their back, and not even letting them know that. Some users will not be happy to learn that after the fact.
Quoted 3 lines
but have the side effect that skip disable network, we need to balance which to choose.
One option is document or notice message in oe-init-build-env, suggest user to disable
unprivileged_usernsor write a profile for bitbake.
I wonder if we can wrap the actual /proc/self/... writing calls in disable_network() (I think this is where things fail without system tweaks?) with an exception handler pointing people to instructions about installing an apparmor profile. It wouldn't be optimal (this happens in a task execution, not in a build setup), but it would help.
Alex