【问题标题】:Block and/or Identify Fake author name/email in GIT在 GIT 中阻止和/或识别虚假作者姓名/电子邮件
【发布时间】:2013-01-14 07:48:34
【问题描述】:

我想阻止git commit 中的虚假用户。这意味着一个用户不得与其他人更改他/她的电子邮件。我用gitolite。如何实现此功能?由于我有用户的公钥,我可以将他们的电子邮件/姓名绑定到该公钥吗?

【问题讨论】:

    标签: git security commit gitolite spoofing


    【解决方案1】:

    由于我有用户的公钥,我可以将电子邮件/姓名与该公钥绑定吗?

    非本地:Gitolite 仅适用于用户 ID(从 http 或 ssh 会话中提取并设置在变量 GL_USER 中)

    所以你需要在别处拥有这些信息。

    我使用的是用户提供并存储在gitolite-admin repo 的gitolite/keys 目录中的公钥。

    一个 ssh 公钥由 3 部分组成:

     ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx WhateverYouWant
    

    最后一部分,在公钥之后,是一个字符串,可以代表你想要的。

    我要求用户提供一个包含其电子邮件地址的密钥(最后)。
    然后,我为所有 repo 设置了一个 VREF (an update hook in gitolite),它将验证提交中看到的 user.email 以及从 ~gitolite/.ssh/authorized_keys 文件中提取的电子邮件。
    该文件由 gitolite 管理,包含user.name 及其电子邮件(因为我希望用户给我他们的公钥)

     command=="..../gitolite-shell user-id" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx WhateverYouWant
    

    如果任何电子邮件与正确的用户名不匹配,VREF 挂钩将拒绝推送。


    我自己的VREF CHECKID(略有不同)目的,在gitolite.conf 中声明为:

    repo    @all
      RW+                            = gitoliteadm
      -     VREF/CHECKID             = @all
    

    【讨论】:

    • 感谢您让我了解 VREF。它真的很有用,但不知何故我无法让它与 user.email 一起工作
    • 我有一个用户 - VREF/EMAIL-CHECK = @all 针对一个存储库,甚至还使用 repo @all - VREF/EMAIL-CHECK = @all 这些都不起作用
    • @Sadi 我已经用 VREF 配置示例编辑了我的答案。
    【解决方案2】:

    我写了一个钩子,它采用与之前的答案略有不同的方法。您在顶部输入一个 EMAILDOMAIN,它确保提交日志上的电子邮件地址等于 [提交用户的 SSH 密钥文件名]@[EMAILDOMAIN]。

    我把它扔进了 gitolite-admin/common-hooks,所以它在推送时运行服务器端。

    #!/bin/bash
    
    EMAILDOMAIN="company.com"
    
    if [[ $2 = 0000000000000000000000000000000000000000 ]] || [[ $3 = 0000000000000000000000000000000000000000 ]]
    then
      exit 0
    fi
    
    # get name and email from git log
    EMAILCMD="git log --format="%ce" $3 -1"
    EMAIL=$($EMAILCMD)  
    NAMECMD="git log --format="%cn" $3 -1"
    NAME=$($NAMECMD)
    
    # environment variable for the gitolite user (the SSH key)
    # echo $GL_USER
    
    # compare email with gitolite user
    EXPEMAIL="$GL_USER@$EMAILDOMAIN"
    if [ "{$EXPEMAIL,,}" != "{$EMAIL,,}" ]
    then
      echo "You're committing with the SSH key for '$GL_USER'. That key belongs to $EXPEMAIL."
      echo "  (You've configured your email as $EMAIL)"
      exit 1
    fi
    
    # TODO: maybe, if we ever bother installing mail on this box, send an email to some admins if someone is trying to key share
    
    # check the name...
    IFS=' ' read -ra NAMEPARTS <<< "${NAME,,}"
    PARTCOUNT=0
    for PART in "${NAMEPARTS[@]}"
    do
      PARTCOUNT=$((PARTCOUNT+1))
    done
    
    # make sure it's a full name
    if (( "$PARTCOUNT" < 2 ))
    then
      echo "You should put in your full name, $NAME."
      echo "If you've really only got one name (like Sting or Madonna), email an admin and we can make an exception for you."
      exit 1
    fi
    
    exit 0
    

    【讨论】:

    • 有趣的方法,与我的回答不同。 +1
    猜你喜欢
    • 2015-07-04
    • 2018-05-27
    • 2018-11-21
    • 2012-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多