fix: silly golang runtime exception

This commit is contained in:
Alexander Ng 2024-01-12 22:22:40 -08:00
parent ed0fa7ff1f
commit ba68c42b6f
No known key found for this signature in database
GPG Key ID: 54CA3BAC2DBFEE4C
4 changed files with 35 additions and 29 deletions

View File

@ -8,4 +8,5 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-s' -o ./s
FROM gcr.io/distroless/static:nonroot FROM gcr.io/distroless/static:nonroot
COPY --from=builder /go/src/github.com/serjs/socks5/socks5 / COPY --from=builder /go/src/github.com/serjs/socks5/socks5 /
ENTRYPOINT ["/socks5"] ENTRYPOINT ["/socks5"]

View File

@ -9,26 +9,31 @@ Simple socks5 server using go-socks5 with authentication, allowed ips list and d
- Run docker container using default container port 1080 and expose it to world using host port 1080, with auth creds - Run docker container using default container port 1080 and expose it to world using host port 1080, with auth creds
```docker run -d --name socks5 -p 1080:1080 -e PROXY_USER=<PROXY_USER> -e PROXY_PASSWORD=<PROXY_PASSWORD> serjs/go-socks5-proxy``` `docker run -d --name socks5 -p 1080:1080 -e PROXY_USER=<PROXY_USER> -e PROXY_PASSWORD=<PROXY_PASSWORD> serjs/go-socks5-proxy`
- Leave `PROXY_USER` and `PROXY_PASSWORD` empty for skip authentication options while running socks5 server, see example below - Leave `PROXY_USER` and `PROXY_PASSWORD` empty for skip authentication options while running socks5 server, see example below
- Run docker container using specifit container port and expose it to host port 1090, without auth creds - Run docker container using specifit container port and expose it to host port 1090, without auth creds
```docker run -d --name socks5 -p 1090:9090 -e PROXY_PORT=9090 serjs/go-socks5-proxy``` `docker run -d --name socks5 -p 1090:9090 -e PROXY_PORT=9090 serjs/go-socks5-proxy`
- Run docker container using default container port 1080 and expose it to world using host port 1080, with PROXY_CREDENTIALS multi-user authentication
`docker run -d --name socks5 -p 1080:1080 -e PROXY_CREDENTIALS='[{"username":"TEST_USERNAME","password":"password123"}]' serjs/go-socks5-proxy`
# List of supported config parameters # List of supported config parameters
|ENV variable|Type|Default|Description| | ENV variable | Type | Default | Description |
|------------|----|-------|-----------| | ----------------- | ----------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|PROXY_USER|String|EMPTY|Set proxy user (also required existed PROXY_PASS)| | PROXY_CREDENTIALS | Json Object | EMPTY | Provide a JSON stringified object representing a list of allowed user/password credential pairs. The form of this object is `{ password: string, username: string }[]`. See |
|PROXY_PASSWORD|String|EMPTY|Set proxy password for auth, used with PROXY_USER| | PROXY_USER | String | EMPTY | Set proxy user (also required existed PROXY_PASS) |
|PROXY_PORT|String|1080|Set listen port for application inside docker container| | PROXY_PASSWORD | String | EMPTY | Set proxy password for auth, used with PROXY_USER |
|ALLOWED_DEST_FQDN|String|EMPTY|Allowed destination address regular expression pattern. Default allows all.| | PROXY_PORT | String | 1080 | Set listen port for application inside docker container |
|ALLOWED_IPS|String|Empty|Set allowed IP's that can connect to proxy, separator `,`| | ALLOWED_DEST_FQDN | String | EMPTY | Allowed destination address regular expression pattern. Default allows all. |
| ALLOWED_IPS | String | Empty | Set allowed IP's that can connect to proxy, separator `,` |
# Build your own image: # Build your own image:
`docker-compose -f docker-compose.build.yml up -d`\ `docker-compose -f docker-compose.build.yml up -d`\
Just don't forget to set parameters in the `.env` file. Just don't forget to set parameters in the `.env` file.
@ -38,22 +43,22 @@ Assuming that you are using container on 1080 host docker port
## Without authentication ## Without authentication
```curl --socks5 <docker host ip>:1080 https://ifcfg.co``` - result must show docker host ip (for bridged network) `curl --socks5 <docker host ip>:1080 https://ifcfg.co` - result must show docker host ip (for bridged network)
or or
```docker run --rm curlimages/curl:7.65.3 -s --socks5 <docker host ip>:1080 https://ifcfg.co``` `docker run --rm curlimages/curl:7.65.3 -s --socks5 <docker host ip>:1080 https://ifcfg.co`
## With authentication ## With authentication
```curl --socks5 <docker host ip>:1080 -U <PROXY_USER>:<PROXY_PASSWORD> http://ifcfg.co``` `curl --socks5 <docker host ip>:1080 -U <PROXY_USER>:<PROXY_PASSWORD> http://ifcfg.co`
or or
```docker run --rm curlimages/curl:7.65.3 -s --socks5 <PROXY_USER>:<PROXY_PASSWORD>@<docker host ip>:1080 http://ifcfg.co``` `docker run --rm curlimages/curl:7.65.3 -s --socks5 <PROXY_USER>:<PROXY_PASSWORD>@<docker host ip>:1080 http://ifcfg.co`
# Authors # Authors
* **Sergey Bogayrets** - **Sergey Bogayrets**
See also the list of [contributors](https://github.com/serjs/socks5-server/graphs/contributors) who participated in this project. See also the list of [contributors](https://github.com/serjs/socks5-server/graphs/contributors) who participated in this project.

View File

@ -2,26 +2,19 @@ package main
import ( import (
"encoding/json" "encoding/json"
"github.com/armon/go-socks5"
) )
type credentials struct { type Credentials struct {
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
} }
func parseCredentials(credsString string) (socks5.StaticCredentials, error) { func parseCredentials(credsString string) ([]Credentials, error) {
var creds []credentials var creds []Credentials
err := json.Unmarshal([]byte(credsString), &creds) err := json.Unmarshal([]byte(credsString), &creds)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var credsMap socks5.StaticCredentials return creds, nil
for _, cred := range creds {
credsMap[cred.Username] = cred.Password
}
return credsMap, nil
} }

View File

@ -31,12 +31,19 @@ func main() {
Logger: log.New(os.Stdout, "", log.LstdFlags), Logger: log.New(os.Stdout, "", log.LstdFlags),
} }
log.Printf(cfg.Creds)
var creds socks5.StaticCredentials var creds socks5.StaticCredentials
if cfg.Creds != "" { if cfg.Creds != "" {
creds, err = parseCredentials(cfg.Creds) var uname_pw_pairs, creds_err = parseCredentials(cfg.Creds)
if err != nil {
if creds_err != nil {
log.Printf("%+v\n", err) log.Printf("%+v\n", err)
} }
for _, kv := range uname_pw_pairs {
creds[kv.Username] = kv.Password
}
} }
if cfg.User+cfg.Password != "" { if cfg.User+cfg.Password != "" {
creds[cfg.User] = cfg.Password creds[cfg.User] = cfg.Password