Skip to content

Commit 6ea07ae

Browse files
feat: update helm secrets (#1839)
Co-authored-by: jeho <[email protected]>
1 parent 8e8e21d commit 6ea07ae

File tree

6 files changed

+34
-15
lines changed

6 files changed

+34
-15
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM linode/apl-tools:v2.8.5 AS ci
1+
FROM linode/apl-tools:v2.8.6 AS ci
22

33
ENV APP_HOME=/home/app/stack
44

@@ -26,7 +26,7 @@ FROM ci AS clean
2626
# below command removes the packages specified in devDependencies and set NODE_ENV to production
2727
RUN npm prune --production
2828

29-
FROM linode/apl-tools:v2.8.5 AS prod
29+
FROM linode/apl-tools:v2.8.6 AS prod
3030
ENV APP_HOME=/home/app/stack
3131
ENV ENV_DIR=/home/app/stack/env
3232
ENV VERBOSITY='0'

bin/common.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function crypt() {
202202
[ -n "$VERBOSE" ] && echo "Found timestamp diff in seconds: $sec_diff"
203203
fi
204204
if [ ! -f $file.dec ] || [ $sec_diff -gt 1 ]; then
205-
helm secrets enc $file >$out
205+
helm secrets encrypt -i $file >$out
206206
ts=$(stat -c %Y $file)
207207
chek_ts=$(expr $ts + 1)
208208
touch -d @$chek_ts $file.dec
@@ -211,7 +211,7 @@ function crypt() {
211211
[ -n "$VERBOSE" ] && echo "Skipping encryption for $file as it is not changed."
212212
fi
213213
else
214-
if helm secrets dec $file >$out; then
214+
if helm secrets decrypt "$file" > "${file}.dec"; then
215215
# we correct timestamp of decrypted file to match source file,
216216
# in order to detect changes for conditional encryption
217217
[ -n "$VERBOSE" ] && echo "Setting timestamp of decrypted file to that of source file."

charts/raw/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mysecret: abc123
119119
```
120120

121121
```
122-
$ helm secrets enc secrets.yaml
122+
$ helm secrets encrypt secrets.yaml
123123
```
124124

125125
#### STEP 2: Install your templated resources.

src/common/crypt.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface Arguments extends BasicArguments {
1515
EventEmitter.defaultMaxListeners = 20
1616

1717
enum CryptType {
18-
ENCRYPT = 'helm secrets enc',
19-
DECRYPT = 'helm secrets dec',
18+
ENCRYPT = 'helm secrets -q encrypt -i',
19+
DECRYPT = 'helm secrets decrypt',
2020
ROTATE = 'sops --input-type=yaml --output-type=yaml -i -r',
2121
}
2222

@@ -60,11 +60,27 @@ const processFileChunk = async (crypt: CR, files: string[]): Promise<(ProcessOut
6060
const commands = files.map(async (file) => {
6161
if (!crypt.condition || (await crypt.condition(file))) {
6262
d.debug(`${crypt.cmd} ${file}`)
63-
const result = $`${crypt.cmd.split(' ')} ${file}`
64-
return result.then(async (res) => {
65-
if (crypt.post) await crypt.post(file)
66-
return res
67-
})
63+
const result = $`${crypt.cmd.split(' ')} ${file}`.quiet()
64+
return result
65+
.then(async (res) => {
66+
if (crypt.cmd === CryptType.DECRYPT) {
67+
const outputFile = `${file}.dec`
68+
await $`echo ${res.stdout} > ${outputFile}`
69+
}
70+
if (crypt.post) await crypt.post(file)
71+
return res
72+
})
73+
.catch(async (error) => {
74+
if (error.message.includes('Already encrypted')) {
75+
const res = await $`helm secrets encrypt ${file}.dec`
76+
await $`echo ${res.stdout} > ${file}`
77+
if (crypt.post) await crypt.post(file)
78+
return res
79+
} else {
80+
d.error(error)
81+
throw error
82+
}
83+
})
6884
}
6985
return undefined
7086
})
@@ -172,8 +188,8 @@ export const encrypt = async (path = env.ENV_DIR, ...files: string[]): Promise<v
172188

173189
const encTS = await stat(absFilePath)
174190
const decTS = await stat(`${absFilePath}.dec`)
175-
d.debug('encTS.mtime: ', encTS.mtime)
176-
d.debug('decTS.mtime: ', decTS.mtime)
191+
d.debug(`${file} encTS.mtime: `, encTS.mtime)
192+
d.debug(`${file} decTS.mtime: `, decTS.mtime)
177193
const timeDiff = Math.round((decTS.mtimeMs - encTS.mtimeMs) / 1000)
178194
if (timeDiff > 1) {
179195
d.info(`Encrypting ${file}, time difference was ${timeDiff} seconds`)

tests/bootstrap/input.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ cluster:
55
domainSuffix: local.host
66
otomi:
77
version: 'main'
8+
kms:
9+
sops:
10+
provider: age
811
apps:
912
metrics-server:
1013
enabled: false

tools/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ARG HELM_VERSION=3.16.2
1010
# https://github.com/databus23/helm-diff/releases
1111
ARG HELM_DIFF_VERSION=3.9.11
1212
# https://github.com/jkroepke/helm-secrets/releases
13-
ARG HELM_SECRETS_VERSION=3.15.0
13+
ARG HELM_SECRETS_VERSION=4.6.2
1414
# https://github.com/mozilla/sops/releases
1515
ARG SOPS_VERSION=3.9.1
1616
# https://github.com/FiloSottile/age/releases

0 commit comments

Comments
 (0)