Skip to content

Commit ad392a4

Browse files
holyspectralBinX-Suse
authored andcommitted
feat: NVSHAS-9494 make manager SLSA capable
1 parent a0ab017 commit ad392a4

File tree

7 files changed

+189
-43
lines changed

7 files changed

+189
-43
lines changed

.dockerignore

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
*.class
2+
*.log
3+
apis.yaml
4+
docker-compose.yml
5+
6+
# sbt specific
7+
.cache
8+
.history
9+
.lib/
10+
target/
11+
lib_managed/
12+
src_managed/
13+
project/boot/
14+
project/plugins/project/
15+
16+
# Scala-IDE specific
17+
.scala_dependencies
18+
.worksheet
19+
*.sc
20+
21+
#IntelliJ specific
22+
.idea
23+
24+
# eclipse specific
25+
*.pydevproject
26+
.project
27+
.metadata
28+
bin/**
29+
tmp/**
30+
tmp/**/*
31+
*.tmp
32+
*.bak
33+
*.swp
34+
*~.nib
35+
local.properties
36+
.classpath
37+
.settings/
38+
.loadpath
39+
40+
# External tool builders
41+
.externalToolBuilders/
42+
43+
# Locally stored "Eclipse launch configurations"
44+
*.launch
45+
46+
# Downloaded dependencies
47+
48+
*.DS_Store
49+
.DS_Store
50+
51+
.sass-cache
52+
.sass-cache/*
53+
54+
.vscode/
55+
admin/webapp/.bsp/
56+
admin/webapp/websrc/.bsp/
57+
token.json
58+
59+
.metals
60+
admin/test/REST_API/output
61+
admin/webapp/root
62+
admin/webapp/.angular
63+
/.bsp/*
64+
/admin/.angular/
65+
/admin/webapp/websrc/assets/mockdata
66+
/admin/webapp/package-lock.json
67+
admin/webapp/websrc/assets/i18n/en.json
68+
admin/webapp/websrc/assets/i18n/zh_cn.json

.github/workflows/release.yml

+25-5
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,45 @@ jobs:
2424
uses: rancher-eio/read-vault-secrets@main
2525
with:
2626
secrets: |
27+
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials username | RANCHER_DOCKER_USERNAME ;
28+
secret/data/github/repo/${{ github.repository }}/dockerhub/rancher/credentials password | RANCHER_DOCKER_PASSWORD ;
2729
secret/data/github/repo/${{ github.repository }}/dockerhub/neuvector/credentials username | DOCKER_USERNAME ;
2830
secret/data/github/repo/${{ github.repository }}/dockerhub/neuvector/credentials password | DOCKER_PASSWORD ;
2931
secret/data/github/repo/${{ github.repository }}/rancher-prime-registry/credentials registry | PRIME_REGISTRY ;
3032
secret/data/github/repo/${{ github.repository }}/rancher-prime-registry/credentials username | PRIME_REGISTRY_USERNAME ;
3133
secret/data/github/repo/${{ github.repository }}/rancher-prime-registry/credentials password | PRIME_REGISTRY_PASSWORD
32-
33-
- name: Publish manifest
34+
- name: Parse target tag
35+
run: |
36+
TARGET=${{ github.ref_name }}
37+
echo "TAG=${TARGET#v}" >> $GITHUB_ENV
38+
- name: Publish neuvector manifest
3439
uses: rancher/ecm-distro-tools/actions/publish-image@master
3540
with:
36-
image: registry-adapter
37-
tag: ${{ github.ref_name }}
41+
push-to-public: true
42+
push-to-prime: false
43+
image: manager
44+
tag: ${{ env.TAG }}
3845
platforms: linux/amd64,linux/arm64
3946

4047
public-registry: docker.io
4148
public-repo: neuvector
4249
public-username: ${{ env.DOCKER_USERNAME }}
4350
public-password: ${{ env.DOCKER_PASSWORD }}
51+
- name: Publish rancher manifest
52+
uses: rancher/ecm-distro-tools/actions/publish-image@master
53+
env:
54+
IMAGE_PREFIX: neuvector-
55+
with:
56+
image: neuvector-manager
57+
tag: ${{ env.TAG }}
58+
platforms: linux/amd64,linux/arm64
59+
60+
public-registry: docker.io
61+
public-repo: rancher
62+
public-username: ${{ env.RANCHER_DOCKER_USERNAME }}
63+
public-password: ${{ env.RANCHER_DOCKER_PASSWORD }}
4464

4565
prime-registry: ${{ env.PRIME_REGISTRY }}
4666
prime-repo: rancher
4767
prime-username: ${{ env.PRIME_REGISTRY_USERNAME }}
48-
prime-password: ${{ env.PRIME_REGISTRY_PASSWORD }}
68+
prime-password: ${{ env.PRIME_REGISTRY_PASSWORD }}

Makefile

+8-21
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jar:
3636
RUNNER := docker
3737
IMAGE_BUILDER := $(RUNNER) buildx
3838
MACHINE := neuvector
39+
BUILDX_ARGS ?= --sbom=true --attest type=provenance,mode=max
3940
DEFAULT_PLATFORMS := linux/amd64,linux/arm64,linux/x390s,linux/riscv64
4041

4142
COMMIT = $(shell git rev-parse --short HEAD)
@@ -48,20 +49,13 @@ ifeq ($(VERSION),)
4849
DIRTY = -dirty
4950
endif
5051

51-
# Prioritise DRONE_TAG for backwards compatibility. However, the git tag
52-
# command should be able to gather the current tag, except when the git
53-
# clone operation was done with "--no-tags".
54-
ifneq ($(DRONE_TAG),)
55-
GIT_TAG = $(DRONE_TAG)
56-
else
57-
GIT_TAG = $(shell git tag -l --contains HEAD | head -n 1)
58-
endif
5952

6053
COMMIT = $(shell git rev-parse --short HEAD)
6154
VERSION = $(COMMIT)$(DIRTY)
6255

6356
# Override VERSION with the Git tag if the current HEAD has a tag pointing to
6457
# it AND the worktree isn't dirty.
58+
GIT_TAG = $(shell git tag -l --contains HEAD | head -n 1)
6559
ifneq ($(GIT_TAG),)
6660
ifeq ($(DIRTY),)
6761
VERSION = $(GIT_TAG)
@@ -81,13 +75,6 @@ STAGE_DIR=stage
8175
REPO ?= neuvector
8276
IMAGE = $(REPO)/manager:$(TAG)
8377
BUILD_ACTION = --load
84-
BUILDX_ARGS ?= --sbom=true --attest type=provenance,mode=max --cache-to type=gha --cache-from type=gha
85-
86-
stage_init:
87-
rm -rf ${STAGE_DIR}; mkdir -p ${STAGE_DIR}
88-
mkdir -p ${STAGE_DIR}/usr/local/bin/
89-
mkdir -p ${STAGE_DIR}/licenses/
90-
mkdir -p ${STAGE_DIR}/usr/lib/jvm/java-17-openjdk/lib/security/
9178

9279
buildx-machine:
9380
docker buildx ls
@@ -100,13 +87,13 @@ test-image:
10087
$(MAKE) build-image BUILD_ACTION="--platform=$(TARGET_PLATFORMS)"
10188

10289
build-image: buildx-machine ## build (and load) the container image targeting the current platform.
103-
$(IMAGE_BUILDER) build -f build/Dockerfile \
90+
$(IMAGE_BUILDER) build -f package/Dockerfile \
10491
--builder $(MACHINE) $(IMAGE_ARGS) \
105-
--build-arg VERSION=$(VERSION) -t "$(IMAGE)" $(BUILD_ACTION) .
92+
--build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) -t "$(IMAGE)" $(BUILD_ACTION) .
10693
@echo "Built $(IMAGE)"
10794

108-
push-image: stage_init buildx-machine
109-
$(IMAGE_BUILDER) build -f build/Dockerfile \
95+
push-image: buildx-machine
96+
$(IMAGE_BUILDER) build -f package/Dockerfile \
11097
--builder $(MACHINE) $(IMAGE_ARGS) $(IID_FILE_FLAG) $(BUILDX_ARGS) \
111-
--build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --platform=$(TARGET_PLATFORMS) -t "$(REPO)/manager:$(TAG)" --push .
112-
@echo "Pushed $(IMAGE)"
98+
--build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --platform=$(TARGET_PLATFORMS) -t "$(REPO)/$(IMAGE_PREFIX)manager:$(TAG)" --push .
99+
@echo "Pushed $(REPO)/$(IMAGE_PREFIX)manager:$(TAG)"

make_jar.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
export CHROME_BIN=/usr/bin/google-chrome
4+
5+
rm -rf admin/target
6+
pushd admin/webapp
7+
if [[ $# > 0 ]]; then
8+
case $1 in
9+
-d)
10+
mkdir -p /root/.ivy2
11+
ln -s /prebuild/manager/cache /root/.ivy2/cache
12+
# ln -s /prebuild/manager/node_modules node_modules
13+
;;
14+
*)
15+
;;
16+
esac
17+
fi
18+
npm install --legacy-peer-deps 2>&1
19+
if [ $? -eq 0 ]; then
20+
echo npm package installation SUCCEED
21+
else
22+
npm cache clean --force 2>&1
23+
sleep 10
24+
npm install 2>&1
25+
if [ $? -eq 0 ]; then
26+
echo npm package installation SUCCEED
27+
else
28+
echo ================================
29+
echo npm package installation FAILED
30+
echo ================================
31+
exit 1
32+
fi
33+
fi
34+
npm run build 2>&1
35+
if [ $? -eq 0 ]; then
36+
echo UI build SUCCEED
37+
else
38+
echo ================================
39+
echo UI build FAILED
40+
echo ================================
41+
exit 1
42+
fi
43+
# npm run unittest
44+
popd
45+
env JAVA_OPTS="-Xms2g -Xmx3g" sbt admin/assembly
46+
zip -d admin/target/scala-3.3.4/admin-assembly-1.0.jar rest-management-private-classpath\*
47+
rm -rf admin/webapp/root/.sass-cache

build/Dockerfile package/Dockerfile

+35-15
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@ FROM registry.suse.com/bci/openjdk:17 AS builder
44
ARG TARGETOS
55
ARG TARGETARCH
66

7-
COPY . /src
7+
COPY admin /src/admin
8+
COPY cli /src/cli
9+
COPY common /src/common
10+
COPY images /src/images
11+
COPY licenses /src/licenses
12+
COPY java.security /src/java.security
13+
COPY package /src/package
14+
COPY project /src/project
15+
COPY scripts /src/scripts
16+
COPY build.sbt .scalafix.conf .scalafmt.conf /src/
17+
818
WORKDIR /src
919

1020
RUN zypper refresh && \
1121
zypper install -y ca-certificates wget curl zip git awk nodejs20 npm20
1222

23+
ARG VERSION
24+
25+
ARG CS_VERSION=v2.1.18
1326
RUN if [ "$TARGETARCH" = "amd64" ]; then \
14-
curl -fL https://github.com/coursier/launchers/raw/master/cs-x86_64-pc-${TARGETOS}.gz | gzip -d > cs; \
27+
curl -fL https://github.com/coursier/coursier/releases/download/${CS_VERSION}/cs-x86_64-pc-${TARGETOS}.gz | gzip -d > cs; \
1528
elif [ "$TARGETARCH" = "arm64" ]; then \
16-
curl -fL https://github.com/VirtusLab/coursier-m1/releases/latest/download/cs-aarch64-pc-${TARGETOS}.gz | gzip -d > cs; \
29+
curl -fL https://github.com/VirtusLab/coursier-m1/releases/download/${CS_VERSION}/cs-aarch64-pc-${TARGETOS}.gz | gzip -d > cs; \
1730
else \
1831
echo "Unsupported architecture: $ARCH"; \
1932
exit 1; \
@@ -25,12 +38,14 @@ RUN if [ "$TARGETARCH" = "amd64" ]; then \
2538
RUN npm install -g @angular/cli@14 && \
2639
npm install -g npm-force-resolutions
2740

28-
RUN bash build/build_manager.sh
41+
RUN sed -i -e 's/interim.*xxxx/'"$VERSION"'/g' ./common/src/main/resources/application.conf
42+
RUN bash package/build_manager.sh
2943

3044
# Manager unitest
3145
RUN if [ "$ARCH" = "amd64" ]; then \
3246
zypper addrepo https://download.opensuse.org/repositories/M17N:fonts/15.6/M17N:fonts.repo && \
33-
zypper --non-interactive --gpg-auto-import-keys refresh && \
47+
rpm --import https://download.opensuse.org/repositories/M17N/15.6/repodata/repomd.xml.key && \
48+
zypper --non-interactive refresh && \
3449
zypper install -y liberation-fonts && \
3550
wget https://dl.google.com/${OS}/direct/google-chrome-stable_current_${ARCH}.rpm && \
3651
wget https://dl.google.com/${OS}/${OS}_signing_key.pub && \
@@ -42,10 +57,10 @@ fi
4257
FROM registry.suse.com/bci/bci-micro:15.6 AS micro
4358
FROM registry.suse.com/bci/bci-base:15.6 AS base
4459

45-
COPY --from=builder /src/build/requirements.txt /chroot/requirements.txt
60+
COPY --from=builder /src/package/requirements.txt /chroot/requirements.txt
4661
COPY --from=micro / /chroot/
4762

48-
RUN zypper --installroot /chroot -n --gpg-auto-import-keys in --no-recommends \
63+
RUN zypper refresh && zypper --installroot /chroot -n in --no-recommends \
4964
python312 python312-pip iproute2 lsof procps grep awk && \
5065
cp /etc/resolv.conf /chroot/etc/resolv.conf && \
5166
chroot /chroot /usr/bin/python3.12 -m pip install --upgrade pip setuptools && \
@@ -77,22 +92,27 @@ ARG COMMIT
7792
WORKDIR /
7893
COPY --from=base /chroot/ /
7994
COPY --from=base /usr/sbin/useradd /usr/sbin
80-
COPY --from=builder /src/stage /
8195
COPY --from=builder /usr/lib64/ /usr/lib64/
96+
COPY --from=builder /src/stage /
8297

8398
ENV JAVA_HOME=/usr/lib64/jvm/java-17-openjdk-17 \
8499
PATH=/usr/lib64/jvm/java-17-openjdk-17/bin:$PATH \
85100
LD_LIBRARY_PATH=/usr/lib64 \
86101
LANG=C.UTF-8 \
87102
PYTHONUNBUFFERED=1
88103

89-
LABEL name="manager" \
90-
vendor="SUSE Security" \
91-
version=${VERSION} \
92-
release=${VERSION} \
93-
neuvector.image="neuvector/manager" \
94-
neuvector.role="manager" \
95-
neuvector.rev="${COMMIT}"
104+
LABEL "name"="manager" \
105+
"vendor"="SUSE Security" \
106+
"neuvector.image"="neuvector/manager" \
107+
"neuvector.role"="manager" \
108+
"neuvector.rev"="${COMMIT}" \
109+
"io.artifacthub.package.logo-url"=https://avatars2.githubusercontent.com/u/19367275 \
110+
"io.artifacthub.package.readme-url"="https://raw.githubusercontent.com/neuvector/manager/${VERSION}/README.md" \
111+
"org.opencontainers.image.description"="SUSE Security Manager" \
112+
"org.opencontainers.image.title"="SUSE Security Manager" \
113+
"org.opencontainers.image.source"="https://github.com/neuvector/manager/" \
114+
"org.opencontainers.image.version"="${VERSION}" \
115+
"org.opensuse.reference"="neuvector/manager:${VERSION}"
96116

97117
ARG user=manager
98118
RUN echo "$user:x:1000:1000::/nonexistent:/bin/bash" >> /etc/passwd && \

build/build_manager.sh package/build_manager.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23

34
STAGE_DIR=stage
45

@@ -48,10 +49,12 @@ env JAVA_OPTS="-Xms2g -Xmx3g" sbt admin/assembly
4849
zip -d admin/target/scala-3.3.4/admin-assembly-1.0.jar rest-management-private-classpath\*
4950
rm -rf admin/webapp/root/.sass-cache
5051

52+
mkdir -p ${STAGE_DIR}/licenses/ ${STAGE_DIR}/usr/local/bin/ ${STAGE_DIR}/usr/lib/jvm/java-17-openjdk/lib/security ${STAGE_DIR}/usr/lib64/jvm/java-17-openjdk-17/conf/security/
5153
cp licenses/* ${STAGE_DIR}/licenses/
5254
cp cli/cli ${STAGE_DIR}/usr/local/bin/
5355
cp cli/cli.py ${STAGE_DIR}/usr/local/bin/
5456
cp -r cli/prog ${STAGE_DIR}/usr/local/bin/
5557
cp scripts/* ${STAGE_DIR}/usr/local/bin/
56-
cp java.security ${STAGE_DIR}/usr/lib/jvm/java-17-openjdk/lib/security/java.security
58+
cp java.security ${STAGE_DIR}/usr/lib/jvm/java-17-openjdk/lib/security/
59+
cp java.security ${STAGE_DIR}/usr/lib64/jvm/java-17-openjdk-17/conf/security/
5760
cp admin/target/scala-3.3.4/admin-assembly-1.0.jar ${STAGE_DIR}/usr/local/bin/

build/requirements.txt package/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ prettytable==2.5.0
44
requests==2.32.0
55
six==1.11.0
66
supervisor==4.2.5
7-
urllib3==1.26.19
7+
urllib3==1.26.19
8+

0 commit comments

Comments
 (0)