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

Secure Files 管理

  • 版本:Free, Premium, Ultimate
  • 产品:GitLab Self-Managed

您可以将多达 100 个文件作为 secure files 安全存储,以供 CI/CD pipelines 使用。这些文件安全地存储在您项目的仓库之外,并且不进行版本控制。在这些文件中存储敏感信息是安全的。Secure files 支持纯文本和二进制文件类型,大小必须为 5 MB 或更小。

这些文件的存储位置可以使用下面描述的选项进行配置,但默认位置为:

  • 对于使用 Linux package 的安装,路径为 /var/opt/gitlab/gitlab-rails/shared/ci_secure_files
  • 对于自行编译的安装,路径为 /home/git/gitlab/shared/ci_secure_files

对于 GitLab Helm chart 安装,请使用 external object storage 配置。

禁用 Secure Files

您可以在整个 GitLab 实例中禁用 Secure Files。您可能希望禁用 Secure Files 以减少磁盘空间,或移除对该功能的访问权限。

要禁用 Secure Files,请根据您的安装类型按照以下步骤操作。

前提条件:

  • 您必须是管理员。

对于 Linux package 安装

  1. 编辑 /etc/gitlab/gitlab.rb 并添加以下行:

    gitlab_rails['ci_secure_files_enabled'] = false
  2. 保存文件并重新配置 GitLab

对于自行编译的安装

  1. 编辑 /home/git/gitlab/config/gitlab.yml 并添加或修改以下行:

    ci_secure_files:
      enabled: false
  2. 保存文件并重启 GitLab以使更改生效。

使用本地存储

默认配置使用本地存储。要更改 Secure Files 的本地存储位置,请按照以下步骤操作。

对于 Linux package 安装

  1. 例如,要将存储路径更改为 /mnt/storage/ci_secure_files,请编辑 /etc/gitlab/gitlab.rb 并添加以下行:

    gitlab_rails['ci_secure_files_storage_path'] = "/mnt/storage/ci_secure_files"
  2. 保存文件并重新配置 GitLab

对于自行编译的安装

  1. 例如,要将存储路径更改为 /mnt/storage/ci_secure_files,请编辑 /home/git/gitlab/config/gitlab.yml 并添加或修改以下行:

    ci_secure_files:
      enabled: true
      storage_path: /mnt/storage/ci_secure_files
  2. 保存文件并重启 GitLab 以使更改生效。

使用对象存储

  • 版本:Free, Premium, Ultimate
  • 产品:GitLab Self-Managed

与其将 Secure Files 存储在磁盘上,您应该使用一种受支持的对象存储选项。 此配置依赖于已配置的有效凭据。

统一对象存储

建议使用对象存储的统一形式

特定于存储的对象存储

以下设置是:

  • 在自行编译的安装中,嵌套在 ci_secure_files: 之下,然后是 object_store:
  • 在 Linux package 安装中,以 ci_secure_files_object_store_ 为前缀。
设置 描述 默认值
enabled 启用/禁用对象存储 false
remote_directory 存储 Secure Files 的 bucket 名称
connection 下面描述的各种连接选项

S3 兼容的连接设置

请参阅不同提供商可用的连接设置

  1. 编辑 /etc/gitlab/gitlab.rb 并添加以下行,但使用您想要的值:

    gitlab_rails['ci_secure_files_object_store_enabled'] = true
    gitlab_rails['ci_secure_files_object_store_remote_directory'] = "ci_secure_files"
    gitlab_rails['ci_secure_files_object_store_connection'] = {
      'provider' => 'AWS',
      'region' => 'eu-central-1',
      'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
      'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY'
    }

如果您使用的是 AWS IAM 配置文件,请务必省略 AWS 访问密钥和秘密访问密钥/值对:

gitlab_rails['ci_secure_files_object_store_connection'] = {
  'provider' => 'AWS',
  'region' => 'eu-central-1',
  'use_iam_profile' => true
}
  1. 保存文件并重新配置 GitLab:

    sudo gitlab-ctl reconfigure
  2. 将任何现有的本地状态迁移到对象存储

  1. 编辑 /home/git/gitlab/config/gitlab.yml 并添加或修改以下行:

    ci_secure_files:
      enabled: true
      object_store:
        enabled: true
        remote_directory: "ci_secure_files"  # bucket 名称
        connection:
          provider: AWS  # 目前仅支持 AWS
          aws_access_key_id: AWS_ACCESS_KEY_ID
          aws_secret_access_key: AWS_SECRET_ACCESS_KEY
          region: eu-central-1
  2. 保存文件并重启 GitLab:

    # 对于运行 systemd 的系统
    sudo systemctl restart gitlab.target
    
    # 对于运行 SysV init 的系统
    sudo service gitlab restart
  3. 将任何现有的本地状态迁移到对象存储

迁移到对象存储

无法将 Secure Files 从对象存储迁移回本地存储,因此请谨慎操作。

要将 Secure Files 迁移到对象存储,请按照以下说明操作。

  • 对于 Linux package 安装:

    sudo gitlab-rake gitlab:ci_secure_files:migrate
  • 对于自行编译的安装:

    sudo -u git -H bundle exec rake gitlab:ci_secure_files:migrate RAILS_ENV=production