python / python/cpython

zipapp creates executable files with wrong permissions bits

Offen
#96,867 3 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@pfmoore arbeitet bereits daran.

Seit 30.7.2026.

stdlib type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Owing to the fact that open() has no flags field for marking a file as executable, and doing that after the fact is difficult (since it involves playing around with umask), the current implementation of zipapp uses the following code to attempt to set the file executable:

os.chmod(new_archive, os.stat(new_archive).st_mode | stat.S_IEXEC)

Which is incorrect: this sets only the execute bit for the user, and will never set it for the group or "other" categories, regardless of the umask.

This was discussed in a series of comments in #96772, starting around

https://github.com/python/cpython/issues/67679#issuecomment-1093675286

Create and open executable file respecting the Unix user's umask:

os.fdopen(os.open(filename, os.O_CREAT|os.O_RDWR), "rw")

and ending with

https://github.com/python/cpython/issues/67679#issuecomment-1093675294

OK, thanks. I don't propose to go there with the initial implementation. If it's a problem in practice, someone can raise a bug and we'll fix it then. (I've never seen actual Python code in the wild that does all of that...)

This is a problem in practice for us.

We're trying to replace the C version of Cockpit with a Python zipapp, and the file gets created with permissions that allow the current user to run it, but won't allow the file to be installed in /usr/bin so everyone can run it.

We can work around it easy enough — chmod +x in the Makefile after we call zipapp, but this is a bug in zipapp that really ought to be fixed.

For what it's worth, I think the os.fdopen() approach originally proposed by "dholth" is the best one.

Linked PRs
  • gh-151970

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.