2017-08-05 42 views
0

我們的校園裏有一臺Solaris服務器,每個學生和工作人員都有一個帳戶。我想要託管一個純粹的Git倉庫並讓它只能被某些用戶訪問。致命:無法執行'掛鉤/更新':使用Git時的權限被拒絕

現在,因爲我不管理服務器,所以我不能搞亂組和用戶帳戶。我知道我可以使用Giotlite併爲我的用戶創建公鑰,但似乎很愚蠢,因爲他們已經在服務器上擁有自己的用戶帳戶。所以我正在做的是使用FACL來訪問特定的用戶。

這裏是我做過什麼來設置使用cs101帳戶在其主目錄回購(這是過程帳戶):

  1. 我創建的回購目錄:mkdir cs101.git
  2. 設置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 
    
  3. 後來終於初始化訪問的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

+0

'getfacl'的輸出表明它*對於'user:welcomb'是可執行的,所以Git會嘗試執行它。目前尚不清楚爲什麼隨後會失敗(是否解釋了?考慮到小文件的大小,我想是這樣;如果是這樣,解釋者的權限是否被拒絕?)。 – torek

+0

'update'的umask不可執行,實際上我無法從終端執行它。你認爲Git認爲它可以從acl執行並嘗試運行它嗎?我該如何檢查它是否被解釋?我不太明白你的意思。 – welcomb

+0

Git調用'access(path,X_OK)',這取決於系統的'access'調用返回什麼,但我期望它更喜歡ACL'stat'模式位。至於它是什麼意思是解釋文件,請參閱https://linux.die.net/man/2/execve – torek

回答

1

getfacl輸出包括線:

user:cs101:rwx   #effective:rwx  
user:welcomb:rwx  #effective:rwx         

這意味着權利要求C庫access(path, X_OK)功能很可能該文件可以被執行(通過execve系統呼叫或類似的運行),在至少對用戶cs101welcomb。這是Git如何確定鉤子是否可執行的。

(請注意,任何其他用戶呼叫access將得到答案:沒有,這個文件不是可執行這是什麼使訪問控制列表等等複雜的部分。)

當OS實際上是嘗試執行它,但是,其他事情出錯了。 出錯,但execve系統調用失敗,出現「權限被拒絕」錯誤,這並不完全清楚。然後Git決定該鉤子失敗,而不是鉤子實際上不可執行(Git假定access將會說而不是對於這些情況)。

鑑於文件的小尺寸(2910字節,來自ls -al update輸出),update鉤子似乎不太可能是shell腳本以外的任何其他東西。如果它是的shell腳本,它需要一個正確的#!解釋器行才能執行,並且該解釋器行必須指向一個本身具有執行權限的文件。

如果您確實希望掛鉤運行,則必須查找實際故障的來源。如果你不要想要運行鉤子,並且不想讓Git到認爲掛鉤應該應該運行,從ACL的各個元素中刪除執行位,或者完全刪除ACL(ACLs和「Unix風格」權限通常是底層系統中的獨立實體,儘管ZFS在此處有所不同)。

相關問題