Skip to content

Commit 26c6b88

Browse files
committed
dockerfile fix again, minor logging changes
1 parent d818741 commit 26c6b88

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ ENV GOLANG_VERSION 1.8
1111
ENV GOLANG_SRC_URL https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz
1212
ENV GOLANG_SRC_SHA256 406865f587b44be7092f206d73fc1de252600b79b3cacc587b74b5ef5c623596
1313
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
14-
# https://golang.org/issue/14851
15-
RUN echo -e "diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go\nindex 14f4fa9..5599307 100644\n--- a/src/cmd/link/internal/ld/lib.go\n+++ b/src/cmd/link/internal/ld/lib.go\n@@ -1272,6 +1272,11 @@ func hostlink() {\n \t\targv = append(argv, peimporteddlls()...)\n \t}\n\n+\t// The Go linker does not currently support building PIE\n+\t// executables when using the external linker. See:\n+\t// https://github.com/golang/go/issues/6940\n+\targv = append(argv, \"-fno-PIC\")\n+\n \tif Debug['v'] != 0 {\n \t\tfmt.Fprintf(Bso, \"host link:\")\n \t\tfor _, v := range argv {" > /no-pic.patch
1614
# in one step (to prevent creating superfluous layers):
1715
# 1. fetch and install temporary build programs,
1816
# 2. fetch chisel from github (avoid ADD to reduce image size)
@@ -28,6 +26,9 @@ RUN set -ex \
2826
openssl \
2927
git \
3028
go \
29+
curl \
30+
&& curl -s https://raw.githubusercontent.com/docker-library/golang/132cd70768e3bc269902e4c7b579203f66dc9f64/1.8/alpine/no-pic.patch -o /no-pic.patch \
31+
&& cat /no-pic.patch \
3132
&& export GOROOT_BOOTSTRAP="$(go env GOROOT)" \
3233
&& wget -q "$GOLANG_SRC_URL" -O golang.tar.gz \
3334
&& echo "$GOLANG_SRC_SHA256 golang.tar.gz" | sha256sum -c - \

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ Chisel is a fast TCP tunnel, transported over HTTP, secured via SSH. Single exec
1010

1111
**Binaries**
1212

