Skip to content

Commit 93a6915

Browse files
Support for HTTPS upstream servers (#102)
1 parent a360aa6 commit 93a6915

32 files changed

Lines changed: 200 additions & 8 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## 2.35.0
4+
- Integration routes now support HTTPS upstream servers (with the option to ignore certificate errors)
45
- Development pipeline and workflow improvements
56
- Security and other minor fixes and improvements
67

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,6 @@ test: .backend-prerequisites .backend-test
189189

190190
build-release: .frontend-build .backend-build .build-release-docker-image .build-distribution-files
191191

192-
build-snapshot: .frontend-build .backend-build .build-snapshot-docker-image .build-distribution-files
192+
build-snapshot:
193+
$(MAKE) .frontend-build .backend-build VERSION=0.0.0
194+
$(MAKE) .build-snapshot-docker-image VERSION=$(VERSION)

api/host/artifacts_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func newHostRequestDTO() hostRequestDTO {
2828
TargetURI: new("http://backend"),
2929
Settings: &routeSettingsDTO{
3030
IncludeForwardHeaders: new(true),
31+
IgnoreSSLErrors: new(true),
3132
ProxySslServerName: new(true),
3233
KeepOriginalDomainName: new(true),
3334
IndexFile: new("index.html"),
@@ -69,6 +70,7 @@ func newHost() *host.Host {
6970
TargetURI: new("http://backend"),
7071
Settings: host.RouteSettings{
7172
IncludeForwardHeaders: true,
73+
IgnoreSSLErrors: true,
7274
ProxySSLServerName: true,
7375
KeepOriginalDomainName: true,
7476
IndexFile: new("index.html"),

api/host/converter.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func toRouteSettingsDTO(set *host.RouteSettings) *routeSettingsDTO {
136136
return &routeSettingsDTO{
137137
IncludeForwardHeaders: &set.IncludeForwardHeaders,
138138
ProxySslServerName: &set.ProxySSLServerName,
139+
IgnoreSSLErrors: &set.IgnoreSSLErrors,
139140
KeepOriginalDomainName: &set.KeepOriginalDomainName,
140141
DirectoryListingEnabled: &set.DirectoryListingEnabled,
141142
IndexFile: dropBlankValues(set.IndexFile),
@@ -163,6 +164,7 @@ func toIntegrationConfigDTO(config *host.RouteIntegrationConfig) *integrationCon
163164
return &integrationConfigDTO{
164165
IntegrationID: &config.IntegrationID,
165166
OptionID: &config.OptionID,
167+
UseHTTPS: &config.UseHTTPS,
166168
}
167169
}
168170

@@ -240,6 +242,7 @@ func toRouteSettings(input *routeSettingsDTO) host.RouteSettings {
240242
return host.RouteSettings{
241243
IncludeForwardHeaders: getBoolValue(input.IncludeForwardHeaders),
242244
ProxySSLServerName: getBoolValue(input.ProxySslServerName),
245+
IgnoreSSLErrors: getBoolValue(input.IgnoreSSLErrors),
243246
KeepOriginalDomainName: getBoolValue(input.KeepOriginalDomainName),
244247
DirectoryListingEnabled: getBoolValue(input.DirectoryListingEnabled),
245248
IndexFile: dropBlankValues(input.IndexFile),
@@ -267,6 +270,7 @@ func toRouteIntegrationConfig(input *integrationConfigDTO) *host.RouteIntegratio
267270
return &host.RouteIntegrationConfig{
268271
IntegrationID: getUUIDValue(input.IntegrationID),
269272
OptionID: getStringValue(input.OptionID),
273+
UseHTTPS: getBoolValue(input.UseHTTPS),
270274
}
271275
}
272276

api/host/dto.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type routeSourceCodeDTO struct {
4444
type routeSettingsDTO struct {
4545
IncludeForwardHeaders *bool `json:"includeForwardHeaders"`
4646
ProxySslServerName *bool `json:"proxySslServerName"`
47+
IgnoreSSLErrors *bool `json:"ignoreSslErrors"`
4748
KeepOriginalDomainName *bool `json:"keepOriginalDomainName"`
4849
DirectoryListingEnabled *bool `json:"directoryListingEnabled"`
4950
IndexFile *string `json:"indexFile"`
@@ -53,6 +54,7 @@ type routeSettingsDTO struct {
5354
type integrationConfigDTO struct {
5455
IntegrationID *uuid.UUID `json:"integrationId"`
5556
OptionID *string `json:"optionId"`
57+
UseHTTPS *bool `json:"useHttps"`
5658
}
5759

5860
type staticResponseDTO struct {

core/host/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type RouteSettings struct {
7272
IndexFile *string
7373
IncludeForwardHeaders bool
7474
ProxySSLServerName bool
75+
IgnoreSSLErrors bool
7576
KeepOriginalDomainName bool
7677
DirectoryListingEnabled bool
7778
}
@@ -85,6 +86,7 @@ type RouteStaticResponse struct {
8586
type RouteIntegrationConfig struct {
8687
OptionID string
8788
IntegrationID uuid.UUID
89+
UseHTTPS bool
8890
}
8991

9092
type VPN struct {

core/nginx/cfgfiles/host_configuration_file_provider.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,14 @@ func (p *hostConfigurationFileProvider) buildIntegrationRoute(
350350
return "", coreerror.New(
351351
i18n.M(ctx.context, i18n.K.CoreNginxCfgfilesOptionNotFound).
352352
V("optionID", r.Integration.OptionID),
353-
false,
353+
true,
354354
)
355355
}
356356

357+
if r.Integration.UseHTTPS {
358+
proxyURL = new(strings.Replace(*proxyURL, "http://", "https://", 1))
359+
}
360+
357361
if r.TargetURI != nil && strings.TrimSpace(*r.TargetURI) != "" {
358362
proxyURL = new(*proxyURL + *r.TargetURI)
359363
}
@@ -478,8 +482,13 @@ func (p *hostConfigurationFileProvider) buildRouteSettings(
478482
r *host.Route,
479483
) string {
480484
builder := strings.Builder{}
485+
481486
if r.Settings.ProxySSLServerName {
482-
_, _ = builder.WriteString("proxy_ssl_server_name on;")
487+
_, _ = builder.WriteString("proxy_ssl_server_name on;\n")
488+
}
489+
490+
if r.Settings.IgnoreSSLErrors {
491+
_, _ = builder.WriteString("proxy_ssl_verify off;\n")
483492
}
484493

485494
if r.Settings.IncludeForwardHeaders {

core/nginx/cfgfiles/host_configuration_file_provider_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,31 @@ func Test_hostConfigurationFileProvider(t *testing.T) {
266266
assert.ErrorAs(t, err, &coreErr)
267267
assert.Equal(t, i18n.K.CoreNginxCfgfilesOptionNotFound, coreErr.Message.Key)
268268
})
269+
270+
t.Run("replaces http with https when UseHTTPS is true", func(t *testing.T) {
271+
integrationID := uuid.New()
272+
r := &host.Route{
273+
SourcePath: "/api",
274+
Integration: &host.RouteIntegrationConfig{
275+
IntegrationID: integrationID,
276+
OptionID: "opt-1",
277+
UseHTTPS: true,
278+
},
279+
}
280+
281+
ctrl := gomock.NewController(t)
282+
defer ctrl.Finish()
283+
284+
integrationCmds := integration.NewMockedCommands(ctrl)
285+
integrationCmds.EXPECT().
286+
GetOptionURL(gomock.Any(), integrationID, "opt-1").
287+
Return(new("http://1.2.3.4:80"), nil, nil)
288+
provider.integrationCommands = integrationCmds
289+
290+
result, err := provider.buildIntegrationRoute(ctx, r, host.FeatureSet{})
291+
assert.NoError(t, err)
292+
assert.Contains(t, result, "proxy_pass https://1.2.3.4:80;")
293+
})
269294
})
270295

271296
t.Run("BuildExecuteCodeRoute", func(t *testing.T) {
@@ -407,6 +432,52 @@ func Test_hostConfigurationFileProvider(t *testing.T) {
407432
fmt.Sprintf("include \"/etc/nginx/access-list-%s.conf\";", id),
408433
)
409434
})
435+
436+
t.Run(
437+
"includes proxy_ssl_server_name on when ProxySSLServerName is true",
438+
func(t *testing.T) {
439+
r := &host.Route{
440+
Settings: host.RouteSettings{
441+
ProxySSLServerName: true,
442+
},
443+
}
444+
result := provider.buildRouteSettings(ctx, r)
445+
assert.Contains(t, result, "proxy_ssl_server_name on;")
446+
},
447+
)
448+
449+
t.Run(
450+
"doesn't includes proxy_ssl_server_name when ProxySSLServerName is false",
451+
func(t *testing.T) {
452+
r := &host.Route{
453+
Settings: host.RouteSettings{
454+
ProxySSLServerName: false,
455+
},
456+
}
457+
result := provider.buildRouteSettings(ctx, r)
458+
assert.NotContains(t, result, "proxy_ssl_server_name")
459+
},
460+
)
461+
462+
t.Run("includes proxy_ssl_verify off when IgnoreSSLErrors is true", func(t *testing.T) {
463+
r := &host.Route{
464+
Settings: host.RouteSettings{
465+
IgnoreSSLErrors: true,
466+
},
467+
}
468+
result := provider.buildRouteSettings(ctx, r)
469+
assert.Contains(t, result, "proxy_ssl_verify off;")
470+
})
471+
472+
t.Run("does not include proxy_ssl_verify by default", func(t *testing.T) {
473+
r := &host.Route{
474+
Settings: host.RouteSettings{
475+
IgnoreSSLErrors: false,
476+
},
477+
}
478+
result := provider.buildRouteSettings(ctx, r)
479+
assert.NotContains(t, result, "proxy_ssl_verify")
480+
})
410481
})
411482

412483
t.Run("BuildBinding", func(t *testing.T) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table host_route add column ignore_ssl_errors boolean not null default false;
2+
alter table host_route add column integration_use_https boolean not null default false;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table host_route add column ignore_ssl_errors boolean not null default false;
2+
alter table host_route add column integration_use_https boolean not null default false;

0 commit comments

Comments
 (0)