Skip to content

Commit 3902eda

Browse files
authored
Merge pull request #2068 from dolthub/elian/7628c
Fix Doltgres and Dolt authentication and system table compatibility
2 parents d1dacfe + 95e7544 commit 3902eda

26 files changed

Lines changed: 859 additions & 214 deletions

.github/workflows/ci-postgres-client-tests.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@ jobs:
1111
timeout-minutes: 45
1212
name: Run tests
1313
steps:
14+
- name: Free disk space
15+
run: |
16+
NAME="DISK-CLEANUP"
17+
echo "[${NAME}] Starting background cleanup..."
18+
[ -d "$AGENT_TOOLSDIRECTORY" ] && sudo rm -rf "$AGENT_TOOLSDIRECTORY" &
19+
[ -d /usr/share/dotnet ] && sudo rm -rf /usr/share/dotnet &
20+
[ -d /usr/local/lib/android ] && sudo rm -rf /usr/local/lib/android &
21+
[ -d /opt/ghc ] && sudo rm -rf /opt/ghc &
22+
[ -d /usr/local/share/boost ] && sudo rm -rf /usr/local/share/boost &
1423
- name: Checkout
1524
uses: actions/checkout@v4
16-
- name: Build docker image
25+
- name: Set up Docker
26+
uses: docker/setup-docker-action@v4
27+
- name: Build Docker image
1728
run: docker build -t postgres-client-tests --file testing/PostgresDockerfile .
1829
- name: Run tests
1930
run: docker run --detach=false postgres-client-tests

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20251121014835-d565cf29551c
9+
github.com/dolthub/dolt/go v0.40.5-0.20251209113019-d956afb08a95
1010
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca
1111
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
12-
github.com/dolthub/go-mysql-server v0.20.1-0.20251119215901-006ebc8e42ce
12+
github.com/dolthub/go-mysql-server v0.20.1-0.20251202232204-0b1008f3c7d9
1313
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
14-
github.com/dolthub/vitess v0.0.0-20251107003339-843d10a6a8d4
14+
github.com/dolthub/vitess v0.0.0-20251124192614-8039a9881a64
1515
github.com/fatih/color v1.13.0
1616
github.com/goccy/go-json v0.10.2
1717
github.com/gogo/protobuf v1.3.2

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 h1:I
228228
github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12/go.mod h1:rN7X8BHwkjPcfMQQ2QTAq/xM3leUSGLfb+1Js7Y6TVo=
229229
github.com/dolthub/dolt-mcp v0.2.2 h1:bpROmam74n95uU4EA3BpOIVlTDT0pzeFMBwe/YRq2mI=
230230
github.com/dolthub/dolt-mcp v0.2.2/go.mod h1:S++DJ4QWTAXq+0TNzFa7Oq3IhoT456DJHwAINFAHgDQ=
231-
github.com/dolthub/dolt/go v0.40.5-0.20251121014835-d565cf29551c h1:PNP5m1xY6UpasP8+5OpB3uemIg8paXDWd/NhHksP1sY=
232-
github.com/dolthub/dolt/go v0.40.5-0.20251121014835-d565cf29551c/go.mod h1:xQXjH8tvqvSozkiCMSigudpPnNHVA9cHIRmWTXX2hDo=
231+
github.com/dolthub/dolt/go v0.40.5-0.20251209113019-d956afb08a95 h1:Mw0uCDss/B9cfqCQ7rGq6pv6hSg3N0BToqaS59wW9z0=
232+
github.com/dolthub/dolt/go v0.40.5-0.20251209113019-d956afb08a95/go.mod h1:m1iGy0r1OfkYJ0JibA6yIuz2lKhmZauzN4rIlAyMGog=
233233
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca h1:BGFz/0OlKIuC6qHIZQbvPapFvdAJkeEyGXWVgL5clmE=
234234
github.com/dolthub/eventsapi_schema v0.0.0-20250915094920-eadfd39051ca/go.mod h1:CoDLfgPqHyBtth0Cp+fi/CmC4R81zJNX4wPjShdZ+Bw=
235235
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
@@ -238,8 +238,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
238238
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
239239
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790 h1:zxMsH7RLiG+dlZ/y0LgJHTV26XoiSJcuWq+em6t6VVc=
240240
github.com/dolthub/go-icu-regex v0.0.0-20250916051405-78a38d478790/go.mod h1:F3cnm+vMRK1HaU6+rNqQrOCyR03HHhR1GWG2gnPOqaE=
241-
github.com/dolthub/go-mysql-server v0.20.1-0.20251119215901-006ebc8e42ce h1:qX7/WqsatVUMhULZxad8hNYUDE/gXlZrpBQDi3PBe5k=
242-
github.com/dolthub/go-mysql-server v0.20.1-0.20251119215901-006ebc8e42ce/go.mod h1:HTOKSMPJWcbSgCe1DksDgNPlZyZP1usV+EoA7Utax+A=
241+
github.com/dolthub/go-mysql-server v0.20.1-0.20251202232204-0b1008f3c7d9 h1:jw7LJ/UUyH6ptW5c6pPeKMMquOtZpwyjyQgMCCB4FIA=
242+
github.com/dolthub/go-mysql-server v0.20.1-0.20251202232204-0b1008f3c7d9/go.mod h1:pD0T+xZWBDO5yxHAY9FUqArKvhvw6KYqxRmEk3NfQNw=
243243
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
244244
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
245245
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
@@ -250,8 +250,8 @@ github.com/dolthub/pg_query_go/v6 v6.0.0-20250702135351-29eb6bfc4ea6 h1:UEX3FGaC
250250
github.com/dolthub/pg_query_go/v6 v6.0.0-20250702135351-29eb6bfc4ea6/go.mod h1:nvTHIuoud6e1SfrUaFwHqT0i4b5Nr+1rPWVds3B5+50=
251251
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4EHUcEVQCMRBej8DYxjYjRz/9MdF/NNQh0o70=
252252
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
253-
github.com/dolthub/vitess v0.0.0-20251107003339-843d10a6a8d4 h1:vOF5qPLC0Yd4BN/FKJlRLNELIZZlev40TrckORQqzhA=
254-
github.com/dolthub/vitess v0.0.0-20251107003339-843d10a6a8d4/go.mod h1:FLWqdXsAeeBQyFwDjmBVu0GnbjI2MKeRf3tRVdJEKlI=
253+
github.com/dolthub/vitess v0.0.0-20251124192614-8039a9881a64 h1:E3IfAYxrZ+dXgBHXN9L1ucotg3J8YDCeDr47u78tUI4=
254+
github.com/dolthub/vitess v0.0.0-20251124192614-8039a9881a64/go.mod h1:FLWqdXsAeeBQyFwDjmBVu0GnbjI2MKeRf3tRVdJEKlI=
255255
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
256256
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
257257
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=

