Skip to content

Commit ff819ed

Browse files
authored
fix: create/read sealed secrets (#677)
1 parent 538e802 commit ff819ed

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/otomi-stack.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ import {
8080
testPublicRepoConnect,
8181
} from './utils/coderepoUtils'
8282
import { getPolicies } from './utils/policiesUtils'
83-
import { EncryptedDataRecord, encryptSecretItem, sealedSecretManifest } from './utils/sealedSecretUtils'
83+
import {
84+
EncryptedDataRecord,
85+
encryptSecretItem,
86+
mapObjectToKeyValueArray,
87+
sealedSecretManifest,
88+
} from './utils/sealedSecretUtils'
8489
import { getKeycloakUsers, isValidUsername } from './utils/userUtils'
8590
import { ObjectStorageClient } from './utils/wizardUtils'
8691
import { fetchChartYaml, fetchWorkloadCatalog, NewHelmChartValues, sparseCloneChart } from './utils/workloadUtils'
@@ -1658,6 +1663,19 @@ export default class OtomiStack {
16581663
key,
16591664
value: secretValues?.[key] || value,
16601665
}))
1666+
type SealedSecretMetadata = {
1667+
annotations?: Record<string, string>
1668+
labels?: Record<string, string>
1669+
finalizers?: string[]
1670+
}
1671+
const metadata = sealedSecret?.metadata as SealedSecretMetadata
1672+
if (metadata) {
1673+
sealedSecret.metadata = {
1674+
...metadata,
1675+
annotations: mapObjectToKeyValueArray(metadata.annotations),
1676+
labels: mapObjectToKeyValueArray(metadata.labels),
1677+
}
1678+
}
16611679
const res = { ...sealedSecret, encryptedData, isDisabled } as any
16621680
return res
16631681
}

src/utils/sealedSecretUtils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import crypto, { X509Certificate } from 'crypto'
2+
import { isEmpty } from 'lodash'
23
import { SealedSecret } from 'src/otomi-models'
34

45
function hybridEncrypt(pubKey, plaintext, label) {
@@ -88,12 +89,9 @@ export function sealedSecretManifest(
8889
apiVersion: 'bitnami.com/v1alpha1',
8990
kind: 'SealedSecret',
9091
metadata: {
91-
...data.metadata,
9292
annotations: {
93-
...annotations,
9493
'sealedsecrets.bitnami.com/namespace-wide': 'true',
9594
},
96-
labels,
9795
name: data.name,
9896
namespace,
9997
},
@@ -105,10 +103,19 @@ export function sealedSecretManifest(
105103
metadata: {
106104
name: data.name,
107105
namespace,
106+
...(!isEmpty(annotations) && { annotations }),
107+
...(!isEmpty(labels) && { labels }),
108+
...(!isEmpty(data.metadata?.finalizers) && { finalizers: data.metadata?.finalizers }),
108109
},
109110
},
110111
},
111112
}
112113

113114
return SealedSecretSchema
114115
}
116+
117+
export function mapObjectToKeyValueArray(obj?: Record<string, string>): { key: string; value: string }[] | undefined {
118+
if (Array.isArray(obj)) return obj
119+
if (!obj || isEmpty(obj) || typeof obj !== 'object') return undefined
120+
return Object.entries(obj).map(([key, value]) => ({ key, value }))
121+
}

0 commit comments

Comments
 (0)