git no puede ejecutar 'pack-objects': Permiso denegado

Sep 22 2020

Recibo este error al extraer de un git remoto autohospedado que acabo de agregar.

$ git pull myremote master
fatal: cannot exec 'pack-objects': Permission denied
fatal: git upload-pack: unable to fork git-pack-objects
fatal: The remote end hung up unexpectedly
fatal: protocol error: bad pack header

Buscar en Google " cannot exec 'pack-objects': Permission denied" con comillas no obtuvo ningún resultado, por lo que no es un duplicado. Hay varias preguntas sobre la fatal: protocol error: bad pack headerparte, con respuestas como esta que proponen agregar algunas líneas que limitan la memoria .gitconfig. Eso no resolvió mi problema.

Según la primera línea, creo que a algún pack-objectsejecutable en algún lugar le falta su xpermiso. Pero no es este:

$ ls -l $(which git-upload-pack)
-rwxr-xr-x 1 root root 1559256 Apr 20 10:20 /usr/bin/git-upload-pack

Por contexto, el control remoto es un VPS que ejecuta Debian 10, mientras que el cliente es un antiguo escritorio Intel Celron de alrededor de 2003, que ejecuta Ubuntu 18.04. Por lo tanto, la limitación de recursos en la máquina de tracción podría estar influyendo.

EDITAR :

Todos los binarios de git son ejecutables por todos los usuarios:

 $ ls -l /usr/bin/git*
 -rwxr-xr-x 1 root root 2759388 Apr 20 10:20 /usr/bin/git
 lrwxrwxrwx 1 root root       3 Apr 20 10:20 /usr/bin/git-receive-pack -> git
 -rwxr-xr-x 1 root root 1546968 Apr 20 10:20 /usr/bin/git-shell
 lrwxrwxrwx 1 root root       3 Apr 20 10:20 /usr/bin/git-upload-archive -> git
 -rwxr-xr-x 1 root root 1559256 Apr 20 10:20 /usr/bin/git-upload-pack

Y /usr/binestá en mi RUTA:

$ echo $PATH
/home/keith/bin:/home/keith/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Y puedo ejecutarlos sin sudo:

$ git-upload-pack
usage: git upload-pack [<options>] <dir>

    --stateless-rpc       quit after a single request/response exchange
    --advertise-refs      exit immediately after initial ref advertisement
    --strict              do not try <directory>/.git/ if <directory> is no Git directory
    --timeout <n>         interrupt transfer after <n> seconds of inactivity

EDITAR 2 :

El .gitdirectorio también parece tener los permisos correctos:

$ ls -la .git{,/objects}
.git:
total 56
drwxr-xr-x  8 keith keith 4096 Sep 21 11:36 .
drwxr-xr-x 22 keith keith 4096 Sep 21 13:09 ..
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 branches
-rw-r--r--  1 keith keith  290 Sep 21 11:36 config
-rw-r--r--  1 keith keith   73 Jul 25  2017 description
-rw-r--r--  1 keith keith    0 Sep 21 12:51 FETCH_HEAD
-rw-r--r--  1 keith keith   23 Jul 25  2017 HEAD
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 hooks
-rw-rw-r--  1 keith keith 1555 Sep 21 10:47 index
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 info
drwxr-xr-x  3 keith keith 4096 Jul 25  2017 logs
drwxr-xr-x 37 keith keith 4096 Jul 25  2017 objects
-rw-rw-r--  1 keith keith   41 Apr  2  2018 ORIG_HEAD
-rw-rw-r--  1 keith keith   46 Sep 21 10:47 packed-refs
drwxr-xr-x  5 keith keith 4096 Jul 25  2017 refs

.git/objects:
total 148
drwxr-xr-x 37 keith keith 4096 Jul 25  2017 .
drwxr-xr-x  8 keith keith 4096 Sep 21 11:36 ..
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 06
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 0a
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 17
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 22
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 29
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 2d
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 30
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 32
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 35
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 3c
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 3f
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 43
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 4f
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 50
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 53
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 5a
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 5f
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 6e
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 72
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 82
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 96
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 a5
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 a8
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 b4
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 b7
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 b9
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 bc
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 c0
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 c3
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 c9
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 cd
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 e7
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 ea
drwxr-xr-x  2 keith keith 4096 Jul 25  2017 info
drwxr-xr-x  2 keith keith 4096 Apr  2  2018 pack

