Skip to content

Commit c42fbd3

Browse files
authored
feat: added option to override CA certificates (#905)
1 parent 4668b8e commit c42fbd3

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

cmd/dev/up.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
flagConfigserverImage = "configserver-image"
4444
flagRunService = "run-service"
4545
flagDownOnError = "down-on-error"
46+
flagCACertificates = "ca-certificates"
4647
)
4748

4849
const (
@@ -128,6 +129,11 @@ func CommandUp() *cli.Command { //nolint:funlen
128129
Usage: "Skip confirmation",
129130
EnvVars: []string{"NHOST_YES"},
130131
},
132+
&cli.StringFlag{ //nolint:exhaustruct
133+
Name: flagCACertificates,
134+
Usage: "Mounts and everrides path to CA certificates in the containers",
135+
EnvVars: []string{"NHOST_CA_CERTIFICATES"},
136+
},
131137
},
132138
}
133139
}
@@ -171,6 +177,7 @@ func commandUp(cCtx *cli.Context) error {
171177
},
172178
cCtx.String(flagDashboardVersion),
173179
configserverImage,
180+
cCtx.String(flagCACertificates),
174181
cCtx.StringSlice(flagRunService),
175182
cCtx.Bool(flagDownOnError),
176183
)
@@ -311,6 +318,7 @@ func up( //nolint:funlen,cyclop
311318
ports dockercompose.ExposePorts,
312319
dashboardVersion string,
313320
configserverImage string,
321+
caCertificatesPath string,
314322
runServices []string,
315323
) error {
316324
ctx, cancel := context.WithCancel(ctx)
@@ -364,6 +372,7 @@ func up( //nolint:funlen,cyclop
364372
dashboardVersion,
365373
configserverImage,
366374
clienv.PathExists(ce.Path.Functions()),
375+
caCertificatesPath,
367376
runServicesCfg...,
368377
)
369378
if err != nil {
@@ -513,14 +522,26 @@ func Up(
513522
ports dockercompose.ExposePorts,
514523
dashboardVersion string,
515524
configserverImage string,
525+
caCertificatesPath string,
516526
runServices []string,
517527
downOnError bool,
518528
) error {
519529
dc := dockercompose.New(ce.Path.WorkingDir(), ce.Path.DockerCompose(), ce.ProjectName())
520530

521531
if err := up(
522-
ctx, ce, appVersion, dc, httpPort, useTLS, postgresPort,
523-
applySeeds, ports, dashboardVersion, configserverImage, runServices,
532+
ctx,
533+
ce,
534+
appVersion,
535+
dc,
536+
httpPort,
537+
useTLS,
538+
postgresPort,
539+
applySeeds,
540+
ports,
541+
dashboardVersion,
542+
configserverImage,
543+
caCertificatesPath,
544+
runServices,
524545
); err != nil {
525546
return upErr(ce, dc, downOnError, err) //nolint:contextcheck
526547
}

dockercompose/compose.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,21 @@ type RunService struct {
602602
Path string
603603
}
604604

605-
func ComposeFileFromConfig(
605+
func mountCACertificates(
606+
path string,
607+
services map[string]*Service,
608+
) {
609+
for _, service := range services {
610+
service.Volumes = append(service.Volumes, Volume{
611+
Type: "bind",
612+
Source: path,
613+
Target: "/etc/ssl/certs/ca-certificates.crt",
614+
ReadOnly: ptr(true),
615+
})
616+
}
617+
}
618+
619+
func ComposeFileFromConfig( //nolint:funlen
606620
cfg *model.ConfigConfig,
607621
subdomain string,
608622
projectName string,
@@ -618,6 +632,7 @@ func ComposeFileFromConfig(
618632
dashboardVersion string,
619633
configserverImage string,
620634
startFunctions bool,
635+
caCertificatesPath string,
621636
runServices ...*RunService,
622637
) (*ComposeFile, error) {
623638
services, err := getServices(
@@ -658,6 +673,10 @@ func ComposeFileFromConfig(
658673
}
659674
}
660675

676+
if caCertificatesPath != "" {
677+
mountCACertificates(caCertificatesPath, services)
678+
}
679+
661680
return &ComposeFile{
662681
Services: services,
663682
Volumes: volumes,

0 commit comments

Comments
 (0)