Add support for ephemeral nodes via a special type of pre-auth key. Add
tests for that feature. Other fixes: clean up a few typos in comments. Fix a bug that caused the tests to run four times each. Be more consistent in the use of log rather than fmt to print errors and notices.
This commit is contained in:
parent
1faed2764f
commit
41f6740ddd
17 changed files with 151 additions and 38 deletions
|
@ -65,9 +65,9 @@ var ListNodesCmd = &cobra.Command{
|
|||
log.Fatalf("Error getting nodes: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("name\t\tlast seen\n")
|
||||
fmt.Printf("name\t\tlast seen\t\tephemeral\n")
|
||||
for _, m := range *machines {
|
||||
fmt.Printf("%s\t%s\n", m.Name, m.LastSeen.Format("2006-01-02 15:04:05"))
|
||||
fmt.Printf("%s\t%s\t%t\n", m.Name, m.LastSeen.Format("2006-01-02 15:04:05"), m.AuthKey.Ephemeral)
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -45,10 +45,11 @@ var ListPreAuthKeys = &cobra.Command{
|
|||
expiration = k.Expiration.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
fmt.Printf(
|
||||
"key: %s, namespace: %s, reusable: %v, expiration: %s, created_at: %s\n",
|
||||
"key: %s, namespace: %s, reusable: %v, ephemeral: %v, expiration: %s, created_at: %s\n",
|
||||
k.Key,
|
||||
k.Namespace.Name,
|
||||
k.Reusable,
|
||||
k.Ephemeral,
|
||||
expiration,
|
||||
k.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
)
|
||||
|
@ -71,6 +72,7 @@ var CreatePreAuthKeyCmd = &cobra.Command{
|
|||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
reusable, _ := cmd.Flags().GetBool("reusable")
|
||||
ephemeral, _ := cmd.Flags().GetBool("ephemeral")
|
||||
|
||||
e, _ := cmd.Flags().GetString("expiration")
|
||||
var expiration *time.Time
|
||||
|
@ -83,7 +85,7 @@ var CreatePreAuthKeyCmd = &cobra.Command{
|
|||
expiration = &exp
|
||||
}
|
||||
|
||||
k, err := h.CreatePreAuthKey(n, reusable, expiration)
|
||||
k, err := h.CreatePreAuthKey(n, reusable, ephemeral, expiration)
|
||||
if strings.HasPrefix(o, "json") {
|
||||
JsonOutput(k, err, o)
|
||||
return
|
||||
|
|
|
@ -17,6 +17,7 @@ var ServeCmd = &cobra.Command{
|
|||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
go h.ExpireEphemeralNodes(5000)
|
||||
err = h.Serve()
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/juanfont/headscale"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -37,12 +38,22 @@ func getHeadscaleApp() (*headscale.Headscale, error) {
|
|||
log.Printf("Could not load DERP servers map file: %s", err)
|
||||
}
|
||||
|
||||
// Minimum inactivity time out is keepalive timeout (60s) plus a few seconds
|
||||
// to avoid races
|
||||
minInactivityTimeout, _ := time.ParseDuration("65s")
|
||||
if viper.GetDuration("ephemeral_node_inactivity_timeout") <= minInactivityTimeout {
|
||||
err = fmt.Errorf("ephemeral_node_inactivity_timeout (%s) is set too low, must be more than %s\n", viper.GetString("ephemeral_node_inactivity_timeout"), minInactivityTimeout)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := headscale.Config{
|
||||
ServerURL: viper.GetString("server_url"),
|
||||
Addr: viper.GetString("listen_addr"),
|
||||
PrivateKeyPath: absPath(viper.GetString("private_key_path")),
|
||||
DerpMap: derpMap,
|
||||
|
||||
EphemeralNodeInactivityTimeout: viper.GetDuration("ephemeral_node_inactivity_timeout"),
|
||||
|
||||
DBtype: viper.GetString("db_type"),
|
||||
DBpath: absPath(viper.GetString("db_path")),
|
||||
DBhost: viper.GetString("db_host"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue