Help us learn about your current experience with the documentation. Take the survey.

GitLab Shell 功能列表

发现

允许用户通过 SSH 在实例上识别自己。该命令可以帮助用户快速确认是否拥有对实例的 SSH 访问权限:

ssh git@<hostname>

PTY allocation request failed on channel 0
Welcome to GitLab, @username!
Connection to staging.gitlab.com closed.

当权限被拒绝时,返回:

ssh git@<hostname>
git@<hostname>: Permission denied (publickey).

Git 操作

GitLab Shell 通过处理 git-upload-packgit-receive-packgit-upload-archive SSH 命令,为 Git 操作提供 SSH 支持。 它将命令限制为预定义的 Git 命令:

  • git archive
  • git clone
  • git pull
  • git push

生成新的 2FA 恢复代码

允许用户 生成新的 2FA 恢复代码

$ ssh git@<hostname> 2fa_recovery_codes

Are you sure you want to generate new two-factor recovery codes?
Any existing recovery codes you saved will be invalidated. (yes/no)
yes

Your two-factor authentication recovery codes are:
...

验证 2FA OTP

允许用户验证他们的 2FA 一次性密码 (OTP)

$ ssh git@<hostname> 2fa_verify

OTP: 347419

OTP validation failed.

LFS 认证

允许用户为 LFS 认证生成凭据:

$ ssh git@<hostname> git-lfs-authenticate <project-path> <upload/download>

{"header":{"Authorization":"Basic ..."},"href":"https://gitlab.com/user/project.git/info/lfs","expires_in":7200}

个人访问令牌

允许用户通过 SSH 使用个人访问令牌:

$ ssh git@<hostname> personal_access_token <name> <scope1[,scope2,...]> [ttl_days]

Token:   glpat-...
Scopes:  api
Expires: 2022-02-05

配置选项

管理员可以通过 SSH 控制 PAT 的生成。 要在 GitLab Shell 中配置 PAT 设置:

  1. 编辑 /etc/gitlab/gitlab.rb 文件。

  2. 添加或修改以下配置:

    gitlab_shell['pat'] = { enabled: true, allowed_scopes: [] }
    • enabled: 设置为 true 以启用通过 SSH 生成 PAT,或设置为 false 以禁用它。
    • allowed_scopes: 允许通过 SSH 生成的 PAT 的范围数组。 留空 ([]) 以允许所有范围。
  3. 保存文件并 重启 GitLab

  1. 编辑 values.yaml 文件:

    gitlab:
      gitlab-shell:
        config:
          pat:
            enabled: true
            allowedScopes: []
    • enabled: 设置为 true 以启用通过 SSH 生成 PAT,或设置为 false 以禁用它。
    • allowedScopes: 允许通过 SSH 生成的 PAT 的范围数组。 留空 ([]) 以允许所有
  2. 保存文件并应用新值:

    helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
  1. 编辑 docker-compose.yaml 文件:

    services:
      gitlab:
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            gitlab_shell['pat'] = { enabled: true, allowed_scopes: [] }
    • enabled: 设置为 'true' 以启用通过 SSH 生成 PAT,或设置为 'false' 以禁用它。
    • allowed_scopes: 允许通过 SSH 生成的 PAT 的逗号分隔范围列表。留空 ([]) 以允许所有范围。
  2. 保存文件并重启 GitLab 及其服务:

    docker compose up -d
  1. 编辑 /home/git/gitlab-shell/config.yml 文件:

    pat:
      enabled: true
      allowed_scopes: []
    • enabled: 设置为 true 以启用通过 SSH 生成 PAT,或设置为 false 以禁用它。
    • allowed_scopes: 允许通过 SSH 生成的 PAT 的范围数组。 留空 ([]) 以允许所有范围。
  2. 保存文件并重启 GitLab Shell:

    # For systems running systemd
    sudo systemctl restart gitlab-shell.target
    
    # For systems running SysV init
    sudo service gitlab-shell restart

这些设置仅影响通过 SSH 生成的 PAT,不会影响通过 Web 界面创建的 PAT。