Skip to content

ceph.spec.in: disable -P in python shebang for cephadm binary - #69421

Merged
tchaikov merged 1 commit into
ceph:mainfrom
ShwetaBhosale1:fix_issue_77340_remove_-P_from_shebang_flags
Jun 13, 2026
Merged

tchaikov merged 1 commit into
ceph:mainfrom
ShwetaBhosale1:fix_issue_77340_remove_-P_from_shebang_flags

Conversation

@ShwetaBhosale1

@ShwetaBhosale1 ShwetaBhosale1 commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Without this fix we get error for running cephadm with shebang

Fixes: https://tracker.ceph.com/issues/77340
Signed-off-by: Shweta Bhosale [email protected]

Testing logs:

i checked cephadm binary of image [quay.ceph.io/ceph-ci/ceph:wip-shweta-testing1-2026-06-11-1114-rockylinux-10-x86_64-devel](http://quay.ceph.io/ceph-ci/ceph:wip-shweta-testing1-2026-06-11-1114-rockylinux-10-x86_64-devel)
shwetabhosale:img$ cat cephadm | head -1
#! /usr/bin/python3 -s
shwetabhosale:img$

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@ShwetaBhosale1
ShwetaBhosale1 requested a review from a team as a code owner June 11, 2026 15:09

@phlogistonjohn phlogistonjohn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change content looks ok. Commit title should probably be something more like:
ceph.spec.in: disable -P in python shebang for cephadm binary

@ShwetaBhosale1
ShwetaBhosale1 force-pushed the fix_issue_77340_remove_-P_from_shebang_flags branch from 76d17fb to fbfe653 Compare June 12, 2026 05:14
@ShwetaBhosale1 ShwetaBhosale1 changed the title Fixing shebang flags for cephadm binary from rocky 10 image on rhel/centos9 host ceph.spec.in: disable -P in python shebang for cephadm binary Jun 12, 2026
@ShwetaBhosale1

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@rkachach rkachach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ShwetaBhosale1

Copy link
Copy Markdown
Contributor Author

@rkachach
rkachach requested a review from tchaikov June 12, 2026 11:14
@rkachach

Copy link
Copy Markdown
Contributor

@ShwetaBhosale1 as we discussed I'll wait for approval from @tchaikov or @phlogistonjohn to go ahead. BTW (and I'm not sure if this is possible or not), but probably we can make it conditional so we don't affect newer python versions.. maybe something like (plz double check the syntax as I'm not familiar with the ceph.spec.ini syntax):

# Only drop -P when the build Python is older than 3.11.
%if 0%{?python3_version_nodots} < 311
%undefine _py3_shebang_P
%endif

@ShwetaBhosale1

Copy link
Copy Markdown
Contributor Author

@rkachach For Python versions < 3.11, py3_shebang_flags does not include the -P flag. We remove it only for Python 3.11+ because the Rocky 10 container is used on rhel/centos 9 hosts, and the cephadm binary is copied from the container image to the host.

I considered adding an explicit Python version check (>= 3.11), but since %undefine _py3_shebang_P has no effect when the macro is not defined, it is safe to use on older Python versions as well. Therefore, I omitted the version check.

@phlogistonjohn phlogistonjohn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@phlogistonjohn

Copy link
Copy Markdown
Contributor

Rocky 10 container is used on rhel/centos 9 hosts

The rocky 10 container image is used on all hosts.

The cephadm binary is picked out of the EL (centos/rocky) package builds. So it's also used for bootstrapping, it really needs to have the shebang with the widest compatibility.

One possible downside of the change, which I didn't think was important enough to create a bunch of make-work over is that this change touches all python binaries produced by the rpm build. Not just cephadm. The fedora change that brought this in describes what it does and I didn't feel strongly enough about it to bother discussing it (until now) :-)

@phlogistonjohn

Copy link
Copy Markdown
Contributor

If it becomes an issue in the future we could look into restricting this modification to just cephadm, but I don't think it's benefits are significant enough RN.

@tchaikov

tchaikov commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Rocky 10 container is used on rhel/centos 9 hosts

The rocky 10 container image is used on all hosts.

yes, that's the pain -- we build with python 3.12 (el10) while running the built artifacts on python 3.9 (el9). this practically breaks the check in the detection logic at https://src.fedoraproject.org/rpms/python-rpm-macros/blob/rawhide/f/macros.python3#_31

%__py3_shebang_P %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; print('P' if hasattr(sys.flags, 'safe_path') else '')")

which does test the safe_path support of python3. unfortunately, safe_path is a read-only flag, so we cannot set it after launching the python interpreter:

>> sys.flags.safe_path = True
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    sys.flags.safe_path = True
    ^^^^^^^^^^^^^^^^^^^

see https://docs.python.org/3/library/sys.html#sys.flags.safe_path and https://docs.python.org/3/c-api/init_config.html#c.PyConfig.safe_path.

The cephadm binary is picked out of the EL (centos/rocky) package builds. So it's also used for bootstrapping, it really needs to have the shebang with the widest compatibility.

and yes, if we want to support python3.9 interpreter, we have to avoid using features not exist in python3.9. otherwise we would have to bundle python3.11 (or whatever version we want) in cephadm with a safe glibc version.

One possible downside of the change, which I didn't think was important enough to create a bunch of make-work over is that this change touches all python binaries produced by the rpm build. Not just cephadm. The fedora change that brought this in describes what it does and I didn't feel strongly enough about it to bother discussing it (until now) :-)

apart from bundling python interpreter, i evaluated the option to add -I (https://docs.python.org/3/using/cmdline.html#cmdoption-I), but it prevents cephadm from using the bundled python modules. safe but too safe. so it's also a dead end. if we really care about security level which is ensured by -P (https://docs.python.org/dev/using/cmdline.html#cmdoption-P), we can use use mult-binary approach -- to include cephadm compiled on different python versions. but that might be overkill..

@tchaikov tchaikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm -- we run with python3.9 and build with python 3.12. this is the fact we need to live with.

@tchaikov
tchaikov merged commit 84ac1de into ceph:main Jun 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants