Skip to content

Instantly share code, notes, and snippets.

@vimagick
Last active October 6, 2026 01:00
Show Gist options
  • Select an option

  • Save vimagick/f56a7b1dd250d4e4ccd4da16632c6dde to your computer and use it in GitHub Desktop.

Select an option

Save vimagick/f56a7b1dd250d4e4ccd4da16632c6dde to your computer and use it in GitHub Desktop.
Build outline-ss-server with audit log

GitHub release

Build status

Build on Linux

$ version=1.9.2
$ mkdir -p outline-ss-server_$version-dev
$ cd outline-ss-server_$version-dev

# download files from this gist:
# - private_net.go
# - tcp.patch

$ curl -sSfLO https://github.com/OutlineFoundation/tunnel-server/raw/refs/tags/v$version/service/tcp.go
$ patch -p1 < tcp.patch

$ docker run --rm -it -v $PWD:/tmp golang:1.27
version=1.9.2
go install github.com/OutlineFoundation/tunnel-server/cmd/outline-ss-server@v$version
cd /go/pkg/mod/github.com/\!outline\!foundation/tunnel-server\@v$version/cmd/outline-ss-server
mv /tmp/private_net.go ../../net/
mv /tmp/tcp.go ../../service/
go clean -cache
for GOOS in linux darwin windows; do
  for GOARCH in amd64 arm64; do
    CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w -X 'main.version=$version-dev'" -o outline-ss-server-$GOOS-$GOARCH
  done
done
ls outline-ss-server-*-*
# outline-ss-server-darwin-amd64
# outline-ss-server-darwin-arm64
# outline-ss-server-linux-amd64
# outline-ss-server-linux-arm64
# outline-ss-server-windows-amd64
# outline-ss-server-windows-arm64
mv outline-ss-server-*-* /tmp/outline-ss-server_$version-dev
exit

$ ./outline-ss-server-linux-amd64 -version
1.9.2-dev

$ rm tcp.patch
$ cd ..
$ tar czf outline-ss-server_$version-dev.tar.gz outline-ss-server_$version-dev

$ curl https://api.onlyfiles.com/v1/upload -F file=@outline-ss-server_$version-dev.tar.gz -F expire=0

Tip

Download pre-built binaries:

Install on macOS

# setup
sudo chown root:wheel /Library/LaunchDaemons/outline-ss-server.plist
sudo chmod a+rwx /usr/local/var/log

# enable
sudo launchctl enable system/outline-ss-server

# start
sudo launchctl bootstrap system /Library/LaunchDaemons/outline-ss-server.plist

# restart
sudo launchctl kickstart -kp system/outline-ss-server

# stop
sudo launchctl bootout system/outline-ss-server

# disable
sudo launchctl disable system/outline-ss-server

Important

UserName:nobody need to have full access to /usr/local/var/log
Otherwise you get launchctl error 78: Function not implemented

Caution

Grok pattern: %{URIHOST} doesn't match underscore. (Re-define %{HOSTNAME} to fix)

Caution

Parse outline-ss-server timestamp with ["MMM dd HH:mm:ss.SSS", "MMM d HH:mm:ss.SSS"] (two spaces between MMM and d)

