Skip to content

Commit 0aa8bec

Browse files
authored
skip: bind address flag, serve skip.pac via http (#185)
Add --bind address for local address. Uses kingpin to parse flags simply because this library is already in use in this repo. The skip.pac file is now interpreted as a template so that the local address can be filled in and served on http (instead of previously just installing it with a file://-URL). For this, we use the new "go:embed" feature to embed the template file into the binary (hence the update to go-1.16). Configuring the skip.pac file with an http://-URL appears to make this work in chrome 🎉. Also: - update to go-1.16 (for go:embed, see above) - fix go 1.16 invalid non-alphanumeric build constraint (test-bat-httplib -> testbathttplib) - bump scion dependency to latest scionlab version which builds on go-1.15 - ci: bump machine for integration tests, now runs go-1.15. Some cheat to avoid building scion-skip in integration tests. - ci: fix cache paths for integration tests, separate cache key - update golangci-lint version in Makefile - Makefile: do not run linter on make test/integration, messes up CI - go mod tidy
1 parent dade5c1 commit 0aa8bec

File tree

10 files changed

+152
-90
lines changed

10 files changed

+152
-90
lines changed

.circleci/config.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/golang:1.14
5+
- image: circleci/golang:1.16
66

77
steps:
88
- run:
@@ -14,14 +14,14 @@ jobs:
1414
keys:
1515
- v1-pkg-cache-{{ checksum "go.sum" }}
1616
- v1-pkg-cache
17+
- run:
18+
name: Build
19+
command: make build
1720
- run:
1821
name: Run Linters
1922
command: |
2023
make setup_lint
2124
make lint
22-
- run:
23-
name: Build
24-
command: make all
2525
- run:
2626
name: Run unit tests
2727
command: make test
@@ -32,7 +32,7 @@ jobs:
3232

3333
integration:
3434
machine:
35-
image: ubuntu-1604:202007-01
35+
image: ubuntu-2004:202101-01
3636

3737
steps:
3838
- checkout
@@ -51,9 +51,9 @@ jobs:
5151
git checkout --quiet ${scion_commit}
5252
- restore_cache:
5353
keys:
54-
- v1-pkg-cache-{{ checksum "~/scion/go.sum" }}-{{ checksum "go.sum" }}
55-
- v1-pkg-cache-{{ checksum "~/scion/go.sum" }}-
56-
- v1-pkg-cache-
54+
- v2-integration-pkg-cache-{{ checksum "~/scion/go.sum" }}-{{ checksum "go.sum" }}
55+
- v2-integration-pkg-cache-{{ checksum "~/scion/go.sum" }}-
56+
- v2-integration-pkg-cache-
5757
- run:
5858
name: Build SCION services and install python3 dependencies
5959
command: |
@@ -86,21 +86,23 @@ jobs:
8686
supervisor/supervisor.sh reload
8787
supervisor/supervisor.sh start all
8888
- run:
89-
name: Prepare integration test
90-
command: |
91-
# Handle the two special ones
92-
make setup_lint
89+
name: Install libpam0g-dev
90+
command:
9391
sudo apt-get update && sudo apt-get install -y libpam0g-dev
9492
- run:
9593
name: Integration tests
9694
command: |
95+
# XXX: hack, don't build skip here, needs go-1.16, currently this runs on go-1.15.
96+
# As there are currently no integration tests for scion-skip, we don't need it here.
97+
sed -i '/^\s*scion-skip\s*\\$/d' Makefile
9798
make integration
9899
- store_artifacts:
99100
path: /tmp/scion-apps-integration/
100101
- save_cache:
101-
key: v1-pkg-cache-{{ checksum "~/scion/go.sum" }}-{{ checksum "go.sum" }}
102+
key: v2-integration-pkg-cache-{{ checksum "~/scion/go.sum" }}-{{ checksum "go.sum" }}
102103
paths:
103-
- "/go/pkg"
104+
- "~/.go_workspace/"
105+
- "~/.cache/go-build/"
104106

105107
workflows:
106108
version: 2

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ clean:
3030
go clean ./...
3131
rm -f bin/*
3232

33-
test: lint
33+
test:
3434
go test -v -tags=$(TAGS) ./...
3535

3636
setup_lint:
3737
@# Install golangci-lint (as dumb as this looks, this is the recommended way to install)
38-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ${DESTDIR} v1.31.0
38+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ${DESTDIR} v1.37.1
3939

4040
lint:
4141
@type golangci-lint > /dev/null || ( echo "golangci-lint not found. Install it manually or by running 'make setup_lint'."; exit 1 )
@@ -46,7 +46,7 @@ install: all
4646
mkdir -p $(DESTDIR)
4747
cp -t $(DESTDIR) $(BIN)/scion-*
4848

49-
integration: all
49+
integration: build
5050
go test -v -tags=integration,$(TAGS) ./... ./_examples/helloworld/
5151

5252
.PHONY: scion-bat

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sudo apt install scion-apps-*
1717

1818
### Build:
1919

20-
1. Install go 1.14
20+
1. Install go 1.16
2121

2222
See e.g. https://github.com/golang/go/wiki/Ubuntu
2323

bat/httplib/httplib_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// different value than expected.
1818
// There is not much value in running these tests for our fork anyway, so skip
1919
// them.
20-
// +build test-bat-httplib
20+
// +build testbathttplib
2121

2222
package httplib
2323

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module github.com/netsec-ethz/scion-apps
22

3-
go 1.14
3+
go 1.16
44

55
require (
6-
github.com/BurntSushi/toml v0.3.1
76
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
87
github.com/bclicn/color v0.0.0-20180711051946-108f2023dc84
98
github.com/gorilla/handlers v1.5.1
@@ -22,4 +21,4 @@ require (
2221
gopkg.in/alecthomas/kingpin.v2 v2.2.6
2322
)
2423

25-
replace github.com/scionproto/scion => github.com/netsec-ethz/scion v0.0.0-20201217162907-707a5e6caaff
24+
replace github.com/scionproto/scion => github.com/netsec-ethz/scion v0.0.0-20210209094654-fbc7c985966b

go.sum

Lines changed: 87 additions & 45 deletions
Large diffs are not rendered by default.

skip/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ as either:
2424

2525
In Firefox (currently v84.0), navigate to
2626
**Preferences** / **General** / **Network Settings**, enable "Automatic proxy
27-
configuration URL" and enter `file://` and the path to the `skip.pac` file
28-
(e.g. `file:///home/skipper/scion-apps/skip/skip.pac`).
27+
configuration URL" and enter `http://localhost:8888/skip.pac`.
28+
Adapt the address if you're running skip on a non-default address with `--bind`.
2929

3030
## Usage
3131

@@ -41,7 +41,6 @@ Enter SCION addresses in the URL bar of your browser, mangled as described above
4141

4242
## Limitations
4343

44-
* Chrome does not appear to honor the PAC (WPAD) configuration, even when it reads it. Not sure why.
4544
* Does not support HTTPS
4645
* Does not support WebSockets (HTTP CONNECT) method
4746
* Does not allow specifiying the protocol (e.g. as

skip/main.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,28 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// +build go1.16
16+
1517
package main
1618

1719
import (
20+
"bytes"
1821
"crypto/tls"
22+
_ "embed"
1923
"fmt"
2024
"io"
2125
"io/ioutil"
2226
"log"
27+
"net"
2328
"net/http"
2429
"os"
2530
"regexp"
2631
"strings"
32+
"text/template"
2733

2834
"github.com/gorilla/handlers"
2935
"github.com/netsec-ethz/scion-apps/pkg/shttp"
36+
"gopkg.in/alecthomas/kingpin.v2"
3037
)
3138

3239
var (
@@ -39,20 +46,48 @@ const (
3946
mungedScionAddrHostIndex = 3
4047
)
4148

49+
//go:embed skip.pac
50+
var skipPAC string
51+
var skipPACtemplate = template.Must(template.New("skip.pac").Parse(skipPAC))
52+
53+
type skipPACTemplateParams struct {
54+
ProxyAddress string
55+
}
56+
4257
func main() {
58+
var bindAddress *net.TCPAddr
59+
kingpin.Flag("bind", "Address to bind on").Default("localhost:8888").TCPVar(&bindAddress)
60+
kingpin.Parse()
61+
4362
transport := shttp.NewRoundTripper(&tls.Config{InsecureSkipVerify: true}, nil)
4463
defer transport.Close()
4564
proxy := &proxyHandler{
4665
transport: transport,
4766
}
48-
67+
mux := http.NewServeMux()
68+
mux.Handle("localhost/skip.pac", http.HandlerFunc(handleWPAD))
69+
if bindAddress.IP != nil {
70+
mux.Handle(bindAddress.IP.String()+"/skip.pac", http.HandlerFunc(handleWPAD))
71+
}
72+
mux.Handle("/", proxy) // everything else
4973
server := &http.Server{
50-
Addr: "localhost:8888",
51-
Handler: handlers.LoggingHandler(os.Stdout, proxy),
74+
Addr: bindAddress.String(),
75+
Handler: handlers.LoggingHandler(os.Stdout, mux),
5276
}
5377
log.Fatal(server.ListenAndServe())
5478
}
5579

80+
func handleWPAD(w http.ResponseWriter, req *http.Request) {
81+
buf := &bytes.Buffer{}
82+
err := skipPACtemplate.Execute(buf, skipPACTemplateParams{ProxyAddress: req.Host})
83+
if err != nil {
84+
http.Error(w, "error executing template", 500)
85+
return
86+
}
87+
w.Header().Set("content-type", "application/x-ns-proxy-autoconfig")
88+
_, _ = w.Write(buf.Bytes())
89+
}
90+
5691
type proxyHandler struct {
5792
transport http.RoundTripper
5893
}

skip/skip.pac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function FindProxyForURL(url, host)
22
{
33
let mungedScionAddr = /^\d+-[-_.\dA-Fa-f]+$/
44
if (host.match(mungedScionAddr) != null || shExpMatch(host, "*.scion")) {
5-
return "PROXY localhost:8888";
5+
return "PROXY {{.ProxyAddress}}";
66
}
77
return "DIRECT";
88
}

webapp/development.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,7 @@ Add alternate test forwarding port line in `Vagrantfile`:
7171
config.vm.network "forwarded_port", guest: 8080, host: 8080, protocol: "tcp"
7272
```
7373

74-
Update Go Paths:
75-
```shell
76-
echo 'export GOPATH="$HOME/go"' >> ~/.profile
77-
echo 'export GOBIN="$GOPATH/bin"' >> ~/.profile
78-
echo 'export PATH="$HOME/.local/bin:$GOPATH/bin:/usr/local/go/bin:$PATH"' >> ~/.profile
79-
source ~/.profile
80-
mkdir -p "$GOPATH"
81-
```
82-
83-
Install Go 1.14:
84-
```shell
85-
cd ~
86-
sudo rm -rf /usr/local/go
87-
curl -LO https://golang.org/dl/go1.14.12.linux-amd64.tar.gz
88-
sudo tar -C /usr/local -xzf go1.14.12.linux-amd64.tar.gz
89-
```
74+
Install Go 1.16 (see e.g. https://github.com/golang/go/wiki/Ubuntu).
9075

9176
Build and install `scion-apps`:
9277
```shell

0 commit comments

Comments
 (0)