13-
[![Releases](https://img.shields.io/github/release/jpillora/chisel.svg)](https://github.com/jpillora/chisel/releases) [![Releases](https://img.shields.io/github/downloads/jpillora/chisel/total.svg)](https://github.com/jpillora/chisel/releases)
13+
[![Releases](https://img.shields.io/github/release/jpillora/chisel.svg)](https://github.com/jpillora/chisel/releases) [![Releases](https://img.shields.io/github/downloads/jpillora/chisel/total.svg)](https://github.com/jpillora/chisel/releases)
1414

1515
See [the latest release](https://github.com/jpillora/chisel/releases/latest) or download and install it now with `curl https://i.jpillora.com/chisel! | bash`
1616

1717
**Docker**
1818

19-
[![Docker Pulls](https://img.shields.io/docker/pulls/jpillora/chisel.svg)][dockerhub] [![Image Size](https://images.microbadger.com/badges/image/jpillora/chisel.svg)][dockerhub]
20-
21-
[dockerhub]: https://hub.docker.com/r/jpillora/chisel/
19+
[![Docker Pulls](https://img.shields.io/docker/pulls/jpillora/chisel.svg)](https://hub.docker.com/r/jpillora/chisel/) [![Image Size](https://images.microbadger.com/badges/image/jpillora/chisel.svg)](https://microbadger.com/images/jpillora/chisel)
2220

2321
```sh
2422
docker run --rm -it jpillora/chisel --help
@@ -64,16 +62,16 @@ and then visit [localhost:3000](http://localhost:3000/), we should see a directo
6462
```
6563
$ chisel --help
6664
67-
Usage: chisel [command] [--help]
65+
Usage: chisel [command] [--help]
6866
69-
Version: 0.0.0-src
67+
Version: 0.0.0-src
7068
71-
Commands:
72-
server - runs chisel in server mode
73-
client - runs chisel in client mode
69+
Commands:
70+
server - runs chisel in server mode
71+
client - runs chisel in client mode
7472
75-
Read more:
76-
https://github.com/jpillora/chisel
73+
Read more:
74+
https://github.com/jpillora/chisel
7775
7876
```
7977

main.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,25 @@ var serverHelp = `
9797
and private key pair. All commications will be secured using this
9898
key pair. Share the subsequent fingerprint with clients to enable detection
9999
of man-in-the-middle attacks (defaults to the CHISEL_KEY environment
100-
variable, otherwise a new key is generate each run).
100+
variable, otherwise a new key is generate each run).
101101
102102
--auth, An optional string representing a single user with full
103-
access, in the form of <user:pass>. This is equivalent to creating an
104-
authfile with {"<user:pass>": [""]}.
103+
access, in the form of <user:pass>. This is equivalent to creating an
104+
authfile with {"<user:pass>": [""]}.
105105
106106
--authfile, An optional path to a users.json file. This file should
107107
be an object with users defined like:
108-
"<user:pass>": ["<addr-regex>","<addr-regex>"]
109-
when <user> connects, their <pass> will be verified and then
110-
each of the remote addresses will be compared against the list
111-
of address regular expressions for a match. Addresses will
112-
always come in the form "<host/ip>:<port>".
108+
{
109+
"<user:pass>": ["<addr-regex>","<addr-regex>"]
110+
}
111+
when <user> connects, their <pass> will be verified and then
112+
each of the remote addresses will be compared against the list
113+
of address regular expressions for a match. Addresses will
114+
always come in the form "<host/ip>:<port>".
113115
114116
--proxy, Specifies another HTTP server to proxy requests to when
115-
chisel receives a normal HTTP request. Useful for hiding chisel in
116-
plain sight.
117+
chisel receives a normal HTTP request. Useful for hiding chisel in
118+
plain sight.
117119
118120
--socks5, Allows client to access the internal SOCKS5 proxy. See
119121
chisel client --help for more information.
@@ -201,7 +203,7 @@ var clientHelp = `
201203
socks
202204
5000:socks
203205
204-
*When the chisel server enables --socks5, remotes can
206+
*When the chisel server has --socks5 enabled, remotes can
205207
specify "socks" in place of remote-host and remote-port.
206208
The default local host and port for a "socks" remote is
207209
127.0.0.1:1080. Connections to this remote will terminate
@@ -227,7 +229,7 @@ var clientHelp = `
227229
228230
--proxy, An optional HTTP CONNECT proxy which will be used reach
229231
the chisel server. Authentication can be specified inside the URL.
230-
For example, http://admin:[email protected]:8081
232+
For example, http://admin:[email protected]:8081
231233
` + commonHelp
232234

233235
func client(args []string) {

server/server.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Server struct {
3939
sessions chshare.Users
4040

4141
fingerprint string
42-
wsCount int
42+
wsCount int32
4343
httpServer *chshare.HTTPServer
4444
reverseProxy *httputil.ReverseProxy
4545
sshConfig *ssh.ServerConfig
@@ -200,14 +200,18 @@ var upgrader = websocket.Upgrader{
200200
}
201201

202202
func (s *Server) handleWS(w http.ResponseWriter, req *http.Request) {
203+
204+
id := atomic.AddInt32(&s.wsCount, 1)
205+
clog := s.Fork("session#%d", id)
206+
203207
wsConn, err := upgrader.Upgrade(w, req, nil)
204208
if err != nil {
205-
s.Debugf("Failed to upgrade (%s)", err)
209+
clog.Debugf("Failed to upgrade (%s)", err)
206210
return
207211
}
208212
conn := chshare.NewWebSocketConn(wsConn)
209213
// perform SSH handshake on net.Conn
210-
s.Debugf("Handshaking...")
214+
clog.Debugf("Handshaking...")
211215
sshConn, chans, reqs, err := ssh.NewServerConn(conn, s.sshConfig)
212216
if err != nil {
213217
s.Debugf("Failed to handshake (%s)", err)
@@ -222,7 +226,7 @@ func (s *Server) handleWS(w http.ResponseWriter, req *http.Request) {
222226
}
223227

224228
//verify configuration
225-
s.Debugf("Verifying configuration")
229+
clog.Debugf("Verifying configuration")
226230

227231
//wait for request, with timeout
228232
var r *ssh.Request
@@ -250,7 +254,7 @@ func (s *Server) handleWS(w http.ResponseWriter, req *http.Request) {
250254
if v == "" {
251255
v = "<unknown>"
252256
}
253-
s.Infof("Client version (%s) differs from server version (%s)",
257+
clog.Infof("Client version (%s) differs from server version (%s)",
254258
v, chshare.BuildVersion)
255259
}
256260
//if user is provided, ensure they have
@@ -268,51 +272,48 @@ func (s *Server) handleWS(w http.ResponseWriter, req *http.Request) {
268272
r.Reply(true, nil)
269273

270274
//prepare connection logger
271-
s.wsCount++
272-
id := s.wsCount
273-
l := s.Fork("session#%d", id)
274-
l.Debugf("Open")
275-
go s.handleSSHRequests(l, reqs)
276-
go s.handleSSHChannels(l, chans)
275+
clog.Debugf("Open")
276+
go s.handleSSHRequests(clog, reqs)
277+
go s.handleSSHChannels(clog, chans)
277278
sshConn.Wait()
278-
l.Debugf("Close")
279+
clog.Debugf("Close")
279280
}
280281

281-
func (s *Server) handleSSHRequests(l *chshare.Logger, reqs <-chan *ssh.Request) {
282+
func (s *Server) handleSSHRequests(clientLog *chshare.Logger, reqs <-chan *ssh.Request) {
282283
for r := range reqs {
283284
switch r.Type {
284285
case "ping":
285286
r.Reply(true, nil)
286287
default:
287-
l.Debugf("Unknown request: %s", r.Type)
288+
clientLog.Debugf("Unknown request: %s", r.Type)
288289
}
289290
}
290291
}
291292

292-
func (s *Server) handleSSHChannels(l *chshare.Logger, chans <-chan ssh.NewChannel) {
293+
func (s *Server) handleSSHChannels(clientLog *chshare.Logger, chans <-chan ssh.NewChannel) {
293294
var connCount int32
294295
for ch := range chans {
295296
remote := string(ch.ExtraData())
296297
socks := remote == "socks"
297298
//dont accept socks when --socks5 isn't enabled
298299
if socks && s.socksServer == nil {
299-
l.Debugf("Denied socks request, please enable --socks5")
300+
clientLog.Debugf("Denied socks request, please enable --socks5")
300301
ch.Reject(ssh.Prohibited, "SOCKS5 is not enabled on the server")
301302
continue
302303
}
303304
//accept rest
304305
stream, reqs, err := ch.Accept()
305306
if err != nil {
306-
l.Debugf("Failed to accept stream: %s", err)
307+
clientLog.Debugf("Failed to accept stream: %s", err)
307308
continue
308309
}
309310
go ssh.DiscardRequests(reqs)
310311
//handle stream type
311312
connID := atomic.AddInt32(&connCount, 1)
312313
if socks {
313-
go s.handleSocksStream(l.Fork("socks#%d", connID), stream)
314+
go s.handleSocksStream(clientLog.Fork("socks#%d", connID), stream)
314315
} else {
315-
go s.handleTCPStream(l.Fork("tcp#%d", connID), stream, remote)
316+
go s.handleTCPStream(clientLog.Fork("tcp#%d", connID), stream, remote)
316317
}
317318
}
318319
}

0 commit comments

Comments
 (0)