EDITAR 3 :

No tengo SELinux instalado, así que no sé qué contexto verificar, excepto los permisos de Linux.

Miré /usr/lib/git-core. Todos los archivos (ejecutables y enlaces simbólicos) eran propiedad de root pero tenían permisos rx para todos los usuarios. Más importante:

$ ls -lhZ /usr/lib/git-core/{git-upload-pack,git-pack-objects} 
lrwxrwxrwx 1 root root ?    3 Apr 20 10:20 /usr/lib/git-core/git-pack-objects -> git
-rwxr-xr-x 1 root root ? 1.5M Apr 20 10:20 /usr/lib/git-core/git-upload-pack

Excepto estos:

$ ls -lhZ /usr/lib/git-core/git-sh-*
-rw-r--r-- 1 root root ? 2.3K Apr 20 10:20 /usr/lib/git-core/git-sh-i18n
-rwxr-xr-x 1 root root ? 1.5M Apr 20 10:20 /usr/lib/git-core/git-sh-i18n--envsubst
-rw-r--r-- 1 root root ?  16K Apr 20 10:20 /usr/lib/git-core/git-sh-prompt
-rw-r--r-- 1 root root ? 9.1K Apr 20 10:20 /usr/lib/git-core/git-sh-setup

EDITAR 4 :

Siguiendo la sugerencia de torek de verificar , inicié sesión allí y verifiqué a los mismos sospechosos:myremote

$ ls -lhZ /usr/bin/git* -rwxr-xr-x 1 root root ? 2.7M Apr 19 18:19 /usr/bin/git lrwxrwxrwx 1 root root ? 3 Apr 19 18:19 /usr/bin/git-receive-pack -> git -rwxr-xr-x 1 root root ? 1.5M Apr 19 18:19 /usr/bin/git-shell lrwxrwxrwx 1 root root ? 3 Apr 19 18:19 /usr/bin/git-upload-archive -> git lrwxrwxrwx 1 root root ? 3 Apr 19 18:19 /usr/bin/git-upload-pack -> $ ls -lhZ /usr/lib/git-core/{git-upload-pack,git-pack-objects,git}
-rwxr-xr-- 1 root root ? 2.7M Apr 19 18:19 /usr/lib/git-core/git
lrwxrwxrwx 1 root root ?    3 Apr 19 18:19 /usr/lib/git-core/git-pack-objects -> git
lrwxrwxrwx 1 root root ?    3 Apr 19 18:19 /usr/lib/git-core/git-upload-pack -> git

Ahora veo al culpable.

Respuestas

1 torek Sep 23 2020 at 04:37

La Edición 4 tiene las pistas finales: el problema estaba de hecho en el servidor, que por alguna razón tenía el /usr/lib/git-core/gitbinario como modo 754 ( rwxr-xr--), en lugar del modo 755 ( rwxr-xr-x). Esto significaba que cualquier persona que no fuera el usuario root, y que no estuviera en el grupo root, no podía ejecutarlo, y un simple chmodde ese binario en el servidor solucionaría el problema.

Obsidian Sep 22 2020 at 02:21

Probablemente desee echar un vistazo a su repositorio local .git , especialmente en .git/objects. Consulte las propiedades y los permisos de los archivos y vea si git tiene los derechos para crearlos.

Lo que más probablemente ha sucedido es que probablemente haya ejecutado gituna vez con sudoo haya iniciado sesión temporalmente como root usando su. Siempre que los archivos ya existan, no será un problema porque conservarán sus derechos y propietarios originales, pero si Git tuvo que crear archivos que aún no existen, como la subdirección del objeto empaquetado, si lo hizo como root , es normal no poder explotarlos como su identidad habitual después.

Y esto en realidad podría suceder con cualquier comando, no simplemente con Git. De ahí el mensaje de error, que solo informa el motivo del error dado por el sistema.

EDITAR

Teniendo en cuenta los comentarios a continuación, es probable que también desee consultar el contenido de /usr/libexec/git-core/. Contiene todos los ejecutables que están realmente asociados a los comandos y subcomandos de git.

Entre ellos, mentiras git-pack-objectsque se rigen git-upload-pack. Ambos son ejecutables diferentes y distintos.

Todavía no explica por qué se habrían perdido los derechos aquí, pero sigue siendo un lugar para mirar.

Buena suerte.