端口9418上的未经身份验证的git协议不再受支持。

94

我已经使用 GitHub Actions 有一段时间了,但今天我的部署开始失败了。以下是从 GitHub Action 日志中获取的错误信息:

Command: git
Arguments: ls-remote --tags --heads git://github.com/adobe-webplatform/eve.git
Directory: /home/runner/work/stackstream-fe/stackstream-fe
Output:
fatal: remote error: 
  The unauthenticated git protocol on port 9418 is no longer supported.

经过调查,似乎我yml文件中以下部分引起了问题。

    - name: Installing modules
      run: yarn install

我已经查看了这个变更日志,但似乎无法理解问题。

附加细节: 服务器:EC2实例 Github操作步骤:

  steps:
  - name: Checkout
    uses: actions/checkout@v2

  - id: vars
    run: |
      if [ '${{ github.ref }}' == 'refs/heads/master' ]; then echo "::set-output name=environment::prod_stackstream" ; echo "::set-output name=api-url::api" ; elif [ '${{ github.ref }}' == 'refs/heads/staging' ]; then echo "::set-output name=environment::staging_stackstream"  ; echo "::set-output name=api-url::stagingapi" ; else echo "::set-output name=environment::dev_stackstream" ; echo "::set-output name=api-url::devapi" ; fi

  - uses: pCYSl5EDgo/cat@master
    id: slack
    with:
      path: .github/workflows/slack.txt

  - name: Slack Start Notification
    uses: 8398a7/action-slack@v3
    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
      ENVIRONMENT: '`${{ steps.vars.outputs.environment }}`'
      COLOR: good
      STATUS: '`Started`'
    with:
      status: custom
      fields: workflow,job,commit,repo,ref,author,took
      custom_payload: |
        ${{ steps.slack.outputs.text }}

  - name: Installing modules
    env:
      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
    run: yarn install

  - name: Create Frontend Build
    env:
      REACT_APP_API_URL: 'https://${{ steps.vars.outputs.api-url }}mergestack.com/api/v1'
    run: yarn build

  - name: Deploy to Frontend Server DEV
    if: ${{ contains(github.ref, 'dev') }}
    uses: easingthemes/ssh-deploy@v2.1.5
    env:
      SSH_PRIVATE_KEY: ${{ secrets.DEV_KEY }}
      ARGS: '-rltgoDzvO --delete'
      SOURCE: 'deploy/'
      REMOTE_HOST: ${{ secrets.DEV_HOST }}
      REMOTE_USER: plyfolio-dev
      TARGET: '/home/plyfolio-dev/${{ steps.vars.outputs.environment }}/fe/deploy'

