From 126e694f26f763f38090eecc228ee16125618e14 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 28 Jan 2022 18:08:52 +0000 Subject: [PATCH 1/2] Add generate private-key command This commit adds a command to generate a private key for headscale. Mostly useful for systems were you drive the deployment from another machine and use a secret management system. --- cmd/headscale/cli/generate.go | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 cmd/headscale/cli/generate.go diff --git a/cmd/headscale/cli/generate.go b/cmd/headscale/cli/generate.go new file mode 100644 index 00000000..24844146 --- /dev/null +++ b/cmd/headscale/cli/generate.go @@ -0,0 +1,41 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + "tailscale.com/types/key" +) + +func init() { + rootCmd.AddCommand(generateCmd) + generateCmd.AddCommand(generatePrivateKeyCmd) +} + +var generateCmd = &cobra.Command{ + Use: "generate", + Short: "Generate commands", +} + +var generatePrivateKeyCmd = &cobra.Command{ + Use: "private-key", + Short: "Generate a private key for the headscale server", + Run: func(cmd *cobra.Command, args []string) { + output, _ := cmd.Flags().GetString("output") + machineKey := key.NewMachine() + + machineKeyStr, err := machineKey.MarshalText() + if err != nil { + ErrorOutput( + err, + fmt.Sprintf("Error getting machine key from flag: %s", err), + output, + ) + } + + SuccessOutput(map[string]string{ + "private_key": string(machineKeyStr), + }, + string(machineKeyStr), output) + }, +} From 7aace7eb6b0bf933e785ddfd2e99afc6a7761b7e Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sat, 29 Jan 2022 14:33:12 +0000 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38904b0a..99f4849a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ **TBD (TBD):** +**Changes**: + +- Add new command to generate a private key for `headscale` [#290](https://github.com/juanfont/headscale/pull/290) + **0.12.3 (2022-01-13):** **Changes**: