Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail loading an ACL config if the provided file is empty and enforceTableACLConfig is true #17274

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go/vt/tableacl/tableacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 errors.New("tableACL config file is empty")
}

config := &tableaclpb.Config{}
if err := config.UnmarshalVT(data); err != nil {
// try to parse tableacl as json file
Expand Down
15 changes: 15 additions & 0 deletions go/vt/tableacl/tableacl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ func TestInitWithValidConfig(t *testing.T) {
}
}

func TestInitWithEmptyConfig(t *testing.T) {
tacl := tableACL{factory: &simpleacl.Factory{}}
f, err := os.CreateTemp("", "tableacl")
if err != nil {
t.Fatal(err)
}
defer os.Remove(f.Name())
if err := f.Close(); err != nil {
t.Fatal(err)
}
if err := tacl.init(f.Name(), func() {}); err == nil {
t.Fatal("tableACL config file is empty")
}
}

func TestInitFromProto(t *testing.T) {
tacl := tableACL{factory: &simpleacl.Factory{}}
readerACL := tacl.Authorized("my_test_table", READER)
Expand Down
1 change: 1 addition & 0 deletions go/vt/vttablet/tabletserver/tabletserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func (tsv *TabletServer) initACL(tableACLConfigFile string, enforceTableACLConfi
tsv.ClearQueryPlanCache()
},
)
// Log failure if either there was a problem loading the ACL, or if the ACL is empty
if err != nil {
log.Errorf("Fail to initialize Table ACL: %v", err)
if enforceTableACLConfig {
Expand Down
Loading