Skip to content

Commit 81aa946

Browse files
authored
Add custom CA when deploying replicated-sdk (#4914)
1 parent 99b0561 commit 81aa946

File tree

10 files changed

+60
-44
lines changed

10 files changed

+60
-44
lines changed

cmd/kots/cli/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func PullCmd() *cobra.Command {
8383
NoProxyEnvValue: v.GetString("no-proxy"),
8484
IncludeMinio: v.GetBool("with-minio"),
8585
SkipCompatibilityCheck: v.GetBool("skip-compatibility-check"),
86+
PrivateCAsConfigmap: v.GetString("private-ca-configmap"),
8687
}
8788

8889
if v.GetBool("copy-proxy-env") {
@@ -154,6 +155,7 @@ func PullCmd() *cobra.Command {
154155
cmd.Flags().String("https-proxy", "", "sets HTTPS_PROXY environment variable in all KOTS Admin Console components")
155156
cmd.Flags().String("no-proxy", "", "sets NO_PROXY environment variable in all KOTS Admin Console components")
156157
cmd.Flags().Bool("copy-proxy-env", false, "copy proxy environment variables from current environment into all KOTS Admin Console components")
158+
cmd.Flags().String("private-ca-configmap", "", "the name of a configmap containing private CAs to add to the kotsadm deployment")
157159
cmd.Flags().Bool("rewrite-images", false, "set to true to force all container images to be rewritten and pushed to a local registry")
158160
cmd.Flags().String("image-namespace", "", "the namespace/org in the docker registry to push images to (required when --rewrite-images is set)")
159161
cmd.Flags().String("registry-endpoint", "", "the endpoint of the local docker registry to use when pushing images (required when --rewrite-images is set)")

pkg/kotsadmupstream/upstream.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func DownloadUpdate(appID string, update types.Update, skipPreflights bool, skip
232232
SkipCompatibilityCheck: skipCompatibilityCheck,
233233
KotsKinds: beforeKotsKinds,
234234
AppSelectedChannelID: a.SelectedChannelID,
235+
PrivateCAsConfigmap: os.Getenv("SSL_CERT_CONFIGMAP"),
235236
}
236237

237238
pullOptions.HTTPProxyEnvValue = os.Getenv("HTTP_PROXY")

pkg/online/online.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func CreateAppFromOnline(opts CreateOnlineAppOpts) (_ *kotsutil.KotsKinds, final
158158
AppSelectedChannelID: opts.PendingApp.SelectedChannelID,
159159
ReportingInfo: reporting.GetReportingInfo(opts.PendingApp.ID),
160160
SkipCompatibilityCheck: opts.SkipCompatibilityCheck,
161+
PrivateCAsConfigmap: os.Getenv("SSL_CERT_CONFIGMAP"),
161162
}
162163

163164
pullOptions.HTTPProxyEnvValue = os.Getenv("HTTP_PROXY")

pkg/pull/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type PullOptions struct {
7474
HTTPProxyEnvValue string
7575
HTTPSProxyEnvValue string
7676
NoProxyEnvValue string
77+
PrivateCAsConfigmap string
7778
ReportingInfo *reportingtypes.ReportingInfo
7879
SkipCompatibilityCheck bool
7980
KotsKinds *kotsutil.KotsKinds
@@ -304,6 +305,7 @@ func Pull(upstreamURI string, pullOptions PullOptions) (string, error) {
304305
IsAirgap: pullOptions.IsAirgap,
305306
KotsadmID: k8sutil.GetKotsadmID(clientset),
306307
AppID: pullOptions.AppID,
308+
PrivateCAsConfigmap: pullOptions.PrivateCAsConfigmap,
307309
}
308310
if err := upstream.WriteUpstream(u, writeUpstreamOptions); err != nil {
309311
log.FinishSpinnerWithError()

pkg/registry/registry.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ func RewriteImages(appID string, sequence int64, hostname string, username strin
153153
ReportingInfo: reporting.GetReportingInfo(a.ID),
154154

155155
// TODO: pass in as arguments if this is ever called from CLI
156-
HTTPProxyEnvValue: os.Getenv("HTTP_PROXY"),
157-
HTTPSProxyEnvValue: os.Getenv("HTTPS_PROXY"),
158-
NoProxyEnvValue: os.Getenv("NO_PROXY"),
156+
HTTPProxyEnvValue: os.Getenv("HTTP_PROXY"),
157+
HTTPSProxyEnvValue: os.Getenv("HTTPS_PROXY"),
158+
NoProxyEnvValue: os.Getenv("NO_PROXY"),
159+
PrivateCAsConfigmap: os.Getenv("SSL_CERT_CONFIGMAP"),
159160
}
160161

161162
options.CopyImages = true

pkg/render/render.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ func RenderDir(opts types.RenderDirOptions) error {
156156
RegistrySettings: opts.RegistrySettings,
157157

158158
// TODO: pass in as arguments if this is ever called from CLI
159-
HTTPProxyEnvValue: os.Getenv("HTTP_PROXY"),
160-
HTTPSProxyEnvValue: os.Getenv("HTTPS_PROXY"),
161-
NoProxyEnvValue: os.Getenv("NO_PROXY"),
159+
HTTPProxyEnvValue: os.Getenv("HTTP_PROXY"),
160+
HTTPSProxyEnvValue: os.Getenv("HTTPS_PROXY"),
161+
NoProxyEnvValue: os.Getenv("NO_PROXY"),
162+
PrivateCAsConfigmap: os.Getenv("SSL_CERT_CONFIGMAP"),
162163
}
163164

164165
err = rewrite.Rewrite(reOptions)

pkg/rewrite/rewrite.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type RewriteOptions struct {
5353
HTTPProxyEnvValue string
5454
HTTPSProxyEnvValue string
5555
NoProxyEnvValue string
56+
PrivateCAsConfigmap string
5657
}
5758

5859
func Rewrite(rewriteOptions RewriteOptions) error {
@@ -114,6 +115,7 @@ func Rewrite(rewriteOptions RewriteOptions) error {
114115
HTTPProxyEnvValue: rewriteOptions.HTTPProxyEnvValue,
115116
HTTPSProxyEnvValue: rewriteOptions.HTTPSProxyEnvValue,
116117
NoProxyEnvValue: rewriteOptions.NoProxyEnvValue,
118+
PrivateCAsConfigmap: rewriteOptions.PrivateCAsConfigmap,
117119
}
118120
if err = upstream.WriteUpstream(u, writeUpstreamOptions); err != nil {
119121
log.FinishSpinnerWithError()

pkg/upstream/admin-console.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,9 @@ func GenerateAdminConsoleFiles(renderDir string, options types.WriteOptions) ([]
9292
return nil, errors.Wrap(err, "failed to find existing settings")
9393
}
9494

95-
if options.HTTPProxyEnvValue != "" {
96-
settings.HTTPProxyEnvValue = options.HTTPProxyEnvValue
97-
}
98-
if options.HTTPSProxyEnvValue != "" {
99-
settings.HTTPSProxyEnvValue = options.HTTPSProxyEnvValue
100-
}
101-
if options.NoProxyEnvValue != "" {
102-
settings.NoProxyEnvValue = options.NoProxyEnvValue
103-
}
95+
settings.HTTPProxyEnvValue = options.HTTPProxyEnvValue
96+
settings.HTTPSProxyEnvValue = options.HTTPSProxyEnvValue
97+
settings.NoProxyEnvValue = options.NoProxyEnvValue
10498

10599
return generateNewAdminConsoleFiles(settings)
106100
}

pkg/upstream/helm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ func buildReplicatedValues(u *types.Upstream, options types.WriteOptions) (map[s
278278
replicatedValues["license"] = string(MustMarshalLicense(u.License))
279279
}
280280

281+
if options.PrivateCAsConfigmap != "" {
282+
replicatedValues["privateCAConfigmap"] = options.PrivateCAsConfigmap
283+
}
284+
281285
replicatedValues["extraEnv"] = []struct {
282286
Name string `yaml:"name"`
283287
Value string `yaml:"value"`

pkg/upstream/helm_test.go

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ func Test_configureChart(t *testing.T) {
1919
}
2020

2121
type Test struct {
22-
name string
23-
isAirgap bool
24-
httpProxy string
25-
httpsProxy string
26-
noProxy string
27-
chartContent map[string]string
28-
want map[string]string
29-
wantErr bool
22+
name string
23+
isAirgap bool
24+
httpProxy string
25+
httpsProxy string
26+
noProxy string
27+
privateCAsConfigmap string
28+
chartContent map[string]string
29+
want map[string]string
30+
wantErr bool
3031
}
3132

3233
tests := []Test{
@@ -291,11 +292,12 @@ another: value
291292
// Generate dynamic tests using the supported replicated chart names
292293
for _, chartName := range testReplicatedChartNames {
293294
tests = append(tests, Test{
294-
name: "online - a standalone replicated chart",
295-
isAirgap: false,
296-
httpProxy: "http://10.1.0.1:3128",
297-
httpsProxy: "https://10.1.0.1:3129",
298-
noProxy: "localhost,127.0.0.1",
295+
name: "online - a standalone replicated chart",
296+
isAirgap: false,
297+
httpProxy: "http://10.1.0.1:3128",
298+
httpsProxy: "https://10.1.0.1:3129",
299+
noProxy: "localhost,127.0.0.1",
300+
privateCAsConfigmap: "my-private-cas",
299301
chartContent: map[string]string{
300302
"replicated/Chart.yaml": fmt.Sprintf(`apiVersion: v1
301303
name: %s
@@ -390,6 +392,7 @@ extraEnv:
390392
- name: NO_PROXY
391393
value: localhost,127.0.0.1
392394
isAirgap: false
395+
privateCAConfigmap: my-private-cas
393396
replicatedID: kotsadm-id
394397
`,
395398
},
@@ -502,11 +505,12 @@ global:
502505
})
503506

504507
tests = append(tests, Test{
505-
name: "online - a guestbook chart with the replicated subchart",
506-
isAirgap: false,
507-
httpProxy: "http://10.1.0.1:3128",
508-
httpsProxy: "https://10.1.0.1:3129",
509-
noProxy: "localhost,127.0.0.1",
508+
name: "online - a guestbook chart with the replicated subchart",
509+
isAirgap: false,
510+
httpProxy: "http://10.1.0.1:3128",
511+
httpsProxy: "https://10.1.0.1:3129",
512+
noProxy: "localhost,127.0.0.1",
513+
privateCAsConfigmap: "my-private-cas",
510514
chartContent: map[string]string{
511515
"guestbook/Chart.yaml": `apiVersion: v2
512516
name: guestbook
@@ -600,6 +604,7 @@ image:
600604
- name: NO_PROXY
601605
value: localhost,127.0.0.1
602606
isAirgap: false
607+
privateCAConfigmap: my-private-cas
603608
replicatedID: kotsadm-id
604609
global:
605610
replicated:
@@ -770,11 +775,12 @@ some: value
770775
})
771776

772777
tests = append(tests, Test{
773-
name: "online - a redis chart with the replicated subchart and predefined replicated and global values",
774-
isAirgap: false,
775-
httpProxy: "http://10.1.0.1:3128",
776-
httpsProxy: "https://10.1.0.1:3129",
777-
noProxy: "localhost,127.0.0.1",
778+
name: "online - a redis chart with the replicated subchart and predefined replicated and global values",
779+
isAirgap: false,
780+
httpProxy: "http://10.1.0.1:3128",
781+
httpsProxy: "https://10.1.0.1:3129",
782+
noProxy: "localhost,127.0.0.1",
783+
privateCAsConfigmap: "my-private-cas",
778784
chartContent: map[string]string{
779785
"redis/Chart.yaml": `apiVersion: v1
780786
name: redis
@@ -896,6 +902,7 @@ global:
896902
- name: NO_PROXY
897903
value: localhost,127.0.0.1
898904
isAirgap: false
905+
privateCAConfigmap: my-private-cas
899906
replicatedID: kotsadm-id
900907
`, chartName),
901908
"redis/charts/replicated/Chart.yaml": fmt.Sprintf(`apiVersion: v1
@@ -1298,12 +1305,13 @@ some: value
12981305
}
12991306

13001307
writeOptions := types.WriteOptions{
1301-
KotsadmID: "kotsadm-id",
1302-
AppID: "app-id",
1303-
IsAirgap: tt.isAirgap,
1304-
HTTPProxyEnvValue: tt.httpProxy,
1305-
HTTPSProxyEnvValue: tt.httpsProxy,
1306-
NoProxyEnvValue: tt.noProxy,
1308+
KotsadmID: "kotsadm-id",
1309+
AppID: "app-id",
1310+
IsAirgap: tt.isAirgap,
1311+
HTTPProxyEnvValue: tt.httpProxy,
1312+
HTTPSProxyEnvValue: tt.httpsProxy,
1313+
NoProxyEnvValue: tt.noProxy,
1314+
PrivateCAsConfigmap: tt.privateCAsConfigmap,
13071315
}
13081316

13091317
got, err := configureChart(chartBytes, upstream, writeOptions)

0 commit comments

Comments
 (0)