设为首页 收藏本站
查看: 1256|回复: 0

[经验分享] [macOS] keychain的跳坑之旅!git拉取的权限问题

[复制链接]

尚未签到

发表于 2018-1-14 11:12:13 | 显示全部楼层 |阅读模式
  故事背景,svn与git各有长处,不过git大势所趋吧,那就搞搞。git的服务端,是基于phabricator搭建的,关于它的资料自行google就好了。其实之前运维已经搭好了phabricator了,也给过我叫做test的账号去试过了,只不过还有些问题没处理好,拖了一段时间后,我着手来弄一下。
  1. 建diffusion
  详细就不多说,diffusion名字叫swallowframework,很简单,也有教程。
  第一次,没有分权限,所有人都可以visit, push
  ```
  git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
  ```
  代码可以正常拉取,没问题
  第二次,将用户按项目分了组,只有php项目的人才能visit, push,将我自己加入到php项目里面去
  ```
  git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
  ```
  报错了!
  ```
  fatal: unable to access 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/': The requested URL returned error: 403
  ```
  一看这提示就是权限问题。当然是google啦,找来找去,phabricator上面的设置都是正常的。
  又叫了在php项目的同事去拉代码。卧槽,他们是正常的,而且拉取的时候,会提示让他输入账号,密码,而我的拉取过程,根本就没有提示我去输入账号密码!
  只能通过输出拉取的调试信息来看看问题在哪里了,使用的是GIT_CURL_VERBOSE=1
  ```
  GIT_CURL_VERBOSE=1 git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
  ```
  输出的详细信息如下
  ```
  Cloning into 'eelly_swallow'...
  * Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
  *   Trying 172.18.107.96...
  * TCP_NODELAY set
  * Connected to phabricator.eelly.test (172.18.107.96) port 80 (#0)
  > GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
  Host: phabricator.eelly.test
  User-Agent: git/2.10.1 (Apple Git-78)
  Accept: */*
  Accept-Encoding: gzip
  Pragma: no-cache
  < HTTP/1.1 401 You must log in to access repositories.
  < Server: nginx
  < Date: Thu, 09 Mar 2017 13:59:26 GMT
  < Content-Type: text/html;
  < Transfer-Encoding: chunked
  < Connection: keep-alive
  < WWW-Authenticate: Basic realm="Phabricator Repositories"
  <
  * Curl_http_done: called premature == 0
  * Connection #0 to host phabricator.eelly.test left intact
  * Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
  * Found bundle for host phabricator.eelly.test: 0x7ff01250c7c0 [can pipeline]
  * Hostname phabricator.eelly.test was found in DNS cache
  *   Trying 172.18.107.96...
  * TCP_NODELAY set
  * Connected to phabricator.eelly.test (172.18.107.96) port 80 (#1)
  > GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
  Host: phabricator.eelly.test
  User-Agent: git/2.10.1 (Apple Git-78)
  Accept: */*
  Accept-Encoding: gzip
  Pragma: no-cache
  < HTTP/1.1 401 You must log in to access repositories.
  < Server: nginx
  < Date: Thu, 09 Mar 2017 13:59:26 GMT
  < Content-Type: text/html; charset=utf-8
  < Transfer-Encoding: chunked
  < Connection: keep-alive
  < WWW-Authenticate: Basic realm="Phabricator Repositories"
  <
  * Ignoring the response-body
  * Curl_http_done: called premature == 0
  * Connection #1 to host phabricator.eelly.test left intact
  * Issue another request to this URL: 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack'
  * Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
  * Found bundle for host phabricator.eelly.test: 0x7ff01250c7c0 [can pipeline]
  * Re-using existing connection! (#1) with host phabricator.eelly.test
  * Connected to phabricator.eelly.test (172.18.107.96) port 80 (#1)
  * Server auth using Basic with user 'test'
  > GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
  Host: phabricator.eelly.test
  Authorization: Basic dGVzdDp0MTIzNDU2Nzg=
  User-Agent: git/2.10.1 (Apple Git-78)
  Accept: */*
  Accept-Encoding: gzip
  Pragma: no-cache
  < HTTP/1.1 403 You do not have permission to access this repository.
  < Server: nginx
  < Date: Thu, 09 Mar 2017 13:59:26 GMT
  < Content-Type: text/html; charset=utf-8
  < Transfer-Encoding: chunked
  < Connection: keep-alive
  < Vary: Accept-Encoding
  < Content-Encoding: gzip
  <
  * Curl_http_done: called premature == 0
  * Connection #1 to host phabricator.eelly.test left intact
  fatal: unable to access 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/': The requested URL returned error: 403
  ```
  这里涉及的几次握手的过程就不详细解释了,大家用心看一下还是可以明白的。
  重点关注这几行代码
  ```
  * Ignoring the response-body
  * Curl_http_done: called premature == 0
  * Connection #1 to host phabricator.eelly.test left intact
  * Issue another request to this URL: 'http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack'
  * Couldn't find host phabricator.eelly.test in the .netrc file; using defaults
  * Found bundle for host phabricator.eelly.test: 0x7ff01250c7c0 [can pipeline]
  * Re-using existing connection! (#1) with host phabricator.eelly.test
  * Connected to phabricator.eelly.test (172.18.107.96) port 80 (#1)
  * Server auth using Basic with user 'test'
  > GET /diffusion/SWALLOWFRAMEWORK/swallowframework.git/info/refs?service=git-upload-pack HTTP/1.1
  Host: phabricator.eelly.test
  Authorization: Basic dGVzdDp0MTIzNDU2Nzg=
  User-Agent: git/2.10.1 (Apple Git-78)
  Accept: */*
  Accept-Encoding: gzip
  Pragma: no-cache
  ```
  这里的意思是,Ignoring the response-body,忽略响应的内容,Server auth using Basic with user 'test',直接用test这个账号去尝试登录。我在其它同事debug这个clone的过程,是没有这些步骤的,他们是,去到 WWW-Authenticate: Basic realm="Phabricator Repositories" 这一步的时候,就会显示输入账号密码的过程,怎么回事呢?为什么一直都是用test这个账号去尝试登录呢?
  过程是很复杂的,反正也花了两个小时去找解决方案,也尝试了不同方法。最后在这里找到了头绪,http://git.vger.kernel.narkive.com/iW0NHyKd/git-https-transport-and-wrong-password
  这文章里面关键点在于这些对话
  ```
  1. Using a credential helper that supports secure long-term storage
  (osxkeychain, wincred, etc).
  2. Specifying the username to the credential subsystem explicitly, by
  putting something like:
[credential "https://yourhost/"]

  username = yourusername
  in your git config.
  ```
  意思是说,在你的git config里面,直接针对某个远程地址,设置账号,于是我改了一下自己的git配置
  ```
  vim ~/.gitconfig
  ```
  在后面加入
  ```
[credential "http://phabricator.eelly.test"]

  username = xxxxxxx
  ```
  再次进行拉取
  ```
  GIT_CURL_VERBOSE=1 git clone http://phabricator.eelly.test/diffusion/SWALLOWFRAMEWORK/swallowframework.git eelly_swallow
  ```
  这次就正常了,提示我输入密码,搞掂!从以上文章,大概联想了一下,应该是macOS的keychain保存了一些账号导致在clone的时候,默认使用了test这个账号去进行登录的,于是再看了下keychain里面的东西。真是无语了,果然是这样子

  干脆一做二不休,直接将keychain对应的账号密码,由test改为我自己的账号密码,完成!
  have fun with macOS & git!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-434965-1-1.html 上篇帖子: 新建一个angularjs+requirejs+bootstrap+typescript+gulp+vscode+git的项目 下篇帖子: 使用git命令提交远程github仓库的时候提示"rejected"(拒绝)解决办法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表