Skip to content

Commit 7613410

Browse files
committed
TUN-3548, TUN-3547: Bastion mode can be specified as a service, doesn't
require URL.
1 parent c40cb7d commit 7613410

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

ingress/ingress.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func parseSingleOriginService(c *cli.Context, allowURLFromArgs bool) (OriginServ
8989
if c.IsSet("hello-world") {
9090
return new(helloWorld), nil
9191
}
92-
if c.IsSet("url") {
92+
if c.IsSet("url") || c.IsSet(config.BastionFlag) {
9393
originURL, err := config.ValidateUrl(c, allowURLFromArgs)
9494
if err != nil {
9595
return nil, errors.Wrap(err, "Error validating origin URL")
@@ -128,6 +128,7 @@ func (ing Ingress) CatchAll() *Rule {
128128
func validate(ingress []config.UnvalidatedIngressRule, defaults OriginRequestConfig) (Ingress, error) {
129129
rules := make([]Rule, len(ingress))
130130
for i, r := range ingress {
131+
cfg := setConfig(defaults, r.OriginRequest)
131132
var service OriginService
132133

133134
if prefix := "unix:"; strings.HasPrefix(r.Service, prefix) {
@@ -143,6 +144,12 @@ func validate(ingress []config.UnvalidatedIngressRule, defaults OriginRequestCon
143144
service = &srv
144145
} else if r.Service == "hello_world" || r.Service == "hello-world" || r.Service == "helloworld" {
145146
service = new(helloWorld)
147+
} else if r.Service == "bastion" || cfg.BastionMode {
148+
// Bastion mode will always start a Websocket proxy server, which will
149+
// overwrite the localService.URL field when `start` is called. So,
150+
// leave the URL field empty for now.
151+
cfg.BastionMode = true
152+
service = new(localService)
146153
} else {
147154
// Validate URL services
148155
u, err := url.Parse(r.Service)
@@ -178,7 +185,7 @@ func validate(ingress []config.UnvalidatedIngressRule, defaults OriginRequestCon
178185
Hostname: r.Hostname,
179186
Service: service,
180187
Path: pathRegex,
181-
Config: setConfig(defaults, r.OriginRequest),
188+
Config: cfg,
182189
}
183190
}
184191
return Ingress{Rules: rules, defaults: defaults}, nil

ingress/ingress_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func Test_parseIngress(t *testing.T) {
3535
fourOhFour := newStatusCode(404)
3636
defaultConfig := setConfig(originRequestFromYAML(config.OriginRequestConfig{}), config.OriginRequestConfig{})
3737
require.Equal(t, defaultKeepAliveConnections, defaultConfig.KeepAliveConnections)
38+
tr := true
3839
type args struct {
3940
rawYAML string
4041
}
@@ -209,6 +210,47 @@ ingress:
209210
},
210211
},
211212
},
213+
{
214+
name: "URL isn't necessary if using bastion",
215+
args: args{rawYAML: `
216+
ingress:
217+
- hostname: bastion.foo.com
218+
originRequest:
219+
bastionMode: true
220+
- service: http_status:404
221+
`},
222+
want: []Rule{
223+
{
224+
Hostname: "bastion.foo.com",
225+
Service: &localService{},
226+
Config: setConfig(originRequestFromYAML(config.OriginRequestConfig{}), config.OriginRequestConfig{BastionMode: &tr}),
227+
},
228+
{
229+
Service: &fourOhFour,
230+
Config: defaultConfig,
231+
},
232+
},
233+
},
234+
{
235+
name: "Bastion service",
236+
args: args{rawYAML: `
237+
ingress:
238+
- hostname: bastion.foo.com
239+
service: bastion
240+
- service: http_status:404
241+
`},
242+
want: []Rule{
243+
{
244+
Hostname: "bastion.foo.com",
245+
Service: &localService{},
246+
Config: setConfig(originRequestFromYAML(config.OriginRequestConfig{}), config.OriginRequestConfig{BastionMode: &tr}),
247+
},
248+
{
249+
Service: &fourOhFour,
250+
Config: defaultConfig,
251+
},
252+
},
253+
},
212254
{
213255
name: "Hostname contains port",
214256
args: args{rawYAML: `

ingress/origin_service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ func (o *localService) start(wg *sync.WaitGroup, log logger.Service, shutdownC <
9696
o.transport = transport
9797

9898
// Start a proxy if one is needed
99-
staticHost := o.staticHost()
100-
if originRequiresProxy(staticHost, cfg) {
99+
if staticHost := o.staticHost(); originRequiresProxy(staticHost, cfg) {
101100
if err := o.startProxy(staticHost, wg, log, shutdownC, errC, cfg); err != nil {
102101
return err
103102
}

0 commit comments

Comments
 (0)