Skip to content

Commit

Permalink
feature: expose Headscale gRPC service
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasRosenstein committed Oct 13, 2024
1 parent b0fd9e3 commit 309c902
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ __Contents__
* [Admitting machines to the network](#admitting-machines-to-the-network)
* [Updates](#updates)
* [Advanced configuration and usage](#advanced-configuration-and-usage)
* [Remote control Headscale via the CLI](#remote-control-headscale-via-the-cli)
* [Using ACLs](#using-acls)
* [Configuring OIDC](#configuring-oidc)
* [Using a custom domain](#using-a-custom-domain)
* [Highly available Headscale deployment](#highly-available-headscale-deployment)
Expand Down Expand Up @@ -106,6 +108,28 @@ Simply run `fly deploy` after updating the `[build.image]`. Note that there will

## Advanced configuration and usage

### Remote control Headscale via the CLI

We expose the gRPC endpoint that allows you to remote-control Headscale via the CLI automatically. You need to generate
API key via SSH before you can connect remotely:

$ fly ssh console
ssh > headscale apikeys create --expiration 90d

Then, locally, make sure you have the same version of the Headscale CLI installed that is running on your Fly.io app
and follow [as documented](https://headscale.net/ref/remote-cli/?h=api#download-and-configure-headscale). We use the
same typical gRPC port (`50443`).

$ export HEADSCALE_CLI_ADDRESS=${FLY_APP_NAME}.fly.dev:50443
$ export HEADSCALE_CLI_API_KEY=...
$ headscale node list

### Using ACLs

We configure Headscale to store the ACL in the database instead of from file, this allows updating the ACLs without
a `fly deploy` on every update. Follow the above steps to remote-control the Headscale server and then use the
`headscale policy get` and `headscale policy set` commands.

### Configuring OIDC

To enable OIDC, you must at the minimum provide the following environment variables:
Expand Down
9 changes: 9 additions & 0 deletions fly.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ swap_size_mb = 128
timeout = "5s"
path = "/health"

[[services]]
internal_port = 50443
protocol = "tcp"
[[services.ports]]
handlers = ["tls"]
port = "50443"
[services.ports.tls_options]
alpn = ["h2"]

[[metrics]]
port = 8081
path = "/metrics"
Expand Down
7 changes: 2 additions & 5 deletions headscale-fly-io/config.template.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
server_url: https://${HEADSCALE_DOMAIN_NAME}
listen_addr: 0.0.0.0:8080
metrics_listen_addr: 0.0.0.0:8081

# TODO: Expose GRPC API? So that it can be accessed with the headscale CLI
# externally, see https://github.com/juanfont/headscale/blob/main/docs/remote-cli.md
# grpc_listen_addr: 0.0.0.0:8081
# grpc_allow_insecure: true
grpc_listen_addr: 0.0.0.0:50443
grpc_allow_insecure: true # We use Fly.io's TLS termination.

ephemeral_node_inactivity_timeout: ${HEADSCALE_EPHEMERAL_NODE_INACTIVITY_TIMEOUT}

Expand Down

0 comments on commit 309c902

Please sign in to comment.