Skip to content

Commit 2e84281

Browse files
authored
Optimize LTPA creation and update (#678)
* Add securityUtility binary and decision tree cache * Pull RCO dependency * Remove /opt/ol/wlp ref * Pull RCO dependency * Update Dockerfile * Revert operator-sdk update * Update utils ResourceRequirements * Resolve linter errors * Update Dockerfile user 1001 * Update Dockerfile
1 parent 00b2c9c commit 2e84281

20 files changed

+483
-697
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ tags
8181
.history
8282
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
8383
bin
84-
vendor
84+
vendor
85+
liberty/**

Dockerfile

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
FROM registry.access.redhat.com/ubi8-minimal:latest as builder
33
ARG GO_PLATFORM=amd64
44
ARG GO_VERSION_ARG
5+
ARG LIBERTY_VERSION=25.0.0.2
56
ENV PATH=$PATH:/usr/local/go/bin
6-
RUN microdnf install tar gzip
7+
RUN microdnf install tar gzip unzip
78

89
WORKDIR /workspace
910
# Copy the Go Modules manifests
@@ -16,7 +17,14 @@ RUN if [ -z "${GO_VERSION_ARG}" ]; then \
1617
GO_VERSION=${GO_VERSION_ARG}; \
1718
fi; \
1819
rm -rf /usr/local/go; \
19-
curl -L --output - "https://golang.org/dl/go${GO_VERSION}.linux-${GO_PLATFORM}.tar.gz" | tar -xz -C /usr/local/
20+
curl -L --output - "https://golang.org/dl/go${GO_VERSION}.linux-${GO_PLATFORM}.tar.gz" | tar -xz -C /usr/local/; \
21+
mkdir -p liberty; \
22+
curl -L -o liberty.zip "https://repo1.maven.org/maven2/io/openliberty/openliberty-kernel/${LIBERTY_VERSION}/openliberty-kernel-${LIBERTY_VERSION}.zip"; \
23+
unzip liberty.zip -d liberty; \
24+
mv -f liberty/wlp/* liberty; \
25+
rmdir liberty/wlp; \
26+
rm -f liberty.zip; \
27+
mkdir -p liberty/output;
2028

2129

2230
# cache deps before building and copying source so that we don't need to re-download as much
@@ -34,10 +42,10 @@ RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-s -w" -a -o mana
3442

3543
# Use distroless as minimal base image to package the manager binary
3644
# Refer to https://github.com/GoogleContainerTools/distroless for more details
37-
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
45+
FROM icr.io/appcafe/ibm-semeru-runtimes:open-21-jre-ubi-minimal
3846

39-
ARG USER_ID=65532
40-
ARG GROUP_ID=65532
47+
ARG USER_ID=1001
48+
ARG GROUP_ID=1001
4149

4250
ARG VERSION_LABEL=1.4.2
4351
ARG RELEASE_LABEL=XX
@@ -64,6 +72,7 @@ COPY --chown=${USER_ID}:${GROUP_ID} LICENSE /licenses/
6472
WORKDIR /
6573
COPY --from=builder --chown=${USER_ID}:${GROUP_ID} /workspace/manager .
6674
COPY --from=builder --chown=${USER_ID}:${GROUP_ID} /workspace/internal/controller/assets/ /internal/controller/assets
75+
COPY --from=builder --chown=${USER_ID}:0 /workspace/liberty /liberty
6776

6877
USER ${USER_ID}:${GROUP_ID}
6978

Makefile

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
66
VERSION ?= 1.4.2
77
OPERATOR_SDK_RELEASE_VERSION ?= v1.37.0
8+
LIBERTY_VERSION ?= 25.0.0.2
89

910
# CHANNELS define the bundle channels used in the bundle.
1011
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
@@ -233,9 +234,25 @@ unit-test: ## Run unit tests
233234
go test -v -mod=vendor -tags=unit github.com/OpenLiberty/open-liberty-operator/...
234235

235236
.PHONY: run
236-
run: manifests generate fmt vet ## Run a controller against the configured Kubernetes cluster in ~/.kube/config from your host.
237+
run: manifests generate fmt vet install-secutil ## Run a controller against the configured Kubernetes cluster in ~/.kube/config from your host.
237238
go run ./cmd/main.go
238239

240+
.PHONY: install-secutil
241+
install-secutil:
242+
ifneq (found,$(shell test -e ./liberty/bin/securityUtility && echo -n found))
243+
@mkdir -p ./liberty
244+
@wget -O ./liberty.zip https://repo1.maven.org/maven2/io/openliberty/openliberty-kernel/$(LIBERTY_VERSION)/openliberty-kernel-$(LIBERTY_VERSION).zip
245+
@unzip -d ./liberty ./liberty.zip
246+
@mv -f ./liberty/wlp/* ./liberty
247+
@rmdir ./liberty/wlp
248+
@rm ./liberty.zip
249+
@mkdir -p ./liberty/output
250+
@echo "Liberty securityUtility has been installed!"
251+
else
252+
@mkdir -p ./liberty/output
253+
@echo "Liberty securityUtility is already installed!"
254+
endif
255+
239256
##@ Deployment
240257

241258
ifndef ignore-not-found

bundle/manifests/open-liberty.clusterserviceversion.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -1193,12 +1193,19 @@ spec:
11931193
runAsNonRoot: true
11941194
seccompProfile:
11951195
type: RuntimeDefault
1196+
volumeMounts:
1197+
- mountPath: /liberty/output
1198+
name: scratch
1199+
subPath: create-ltpa-keys
11961200
securityContext:
11971201
runAsNonRoot: true
11981202
seccompProfile:
11991203
type: RuntimeDefault
12001204
serviceAccountName: olo-controller-manager
12011205
terminationGracePeriodSeconds: 10
1206+
volumes:
1207+
- emptyDir: {}
1208+
name: scratch
12021209
permissions:
12031210
- rules:
12041211
- apiGroups:

config/manager/manager.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ spec:
9090
requests:
9191
cpu: 200m
9292
memory: 128Mi
93+
volumeMounts:
94+
- name: scratch
95+
mountPath: /liberty/output
96+
subPath: create-ltpa-keys
97+
volumes:
98+
- name: scratch
99+
emptyDir: {}
93100
serviceAccountName: controller-manager
94101
terminationGracePeriodSeconds: 10
95102
affinity:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package controller
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
7+
"github.com/OpenLiberty/open-liberty-operator/utils"
8+
)
9+
10+
const SECURITY_UTILITY_BINARY = "liberty/bin/securityUtility"
11+
const SECURITY_UTILITY_ENCODE = "encode"
12+
const SECURITY_UTILITY_CREATE_LTPA_KEYS = "createLTPAKeys"
13+
const SECURITY_UTILITY_OUTPUT_FOLDER = "liberty/output"
14+
15+
func encode(password string, passwordKey *string) ([]byte, error) {
16+
params := []string{}
17+
params = append(params, SECURITY_UTILITY_ENCODE)
18+
params = append(params, fmt.Sprintf("--encoding=%s", "aes"))
19+
if passwordKey != nil && len(*passwordKey) > 0 {
20+
params = append(params, fmt.Sprintf("--key=%s", *passwordKey))
21+
}
22+
params = append(params, password)
23+
return callSecurityUtility(params)
24+
}
25+
26+
func createLTPAKeys(password string, passwordKey *string) ([]byte, error) {
27+
tmpFileName := fmt.Sprintf("ltpa-keys-%s.keys", utils.GetRandomAlphanumeric(15))
28+
tmpFilePath := fmt.Sprintf("%s/%s", SECURITY_UTILITY_OUTPUT_FOLDER, tmpFileName)
29+
30+
// delete possible colliding file
31+
callDeleteFile(tmpFilePath)
32+
33+
// mkdir if not exists
34+
// callMkdir(SECURITY_UTILITY_OUTPUT_FOLDER)
35+
36+
// create the key
37+
params := []string{}
38+
params = append(params, SECURITY_UTILITY_CREATE_LTPA_KEYS)
39+
params = append(params, fmt.Sprintf("--file=%s", tmpFilePath))
40+
params = append(params, fmt.Sprintf("--passwordEncoding=%s", "aes")) // use aes encoding
41+
if passwordKey != nil && len(*passwordKey) > 0 {
42+
params = append(params, fmt.Sprintf("--passwordKey=%s", *passwordKey))
43+
}
44+
params = append(params, fmt.Sprintf("--password=%s", password))
45+
callSecurityUtility(params)
46+
47+
// read the key
48+
params = []string{}
49+
params = append(params, "-c")
50+
params = append(params, fmt.Sprintf("cat %s | base64", tmpFilePath))
51+
bytesOut, err := callCommand("/bin/bash", params)
52+
53+
// delete the key
54+
callDeleteFile(tmpFilePath)
55+
return bytesOut, err
56+
}
57+
58+
// func callMkdir(folderPath string) {
59+
// params := []string{}
60+
// params = append(params, "-c")
61+
// params = append(params, fmt.Sprintf("mkdir -p %s", folderPath))
62+
// callCommand("/bin/bash", params)
63+
// }
64+
65+
func callDeleteFile(filePath string) {
66+
params := []string{}
67+
params = append(params, "-c")
68+
params = append(params, fmt.Sprintf("rm -f %s", filePath))
69+
callCommand("/bin/bash", params)
70+
}
71+
72+
func callSecurityUtility(params []string) ([]byte, error) {
73+
return callCommand(SECURITY_UTILITY_BINARY, params)
74+
}
75+
76+
func callCommand(binary string, params []string) ([]byte, error) {
77+
cmd := exec.Command(binary, params...)
78+
stdout, err := cmd.Output()
79+
if err != nil {
80+
return []byte{}, err
81+
}
82+
return stdout, nil
83+
}

0 commit comments

Comments
 (0)