Skip to content

Commit e00c563

Browse files
authored
Merge pull request #2712 from dolthub/daylon/planbuilder-auth
Planbuilder Authorization
2 parents 2766041 + 263d9f2 commit e00c563

File tree

169 files changed

+900
-1339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+900
-1339
lines changed

enginetest/engine_only_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,10 +866,6 @@ func (s SimpleTableFunction) WithChildren(_ ...sql.Node) (sql.Node, error) {
866866
return s, nil
867867
}
868868

869-
func (s SimpleTableFunction) CheckPrivileges(_ *sql.Context, _ sql.PrivilegedOperationChecker) bool {
870-
return true
871-
}
872-
873869
// CollationCoercibility implements the interface sql.CollationCoercible.
874870
func (SimpleTableFunction) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
875871
return sql.Collation_binary, 7

enginetest/memory_engine_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,9 @@ func newMergableIndex(dbs []sql.Database, tableName string, exprs ...sql.Express
10281028
if db == nil {
10291029
return nil
10301030
}
1031+
if tableRevision, ok := table.(*memory.TableRevision); ok {
1032+
table = tableRevision.Table
1033+
}
10311034
return &memory.Index{
10321035
DB: db.Name(),
10331036
DriverName: memory.IndexDriverId,

enginetest/queries/priv_auth_queries.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,10 +1780,10 @@ var UserPrivTests = []UserPrivilegeTest{
17801780
},
17811781
},
17821782
{
1783-
User: "rand_user1",
1784-
Host: "54.244.85.252",
1785-
Query: "SELECT * FROM mydb.test;",
1786-
ExpectedErr: sql.ErrDatabaseAccessDeniedForUser,
1783+
User: "rand_user1",
1784+
Host: "54.244.85.252",
1785+
Query: "SELECT * FROM mydb.test;",
1786+
ExpectedErrStr: "Access denied for user 'rand_user1' (errno 1045) (sqlstate 28000)",
17871787
},
17881788
{
17891789
User: "rand_user2",
@@ -1804,10 +1804,10 @@ var UserPrivTests = []UserPrivilegeTest{
18041804
},
18051805
},
18061806
{
1807-
User: "rand_user2",
1808-
Host: "54.244.85.252",
1809-
Query: "SELECT * FROM mydb.test2;",
1810-
ExpectedErr: sql.ErrDatabaseAccessDeniedForUser,
1807+
User: "rand_user2",
1808+
Host: "54.244.85.252",
1809+
Query: "SELECT * FROM mydb.test2;",
1810+
ExpectedErrStr: "Access denied for user 'rand_user2' (errno 1045) (sqlstate 28000)",
18111811
},
18121812
},
18131813
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20241028204000-267861bc75a0
9+
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683
1010
github.com/go-kit/kit v0.10.0
1111
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1212
github.com/gocraft/dbr/v2 v2.7.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
5858
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
5959
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
6060
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
61-
github.com/dolthub/vitess v0.0.0-20241028204000-267861bc75a0 h1:eeKypNsi1nQmjWxSAAWT6tvRsDWdmll03BozAUUIE4E=
62-
github.com/dolthub/vitess v0.0.0-20241028204000-267861bc75a0/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
61+
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683 h1:2/RJeUfNAXS7mbBnEr9C36htiCJHk5XldDPzhxtEsME=
62+
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
6363
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
6464
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
6565
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

memory/exponential_dist_table.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ func (s ExponentialDistTable) WithChildren(_ ...sql.Node) (sql.Node, error) {
108108
return s, nil
109109
}
110110

111-
func (s ExponentialDistTable) CheckPrivileges(_ *sql.Context, _ sql.PrivilegedOperationChecker) bool {
112-
return true
113-
}
114-
115111
// CollationCoercibility implements the interface sql.CollationCoercible.
116112
func (ExponentialDistTable) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
117113
return sql.Collation_binary, 5

memory/normal_dist_table.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ func (s NormalDistTable) WithChildren(_ ...sql.Node) (sql.Node, error) {
119119
return s, nil
120120
}
121121

122-
func (s NormalDistTable) CheckPrivileges(_ *sql.Context, _ sql.PrivilegedOperationChecker) bool {
123-
return true
124-
}
125-
126122
// CollationCoercibility implements the interface sql.CollationCoercible.
127123
func (NormalDistTable) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
128124
return sql.Collation_binary, 5

memory/sequence_table.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ func (s IntSequenceTable) WithChildren(_ ...sql.Node) (sql.Node, error) {
101101
return s, nil
102102
}
103103

