cmd/relaynode: drop local --acl-file in favour of central packet filter.
relaynode itself is not long for this world, deprecated in favour of tailscale/tailscaled. But now that the control server supports central distribution of packet filters, let's actually take advantage of it in a final, backward compatible release of relaynode.
This commit is contained in:
@ -1,63 +0,0 @@
|
||||
{
|
||||
// Declare static groups of users beyond those in the identity service
|
||||
"Groups": {
|
||||
"group:eng": ["u1@example.com", "u2@example.com"]
|
||||
},
|
||||
|
||||
// Declare convenient hostname aliases to use in place of IP addresses
|
||||
"Hosts": {
|
||||
"h222": "100.2.2.2"
|
||||
},
|
||||
|
||||
// Access control list
|
||||
"ACLs": [
|
||||
{
|
||||
"Action": "accept",
|
||||
// Match any of several users
|
||||
"Users": ["a@example.com", "b@example.com"],
|
||||
// Match any port on h222, and port 22 of 10.1.2.3
|
||||
"Ports": ["h222:*", "10.1.2.3:22"]
|
||||
},
|
||||
{
|
||||
"Action": "accept",
|
||||
// Match any user at all
|
||||
"Users": ["*"],
|
||||
// Match port 80 on one machine, ports 53 and 5353 on a second one,
|
||||
// and ports 8000 through 8080 (a port range) on a third one.
|
||||
"Ports": ["h222:80", "10.8.8.8:53,5353", "10.2.3.4:8000-8080"]
|
||||
},
|
||||
{
|
||||
"Action": "accept",
|
||||
// Match all users in the "Admin" role (network administrators)
|
||||
"Users": ["role:Admin", "group:eng"],
|
||||
// Allow access to port 22 on all servers
|
||||
"Ports": ["*:22"]
|
||||
},
|
||||
{
|
||||
"Action": "accept",
|
||||
"Users": ["role:User"],
|
||||
// Match only windows and linux workstations (not implemented yet)
|
||||
"OS": ["windows", "linux"],
|
||||
// Only desktop machines are allowed to access this server
|
||||
"Ports": ["10.1.1.1:443"]
|
||||
},
|
||||
{
|
||||
"Action": "accept",
|
||||
"Users": ["*"],
|
||||
// Match machines which have never been authorized, or which expired.
|
||||
// (not implemented yet)
|
||||
"MachineAuth": ["unauthorized", "expired"],
|
||||
// Logged-in users on unauthorized machines can access the email server.
|
||||
// Open the TLS ports for SMTP, IMAP, and HTTP.
|
||||
"Ports": ["10.1.2.3:465", "10.1.2.3:993", "10.1.2.3:443"]
|
||||
},
|
||||
|
||||
// Match absolutely everything. Comment out this section if you want
|
||||
// the above ACLs to apply.
|
||||
{ "Action": "accept", "Users": ["*"], "Ports": ["*:*"] },
|
||||
|
||||
// Leave this line here so that every rule can end in a comma.
|
||||
// It has no effect since it has no matching rules.
|
||||
{"Action": "accept"}
|
||||
]
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
relaynode /usr/sbin
|
||||
tailscale-login /usr/sbin
|
||||
taillogin /usr/sbin
|
||||
acl.json /etc/tailscale
|
||||
|
@ -5,7 +5,7 @@ ConditionPathExists=/var/lib/tailscale/relay.conf
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=/etc/default/tailscale-relay
|
||||
ExecStart=/usr/sbin/relaynode --config=/var/lib/tailscale/relay.conf --tun=wg0 $PORT $ACL_FILE $FLAGS
|
||||
ExecStart=/usr/sbin/relaynode --config=/var/lib/tailscale/relay.conf --tun=wg0 $PORT $FLAGS
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
|
@ -11,6 +11,7 @@ arch=$(dpkg --print-architecture)
|
||||
)
|
||||
cp -a "$S/$dir/debian" "$dir/debtmp/"
|
||||
rm -f "$dir/debtmp/debian/$package.debhelper.log"
|
||||
rm -f "$dir/${package}_${version}_${arch}.deb"
|
||||
(
|
||||
cd "$dir/debtmp" &&
|
||||
debian/rules build &&
|
||||
|
@ -8,7 +8,6 @@ mkdir "$outdir"
|
||||
touch $outdir/.stamp
|
||||
sfiles="
|
||||
tailscale-login
|
||||
acl.json
|
||||
debian/*.service
|
||||
*.defaults
|
||||
"
|
||||
|
@ -10,5 +10,6 @@ rpmbase=$HOME/rpmbuild
|
||||
|
||||
mkdir -p "$rpmbase/SOURCES/"
|
||||
cp "$dir/$pkg.tar.gz" "$rpmbase/SOURCES/"
|
||||
rm -f "$rpmbase/RPMS/$machine/$pkg-$pkgver.$machine.rpm"
|
||||
rpmbuild -bb "$dir/$pkg.spec"
|
||||
mv "$rpmbase/RPMS/$machine/$pkg-$pkgver.$machine.rpm" $3
|
||||
|
@ -29,7 +29,6 @@ import (
|
||||
"github.com/tailscale/wireguard-go/wgcfg"
|
||||
"tailscale.com/atomicfile"
|
||||
"tailscale.com/control/controlclient"
|
||||
"tailscale.com/control/policy"
|
||||
"tailscale.com/logpolicy"
|
||||
"tailscale.com/version"
|
||||
"tailscale.com/wgengine"
|
||||
@ -52,7 +51,6 @@ func main() {
|
||||
rroutes := getopt.BoolLong("remote-routes", 'R', "allow routing subnets to remote nodes")
|
||||
droutes := getopt.BoolLong("default-routes", 'D', "allow default route on remote node")
|
||||
routes := getopt.StringLong("routes", 0, "", "list of IP ranges this node can relay")
|
||||
aclfile := getopt.StringLong("acl-file", 0, "", "restrict traffic relaying according to json ACL file")
|
||||
debug := getopt.StringLong("debug", 0, "", "Address of debug server")
|
||||
getopt.Parse()
|
||||
if len(getopt.Args()) > 0 {
|
||||
@ -83,18 +81,11 @@ func main() {
|
||||
}
|
||||
|
||||
e = wgengine.NewWatchdog(e)
|
||||
var lastacljson string
|
||||
var p *policy.Policy
|
||||
|
||||
if *aclfile == "" {
|
||||
e.SetFilter(nil)
|
||||
} else {
|
||||
lastacljson = readOrFatal(*aclfile)
|
||||
p = installFilterOrFatal(e, *aclfile, lastacljson, nil)
|
||||
}
|
||||
// Default filter blocks everything, until Start() is called.
|
||||
e.SetFilter(filter.NewAllowNone())
|
||||
|
||||
var lastNetMap *controlclient.NetworkMap
|
||||
var lastUserMap map[string][]filter.IP
|
||||
statusFunc := func(new controlclient.Status) {
|
||||
if new.URL != "" {
|
||||
fmt.Fprintf(os.Stderr, "To authenticate, visit:\n\n\t%s\n\n", new.URL)
|
||||
@ -122,6 +113,9 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("packet filter: %v\n", m.PacketFilter)
|
||||
e.SetFilter(filter.New(m.PacketFilter))
|
||||
|
||||
wgcfg, err := m.WGCfg(uflags, m.DNS)
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting wg config: %v\n", err)
|
||||
@ -130,14 +124,6 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("Error reconfiguring engine: %v\n", err)
|
||||
}
|
||||
lastUserMap = m.UserMap()
|
||||
if p != nil {
|
||||
matches, err := p.Expand(lastUserMap)
|
||||
if err != nil {
|
||||
log.Fatalf("Error expanding ACLs: %v\n", err)
|
||||
}
|
||||
e.SetFilter(filter.New(matches))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,31 +189,8 @@ func main() {
|
||||
signal.Notify(sigCh, os.Interrupt)
|
||||
signal.Notify(sigCh, syscall.SIGTERM)
|
||||
|
||||
t := time.NewTicker(5 * time.Second)
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-t.C:
|
||||
// For the sake of curiosity, request a status
|
||||
// update periodically.
|
||||
e.RequestStatus()
|
||||
|
||||
// check if aclfile has changed.
|
||||
// TODO(apenwarr): use fsnotify instead of polling?
|
||||
if *aclfile != "" {
|
||||
json := readOrFatal(*aclfile)
|
||||
if json != lastacljson {
|
||||
logf("ACL file (%v) changed. Reloading filter.\n", *aclfile)
|
||||
lastacljson = json
|
||||
p = installFilterOrFatal(e, *aclfile, json, lastUserMap)
|
||||
}
|
||||
}
|
||||
case <-sigCh:
|
||||
logf("signal received, exiting")
|
||||
t.Stop()
|
||||
break loop
|
||||
}
|
||||
}
|
||||
<-sigCh
|
||||
logf("signal received, exiting")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
@ -267,21 +230,6 @@ func readOrFatal(filename string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func installFilterOrFatal(e wgengine.Engine, filename, acljson string, usermap map[string][]filter.IP) *policy.Policy {
|
||||
p, err := policy.Parse(acljson)
|
||||
if err != nil {
|
||||
log.Fatalf("%v: json filter: %v\n", filename, err)
|
||||
}
|
||||
|
||||
matches, err := p.Expand(usermap)
|
||||
if err != nil {
|
||||
log.Fatalf("%v: json filter: %v\n", filename, err)
|
||||
}
|
||||
|
||||
e.SetFilter(filter.New(matches))
|
||||
return p
|
||||
}
|
||||
|
||||
func runDebugServer(addr string) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
|
@ -4,11 +4,5 @@
|
||||
# settings.
|
||||
PORT="--port=41641"
|
||||
|
||||
# Comment out this line to allow all traffic to be relayed.
|
||||
# Or edit the given file to allow specific traffic.
|
||||
# The example file is unlikely to match any users on your network, so it
|
||||
# will block all incoming traffic by default.
|
||||
ACL_FILE="--acl-file=/etc/tailscale/acl.json"
|
||||
|
||||
# Extra flags you might want to pass to relaynode.
|
||||
FLAGS=""
|
||||
|
@ -28,14 +28,12 @@ mkdir -p $D/usr/sbin $D/lib/systemd/system $D/etc/default $D/etc/tailscale
|
||||
cp taillogin tailscale-login relaynode $D/usr/sbin
|
||||
cp tailscale-relay.service $D/lib/systemd/system/
|
||||
cp tailscale-relay.defaults $D/etc/default/tailscale-relay
|
||||
cp acl.json $D/etc/tailscale/acl.json
|
||||
|
||||
%clean
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%config(noreplace) /etc/default/tailscale-relay
|
||||
%config(noreplace) /etc/tailscale/acl.json
|
||||
/lib/systemd/system/tailscale-relay.service
|
||||
/usr/sbin/taillogin
|
||||
/usr/sbin/tailscale-login
|
||||
|
Reference in New Issue
Block a user