package.json文件

   {
  "name": "stackstream-fe",
  "version": "1.0.0",
  "authors": [
    "fayyaznofal@gmail.com"
  ],
  "private": true,
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.34",
    "@fortawesome/free-solid-svg-icons": "^5.15.2",
    "@fortawesome/react-fontawesome": "^0.1.14",
    "@fullcalendar/bootstrap": "^5.5.0",
    "@fullcalendar/core": "^5.5.0",
    "@fullcalendar/daygrid": "^5.5.0",
    "@fullcalendar/interaction": "^5.5.0",
    "@fullcalendar/react": "^5.5.0",
    "@lourenci/react-kanban": "^2.1.0",
    "@redux-saga/simple-saga-monitor": "^1.1.2",
    "@testing-library/jest-dom": "^5.11.9",
    "@testing-library/react": "^11.2.3",
    "@testing-library/user-event": "^12.6.0",
    "@toast-ui/react-chart": "^1.0.2",
    "@types/jest": "^26.0.14",
    "@types/node": "^14.10.3",
    "@types/react": "^16.9.49",
    "@types/react-dom": "^16.9.8",
    "@vtaits/react-color-picker": "^0.1.1",
    "apexcharts": "^3.23.1",
    "availity-reactstrap-validation": "^2.7.0",
    "axios": "^0.21.1",
    "axios-mock-adapter": "^1.19.0",
    "axios-progress-bar": "^1.2.0",
    "bootstrap": "^5.0.0-beta2",
    "chart.js": "^2.9.4",
    "chartist": "^0.11.4",
    "classnames": "^2.2.6",
    "components": "^0.1.0",
    "dotenv": "^8.2.0",
    "draft-js": "^0.11.7",
    "echarts": "^4.9.0",
    "echarts-for-react": "^2.0.16",
    "firebase": "^8.2.3",
    "google-maps-react": "^2.0.6",
    "history": "^4.10.1",
    "i": "^0.3.6",
    "i18next": "^19.8.4",
    "i18next-browser-languagedetector": "^6.0.1",
    "jsonwebtoken": "^8.5.1",
    "leaflet": "^1.7.1",
    "lodash": "^4.17.21",
    "lodash.clonedeep": "^4.5.0",
    "lodash.get": "^4.4.2",
    "metismenujs": "^1.2.1",
    "mkdirp": "^1.0.4",
    "moment": "2.29.1",
    "moment-timezone": "^0.5.32",
    "nouislider-react": "^3.3.9",
    "npm": "^7.6.3",
    "prop-types": "^15.7.2",
    "query-string": "^6.14.0",
    "react": "^16.13.1",
    "react-apexcharts": "^1.3.7",
    "react-auth-code-input": "^1.0.0",
    "react-avatar": "^3.10.0",
    "react-bootstrap": "^1.5.0",
    "react-bootstrap-editable": "^0.8.2",
    "react-bootstrap-sweetalert": "^5.2.0",
    "react-bootstrap-table-next": "^4.0.3",
    "react-bootstrap-table2-editor": "^1.4.0",
    "react-bootstrap-table2-paginator": "^2.1.2",
    "react-bootstrap-table2-toolkit": "^2.1.3",
    "react-chartist": "^0.14.3",
    "react-chartjs-2": "^2.11.1",
    "react-color": "^2.19.3",
    "react-confirm-alert": "^2.7.0",
    "react-content-loader": "^6.0.1",
    "react-countdown": "^2.3.1",
    "react-countup": "^4.3.3",
    "react-cropper": "^2.1.4",
    "react-data-table-component": "^6.11.8",
    "react-date-picker": "^8.0.6",
    "react-datepicker": "^3.4.1",
    "react-dom": "^16.13.1",
    "react-draft-wysiwyg": "^1.14.5",
    "react-drag-listview": "^0.1.8",
    "react-drawer": "^1.3.4",
    "react-dropzone": "^11.2.4",
    "react-dual-listbox": "^2.0.0",
    "react-facebook-login": "^4.1.1",
    "react-flatpickr": "^3.10.6",
    "react-google-login": "^5.2.2",
    "react-hook-form": "^7.15.2",
    "react-i18next": "^11.8.5",
    "react-icons": "^4.2.0",
    "react-image-lightbox": "^5.1.1",
    "react-input-mask": "^2.0.4",
    "react-jvectormap": "^0.0.16",
    "react-leaflet": "^3.0.5",
    "react-meta-tags": "^1.0.1",
    "react-modal-video": "^1.2.6",
    "react-notifications": "^1.7.2",
    "react-number-format": "^4.7.3",
    "react-perfect-scrollbar": "^1.5.8",
    "react-rangeslider": "^2.2.0",
    "react-rating": "^2.0.5",
    "react-rating-tooltip": "^1.1.6",
    "react-redux": "^7.2.1",
    "react-responsive-carousel": "^3.2.11",
    "react-router-dom": "^5.2.0",
    "react-script": "^2.0.5",
    "react-scripts": "3.4.3",
    "react-select": "^4.3.1",
    "react-sparklines": "^1.7.0",
    "react-star-ratings": "^2.3.0",
    "react-super-responsive-table": "^5.2.0",
    "react-switch": "^6.0.0",
    "react-table": "^7.6.3",
    "react-toastify": "^7.0.3",
    "react-toastr": "^3.0.0",
    "react-twitter-auth": "0.0.13",
    "reactstrap": "^8.8.1",
    "recharts": "^2.0.8",
    "redux": "^4.0.5",
    "redux-saga": "^1.1.3",
    "reselect": "^4.0.0",
    "sass": "^1.37.5",
    "simplebar-react": "^2.3.0",
    "styled": "^1.0.0",
    "styled-components": "^5.2.1",
    "toastr": "^2.1.4",
    "typescript": "^4.0.2",
    "universal-cookie": "^4.0.4"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.27.0",
    "@typescript-eslint/parser": "^2.27.0",
    "@typescript-eslint/typescript-estree": "^4.15.2",
    "eslint-config-prettier": "^6.10.1",
    "eslint-plugin-prettier": "^3.1.2",
    "husky": "^4.2.5",
    "lint-staged": "^10.1.3",
    "prettier": "^1.19.1",
    "react-test-renderer": "^16.13.1",
    "redux-devtools-extension": "^2.13.8",
    "redux-mock-store": "^1.5.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build && mv build ./deploy/build",
    "build-local": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,ts,tsx}": [
      "eslint --fix"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

