Skip to content

Commit c579850

Browse files
authored
Add flag to decrypt the configuration (#307)
1 parent f68b9c7 commit c579850

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

beehive.go

+39
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
package main
2525

2626
import (
27+
"encoding/json"
2728
"fmt"
29+
"net/url"
2830
"os"
2931
"os/signal"
3032
"syscall"
@@ -45,6 +47,7 @@ var (
4547
configURL string
4648
versionFlag bool
4749
debugFlag bool
50+
decryptFlag bool
4851
)
4952

5053
func main() {
@@ -67,6 +70,12 @@ func main() {
6770
Value: false,
6871
Desc: "Turn on debugging",
6972
},
73+
{
74+
V: &decryptFlag,
75+
Name: "decrypt",
76+
Value: false,
77+
Desc: "Decrypt and print the configuration file",
78+
},
7079
})
7180

7281
// Parse command-line args for all registered bees
@@ -77,6 +86,10 @@ func main() {
7786
os.Exit(0)
7887
}
7988

89+
if decryptFlag {
90+
decryptConfig(configURL)
91+
}
92+
8093
api.Run()
8194

8295
if debugFlag {
@@ -164,6 +177,32 @@ func main() {
164177
}
165178
}
166179

180+
func decryptConfig(u string) {
181+
b := cfg.AESBackend{}
182+
183+
pu, err := url.Parse(u)
184+
if err != nil {
185+
log.Fatal("Invalid configuration URL. err: ", err)
186+
}
187+
188+
_, err = os.Stat(pu.Path)
189+
if err != nil {
190+
log.Fatalf("Invalid configuration file %s", pu.Path)
191+
}
192+
193+
config, err := b.Load(pu)
194+
if err != nil {
195+
log.Fatal("Error decrypting the configuration file. err: ", err)
196+
}
197+
198+
j, err := json.MarshalIndent(config, "", " ")
199+
if err != nil {
200+
log.Fatal("Error encoding the configuraiton file. err: ", err)
201+
}
202+
fmt.Println(string(j))
203+
os.Exit(0)
204+
}
205+
167206
func init() {
168207
log.SetFormatter(&log.TextFormatter{ForceColors: true})
169208
log.SetOutput(colorable.NewColorableStdout())

docs/config_encryption.md

+20
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ A sample wrapper script (Linux only) is provided in [tools/encrypted-config-wrap
3333

3434
Something similar could be written to do it on macOS using Keychain and its `security(1)` CLI.
3535

36+
## Decrypting the configuration
37+
38+
Use `--decrypt` with a valid password:
39+
40+
```
41+
beehive --decrypt --config crypto://mysecret@/path/to/config/file
42+
```
43+
44+
or using an environment variable:
45+
46+
```
47+
BEEHIVE_CONFIG_PASSWORD=mysecret beehive --decrypt --config crypto:///path/to/config/file
48+
```
49+
50+
You can also use omit `--config` when using the default configuration path:
51+
52+
```
53+
BEEHIVE_CONFIG_PASSWORD=mysecret beehive --decrypt
54+
```
55+
3656
## Troubleshooting
3757

3858
```

watchdog_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ func init() {
2222
// returns the configured WatchdogSec in the service unit as time.Duration
2323
interval, err := daemon.SdWatchdogEnabled(false)
2424
if err != nil || interval == 0 {
25-
log.Printf("Systemd watchdog not enabled")
25+
log.Debug("Systemd watchdog not enabled")
2626
return
2727
}
2828

2929
// We want to notify the watchdog every WatchdogSec/3, that is, if WatchdogSec is
3030
// set to 30 seconds, we'll send a notification to systemd every 10 seconds.
3131
runEvery := interval / 3
32-
log.Printf("Systemd watchdog notifications every %.2f seconds", runEvery.Seconds())
32+
log.Debugf("Systemd watchdog notifications every %.2f seconds", runEvery.Seconds())
3333

3434
go func() {
3535
for {

0 commit comments

Comments
 (0)