Skip to content

Commit

Permalink
Don't exit tablet server on reloading invalid ACL
Browse files Browse the repository at this point in the history
This fixes potentially bringing down a tablet with an innocuous SIGHUP.

It also logs the fact it's reading the ACL file, to fix not getting any
feedback on SIGHUP.

#17139

Signed-off-by: Wiebe Cazemier <[email protected]>
  • Loading branch information
wiebeytec committed Jan 9, 2025
1 parent 6ac8998 commit 2c30527
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions go/vt/tableacl/tableacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error {
}
data, err := os.ReadFile(configFile)
if err != nil {
log.Infof("unable to read tableACL config file: %v Error: %v", configFile, err)
log.Errorf("unable to read tableACL config file: %v Error: %v", configFile, err)
return err
}
config := &tableaclpb.Config{}
if err := config.UnmarshalVT(data); err != nil {
// try to parse tableacl as json file
if jsonErr := json2.UnmarshalPB(data, config); jsonErr != nil {
log.Infof("unable to parse tableACL config file as a protobuf or json file. protobuf err: %v json err: %v", err, jsonErr)
log.Errorf("unable to parse tableACL config file as a protobuf or json file. protobuf err: %v json err: %v", err, jsonErr)
return fmt.Errorf("unable to unmarshal Table ACL data: %s", data)
}
}
Expand Down
18 changes: 11 additions & 7 deletions go/vt/vttablet/tabletserver/tabletserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (tsv *TabletServer) SetQueryRules(ruleSource string, qrs *rules.Rules) erro
return nil
}

func (tsv *TabletServer) initACL(tableACLConfigFile string, enforceTableACLConfig bool) {
func (tsv *TabletServer) initACL(tableACLConfigFile string) error {
// tabletacl.Init loads ACL from file if *tableACLConfig is not empty
err := tableacl.Init(
tableACLConfigFile,
Expand All @@ -369,21 +369,25 @@ func (tsv *TabletServer) initACL(tableACLConfigFile string, enforceTableACLConfi
)
if err != nil {
log.Errorf("Fail to initialize Table ACL: %v", err)
if enforceTableACLConfig {
log.Exit("Need a valid initial Table ACL when enforce-tableacl-config is set, exiting.")
}
}

return err
}

// InitACL loads the table ACL and sets up a SIGHUP handler for reloading it.
func (tsv *TabletServer) InitACL(tableACLConfigFile string, enforceTableACLConfig bool, reloadACLConfigFileInterval time.Duration) {
tsv.initACL(tableACLConfigFile, enforceTableACLConfig)
err := tsv.initACL(tableACLConfigFile)

if enforceTableACLConfig && err != nil {
log.Exit("Need a valid initial Table ACL when enforce-tableacl-config is set, exiting.")
}

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGHUP)
go func() {
for range sigChan {
tsv.initACL(tableACLConfigFile, enforceTableACLConfig)
for sig := range sigChan {
log.Infof("Signal '%v' received, reloading ACL", sig)
tsv.initACL(tableACLConfigFile)
}
}()

Expand Down

0 comments on commit 2c30527

Please sign in to comment.