package-lock.json


5
我对不对,这个问题对于许多Yocto项目层来说都将是一个巨大的问题。 - Logan
1
@Mixxiphoid 他们(GitHub)可能错过了项目拉取的所有间接依赖项,而这些间接依赖项仍然可能包括一些 git:// URL。 - VonC
1
所以,我认为会有很多人在他们的项目中有这种依赖关系。 - monofal
3
@Logan:这是一个为期4个月的警告。整个互联网已经在过去十年中逐渐远离未经身份验证和未加密的协议,这并不是一个巨大的惊喜。就个人而言,我认为这不是一个"问题",而更像是"检测未维护依赖项"。此外,现在只是停机期,因此协议将仅被短暂禁用,以便开发人员发现问题。永久关闭要等到三月份。 - Jörg W Mittag
7
四个月?是给谁和在哪里呢,我很好奇,这是我第一次听说! - deep64blue
显示剩余2条评论
10个回答

111
首先,这个错误消息确实是在2022年1月11日预期的。请参见“Improving Git protocol security on GitHub”。

2022年1月11日 最终停机期。

这是完整的停机期,在此期间我们将暂时停止接受已弃用的密钥和签名类型、密码、MAC以及未加密的Git协议。
这将帮助客户端发现任何旧密钥或旧URL的残留使用。

其次,请检查您的package.json依赖项中是否有任何git:// URL,如this example所示,已在this PR中修复。
正如Jörg W Mittag所指出的那样:noted
有4个月的警告。 整个互联网已经在过去十年中逐渐摆脱未经身份验证、未加密的协议,这不是一个巨大的惊喜。 就个人而言,我认为这不是一个“问题”,而是“检测到未维护的依赖项”。 此外,这仍然只是短暂的减少期,所以协议只会被禁用一小段时间,让开发者发现问题。 永久关闭要到3月15日才会进行。

针对 GitHub Actions:

正如actions/checkout issue 14所述,您可以将其作为第一步添加:

    - name: Fix up git URLs
      run: echo -e '[url "https://github.com/"]\n  insteadOf = "git://github.com/"' >> ~/.gitconfig

这将把任何git://github.com/更改为https://github.com/

对于本地项目

对于您的所有存储库,您可以设置:

git config --global url."https://github.com/".insteadOf git://github.com/

你也可以使用SSH,但GitHub安全提醒我们,自2022年3月15日起,GitHub停止接受DSA密钥。在2021年11月2日之后上传的RSA密钥仅能使用SHA-2签名。
废弃的MAC、密码和未加密的Git协议已经被永久禁用。

因此,以下内容(使用正确的密钥)将有效:

git config --global url."git@github.com:".insteadOf git://github.com/

这将把任何git://github.com/(未加密的Git协议)转换为git@github.com:(SSH URL)。


谢谢@VonC。我确实检查了package.json和package-lock.json,但没有使用git://的依赖项。 - monofal
@monofal 可能是一些间接依赖关系。如果可能的话,您应该设置一个 insteadOf Git 设置:https://dev59.com/C3I-5IYBdhLWcg3wsKv9#11383587 - VonC
@monofal 示例:https://github.com/actions/checkout/issues/14#issuecomment-523916396 - VonC
我应该将其用于Git子模块吗? - sejn
@sejn 是的,这对子模块 URL 也适用。 - VonC

77

在安装之前,请尝试使用以下命令:

git config --global url."https://".insteadOf git://

附言或更好的选择(感谢 @bgraves)

git config --global url."https://github.com/".insteadOf git://github.com/

2
可行!避免等待仓库更新。 - Collin Price
28
建议使用简化版 git config --global url."https://github.com/".insteadOf git://github.com/ - bgraves

19

尝试使用https://github.com而不是git://github.com


1
这是最简单和最有效的方法。 - BuffMcBigHuge
2
@BuffMcBigHuge,我在我的答案中已经提到了一个,它是在 GitHub Action yaml 上下文中使用的,因为问题是关于 GitHub Action 的。 - VonC
3
这正是GitHub在他们的博客文章中所推荐的。引用这个准官方资源可以作为您提出的解决方案正确性和适用性的依据,从而提高您答案的质量。 - Cody Gray

