From eca5d61c0e2157c18d969df6799be1d00396451c Mon Sep 17 00:00:00 2001 From: garfthoffman <109185460+garfthoffman@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:05:58 +0000 Subject: [PATCH] validate instead that file data is not empty Signed-off-by: garfthoffman <109185460+garfthoffman@users.noreply.github.com> --- go/vt/tableacl/tableacl.go | 10 +++++++--- go/vt/vttablet/tabletserver/tabletserver.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/go/vt/tableacl/tableacl.go b/go/vt/tableacl/tableacl.go index 1b236cb1812..d68a0642ef0 100644 --- a/go/vt/tableacl/tableacl.go +++ b/go/vt/tableacl/tableacl.go @@ -96,11 +96,11 @@ var currentTableACL tableACL // } // ] // } -func Init(configFile string, aclCB func()) error { - return currentTableACL.init(configFile, aclCB) +func Init(configFile string, aclCB func(), enforceTableACLConfig string) error { + return currentTableACL.init(configFile, aclCB, enforceTableACLConfig string) } -func (tacl *tableACL) init(configFile string, aclCB func()) error { +func (tacl *tableACL) init(configFile string, aclCB func(), enforceTableACLConfig string) error { tacl.SetCallback(aclCB) if configFile == "" { return nil @@ -110,6 +110,10 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error { log.Infof("unable to read tableACL config file: %v Error: %v", configFile, err) return err } + if len(data) == 0 { + return error.New("tableACL config file is empty") + } + config := &tableaclpb.Config{} if err := config.UnmarshalVT(data); err != nil { // try to parse tableacl as json file diff --git a/go/vt/vttablet/tabletserver/tabletserver.go b/go/vt/vttablet/tabletserver/tabletserver.go index 7d00c85704c..8fb167efc80 100644 --- a/go/vt/vttablet/tabletserver/tabletserver.go +++ b/go/vt/vttablet/tabletserver/tabletserver.go @@ -368,7 +368,7 @@ func (tsv *TabletServer) initACL(tableACLConfigFile string, enforceTableACLConfi }, ) // Log failure if either there was a problem loading the ACL, or if the ACL is empty - if err != nil || tableacl.GetCurrentConfig().String() == "" { + 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.")