Harbor 配置

一些 Harbor 配置与 配置 Harbor YML 文件 部分分开配置。您可以在 Harbor 界面中、通过 HTTP 请求或使用环境变量更改配置。本页介绍可用的配置项,以及如何使用命令行或环境变量更新配置。

命令行配置命令示例

获取当前配置

curl -u "<username>:<password>" -H "Content-Type: application/json" -ki <Harbor Server URL>/api/v2.0/configurations

更新当前配置

curl -X PUT -u "<username>:<password>" -H "Content-Type: application/json" -ki <Harbor Server URL>/api/v2.0/configurations -d'{"<item_name>":"<item_value>"}'

更新 Harbor 以使用 LDAP 身份验证

命令

curl -X PUT -u "<username>:<password>" -H "Content-Type: application/json" -ki https://harbor.sample.domain/api/v2.0/configurations -d'{"auth_mode":"ldap_auth"}'

输出

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 08 May 2019 08:22:02 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 0
Connection: keep-alive
Set-Cookie: sid=a5803a1265e2b095cf65ce1d8bbd79b1; Path=/; HttpOnly

限制项目创建仅限 Harbor 管理员

命令

curl -X PUT -u "<username>:<password>" -H "Content-Type: application/json" -ki https://harbor.sample.domain/api/v2.0/configurations -d'{"project_creation_restriction":"adminonly"}'

输出

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 08 May 2019 08:24:32 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 0
Connection: keep-alive
Set-Cookie: sid=b7925eaf7af53bdefb13bdcae201a14a; Path=/; HttpOnly

更新令牌过期时间

命令

curl -X PUT -u "<username>:<password>" -H "Content-Type: application/json" -ki https://harbor.sample.domain/api/v2.0/configurations -d'{"token_expiration":"300"}'

输出

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 08 May 2019 08:23:38 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 0
Connection: keep-alive
Set-Cookie: sid=cc1bc93ffa2675253fc62b4bf3d9de0e; Path=/; HttpOnly

使用环境变量设置配置项

在 2.3.0 版本中引入了在核心容器中使用环境变量 CONFIG_OVERWRITE_JSON 设置配置的功能。一旦设置了 CONFIG_OVERWRITE_JSON 变量,您只能通过更新 CONFIG_OVERWRITE_JSON 并重启容器来更新或删除配置。您将无法在 Harbor 界面或命令行中更新配置。

CONFIG_OVERWRITE_JSON 配置示例

CONFIG_OVERWRITE_JSON={"ldap_verify_cert":"false", "auth_mode":"ldap_auth","ldap_base_dn":"dc=example,dc=com", "ldap_search_dn":"cn=admin,dc=example,dc=com","ldap_search_password":"admin","ldap_url":"myldap.example.com", "ldap_scope":2}

有关 CONFIG_OVERWRITE_JSON 可用输入的更多信息,请参阅下面的Harbor 配置项表。

如果您的 Harbor 实例中存在旧版用户,则无法通过环境变量 CONFIG_OVERWRITE_JSON 更改身份验证模式。

Harbor 配置项

