-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `tailscale` module can be used to add an ot-sim device (bare metal, VM, Docker container, etc) to a Tailscale tailnet at the underlying OS level. It does so by shelling out to start the `tailscaled` daemon and then shelling out to `tailscale up` to add the device to the tailnet. A Tailscale auth key must be provided, either in the XML config or via an environment variable. A hostname to use for the device on the tailnet can also be provided. If not provided, the underlying OS hostname is used. ``` <tailscale> <auth-key>tskey-auth-...</auth-key> <hostname>foobar</hostname> <accept-dns>false</accept-dns> </tailscale> ``` The `OTSIM_TAILSCALE_AUTHKEY` environment variable can be used instead of the `<auth-key>` configuration element if needed. Note that the underlying OS (bare metal, VM, Docker container) must already have the `tailscaled` and `tailscale` executables installed. See the main OT-sim Dockerfile for an example of how to install the Tailscale executables. Also note that, in order for Tailscale to work in a Docker container, the `NET_ADMIN` capability must be added and the `/dev/net/tun` and `/lib/modules` volumes must be mounted (`/lib/modules` can be mounted read-only).
- Loading branch information
1 parent
c1e7efb
commit 014bab7
Showing
4 changed files
with
381 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
otsim "github.com/patsec/ot-sim" | ||
"github.com/patsec/ot-sim/util" | ||
"github.com/patsec/ot-sim/util/sigterm" | ||
|
||
// This will cause the Tailscale module to register itself with the otsim | ||
// package so it gets run by the otsim.Start function below. | ||
_ "github.com/patsec/ot-sim/tailscale" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
panic("path to config file not provided") | ||
} | ||
|
||
if err := otsim.ParseConfigFile(os.Args[1]); err != nil { | ||
fmt.Printf("Error parsing config file: %v\n", err) | ||
os.Exit(util.ExitNoRestart) | ||
} | ||
|
||
ctx := sigterm.CancelContext(context.Background()) | ||
|
||
if err := otsim.Start(ctx); err != nil { | ||
fmt.Printf("Error starting Tailscale module: %v\n", err) | ||
|
||
var exitErr util.ExitError | ||
if errors.As(err, &exitErr) { | ||
os.Exit(exitErr.ExitCode) | ||
} | ||
|
||
os.Exit(1) | ||
} | ||
|
||
<-ctx.Done() | ||
|
||
if err := ctx.Err(); err != nil && !errors.Is(err, context.Canceled) { | ||
fmt.Printf("Error running Tailscale module: %v\n", err) | ||
|
||
var exitErr util.ExitError | ||
if errors.As(err, &exitErr) { | ||
os.Exit(exitErr.ExitCode) | ||
} | ||
|
||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.