mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
logpolicy: fix config initialization bug (#5010)
If ConfigFromFile cannot find the configuration file, we must not initialize it with NewConfig. Instead, we need it to fail validation so that it eventually writes a newly constructed configuration file. Otherwise, new tailscale instances will never be able store a persistent log config and start with a new config file upon every bootup. Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
d6817d0f22
commit
fe3426b4c7
@ -112,6 +112,8 @@ func NewConfig(collection string) *Config {
|
|||||||
// and that the PrivateID and PublicID pair are sensible.
|
// and that the PrivateID and PublicID pair are sensible.
|
||||||
func (c *Config) Validate(collection string) error {
|
func (c *Config) Validate(collection string) error {
|
||||||
switch {
|
switch {
|
||||||
|
case c == nil:
|
||||||
|
return errors.New("config is nil")
|
||||||
case c.Collection != collection:
|
case c.Collection != collection:
|
||||||
return fmt.Errorf("config collection %q does not match %q", c.Collection, collection)
|
return fmt.Errorf("config collection %q does not match %q", c.Collection, collection)
|
||||||
case c.PrivateID.IsZero():
|
case c.PrivateID.IsZero():
|
||||||
@ -509,11 +511,10 @@ func New(collection string) *Policy {
|
|||||||
newc, err := ConfigFromFile(cfgPath)
|
newc, err := ConfigFromFile(cfgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
earlyLogf("logpolicy.ConfigFromFile %v: %v", cfgPath, err)
|
earlyLogf("logpolicy.ConfigFromFile %v: %v", cfgPath, err)
|
||||||
newc = NewConfig(collection)
|
|
||||||
}
|
}
|
||||||
if err := newc.Validate(collection); err != nil {
|
if err := newc.Validate(collection); err != nil {
|
||||||
earlyLogf("logpolicy.Config.Validate for %q: %v", cfgPath, err)
|
earlyLogf("logpolicy.Config.Validate for %v: %v", cfgPath, err)
|
||||||
newc := NewConfig(collection)
|
newc = NewConfig(collection)
|
||||||
if err := newc.Save(cfgPath); err != nil {
|
if err := newc.Save(cfgPath); err != nil {
|
||||||
earlyLogf("logpolicy.Config.Save for %v: %v", cfgPath, err)
|
earlyLogf("logpolicy.Config.Save for %v: %v", cfgPath, err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user