代码之家  ›  专栏  ›  技术社区  ›  Ibrahim

git post receive hook更新其他用户拥有的本地克隆

  •  10
  • Ibrahim  · 技术社区  · 15 年前

    我正在尝试设置一个git post-receive挂钩,这样当接收到提交时,计算机上存储库的另一个克隆将得到更新(即 git pull origin master )我正在使用Gitosi为存储库服务,因此我相信Post-Receive钩子将作为 gitosis 用户,而我要在接收时更新的存储库属于 www-data . 我该怎么做呢?

    我听说过 setuid 脚本,但我不确定这是否有安全风险?如果这不是安全风险,我该怎么做呢?我想我会做一些事情,比如让剧本归 万维网数据 并使其成为世界可执行文件并启用setuid位?我想这个脚本将是相当无害的,因为它所做的只是更新存储库,但我想确定。谢谢!

    编辑:有什么方法可以用 sudo ?那会比 设置用户标识符 ?我的意思是,我觉得没有什么问题 设置用户标识符 如果用户不是根用户,但一切都一样,似乎我必须跳过几个圈才能得到一个 设置用户标识符 要运行的脚本。

    第二次编辑:看起来我 可以 可以用一些 /etc/sudoers 魔法与 sudo -u . 也许我应该把这个贴在serverfault上,但至少我从这项工作中学到了一些东西。

    2 回复  |  直到 13 年前
        1
  •  14
  •   Kimvais    15 年前

    imho这应该是serverfault,但这里是答案;

    添加:

    gitosis ALL=(www-data) NOPASSWD: /path/to/git
    

    向/ ETC /苏道人

    并以如下方式运行命令 sudo -u www-data <whatever the command is>

        2
  •  4
  •   Taai    13 年前

    注意我正在使用 吉特 用户名,因此,如果您使用 甲状腺机能亢进 或任何其他用户名,只需填写您的!

    在控制台 用户执行此命令:

    visudo
    

    将打开“vi”编辑器。添加这些行:

    Defaults:git    !authenticate
    git ALL=(www-data) ALL
    

    结果文件(通过调用“visudo”在“vi”编辑器中打开)应该如下所示:

    # /etc/sudoers
    #
    # This file MUST be edited with the 'visudo' command as root.
    #
    # See the man page for details on how to write a sudoers file.
    #
    
    Defaults    env_reset
    Defaults:git    !authenticate
    
    # Host alias specification
    
    # User alias specification
    
    # Cmnd alias specification
    
    # User privilege specification
    root    ALL=(ALL) ALL
    git ALL=(www-data) ALL
    
    
    # Allow members of group sudo to execute any command
    # (Note that later entries override this, so you might need to move
    # it further down)
    %sudo ALL=(ALL) ALL
    #
    #includedir /etc/sudoers.d
    

    然后按ctrl+o保存文件,然后按enter接受文件名(bla bla bla),然后按ctrl+x关闭“vi”编辑器。

    哇!现在 吉特 用户可以执行命令 万维网数据 用户:

    sudo -u www-data git pull origin master
    
    推荐文章