# ============================== Filebeat inputs ===============================
# https://dissect-tester.jorgelbg.me/
# https://grokdebugger.com/
# filebeat -e -d processors -c /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: journald
id: outline-ss-server
seek: tail
units:
- outline-ss-server.service
fields:
project: vpn
region: sh
server_port: 9443
fields_under_root: true
processors:
- drop_event:
when.not.contains.message: "TCP: Proxy connection."
- dissect:
tokenizer: "%{?ts} %{?host} %{?proc}[%{?pid}]: %{message}"
field: "message"
overwrite_keys: true
target_prefix: ""
ignore_failure: false
- replace:
fields:
- field: "message"
pattern: " INF "
replacement: " INFO "
ignore_missing: true
fail_on_error: false
- include_fields:
fields: ["message", "project", "region", "server_port"]
filter {
if [project] == "vpn" {
grok {
pattern_definitions => {
"HOSTNAME" => '\b(?:[0-9A-Za-z][0-9A-Za-z_-]{0,62})(?:\.(?:[0-9A-Za-z][0-9A-Za-z_-]{0,62}))*(\.?|\b)'
}
match => { "message" => [
"%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:loglevel}: \[%{IPV4:client}\] connect to (?<remote>%{URIHOST}|\[%{IPV6}\]):%{POSINT:port}",
"%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:loglevel} .*established tcp tunnel %{IPV4:client}:%{POSINT:client_port} <-> (?:\[%{IPV6:remote}\]|%{URIHOST:remote}):%{POSINT:port}",
"%{SYSLOGTIMESTAMP:timestamp} %{LOGLEVEL:loglevel} TCP: Proxy connection\. ID=%{WORD:client_id} client=%{IPV4:client}:%{POSINT:client_port} target=%{URIHOST:remote}:%{POSINT:port}"
]}
remove_field => [ "message" ]
}
date {
match => [ "timestamp", "yyyy-MM-dd HH:mm:ss", "MMM dd HH:mm:ss.SSS", "MMM d HH:mm:ss.SSS" ]
remove_field => [ "timestamp" ]
}
mutate {
remove_field => [ "[host]", "[agent]", "[ecs][version]" ]
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>outline-ss-server</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/outline-ss-server</string>
<string>-config=config.yml</string>
<string>-ip_asn_db=ip-asn.mmdb</string>
<string>-ip_country_db=ip-country.mmdb</string>
<string>-metrics=127.0.0.1:9092</string>
<string>-replay_history=10000</string>
</array>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/outline-ss-server.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/outline-ss-server.log</string>
<key>EnvironmentVariables</key>
<dict>
<key>TZ</key>
<string>GMT</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local/etc/outline-ss-server</string>
<key>UserName</key>
<string>nobody</string>
</dict>
</plist>
// Copyright 2026 EasyPi Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package net
import (
"fmt"
stdnet "net"
"os"
"strconv"
"strings"
)
var (
allowIPs []stdnet.IP
allowCIDRs []*stdnet.IPNet
allowPrivate bool
allowLoopback bool
)
func init() {
allowPrivate = envBool("ALLOW_PRIVATE_IPS")
allowLoopback = envBool("ALLOW_LOOPBACK_IPS")
for _, s := range strings.Split(os.Getenv("ALLOW_IPS"), ",") {
s = strings.TrimSpace(s)
if s == "" {
continue
}
if ip := stdnet.ParseIP(s); ip != nil {
allowIPs = append(allowIPs, ip)
continue
}
if _, cidr, err := stdnet.ParseCIDR(s); err == nil {
allowCIDRs = append(allowCIDRs, cidr)
}
}
}
func envBool(key string) bool {
v, _ := strconv.ParseBool(os.Getenv(key))
return v
}
func inAllowList(ip stdnet.IP) bool {
for _, a := range allowIPs {
if a.Equal(ip) {
return true
}
}
for _, c := range allowCIDRs {
if c.Contains(ip) {
return true
}
}
return false
}
// TargetIPValidator is a type alias for checking if an IP is allowed.
type TargetIPValidator = func(stdnet.IP) error
// RequirePublicIP returns an error if the destination IP is not a
// standard public IP.
func RequirePublicIP(ip stdnet.IP) error {
if inAllowList(ip) {
return nil
}
if ip.IsPrivate() {
if allowPrivate {
return nil
}
return NewConnectionError("ERR_ADDRESS_PRIVATE", fmt.Sprintf("Address is private: %s", ip.String()), nil)
}
if ip.IsLoopback() {
if allowLoopback {
return nil
}
return NewConnectionError("ERR_ADDRESS_LOOPBACK", fmt.Sprintf("Address is loopback: %s", ip.String()), nil)
}
if !ip.IsGlobalUnicast() {
return NewConnectionError("ERR_ADDRESS_INVALID", fmt.Sprintf("Address is not public: %s", ip.String()), nil)
}
return nil
}
--- a/tcp.go
+++ b/tcp.go
@@ -342,6 +342,7 @@
// Read target address and dial it.
tgtAddr, err := getProxyRequest(innerConn)
+ h.logger.LogAttrs(nil, slog.LevelInfo, "TCP: Proxy connection.", slog.String("ID", id), slog.String("client", innerConn.RemoteAddr().String()), slog.String("target", tgtAddr))
// Clear the deadline for the target address
outerConn.SetReadDeadline(time.Time{})
if err != nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment