summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Su <chris@lesscrowds.org>2022-04-27 23:43:23 +0800
committerJakov Smolić <jsmolic@gentoo.org>2022-04-27 17:59:58 +0200
commit5aa57d09a9ad9c907b69afc2c9cc340663980c18 (patch)
tree60392e64ff06beb6d65b38d23ac9807241a338a6
parentacct-user/headscale: new package, add 0 (diff)
downloadgentoo-5aa57d09a9ad9c907b69afc2c9cc340663980c18.tar.gz
gentoo-5aa57d09a9ad9c907b69afc2c9cc340663980c18.tar.bz2
gentoo-5aa57d09a9ad9c907b69afc2c9cc340663980c18.zip
net-vpn/headscale: new package, add 0.15.0
Headsacle is an open-source, self-hosted implementation of the Tailscale control server. Using headscale, we can easily build a control server to form our own vpn, the corresponding node authorization, set the acl, etc. Closes: https://bugs.gentoo.org/841017 Signed-off-by: Chris Su <chris@lesscrowds.org> Closes: https://github.com/gentoo/gentoo/pull/25212 Signed-off-by: Jakov Smolić <jsmolic@gentoo.org>
-rw-r--r--net-vpn/headscale/Manifest2
-rw-r--r--net-vpn/headscale/files/config.yaml.example221
-rw-r--r--net-vpn/headscale/files/headscale.conf8
-rw-r--r--net-vpn/headscale/files/headscaled.initd29
-rw-r--r--net-vpn/headscale/files/headscaled.service24
-rw-r--r--net-vpn/headscale/headscale-0.15.0.ebuild49
-rw-r--r--net-vpn/headscale/metadata.xml16
7 files changed, 349 insertions, 0 deletions
diff --git a/net-vpn/headscale/Manifest b/net-vpn/headscale/Manifest
new file mode 100644
index 000000000000..d27143f85e93
--- /dev/null
+++ b/net-vpn/headscale/Manifest
@@ -0,0 +1,2 @@
+DIST headscale-0.15.0-deps.tar.xz 199844288 BLAKE2B 17c9e4a8877ee05f75f08c20794f6c084019f4554769ebabfc8d37e1ec309ac0cc2d18d341db241927df4ba3e43da39e8acb6a33a4a68435f9b3d3f7aebc098b SHA512 aa942787a4bc8644bb5e041fef293fd53a8d4ebc84faa8964c56fe9022b0359cd08ddd568898bc8fa4b2bc358f4c911b8a204438d676c5c4030bd89612d01c01
+DIST headscale-0.15.0.tar.gz 311959 BLAKE2B e4bcbf431c3b903024df95782b4070591e30439263796258f9a3cc07c7a2f4ea3f9895fb2869b642d6c37dc92fe492cc9d3b78261d8faa0a8e2c9eba3906aa20 SHA512 29b867f109e48bf04ab4f8a81bfab94155050f59f6c2aa2b4971567a7fb24ed343b869636e66e9cbb7b1b8df7d7415e769a85a7c3864d0fae169c15b6c7b6eb2
diff --git a/net-vpn/headscale/files/config.yaml.example b/net-vpn/headscale/files/config.yaml.example
new file mode 100644
index 000000000000..603b941dac9d
--- /dev/null
+++ b/net-vpn/headscale/files/config.yaml.example
@@ -0,0 +1,221 @@
+---
+# headscale will look for a configuration file named `config.yaml` (or `config.json`) in the following order:
+#
+# - `/etc/headscale`
+# - `~/.headscale`
+# - current working directory
+
+# The url clients will connect to.
+# Typically this will be a domain like:
+#
+# https://myheadscale.example.com:443
+#
+server_url: http://127.0.0.1:8080
+
+# Address to listen to / bind to on the server
+#
+listen_addr: 0.0.0.0:8080
+
+# Address to listen to /metrics, you may want
+# to keep this endpoint private to your internal
+# network
+#
+metrics_listen_addr: 127.0.0.1:9090
+
+# Address to listen for gRPC.
+# gRPC is used for controlling a headscale server
+# remotely with the CLI
+# Note: Remote access _only_ works if you have
+# valid certificates.
+grpc_listen_addr: 0.0.0.0:50443
+
+# Allow the gRPC admin interface to run in INSECURE
+# mode. This is not recommended as the traffic will
+# be unencrypted. Only enable if you know what you
+# are doing.
+grpc_allow_insecure: false
+
+# Private key used encrypt the traffic between headscale
+# and Tailscale clients.
+# The private key file which will be
+# autogenerated if it's missing
+private_key_path: /var/lib/headscale/private.key
+
+# List of IP prefixes to allocate tailaddresses from.
+# Each prefix consists of either an IPv4 or IPv6 address,
+# and the associated prefix length, delimited by a slash.
+ip_prefixes:
+ - fd7a:115c:a1e0::/48
+ - 100.64.0.0/10
+
+# DERP is a relay system that Tailscale uses when a direct
+# connection cannot be established.
+# https://tailscale.com/blog/how-tailscale-works/#encrypted-tcp-relays-derp
+#
+# headscale needs a list of DERP servers that can be presented
+# to the clients.
+derp:
+ server:
+ # If enabled, runs the embedded DERP server and merges it into the rest of the DERP config
+ # The Headscale server_url defined above MUST be using https, DERP requires TLS to be in place
+ enabled: false
+
+ # Region ID to use for the embedded DERP server.
+ # The local DERP prevails if the region ID collides with other region ID coming from
+ # the regular DERP config.
+ region_id: 999
+
+ # Region code and name are displayed in the Tailscale UI to identify a DERP region
+ region_code: "headscale"
+ region_name: "Headscale Embedded DERP"
+
+ # Listens in UDP at the configured address for STUN connections to help on NAT traversal.
+ # When the embedded DERP server is enabled stun_listen_addr MUST be defined.
+ #
+ # For more details on how this works, check this great article: https://tailscale.com/blog/how-tailscale-works/
+ stun_listen_addr: "0.0.0.0:3478"
+
+ # List of externally available DERP maps encoded in JSON
+ urls:
+ - https://controlplane.tailscale.com/derpmap/default
+
+ # Locally available DERP map files encoded in YAML
+ #
+ # This option is mostly interesting for people hosting
+ # their own DERP servers:
+ # https://tailscale.com/kb/1118/custom-derp-servers/
+ #
+ # paths:
+ # - /etc/headscale/derp-example.yaml
+ paths: []
+
+ # If enabled, a worker will be set up to periodically
+ # refresh the given sources and update the derpmap
+ # will be set up.
+ auto_update_enabled: true
+
+ # How often should we check for DERP updates?
+ update_frequency: 24h
+
+# Disables the automatic check for headscale updates on startup
+disable_check_updates: false
+
+# Time before an inactive ephemeral node is deleted?
+ephemeral_node_inactivity_timeout: 30m
+
+# SQLite config
+db_type: sqlite3
+db_path: /var/lib/headscale/db.sqlite
+
+# # Postgres config
+# db_type: postgres
+# db_host: localhost
+# db_port: 5432
+# db_name: headscale
+# db_user: foo
+# db_pass: bar
+
+### TLS configuration
+#
+## Let's encrypt / ACME
+#
+# headscale supports automatically requesting and setting up
+# TLS for a domain with Let's Encrypt.
+#
+# URL to ACME directory
+acme_url: https://acme-v02.api.letsencrypt.org/directory
+
+# Email to register with ACME provider
+acme_email: ""
+
+# Domain name to request a TLS certificate for:
+tls_letsencrypt_hostname: ""
+
+# Client (Tailscale/Browser) authentication mode (mTLS)
+# Acceptable values:
+# - disabled: client authentication disabled
+# - relaxed: client certificate is required but not verified
+# - enforced: client certificate is required and verified
+tls_client_auth_mode: relaxed
+
+# Path to store certificates and metadata needed by
+# letsencrypt
+tls_letsencrypt_cache_dir: /var/lib/headscale/cache
+
+# Type of ACME challenge to use, currently supported types:
+# HTTP-01 or TLS-ALPN-01
+# See [docs/tls.md](docs/tls.md) for more information
+tls_letsencrypt_challenge_type: HTTP-01
+# When HTTP-01 challenge is chosen, letsencrypt must set up a
+# verification endpoint, and it will be listning on:
+# :http = port 80
+tls_letsencrypt_listen: ":http"
+
+## Use already defined certificates:
+tls_cert_path: ""
+tls_key_path: ""
+
+log_level: info
+
+# Path to a file containg ACL policies.
+# ACLs can be defined as YAML or HUJSON.
+# https://tailscale.com/kb/1018/acls/
+acl_policy_path: ""
+
+## DNS
+#
+# headscale supports Tailscale's DNS configuration and MagicDNS.
+# Please have a look to their KB to better understand the concepts:
+#
+# - https://tailscale.com/kb/1054/dns/
+# - https://tailscale.com/kb/1081/magicdns/
+# - https://tailscale.com/blog/2021-09-private-dns-with-magicdns/
+#
+dns_config:
+ # List of DNS servers to expose to clients.
+ nameservers:
+ - 1.1.1.1
+
+ # Split DNS (see https://tailscale.com/kb/1054/dns/),
+ # list of search domains and the DNS to query for each one.
+ #
+ # restricted_nameservers:
+ # foo.bar.com:
+ # - 1.1.1.1
+ # darp.headscale.net:
+ # - 1.1.1.1
+ # - 8.8.8.8
+
+ # Search domains to inject.
+ domains: []
+
+ # Whether to use [MagicDNS](https://tailscale.com/kb/1081/magicdns/).
+ # Only works if there is at least a nameserver defined.
+ magic_dns: true
+
+ # Defines the base domain to create the hostnames for MagicDNS.
+ # `base_domain` must be a FQDNs, without the trailing dot.
+ # The FQDN of the hosts will be
+ # `hostname.namespace.base_domain` (e.g., _myhost.mynamespace.example.com_).
+ base_domain: example.com
+
+# Unix socket used for the CLI to connect without authentication
+# Note: for local development, you probably want to change this to:
+unix_socket: /run/headscale/headscale.sock
+unix_socket_permission: "0770"
+#
+# headscale supports experimental OpenID connect support,
+# it is still being tested and might have some bugs, please
+# help us test it.
+# OpenID Connect
+# oidc:
+# issuer: "https://your-oidc.issuer.com/path"
+# client_id: "your-oidc-client-id"
+# client_secret: "your-oidc-client-secret"
+#
+# If `strip_email_domain` is set to `true`, the domain part of the username email address will be removed.
+# This will transform `first-name.last-name@example.com` to the namespace `first-name.last-name`
+# If `strip_email_domain` is set to `false` the domain part will NOT be removed resulting to the following
+# namespace: `first-name.last-name.example.com`
+#
+# strip_email_domain: true
diff --git a/net-vpn/headscale/files/headscale.conf b/net-vpn/headscale/files/headscale.conf
new file mode 100644
index 000000000000..5bf65c68e358
--- /dev/null
+++ b/net-vpn/headscale/files/headscale.conf
@@ -0,0 +1,8 @@
+HEADSCALE_USER=headscale
+HEADSCALE_GROUP=headscale
+
+# max number of open files (for floodfill)
+rc_ulimit="-n 4096"
+
+# Options to headscale
+HEADSCALE_OPTIONS="serve"
diff --git a/net-vpn/headscale/files/headscaled.initd b/net-vpn/headscale/files/headscaled.initd
new file mode 100644
index 000000000000..5a12887f444b
--- /dev/null
+++ b/net-vpn/headscale/files/headscaled.initd
@@ -0,0 +1,29 @@
+#!/sbin/openrc-run
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+description="Headscale Server daemon"
+command="/usr/bin/headscale"
+user="${HEADSCALE_USER}:${HEADSCALE_GROUP}"
+directory="/var/lib/headscale"
+output_log="/var/log/headscale.log"
+error_log="/var/log/headscale.log"
+
+start_stop_daemon_args="--user \"${user}\" ${HEADSCALE_OPTIONS} --background"
+
+depend() {
+ need net
+}
+
+start_pre() {
+ if [ ! -s /etc/headscale/config.yaml ] ; then
+ eerror "Missing headscale configuration file"
+ eerror "Please use /etc/headscale/config.yaml.example as example"
+ return 1
+ fi
+
+ checkpath -d -m 700 -o "${user}" /run/headscale /var/lib/headscale
+ checkpath -f -m 600 -o "${user}" /var/lib/headscale/db.sqlite /var/log/headscale.log
+ checkpath -f -m 600 -o "${user}" /etc/headscale/config.yaml
+}
+
diff --git a/net-vpn/headscale/files/headscaled.service b/net-vpn/headscale/files/headscaled.service
new file mode 100644
index 000000000000..fb27b40d4e31
--- /dev/null
+++ b/net-vpn/headscale/files/headscaled.service
@@ -0,0 +1,24 @@
+[Unit]
+Description=headscale controller
+After=syslog.target
+After=network.target
+
+[Service]
+Type=simple
+User=headscale
+Group=headscale
+ExecStart=/usr/bin/headscale serve
+Restart=always
+RestartSec=5
+
+# Optional security enhancements
+NoNewPrivileges=yes
+PrivateTmp=yes
+ProtectSystem=strict
+ProtectHome=yes
+ReadWritePaths=/var/lib/headscale /run/headscale
+AmbientCapabilities=CAP_NET_BIND_SERVICE
+RuntimeDirectory=headscale
+
+[Install]
+WantedBy=multi-user.target
diff --git a/net-vpn/headscale/headscale-0.15.0.ebuild b/net-vpn/headscale/headscale-0.15.0.ebuild
new file mode 100644
index 000000000000..93a52a9f0cde
--- /dev/null
+++ b/net-vpn/headscale/headscale-0.15.0.ebuild
@@ -0,0 +1,49 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit go-module systemd
+
+DESCRIPTION="An open source, self-hosted implementation of the Tailscale control server"
+HOMEPAGE="https://github.com/juanfont/headscale"
+SRC_URI="
+ https://github.com/juanfont/headscale/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
+ https://dev.gentoo.org/~jsmolic/distfiles/net-vpn/headscale/${P}-deps.tar.xz
+"
+
+LICENSE="BSD Apache-2.0 MIT"
+SLOT="0"
+KEYWORDS="~amd64"
+
+DEPEND="
+ acct-group/headscale
+ acct-user/headscale
+"
+RDEPEND="
+ ${DEPEND}
+ net-firewall/iptables
+"
+
+src_install() {
+ keepdir /var/lib/headscale
+ keepdir /etc/headscale
+
+ dobin headscale
+
+ insinto /etc/headscale
+ doins "${FILESDIR}"/config.yaml.example
+
+ fowners -R ${PN}:${PN} /etc/headscale
+ fowners -R ${PN}:${PN} /var/lib/headscale
+
+ systemd_dounit "${FILESDIR}"/headscaled.service
+ newinitd "${FILESDIR}"/headscaled.initd headscaled
+ newconfd "${FILESDIR}"/headscale.conf headscaled
+}
+
+pkg_postinst() {
+ elog "You will need to set up your /etc/headscale/config.yaml file before starting the service"
+ elog "Please use /etc/headscale/config.yaml.example as example"
+ elog "More in the official documentation https://github.com/juanfont/headscale/tree/main/docs"
+}
diff --git a/net-vpn/headscale/metadata.xml b/net-vpn/headscale/metadata.xml
new file mode 100644
index 000000000000..73d345656db7
--- /dev/null
+++ b/net-vpn/headscale/metadata.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="person" proxied="yes">
+ <email>chris@lesscrowds.org</email>
+ <name>Chris Su</name>
+ </maintainer>
+ <maintainer type="person" proxied="proxy">
+ <email>dlan@gentoo.org</email>
+ <name>Yixun Lan</name>
+ </maintainer>
+ <maintainer type="person" proxied="proxy">
+ <email>jsmolic@gentoo.org</email>
+ <name>Jakov Smolić</name>
+ </maintainer>
+</pkgmetadata>