8
我希望这个答案能提供其他答案中省略的更多上下文信息。
Git可以使用四种协议来传输数据:
  • 本地(此处不相关)
  • (智能) HTTP - 运行在标准HTTPS端口上,并且可以使用各种HTTP身份验证机制(例如用户名/密码)如果需要验证。该协议允许您使用相同的URL提供读取和写入访问权限;如果需要验证,服务器将提示客户端。
  • 安全外壳层 (SSH) - 认证工作流程,其中读取和写入都经过身份验证。它不支持未经身份验证的(即匿名的)访问。用户需要在本地生成一个SSH密钥对(包含私钥和公钥),并将其公钥上传到服务器。
  • Git协议 - 未加密且未经身份验证。有一个Git Daemon在Git服务器上运行,监听端口9418并服务请求。
每个协议使用不同的URL:
  • 本地:
    • 绝对路径(如/srv/git/project.git
    • 使用file://协议前缀的绝对路径(如file:///srv/git/project.git
  • HTTP:https://example.com/gitproject.git
  • SSH
    • ssh://[user@]server/project.git
    • 更短的SCP类似语法 - [user@]server:project.git
  • Git协议 - 以git://开头

GitHub已经停止支持所有未加密协议, 这仅包括使用git://前缀的Git协议。因此,The unauthenticated git protocol on port 9418 is no longer supported.错误证实了这一点。

减轻这个问题的方法是在你的package.json和锁定文件(例如yarn.lockpackage-lock.json)中搜索字符串git://,以确定有问题的包,并将其升级到不使用解析为带有git://前缀的依赖项版本。如果有问题的包不在你的package.json中,你可能会发现运行像yarn why这样的命令有助于理解为什么安装了该包。
如果这不可能,并且存储库是公共的,一个临时的解决方案是手动将git://替换为https://。但这个解决方案并不是永久的,下一次写入锁定文件时可能会被覆盖。

8

@toast-ui/react-chart依赖在这里给您带来了问题。

如果您仔细查看package-lock.json文件,可以追溯到eve,然后追踪到@toast-ui/react-chart

您可以使用同样的技巧查找项目中的其他问题。


2
感谢@ahmad faraz的帮助。确实如此,这就是问题所在。我的package.json文件中有一些依赖项,而这些依赖项又使用了一些其他的依赖项,这导致了GitHub最新升级时出现了问题。我并不需要那个特定的依赖项,所以我将其删除了,然后它就像魔术般地工作了。 - monofal

7
将您存储库的 .git/config 文件中的 git://github.com/<blah> 更改为 git@github.com:<blah>(请注意结尾处的 /:)。
在我的存储库的 .git/config 文件中,我有这行内容。
[remote "upstream"]
    url = git://github.com/curlconverter/curlconverter.git
    fetch = +refs/heads/*:refs/remotes/upstream/*

我将其更改为

[remote "upstream"]
    url = git@github.com:curlconverter/curlconverter.git
    fetch = +refs/heads/*:refs/remotes/upstream/*

并且不再收到此错误。


2
请将以下代码添加到 ~/.gitconfig 文件中:

[url "https://"]

    insteadOf = ssh://

[网址 "https://"]

    insteadOf = git://

2
当其他方法都无法解决问题时,请尝试编辑全局配置并移除所有的instead of声明。git config --global --edit

唯一对我有用的答案。我的配置文件里充斥着来自各方的所有insteadOf命令。 - 55 Cancri

1

你好,尝试以下选项-这个对我有效:

git config --global url."https://github".insteadOf git://github

现在 GitHub 将不支持未经身份验证的 Git 协议。 https://github.blog/2021-09-01-improving-git-protocol-security-github/ 我之前遇到了以下错误:
Unhandled rejection Error: Command failed: /usr/bin/git submodule update -q --init --recursive
warning: templates not found /tmp/pacote-git-template-tmp/git-clone-a001527f
fatal: remote error:
  The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
fatal: clone of 'git://github.com/jquery/sizzle.git' into submodule path '/root/.npm/_cacache/tmp/git-clone-19674e32/src/sizzle' failed
Failed to clone 'src/sizzle'. Retry scheduled
warning: templates not found /tmp/pacote-git-template-tmp/git-clone-a001527f

1
是的,您将在我两个月前的答案中看到相同的git配置行。 - VonC

1

如果您在运行类似于pip install git+git://github.com/SomeCompany/somerepo.git@sometag的命令时遇到此问题,则只需更改git+git的第二部分,即变成pip install git+https://github.com/SomeCompany/somerepo.git@sometag


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接