server/functions/dolt_procedures.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ import (
2727
"github.com/dolthub/go-mysql-server/sql/plan"
2828
"github.com/dolthub/go-mysql-server/sql/types"
2929

30+
"github.com/dolthub/doltgresql/server/auth"
3031
"github.com/dolthub/doltgresql/server/functions/framework"
3132
pgtypes "github.com/dolthub/doltgresql/server/types"
3233
)
3334

35+
var (
36+
ErrDoltProcedurePermissionDenied = errors.New("permission denied for Dolt procedure")
37+
ErrDoltProcedureSelectOnly = errors.New("Dolt stored procedure may only be invoked using SELECT")
38+
)
39+
3440
func initDoltProcedures() {
3541
for _, procDef := range dprocedures.DoltProcedures {
3642
p, err := resolveExternalStoredProcedure(nil, procDef)
@@ -40,8 +46,7 @@ func initDoltProcedures() {
4046

4147
funcVal := reflect.ValueOf(procDef.Function)
4248
varArgCallable := varArgCallableForDoltProcedure(p, funcVal)
43-
noArgCallable := noArgCallableForDoltProcedure(funcVal)
44-
49+
noArgCallable := noArgCallableForDoltProcedure(p, funcVal)
4550
framework.RegisterFunction(framework.Function1{
4651
Name: procDef.Name,
4752
Return: pgtypes.TextArray,
@@ -63,6 +68,11 @@ func varArgCallableForDoltProcedure(p *plan.ExternalProcedure, funcVal reflect.V
6368
funcType := funcVal.Type()
6469

6570
return func(ctx *sql.Context, paramsAndReturn [2]*pgtypes.DoltgresType, val1 any) (any, error) {
71+
err := checkDoltProcedureAccess(ctx, p)
72+
if err != nil {
73+
return nil, err
74+
}
75+
6676
values, ok := val1.([]any)
6777
if !ok {
6878
return nil, sql.ErrExternalProcedureInvalidParamType.New(reflect.TypeOf(val1).String())
@@ -111,8 +121,13 @@ func varArgCallableForDoltProcedure(p *plan.ExternalProcedure, funcVal reflect.V
111121

112122
// noArgCallableForDoltProcedure creates a callable function that does not take any parameters. This is equivalent to
113123
// calling "DOLT_PROC_NAME()".
114-
func noArgCallableForDoltProcedure(funcVal reflect.Value) func(ctx *sql.Context) (any, error) {
124+
func noArgCallableForDoltProcedure(p *plan.ExternalProcedure, funcVal reflect.Value) func(ctx *sql.Context) (any, error) {
115125
return func(ctx *sql.Context) (any, error) {
126+
err := checkDoltProcedureAccess(ctx, p)
127+
if err != nil {
128+
return nil, err
129+
}
130+
116131
funcParams := []reflect.Value{reflect.ValueOf(ctx)}
117132
out := funcVal.Call(funcParams)
118133
if err, ok := out[1].Interface().(error); ok { // Only evaluates to true when error is not nil
@@ -129,6 +144,25 @@ func noArgCallableForDoltProcedure(funcVal reflect.Value) func(ctx *sql.Context)
129144
}
130145
}
131146

147+
// checkDoltProcedureAccess ensures the current user is authorized as a SUPERUSER if the given |procedure| requires
148+
// admin.
149+
func checkDoltProcedureAccess(ctx *sql.Context, procedure *plan.ExternalProcedure) error {
150+
if !procedure.AdminOnly {
151+
return nil
152+
}
153+
154+
var userRole auth.Role
155+
auth.LockRead(func() {
156+
userRole = auth.GetRole(ctx.Client().User)
157+
})
158+
159+
if !userRole.IsValid() || !userRole.IsSuperUser {
160+
return ErrDoltProcedurePermissionDenied
161+
}
162+
163+
return nil
164+
}
165+
132166
func drainRowIter(ctx *sql.Context, rowIter sql.RowIter) (any, error) {
133167
defer rowIter.Close(ctx)
134168

server/initialization/initialization.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/dolthub/doltgresql/server/functions/framework"
3535
"github.com/dolthub/doltgresql/server/functions/unary"
3636
"github.com/dolthub/doltgresql/server/tables"
37-
"github.com/dolthub/doltgresql/server/tables/dprocedures"
3837
"github.com/dolthub/doltgresql/server/tables/dtables"
3938
"github.com/dolthub/doltgresql/server/tables/information_schema"
4039
"github.com/dolthub/doltgresql/server/tables/pgcatalog"
@@ -64,6 +63,5 @@ func Initialize(dEnv *env.DoltEnv) {
6463
pgcatalog.Init()
6564
information_schema.Init()
6665
dtables.Init()
67-
dprocedures.Init()
6866
})
6967
}

server/node/call.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package node
1616

1717
import (
18+
"strings"
19+
1820
"github.com/cockroachdb/errors"
1921
"github.com/dolthub/go-mysql-server/sql"
2022
"github.com/dolthub/go-mysql-server/sql/plan"
@@ -24,6 +26,7 @@ import (
2426
"github.com/dolthub/doltgresql/core/extensions"
2527
"github.com/dolthub/doltgresql/core/id"
2628
pgexprs "github.com/dolthub/doltgresql/server/expression"
29+
"github.com/dolthub/doltgresql/server/functions"
2730
"github.com/dolthub/doltgresql/server/functions/framework"
2831
pgtypes "github.com/dolthub/doltgresql/server/types"
2932
)
@@ -98,16 +101,10 @@ func (c *Call) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) {
98101
return nil, err
99102
}
100103
if len(overloads) == 0 {
101-
// We're going to assume that this is calling one of the few remaining Dolt stored procedures
102-
sch, rowIter, _, err := c.Runner.Runner.QueryWithBindings(ctx, "", &vitess.Call{
103-
ProcName: vitess.ProcedureName{
104-
Name: vitess.NewColIdent(c.ProcedureName),
105-
Qualifier: vitess.NewTableIdent(c.SchemaName),
106-
},
107-
Params: c.originalExprs,
108-
}, nil, nil)
109-
c.cachedSch = sch
110-
return rowIter, err
104+
if strings.HasPrefix(c.ProcedureName, "dolt_") {
105+
return nil, functions.ErrDoltProcedureSelectOnly
106+
}
107+
return nil, sql.ErrStoredProcedureDoesNotExist.New(c.ProcedureName)
111108
}
112109

113110
overloadTree := framework.NewOverloads()

server/tables/dprocedures/init.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

server/tables/dtables/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ import (
1818
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
1919
"github.com/dolthub/dolt/go/libraries/doltcore/merge"
2020
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
21+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/adapters"
2122
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dprocedures"
2223
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
2324
)
2425

2526
// Init handles initialization of all Postgres-specific and Doltgres-specific Dolt system tables.
2627
func Init() {
28+
adapters.DoltTableAdapterRegistry.AddAdapter(doltdb.StatusTableName, DoltgresDoltStatusTableAdapter{}, DoltgresDoltStatusTableName)
29+
2730
// Table names
2831
doltdb.GetBranchesTableName = getBranchesTableName
2932
doltdb.GetDocTableName = getDocTableName
@@ -37,7 +40,6 @@ func Init() {
3740
doltdb.GetRemoteBranchesTableName = getRemoteBranchesTableName
3841
doltdb.GetRemotesTableName = getRemotesTableName
3942
doltdb.GetSchemaConflictsTableName = getSchemaConflictsTableName
40-
doltdb.GetStatusTableName = getStatusTableName
4143
doltdb.GetTableOfTablesInConflictName = getTableOfTablesInConflictName
4244
doltdb.GetTableOfTablesWithViolationsName = getTableOfTablesWithViolationsName
4345
doltdb.GetTagsTableName = getTagsTableName
@@ -48,7 +50,6 @@ func Init() {
4850
dtables.GetDoltIgnoreSchema = getDoltIgnoreSchema
4951
dtables.GetDoltMergeStatusSchema = getDoltMergeStatusSchema
5052
dprocedures.GetDoltRebaseSystemTableSchema = getRebaseSchema
51-
dtables.GetDoltStatusSchema = getDoltStatusSchema
5253
dtables.GetUnscopedDoltDiffSchema = getUnscopedDoltDiffSchema
5354
dtables.GetDoltWorkspaceBaseSqlSchema = getDoltWorkspaceBaseSqlSchema
5455

0 commit comments

Comments
 (0)