Skip to content

Commit c2a32de

Browse files
committed
TUN-5737: Support https protocol over unix socket origin
1 parent a1d485e commit c2a32de

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

ingress/ingress.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func parseSingleOriginService(c *cli.Context, allowURLFromArgs bool) (OriginServ
126126
if err != nil {
127127
return nil, errors.Wrap(err, "Error validating --unix-socket")
128128
}
129-
return &unixSocketPath{path: path}, nil
129+
return &unixSocketPath{path: path, scheme: "http"}, nil
130130
}
131131
u, err := url.Parse("http://localhost:8080")
132132
return &httpService{url: u}, err
@@ -169,7 +169,10 @@ func validateIngress(ingress []config.UnvalidatedIngressRule, defaults OriginReq
169169
if prefix := "unix:"; strings.HasPrefix(r.Service, prefix) {
170170
// No validation necessary for unix socket filepath services
171171
path := strings.TrimPrefix(r.Service, prefix)
172-
service = &unixSocketPath{path: path}
172+
service = &unixSocketPath{path: path, scheme: "http"}
173+
} else if prefix := "unix+tls:"; strings.HasPrefix(r.Service, prefix) {
174+
path := strings.TrimPrefix(r.Service, prefix)
175+
service = &unixSocketPath{path: path, scheme: "https"}
173176
} else if prefix := "http_status:"; strings.HasPrefix(r.Service, prefix) {
174177
status, err := strconv.Atoi(strings.TrimPrefix(r.Service, prefix))
175178
if err != nil {

ingress/ingress_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,21 @@ ingress:
2626
`
2727
ing, err := ParseIngress(MustReadIngress(rawYAML))
2828
require.NoError(t, err)
29-
_, ok := ing.Rules[0].Service.(*unixSocketPath)
29+
s, ok := ing.Rules[0].Service.(*unixSocketPath)
3030
require.True(t, ok)
31+
require.Equal(t, "http", s.scheme)
32+
}
33+
34+
func TestParseUnixSocketTLS(t *testing.T) {
35+
rawYAML := `
36+
ingress:
37+
- service: unix+tls:/tmp/echo.sock
38+
`
39+
ing, err := ParseIngress(MustReadIngress(rawYAML))
40+
require.NoError(t, err)
41+
s, ok := ing.Rules[0].Service.(*unixSocketPath)
42+
require.True(t, ok)
43+
require.Equal(t, "https", s.scheme)
3144
}
3245

3346
func Test_parseIngress(t *testing.T) {

ingress/origin_proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type StreamBasedOriginProxy interface {
2323
}
2424

2525
func (o *unixSocketPath) RoundTrip(req *http.Request) (*http.Response, error) {
26-
req.URL.Scheme = "http"
26+
req.URL.Scheme = o.scheme
2727
return o.transport.RoundTrip(req)
2828
}
2929

ingress/origin_service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ type OriginService interface {
3333
start(log *zerolog.Logger, shutdownC <-chan struct{}, cfg OriginRequestConfig) error
3434
}
3535

36-
// unixSocketPath is an OriginService representing a unix socket (which accepts HTTP)
36+
// unixSocketPath is an OriginService representing a unix socket (which accepts HTTP or HTTPS)
3737
type unixSocketPath struct {
3838
path string
39+
scheme string
3940
transport *http.Transport
4041
}
4142

0 commit comments

Comments
 (0)