104-
func (s IntSequenceTable) CheckPrivileges(_ *sql.Context, _ sql.PrivilegedOperationChecker) bool {
105-
return true
106-
}
107-
108104
// CollationCoercibility implements the interface sql.CollationCoercible.
109105
func (IntSequenceTable) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
110106
return sql.Collation_binary, 5

memory/table_function.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ func (s TableFunc) WithChildren(_ ...sql.Node) (sql.Node, error) {
9191
return s, nil
9292
}
9393

94-
func (s TableFunc) CheckPrivileges(_ *sql.Context, _ sql.PrivilegedOperationChecker) bool {
95-
return true
96-
}
97-
9894
// CollationCoercibility implements the interface sql.CollationCoercible.
9995
func (TableFunc) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) {
10096
return sql.Collation_binary, 5

sql/analyzer/catalog.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Catalog struct {
3434
StatsProvider sql.StatsProvider
3535

3636
DbProvider sql.DatabaseProvider
37+
AuthHandler sql.AuthorizationHandler
3738
builtInFunctions function.Registry
3839

3940
// BinlogReplicaController holds an optional controller that receives forwarded binlog
@@ -64,14 +65,16 @@ type sessionLocks map[uint32]dbLocks
6465

6566
// NewCatalog returns a new empty Catalog with the given provider
6667
func NewCatalog(provider sql.DatabaseProvider) *Catalog {
67-
return &Catalog{
68+
c := &Catalog{
6869
MySQLDb: mysql_db.CreateEmptyMySQLDb(),
6970
InfoSchema: information_schema.NewInformationSchemaDatabase(),
7071
DbProvider: provider,
7172
builtInFunctions: function.NewRegistry(),
7273
StatsProvider: memory.NewStatsProv(),
7374
locks: make(sessionLocks),
7475
}
76+
c.AuthHandler = sql.GetAuthorizationHandlerFactory().CreateHandler(c)
77+
return c
7578
}
7679

7780
func (c *Catalog) HasBinlogReplicaController() bool {
@@ -109,7 +112,7 @@ func (c *Catalog) AllDatabases(ctx *sql.Context) []sql.Database {
109112
dbs = append(dbs, c.InfoSchema)
110113

111114
if c.MySQLDb.Enabled() {
112-
dbs = append(dbs, mysql_db.NewPrivilegedDatabaseProvider(c.MySQLDb, c.DbProvider).AllDatabases(ctx)...)
115+
dbs = append(dbs, mysql_db.NewPrivilegedDatabaseProvider(c.MySQLDb, c.DbProvider, c.AuthHandler).AllDatabases(ctx)...)
113116
} else {
114117
dbs = append(dbs, c.DbProvider.AllDatabases(ctx)...)
115118
}
@@ -162,7 +165,7 @@ func (c *Catalog) HasDatabase(ctx *sql.Context, db string) bool {
162165
if db == "information_schema" {
163166
return true
164167
} else if c.MySQLDb.Enabled() {
165-
return mysql_db.NewPrivilegedDatabaseProvider(c.MySQLDb, c.DbProvider).HasDatabase(ctx, db)
168+
return mysql_db.NewPrivilegedDatabaseProvider(c.MySQLDb, c.DbProvider, c.AuthHandler).HasDatabase(ctx, db)
166169
} else {
167170
return c.DbProvider.HasDatabase(ctx, db)
168171
}
@@ -173,7 +176,7 @@ func (c *Catalog) Database(ctx *sql.Context, db string) (sql.Database, error) {
173176
if strings.ToLower(db) == "information_schema" {
174177
return c.InfoSchema, nil
175178
} else if c.MySQLDb.Enabled() {
176-
return mysql_db.NewPrivilegedDatabaseProvider(c.MySQLDb, c.DbProvider).Database(ctx, db)
179+
return mysql_db.NewPrivilegedDatabaseProvider(c.MySQLDb, c.DbProvider, c.AuthHandler).Database(ctx, db)
177180
} else {
178181
return c.DbProvider.Database(ctx, db)
179182
}
@@ -440,6 +443,10 @@ func (c *Catalog) DataLength(ctx *sql.Context, db string, table sql.Table) (uint
440443
return st.DataLength(ctx)
441444
}
442445

446+
func (c *Catalog) AuthorizationHandler() sql.AuthorizationHandler {
447+
return c.AuthHandler
448+
}
449+
443450
func getStatisticsTable(table sql.Table, prevTable sql.Table) (sql.StatisticsTable, bool) {
444451
// Some TableNodes return themselves for UnderlyingTable, so we need to check for that
445452
if table == prevTable {

0 commit comments

Comments
 (0)