Make populating garage ports optional

This commit is contained in:
Brian Picciano 2022-10-26 21:47:39 +02:00
parent 6ef21ff186
commit 2200d85992
4 changed files with 60 additions and 31 deletions

View File

@ -66,11 +66,18 @@ storage:
# #
# The ports are all required and must all be unique within and across # The ports are all required and must all be unique within and across
# allocations. # allocations.
#
# THe ports are all _optional_, and will be automatically assigned if they are
# not specified. If ports any ports are specified then all should be
# specified, and each should be unique across all allocations.
#
# Once assigned (either implicitly or explicitly) the rpc_port of an
# allocation should not be changed.
allocations: allocations:
#- data_path: /foo/bar/data #- data_path: /foo/bar/data
# meta_path: /foo/bar/meta # meta_path: /foo/bar/meta
# capacity: 1200 # capacity: 1200
# s3_api_port: 3900 # #s3_api_port: 3900
# rpc_port: 3901 # #rpc_port: 3901
# admin_port: 3902 # #admin_port: 3902

View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"net" "net"
"path/filepath" "path/filepath"
"strconv"
"code.betamike.com/cryptic-io/pmux/pmuxlib" "code.betamike.com/cryptic-io/pmux/pmuxlib"
) )
@ -36,6 +35,8 @@ func waitForNebula(ctx context.Context, env crypticnet.Env) error {
func nebulaPmuxProcConfig(env crypticnet.Env) (pmuxlib.ProcessConfig, error) { func nebulaPmuxProcConfig(env crypticnet.Env) (pmuxlib.ProcessConfig, error) {
thisDaemon := env.ThisDaemon()
var ( var (
lighthouseHostIPs []string lighthouseHostIPs []string
staticHostMap = map[string][]string{} staticHostMap = map[string][]string{}
@ -63,8 +64,9 @@ func nebulaPmuxProcConfig(env crypticnet.Env) (pmuxlib.ProcessConfig, error) {
"respond": true, "respond": true,
}, },
"tun": map[string]interface{}{ "tun": map[string]interface{}{
"dev": "cryptic-nebula1", "dev": "cryptic-net-nebula",
}, },
"firewall": thisDaemon.VPN.Firewall,
} }
if publicAddr := env.ThisDaemon().VPN.PublicAddr; publicAddr == "" { if publicAddr := env.ThisDaemon().VPN.PublicAddr; publicAddr == "" {
@ -97,32 +99,6 @@ func nebulaPmuxProcConfig(env crypticnet.Env) (pmuxlib.ProcessConfig, error) {
} }
} }
thisDaemon := env.ThisDaemon()
var firewallInbound []crypticnet.ConfigFirewallRule
for _, alloc := range thisDaemon.Storage.Allocations {
firewallInbound = append(
firewallInbound,
crypticnet.ConfigFirewallRule{
Port: strconv.Itoa(alloc.S3APIPort),
Proto: "tcp",
Host: "any",
},
crypticnet.ConfigFirewallRule{
Port: strconv.Itoa(alloc.RPCPort),
Proto: "tcp",
Host: "any",
},
)
}
firewall := thisDaemon.VPN.Firewall
firewall.Inbound = append(firewallInbound, firewall.Inbound...)
config["firewall"] = firewall
nebulaYmlPath := filepath.Join(env.RuntimeDirPath, "nebula.yml") nebulaYmlPath := filepath.Join(env.RuntimeDirPath, "nebula.yml")
if err := yamlutil.WriteYamlFile(config, nebulaYmlPath); err != nil { if err := yamlutil.WriteYamlFile(config, nebulaYmlPath); err != nil {

View File

@ -1,5 +1,7 @@
package crypticnet package crypticnet
import "strconv"
type ConfigFirewall struct { type ConfigFirewall struct {
Conntrack ConfigConntrack `yaml:"conntrack"` Conntrack ConfigConntrack `yaml:"conntrack"`
Outbound []ConfigFirewallRule `yaml:"outbound"` Outbound []ConfigFirewallRule `yaml:"outbound"`
@ -49,3 +51,45 @@ type DaemonYml struct {
Allocations []DaemonYmlStorageAllocation Allocations []DaemonYmlStorageAllocation
} `yaml:"storage"` } `yaml:"storage"`
} }
// FillDefaults fills in default values in the DaemonYml.
func (d *DaemonYml) FillDefaults() {
var firewallGarageInbound []ConfigFirewallRule
for i := range d.Storage.Allocations {
if d.Storage.Allocations[i].RPCPort == 0 {
d.Storage.Allocations[i].RPCPort = 3900 + (i * 10)
}
if d.Storage.Allocations[i].S3APIPort == 0 {
d.Storage.Allocations[i].S3APIPort = 3901 + (i * 10)
}
if d.Storage.Allocations[i].AdminPort == 0 {
d.Storage.Allocations[i].AdminPort = 3902 + (i * 10)
}
alloc := d.Storage.Allocations[i]
firewallGarageInbound = append(
firewallGarageInbound,
ConfigFirewallRule{
Port: strconv.Itoa(alloc.S3APIPort),
Proto: "tcp",
Host: "any",
},
ConfigFirewallRule{
Port: strconv.Itoa(alloc.RPCPort),
Proto: "tcp",
Host: "any",
},
)
}
d.VPN.Firewall.Inbound = append(
d.VPN.Firewall.Inbound,
firewallGarageInbound...,
)
}

View File

@ -215,6 +215,8 @@ func (e Env) ThisDaemon() DaemonYml {
if err := yamlutil.LoadYamlFile(&e.thisDaemon, e.DaemonYmlPath); err != nil { if err := yamlutil.LoadYamlFile(&e.thisDaemon, e.DaemonYmlPath); err != nil {
panic(err) panic(err)
} }
e.thisDaemon.FillDefaults()
}) })
return e.thisDaemon return e.thisDaemon
} }