我們的校園裏有一臺Solaris服務器,每個學生和工作人員都有一個帳戶。我想要託管一個純粹的Git倉庫並讓它只能被某些用戶訪問。致命:無法執行'掛鉤/更新':使用Git時的權限被拒絕
現在,因爲我不管理服務器,所以我不能搞亂組和用戶帳戶。我知道我可以使用Giotlite併爲我的用戶創建公鑰,但似乎很愚蠢,因爲他們已經在服務器上擁有自己的用戶帳戶。所以我正在做的是使用FACL來訪問特定的用戶。
這裏是我做過什麼來設置使用cs101
帳戶在其主目錄回購(這是過程帳戶):
- 我創建的回購目錄:
mkdir cs101.git
設置FACL用給我的用戶帳戶
setfacl -m d:u::rwx,d:g::---,d:o:---,d:m:rwx cs101.git setfacl -m d:u:cs101:rwx,u:cs101:rwx,d:u:welcomb:rwx,u:welcomb:rwx cs101.git
後來終於初始化訪問的Git
權限cd cs101.git git init --bare --shared
的目錄列表顯示
total 88
drwx--S---+ 7 cs101 cs101 4096 Aug 3 14:33 .
drwx-----x 6 cs101 cs101 4096 Aug 5 15:02 ..
drwxrws---+ 2 cs101 cs101 4096 Aug 3 14:33 branches
-rw-rw----+ 1 cs101 cs101 126 Aug 3 14:33 config
-rw-rw----+ 1 cs101 cs101 73 Aug 3 14:33 description
-rw-rw----+ 1 cs101 cs101 23 Aug 3 14:33 HEAD
drwxrws---+ 2 cs101 cs101 4096 Aug 3 14:33 hooks
drwxrws---+ 2 cs101 cs101 4096 Aug 3 14:33 info
drwxrws---+ 33 cs101 cs101 4096 Aug 5 15:10 objects
drwxrws---+ 4 cs101 cs101 4096 Aug 3 14:33 refs
權限的目錄似乎是正確的
# file: hooks/
# owner: cs101
# group: cs101
user::rwx
user:cs101:rwx #effective:rwx
user:welcomb:rwx #effective:rwx
group::rwx #effective:rwx
mask:rwx
other:---
default:user::rwx
default:user:cs101:rwx
default:user:welcomb:rwx
default:group::---
default:mask:rwx
default:other:---
仍在使用過程帳戶cs101
,我把一些文件到回購。
現在,我退出過程帳戶和登錄使用我自己的用戶帳戶,我能夠克隆回購[email protected]$ git clone ~cs101/cs101.git
到目前爲止好,一切都顯示正常。
現在的問題是,我無法用我自己的用戶帳戶推新提交回回購:
[email protected]$ GIT_TRACE=1 git push
trace: built-in: git 'push'
trace: run_command: 'git-receive-pack '\''/home/course/cs101'\'''
trace: exec: '/bin/bash' '-c' 'git-receive-pack '\''/home/course/cs101'\''' 'git-receive-pack '\''/home/course/cs101'\'''
trace: built-in: git 'receive-pack' '/home/course/cs101'
trace: run_command: 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '-q'
trace: exec: 'git' 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '-q'
trace: built-in: git 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '-q'
trace: run_command: 'unpack-objects' '--pack_header=2,3' '-q'
remote: trace: exec: 'git' 'unpack-objects' '--pack_header=2,3' '-q'
remote: trace: built-in: git 'unpack-objects' '--pack_header=2,3' '-q'
trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all'
trace: exec: 'git' 'rev-list' '--objects' '--stdin' '--not' '--all'
trace: built-in: git 'rev-list' '--objects' '--stdin' '--not' '--all'
trace: run_command: 'hooks/update' 'refs/heads/master' '629b5b1f0122de95bd4e7b50a7968e64aaef6e65' 'b2072da84ee7d3fde6c6daf2cae61dbae6b0a5d9'
fatal: cannot exec 'hooks/update': Permission denied
remote: error: hook declined to update refs/heads/master
trace: run_command: 'gc' '--auto' '--quiet'
trace: exec: 'git' 'gc' '--auto' '--quiet'
trace: built-in: git 'gc' '--auto' '--quiet'
To /home/course/cs101
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to '/home/course/cs101'
現在看來,這是無法執行hooks/update
。
fatal: cannot exec 'hooks/update': Permission denied
但hooks/update
EXEC位 甚至沒有設置,這意味着Git的應該忽略運行它。
/home/course/cs101/cs101.git/hooks$ getfacl update
# file: update
# owner: cs101
# group: cs101
user::rw-
user:cs101:rwx #effective:rwx
user:welcomb:rwx #effective:rwx
group::rw- #effective:rw-
mask:rwx
other:---
/home/course/cs101/cs101.git/hooks$ ls -al update
-rw-rw---- 1 cs101 cs101 2910 Aug 4 10:50 update
我可以訪問這些文件的目錄,甚至用我的帳戶
/home/course/cs101/cs101.git/hooks$ ./update.sample
Don't run this script from the command line.
(if you want, you could supply GIT_DIR then run
./update.sample <ref> <oldrev> <newrev>)
所以我想不通爲什麼推送操作失敗更新回購執行update.sample
。
'getfacl'的輸出表明它*對於'user:welcomb'是可執行的,所以Git會嘗試執行它。目前尚不清楚爲什麼隨後會失敗(是否解釋了?考慮到小文件的大小,我想是這樣;如果是這樣,解釋者的權限是否被拒絕?)。 – torek
'update'的umask不可執行,實際上我無法從終端執行它。你認爲Git認爲它可以從acl執行並嘗試運行它嗎?我該如何檢查它是否被解釋?我不太明白你的意思。 – welcomb
Git調用'access(path,X_OK)',這取決於系統的'access'調用返回什麼,但我期望它更喜歡ACL'stat'模式位。至於它是什麼意思是解釋文件,請參閱https://linux.die.net/man/2/execve – torek