---
# System prepended metadata

title: NeuVector與Harbor整合(也可以使用Trivy)，或是跟gitlab整合
tags: [mohw]

---

# NeuVector與Harbor整合(也可以使用Trivy)

grype沒有api，為了讓整個pipeline尾巴改成放到registry，後續再給deploy流程去跑，所以移除grype，改用NeuVector，本來包成tar的流程，也改成push上harbor。

先看一下強大的NeuVector的功能介紹吧!!!

https://www.cnblogs.com/rancherlabs/p/16111452.html

## 先建起來harbor吧

1. 下載最新版harbor
https://github.com/goharbor/harbor/releases/tag/v2.9.0
2. 調整harbor.yml設定
https://goharbor.io/docs/2.9.0/install-config/configure-yml-file/
- hostname一定要設定
- 443如果還沒ready就comment掉
- 預設帳號admin，密碼也可以改
3. 執行install.sh，將建立/var/log/harbor與/data兩個資料夾
參考：
https://goharbor.io/docs/2.9.0/install-config/download-installer/
4. 後續執行只要用docker-compose即可
5. 建立project

![](https://hackmd.io/_uploads/SkyxcV8Z6.png)

6. push image
- nano /etc/docker/daemon.json
- systemctl restart docker
- docker tag
- docker login
- docker push

記得image命名原則：
> harbor server name/project name/images name:version

參考：
https://goharbor.io/docs/2.9.0/working-with-projects/working-with-images/pulling-pushing-images/

insecure registry的設定參考：
https://docs.docker.com/registry/insecure/


## 再來建立NeuVector，先看看Trivy

Harbor以前是使用Clair，現在是用Trivy
https://github.com/quay/clair

預設的掃描器是Trivy
https://goharbor.io/docs/2.9.0/administration/vulnerability-scanning/

如果要預設使用安全掃描器Trivy，安裝時可以下以下指令：
> sudo ./install.sh --with-trivy

參考：
https://goharbor.io/docs/2.9.0/install-config/run-installer-script/

Trivy介紹：
https://aquasecurity.github.io/trivy/v0.45/

## 來建置Neuvector

https://github.com/neuvector/neuvector

後來選擇這個，添加一下service寫法，以及network指定ip，就可以正常運作(NO privileged mode)：
https://open-docs.neuvector.com/deploying/docker#deploy-allinone-no-privileged-mode-with-docker-compose

先設定ap_net

>sudo  docker network create --driver bridge --subnet 172.18.0.0/24 --gateway 172.18.0.1 ap_net

```
version: "3"
services:
 allinone:
    pid: host
    image: neuvector/allinone
    container_name: neuvector.allinone
    cap_add:
        - SYS_ADMIN
        - NET_ADMIN
        - SYS_PTRACE
        - IPC_LOCK
    security_opt:
        - apparmor=unconfined
        - seccomp=unconfined
        - label=disable
    environment:
        - CLUSTER_JOIN_ADDR=172.18.0.200
        - NV_PLATFORM_INFO=platform=Docker
    ports:
        - 18300:18300
        - 18301:18301
        - 18400:18400
        - 18401:18401
        - 18301:18301/udp
        - 8443:8443
    volumes:
        - /lib/modules:/lib/modules:ro
        - /var/run/docker.sock:/var/run/docker.sock:ro
        - /proc:/host/proc:ro
        - /sys/fs/cgroup:/host/cgroup:ro
        - /var/neuvector:/var/neuvector
    networks:
        ap_net:
            ipv4_address: 172.18.0.200
 Scanner:
    image: neuvector/scanner:latest
    container_name: scanner
    environment:
        - CLUSTER_JOIN_ADDR=172.18.0.200
    ports:
        - 18402:18402
    volumes:
        - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
        - ap_net
networks:
    ap_net:
        external: true
```

預設帳密：admin/admin
https://github.com/neuvector/neuvector-operator/blob/master/docs/NeuVectorDeployKubernetes.md

![](https://hackmd.io/_uploads/H1vcnD8ba.png)
相當完整的資安平台呀...

提醒一下：
- allinone是controller跟enforcer整合的版本，但好像沒有scanner，所以記得compose要加上去一下
 Allinone container if controller and enforcer functions are desired on a node. 

## 或是我們來啟動gitlab的陽春container registry

https://russ_liu.gitlab.io/blog/2022/02/08/Enable-Gitlab-Container-Registry/

gitlab的環境變數微調一下，就可以啟用了
```
        registry_external_url 'http://registry.docker.localhost'
        # 關閉container registry
        #gitlab_rails['gitlab_default_projects_features_container_registry'] = false
        #gitlab_rails['registry_enabled'] = false
        #registry['enable'] = false
        #registry_nginx['enable'] = false
```

![](https://hackmd.io/_uploads/Sy9QO_Uba.png)

記得要用PAT喔
![](https://hackmd.io/_uploads/H1zIuuIZp.png)

再來我們來push上去吧
> docker login registry.docker.localhost
> docker tag xxx:1121012 registry.docker.localhost/root/xxx:1121012 
> docker push registry.docker.localhost/root/xxx:1121012 
## 再來我們整合一下(gitlab與neuvector)

https://goharbor.io/docs/2.9.0/administration/vulnerability-scanning/pluggable-scanners/

注意，neuvector要跟gitlab整合的話，會要求要用https

![](https://hackmd.io/_uploads/SyXzFOLbT.png)

因為考量gitlab container registry蠻陽春，就中止了

## 我們認真來整合吧(harbor與neuvector)

https://www.cnblogs.com/rancherlabs/p/16111452.html
這篇看起來是可以把harbor使用docker registry的連結方式整合

但我這邊會遇到問題：harbor的ip是什麼？

要回答這個問題，要有兩個步驟：

1. ps,inspect一下

![](https://hackmd.io/_uploads/BJo_zYIWa.png)
我們看到harbor有對外的是這個container
![](https://hackmd.io/_uploads/HJFjzF8ba.png)
看到它的ip了

2. nginx後面真實的port

我們知道我們設定的對外port是8089，但真實的port要看nginx的設定
![](https://hackmd.io/_uploads/HJeXfY8Z6.png)

3. 真的取得ip:port

依照上述的方式取得ip:port，就可以放進去neuvector

![](https://hackmd.io/_uploads/ByxlmKL-p.png)

設定成功~~~

## 有可能讓harbor去取得neuvector scanner api?
目前還需要找方法...

## 更新harbor摘要

本次曾經作過2.7更新到2.9，本來移植舊版的common資料夾跟harbor.yml，結果會噴錯誤
所以，/data可以共用外，harbor.yml也不能共用