用docker-compose安装harbor v2.5.3(+离线版trivy )

环境

1. 使用oras 拉取trivy-db:2

因为国内访问trivy-db经常出现网络问题,这边使用oras工具提前将trivy-db下载下来,使用离线的trivy-db对镜像进行扫描。
安装oras

export VERSION="1.0.0" 
curl -LO "https://github.com/oras-project/oras/releases/download/v${VERSION}/oras_${VERSION}_linux_amd64.tar.gz"
mkdir -p oras-install/
tar -zxf oras_${VERSION}_*.tar.gz -C oras-install/
sudo mv oras-install/oras /usr/local/bin/
rm -rf oras_${VERSION}_*.tar.gz oras-install/

查看oras版本

/home # oras version                                                                                                                                                      
Version:        1.0.0
Go version:     go1.20.2
Git commit:     b58e7b910ca556973d111e9bd734a71baef03db2
Git tree state: clean

使用oras拉取trivy-db 2

oran@trivy:~$ oras pull ghcr.io/aquasecurity/trivy-db:2
Downloading 0d70da8057a9 db.tar.gz
Downloaded  0d70da8057a9 db.tar.gz
Pulled [registry] ghcr.io/aquasecurity/trivy-db:2
Digest: sha256:e455efdcc885690b91a01ee58d5c449705c899203de35e1d9377a4f46a1c8674
oran@trivy:~$ ls -lh db.tar.gz
-rw-rw-r-- 1 oran oran 37M Mar 24 06:19 db.tar.gz

2. 下载harbor

下载harbor installer

wget https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-online-installer-v2.5.3.tgz

解压到本地

tar -xzvf harbor-offline-installer-v2.5.3.tgz 

拷贝harbor.yml

cp harbor.yml.tmpl harbor.yml

3. 修改配置文件

3.1 创建私有证书

#创建ca.key
oran@trivy:~$ openssl genrsa -out ca.key 4096
#创建c.crt
oran@trivy:~$ sudo openssl req -x509 -new -nodes -sha512 -days 3650  -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=oran-registry.harbor.k8s.local" -key ca.key  -out ca.crt
#创建server.key
oran@trivy:~$ sudo openssl genrsa -out oran-registry.key 4096
#创建server.csr
oran@trivy:~$ sudo openssl req -sha512 -new     -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=oran-registry.harbor.k8s.local"  -key oran-registry.key -out oran-registry.csr
#创建x509 v3 扩展 文件
oran@trivy:/home/certs$ cat v3.ext 
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1=oran-registry.harbor.k8s.local
DNS.2=oran-registry
#使用v3.ext文件为harbor服务器创建证书
oran@trivy:~$ sudo openssl x509 -req -sha512 -days 3650     -extfile v3.ext     -CA ca.crt -CAkey ca.key -CAcreateserial     -in oran-registry.csr -out oran-registry.crt
-out oran-registry.crt
Certificate request self-signature ok
subject=C = CN, ST = Beijing, L = Beijing, O = example, OU = Personal, CN = oran-registry.harbor.k8s.local

将证书放在对应目录下

#创建目录
oran@trivy:~$ mkdir -p /etc/docker/certs.d/oran-registry.harbor.k8s.local
#将crt文件转换为cert文件
oran@trivy:~$ openssl x509 -inform PEM -in oran-registry.crt -outoran-registry.cert
#将cert和key放在对应目录下
oran@trivy:~$ cp oran-registry.cert oran-registry.key ca.crt/etc/docker/certs.d/oran-registry.harbor.k8s.local/

重启docker

oran@trivy:~$ systemctl restart docker

3.2 修改hostname

我这里使用的示例为hostname: oran-registry.harbor.k8s.local,修改为自己对应的hostname即可。

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: oran-registry.harbor.k8s.local

3.3 修改证书路径

修改为对应的证书路径

https:
  # https port for harbor, default is 443
  port: 443
  # The path of cert and key files for nginx
  certificate: /home/certs/oran-registry.crt
  private_key: /home/certs/oran-registry.key

3.4 修改密码

根据个人需求修改harbor的password和database的password

harbor_admin_password: <Your Password>

