Skip to content

Commit f46596a

Browse files
Fail loading an ACL config if the provided file is empty and enforceTableACLConfig is true (vitessio#17274) (#173)
Signed-off-by: garfthoffman <[email protected]> Signed-off-by: Mohamed Hamza <[email protected]> Co-authored-by: garfthoffman <[email protected]>
1 parent 8bb6c73 commit f46596a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

go/vt/tableacl/tableacl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error {
110110
log.Infof("unable to read tableACL config file: %v Error: %v", configFile, err)
111111
return err
112112
}
113+
if len(data) == 0 {
114+
return errors.New("tableACL config file is empty")
115+
}
116+
113117
config := &tableaclpb.Config{}
114118
if err := config.UnmarshalVT(data); err != nil {
115119
// try to parse tableacl as json file

go/vt/tableacl/tableacl_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"reflect"
2424
"testing"
2525

26+
"github.com/stretchr/testify/require"
2627
"google.golang.org/protobuf/proto"
2728

2829
"vitess.io/vitess/go/vt/tableacl/acl"
@@ -74,6 +75,19 @@ func TestInitWithValidConfig(t *testing.T) {
7475
}
7576
}
7677

78+
func TestInitWithEmptyConfig(t *testing.T) {
79+
tacl := tableACL{factory: &simpleacl.Factory{}}
80+
f, err := os.CreateTemp("", "tableacl")
81+
require.NoError(t, err)
82+
83+
defer os.Remove(f.Name())
84+
err = f.Close()
85+
require.NoError(t, err)
86+
87+
err = tacl.init(f.Name(), func() {})
88+
require.Error(t, err)
89+
}
90+
7791
func TestInitFromProto(t *testing.T) {
7892
tacl := tableACL{factory: &simpleacl.Factory{}}
7993
readerACL := tacl.Authorized("my_test_table", READER)

0 commit comments

Comments
 (0)