Indefero

Issue 505: Plugin SyncGit : File /tmp/SYNC-GIT can't be deleted

Reported by Adrien Sulpice, Jul 11, 2010

French :

Je viens de rencontrer un bug avec le plugin SyncGit. Pour mettre à 
jour les clés rsa acceptées par l'utilisateur git 
(~git/.ssh/accepted_keys), lors d'un ajout d'une clé sur le site, 
l'utilisateur www-data crée un fichier nommé 
$cfg['idf_plugin_syncgit_sync_file']. Le nom conseillé dans la 
documentation est /tmp/SYNC-GIT. Le fichier gitcront.php est exécuté 
par un cron ayout pour utilisateur git qui supprime le fichier pour 
dire qu'il a mis à jour. Seulement l'utilisateur git ne peut pas 
supprimer le fichier car il est dans le répertoire /tmp qui 
aparament autorise la suppression seulement au créateur du fichier. 
Le fichier n'est donc jamais supprimé et le script php de 
synchronisation est donc exécuté à chaque fois ce qui est 
consommateur de ressources.

FIX : J'ai trouvé un moyen de contourner ce problème. J'ai créé un 
répertoire nommé sync dans ~git avec comme utilisateur git et comme 
groupe www-data. les permissions sont ensuite définies à 770 soit :

drwxrwx--- 2 git www-data 4096 jui 11 00:34 sync

J'ai ensuite définit la variable dans idf.php :

$cfg['idf_plugin_syncgit_sync_file'] = 
$cfg['idf_plugin_syncgit_git_home_dir'].'/sync/SYNC-GIT';

L'utilisateur www-data peut donc créer le fichier et l'utilisateur 
git peut supprimer le fichier. Le script n'est donc plus exécuté à 
chaque exécution du cron.

Part in english : For the plugin SyncGit, the www-data user creates 
a file in /tmp commonly named SYNC-GIT to advertise the cron that a 
new rsa-key has been added. The cron is executed by the git user. It 
has to delete the file after the update but it has not the 
permissions. The file is not deleted and the cron updates each time 
the keys.

FIX : create a directory named sync in ~git with the user set to 
git, the group www-data and the permissions 770 :

drwxrwx--- 2 git www-data 4096 jui 11 00:34 sync

Then set the variable in idf.php : 

$cfg['idf_plugin_syncgit_sync_file'] = 
$cfg['idf_plugin_syncgit_git_home_dir'].'/sync/SYNC-GIT';

With this configuration, everything works fine.

Comment 1 by Ludovic Bellière, Jul 11, 2010

Symptoms are the same than that following this line.

I'm using a system user (uid<1000) to create a world writeable 
test file in the /tmp directory. Then, login to another system user 
to delete it. In this case : apache and mysql users.

I belive this issue can be resolved in a cleaner way than the fix in 
the first post, but if it works :)

-bash-4.1$ ll test
-rwxrwxrwx 1 apache nogroup 0 2010-07-11 00:20 test*
-bash-4.1$ ll -d .
drwxrwxrwt 19 root root 4096 2010-07-11 00:44 ./
-bash-4.1$ LC_ALL=C rm -fv test
rm: cannot remove `test': Operation not permitted

Comment 2 by Thomas Keller, Sep 1, 2010

Messing around with plain unix permissions is not a good idea, two 
proper ways to the rescue:

1) use fcgi and suexec, so IDF does not run as www-user, but git 
user (this also has the neat aspect that you don't have to give your 
general www-user write access to something you don't really want, 
especially if the user is shared among several vhosts)

2) use at least ACLs, i.e. by applying a default rule for the 
directory in question:

  $ setfacl -m d:u:www-data:rwx /path/to/sync/dir
  $ setfacl -m d:u:<whatever-your-git-user-is>:rwx 
/path/to/sync/dir

Created: 1 year 10 months ago by Adrien Sulpice

Updated: 1 year 8 months ago

Status: New

Followed by: 2 persons

Labels:
Type:Defect
Priority:Medium