# Harbor DB configuration
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: <Your Password>
  # The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
  max_idle_conns: 100
  # The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
  # Note: the default number of connections is 1024 for postgres of harbor.
  max_open_conns: 900

3.5 为trivy设置离线配置

因为trivy扫描会联网拉取trivy-db,国内网络无法访问,这里使用离线版trivy-db v2版本。设置跳过更新和离线扫描都为true。

trivy:
  # ignoreUnfixed The flag to display only fixed vulnerabilities
  ignore_unfixed: false
  # skipUpdate The flag to enable or disable Trivy DB downloads from GitHub
  #
  # You might want to enable this flag in test or CI/CD environments to avoid GitHub rate limiting issues.
  # If the flag is enabled you have to download the `trivy-offline.tar.gz` archive manually, extract `trivy.db` and
  # `metadata.json` files and mount them in the `/home/scanner/.cache/trivy/db` path.
  skip_update: true
  #
  # The offline_scan option prevents Trivy from sending API requests to identify dependencies.
  # Scanning JAR files and pom.xml may require Internet access for better detection, but this option tries to avoid it.
  # For example, the offline mode will not try to resolve transitive dependencies in pom.xml when the dependency doesn't
  # exist in the local repositories. It means a number of detected vulnerabilities might be fewer in offline mode.
  # It would work if all the dependencies are in local.
  # This option doesn’t affect DB download. You need to specify "skip-update" as well as "offline-scan" in an air-gapped environment.
  offline_scan: true
  #
  # insecure The flag to skip verifying registry certificate
  insecure: false

3.5.1 拷贝trivy-db到本地

创建db目录并将下载好的db文件放在里面并修改权限

mkdir -p /data/trivy-adapter/trivy/db/

*注:如果之前启动了harbor需要使用docker-compose down 命令将服务停下;如果之前通过install.sh --with-trivy安装过trivy则需要将/data/trivy-adapter/trivy/db/下的文件清空rm -rf /data/trivy-adapter/trivy/db/

解压db.tar.gz到对应目录

tar -xzvf db.tar.gz -C /data/trivy-adapter/trivy/db/

修改trivy-db权限

chown -R 10000:10000 /data/trivy-adapter/trivy/db/

4. 安装harbor

安装带有trivy的harbor,可根据个人需求添加相关参数

bash install.sh --with-trivy

查看harbor,运行都为healthy


image.png

5. 测试

5.1 docker login

oran@trivy:~/harbor/harbor$ sudo docker login oran-registry.harbor.k8s.local
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

5.2 harbor web

image.png

5.3 镜像的拉取与推送

docker push

oran@trivy:~/harbor/harbor$ sudo docker push oran-registry.harbor.k8s.local/library/nginx:latest 
The push refers to repository [oran-registry.harbor.k8s.local/library/nginx]
a1bd4a5c5a79: Pushed 
597a12cbab02: Pushed 
8820623d95b7: Pushed 
338a545766ba: Pushed 
e65242c66bbe: Pushed 
3af14c9a24c9: Pushed 
latest: digest: sha256:557c9ede65655e5a70e4a32f1651638ea3bfb0802edd982810884602f700ba25 size: 1570

docker pull

oran@trivy:~/harbor/harbor$ sudo docker pull oran-registry.harbor.k8s.local/library/nginx:latest
latest: Pulling from library/nginx
f1f26f570256: Pull complete 
84181e80d10e: Pull complete 
1ff0f94a8007: Pull complete 
d776269cad10: Pull complete 
e9427fcfa864: Pull complete 
d4ceccbfc269: Pull complete 
Digest: sha256:557c9ede65655e5a70e4a32f1651638ea3bfb0802edd982810884602f700ba25
Status: Downloaded newer image for oran-registry.harbor.k8s.local/library/nginx:latest
oran-registry.harbor.k8s.local/library/nginx:latest

5.4 漏洞扫描

点击扫描


image.png

扫描成功


image.png

查看漏洞详情


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,657评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,662评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,143评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,732评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,837评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,036评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,126评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,868评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,315评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,641评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,773评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,470评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,126评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,859评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,095评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,584评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,676评论 2 351