配置项名称 描述 类型 必需 默认值
auth_mode 身份验证模式,可以是 db_auth、ldap_auth、uaa_auth 或 oidc_auth 字符串
primary_auth_mode 设置身份提供商作为主要身份验证方法 布尔值 可选 false
ldap_url LDAP URL 字符串 必需
ldap_base_dn LDAP base DN 字符串 必需 (ldap_auth)
ldap_filter LDAP 过滤器 字符串 可选
ldap_scope LDAP 搜索范围,0-Base Level,1-One Level,2-Sub Tree 数字 可选 2-Sub Tree
ldap_search_dn 用于搜索 LDAP 用户的 LDAP DN 字符串 必需 (ldap_auth)
ldap_search_password LDAP DN 的密码 字符串 必需 (ldap_auth)
ldap_timeout LDAP 连接超时 数字 可选 5
ldap_uid LDAP 属性,用于指示 Harbor 中的用户名 字符串 可选 cn
ldap_verify_cert 在与 LDAP 服务器创建 SSL 连接时验证证书,true 或 false 布尔值 可选 true
ldap_group_admin_dn LDAP 群组管理员 DN 字符串 可选
ldap_group_attribute_name LDAP 群组属性,LDAP 属性指示 Harbor 中的群组名称,可以是 gid 或 cn 字符串 可选 cn
ldap_group_base_dn 用于搜索 LDAP 群组的 Base DN 字符串 必需 (ldap_auth 和 LDAP 群组)
ldap_group_search_filter 用于搜索 LDAP 群组的过滤器 字符串 可选
ldap_group_search_scope LDAP 群组搜索范围,0-Base Level,1-One Level,2-Sub Tree 数字 可选 2-Sub Tree
ldap_group_membership_attribute LDAP 群组成员属性,用于指示群组成员身份,可以是 memberof 或 ismemberof 字符串 可选 memberof
project_creation_restriction 指示用户是否可以创建对象的选项,可以是 everyone、adminonly 字符串 可选 everyone
read_only 设置仓库只读的选项,可以是 true 或 false 布尔值 可选 false
self_registration 用户可以在 Harbor 中注册帐户,可以是 true 或 false 布尔值 可选 true
token_expiration 安全令牌过期时间,以分钟为单位 数字 可选 30
uaa_client_id UAA 客户端 ID 字符串 必需 (uaa_auth)
uaa_client_secret UAA 证书 字符串 必需 (uaa_auth)
uaa_endpoint UAA 端点 字符串 必需 (uaa_auth)
uaa_verify_cert UAA 验证证书,true 或 false 布尔值 可选 true
oidc_name OIDC 身份验证的名称 字符串 必需 (oidc_auth)
oidc_endpoint OIDC 身份验证的端点 字符串 必需 (oidc_auth)
oidc_extra_redirect_parms 将请求重定向到 OIDC 提供程序时要添加的额外参数 字符串 可选 {}
oidc_client_id OIDC 身份验证的客户端 ID 字符串 必需 (oidc_auth)
oidc_client_secret OIDC 身份验证的客户端密钥 字符串 必需 (oidc_auth)
oidc_groups_claim 您在 OIDC 提供程序中配置的自定义群组声明的名称,其中包括要添加到 Harbor 的群组 字符串 可选
oidc_admin_group 管理员群组的名称,如果用户的 ID 令牌显示他是此群组的成员,则该用户将在 Harbor 中拥有管理员权限。注意:您只能设置一个管理员群组。 字符串 可选
oidc_scope OIDC 身份验证的范围 字符串 必需 (oidc_auth)
oidc_verify_cert 验证 OIDC 身份验证的证书,true 或 false 布尔值 可选 true
oidc_auto_onboard 跳过引导屏幕,以便用户无法更改其用户名。用户名从 ID 令牌提供,true 或 false 布尔值 可选 false
oidc_user_claim 从 ID 令牌检索用户名的声明名称 字符串 可选 name
robot_token_duration 机器人令牌过期时间,以分钟为单位 数字 可选 43200 (30天)
robot_name_prefix 每个机器人帐户名称的前缀字符串 字符串 可选 robot$
audit_log_forward_endpoint 将审计日志转发到 syslog 端点,例如:harbor-log:10514 字符串 可选
skip_audit_log_database 跳过在数据库中记录审计日志,仅在配置审计日志转发端点时可用 布尔值 可选 false
scanner_skip_update_pulltime 漏洞扫描器(例如 Trivy)在扫描镜像时不会更新镜像的“上次拉取时间” 布尔值 可选
banner_message UI 的横幅消息。它是横幅消息对象的字符串化结果 字符串 可选
布尔值和数字都可以用双引号括起来,例如:123"123""true"true 都可以。