Skip to content

Commit ad8b264

Browse files
committed
crosscluster: extra priv tests
This patch adds further e2e privilege tests for LDR and PCR Epic: none Release note: none
1 parent 084c62f commit ad8b264

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

pkg/crosscluster/logical/logical_replication_job_test.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ func TestUserPrivileges(t *testing.T) {
19531953
},
19541954
}
19551955

1956-
server, s, dbA, _ := setupLogicalTestServer(t, ctx, clusterArgs, 1)
1956+
server, s, dbA, dbB := setupLogicalTestServer(t, ctx, clusterArgs, 1)
19571957
defer server.Stopper().Stop(ctx)
19581958

19591959
dbBURL := replicationtestutils.GetExternalConnectionURI(t, s, s, serverutils.DBName("b"))
@@ -1966,7 +1966,8 @@ func TestUserPrivileges(t *testing.T) {
19661966
testuser2 := sqlutils.MakeSQLRunner(s.SQLConn(t, serverutils.User(username.TestUser+"2"), serverutils.DBName("a")))
19671967

19681968
var jobAID jobspb.JobID
1969-
testuser2.QueryRow(t, "CREATE LOGICAL REPLICATION STREAM FROM TABLE tab ON $1 INTO TABLE tab", dbBURL.String()).Scan(&jobAID)
1969+
createStmt := "CREATE LOGICAL REPLICATION STREAM FROM TABLE tab ON $1 INTO TABLE tab"
1970+
testuser2.QueryRow(t, createStmt, dbBURL.String()).Scan(&jobAID)
19701971

19711972
t.Run("view-control-job", func(t *testing.T) {
19721973
showJobStmt := "select job_id from [SHOW JOBS] where job_id=$1"
@@ -2006,11 +2007,17 @@ func TestUserPrivileges(t *testing.T) {
20062007
testuser.Exec(t, fmt.Sprintf(testingUDFAcceptProposedBaseWithSchema, "testschema", "tab"))
20072008
})
20082009

2009-
t.Run("replication", func(t *testing.T) {
2010-
createWithUDFStmt := "CREATE LOGICAL REPLICATION STREAM FROM TABLE tab ON $1 INTO TABLE tab WITH DEFAULT FUNCTION = 'testschema.repl_apply'"
2011-
testuser.ExpectErr(t, "user testuser does not have REPLICATION system privilege", createWithUDFStmt, dbBURL.String())
2010+
t.Run("replication-dest", func(t *testing.T) {
2011+
testuser.ExpectErr(t, "user testuser does not have REPLICATION system privilege", createStmt, dbBURL.String())
20122012
dbA.Exec(t, fmt.Sprintf("GRANT SYSTEM REPLICATION TO %s", username.TestUser))
2013-
testuser.QueryRow(t, createWithUDFStmt, dbBURL.String()).Scan(&jobAID)
2013+
testuser.QueryRow(t, createStmt, dbBURL.String()).Scan(&jobAID)
2014+
})
2015+
t.Run("replication-src", func(t *testing.T) {
2016+
dbB.Exec(t, "CREATE USER testuser3")
2017+
dbBURL2 := replicationtestutils.GetExternalConnectionURI(t, s, s, serverutils.DBName("b"), serverutils.User(username.TestUser+"3"))
2018+
testuser.ExpectErr(t, "user testuser3 does not have REPLICATION system privilege", createStmt, dbBURL2.String())
2019+
dbB.Exec(t, fmt.Sprintf("GRANT SYSTEM REPLICATION TO %s", username.TestUser+"3"))
2020+
testuser.QueryRow(t, createStmt, dbBURL2.String()).Scan(&jobAID)
20142021
})
20152022
}
20162023

pkg/crosscluster/physical/replication_stream_e2e_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"net/http"
1212
"net/http/httptest"
13+
"net/url"
1314
"sync/atomic"
1415
"testing"
1516
"time"
@@ -25,6 +26,7 @@ import (
2526
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/protectedts"
2627
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/protectedts/ptpb"
2728
"github.com/cockroachdb/cockroach/pkg/roachpb"
29+
"github.com/cockroachdb/cockroach/pkg/security/username"
2830
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
2931
"github.com/cockroachdb/cockroach/pkg/sql"
3032
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
@@ -50,6 +52,35 @@ import (
5052
"github.com/stretchr/testify/require"
5153
)
5254

55+
func TestPCRPrivs(t *testing.T) {
56+
defer leaktest.AfterTest(t)()
57+
defer log.Scope(t).Close(t)
58+
59+
ctx := context.Background()
60+
args := replicationtestutils.DefaultTenantStreamingClustersArgs
61+
c, cleanup := replicationtestutils.CreateTenantStreamingClusters(ctx, t, args)
62+
defer cleanup()
63+
64+
c.DestSysSQL.Exec(t, fmt.Sprintf("CREATE USER %s", username.TestUser))
65+
c.SrcSysSQL.Exec(t, fmt.Sprintf("CREATE USER %s", username.TestUser+"2"))
66+
testuser := sqlutils.MakeSQLRunner(c.DestSysServer.SQLConn(t, serverutils.User(username.TestUser)))
67+
srcURL, cleanupSinkCert := sqlutils.PGUrl(t, c.SrcSysServer.AdvSQLAddr(), t.Name(), url.User(username.TestUser+"2"))
68+
defer cleanupSinkCert()
69+
70+
streamReplStmt := fmt.Sprintf("CREATE TENANT %s FROM REPLICATION OF %s ON '%s'",
71+
c.Args.DestTenantName,
72+
c.Args.SrcTenantName,
73+
srcURL.String())
74+
75+
testuser.ExpectErr(t, "user testuser does not have MANAGEVIRTUALCLUSTER system privilege", streamReplStmt)
76+
77+
c.DestSysSQL.Exec(t, fmt.Sprintf("GRANT SYSTEM MANAGEVIRTUALCLUSTER TO %s", username.TestUser))
78+
testuser.ExpectErr(t, "user testuser2 does not have REPLICATION system privilege", streamReplStmt)
79+
80+
c.SrcSysSQL.Exec(t, fmt.Sprintf("GRANT SYSTEM REPLICATION TO %s", username.TestUser+"2"))
81+
c.DestSysSQL.Exec(t, streamReplStmt)
82+
83+
}
5384
func TestTenantStreamingProducerJobTimedOut(t *testing.T) {
5485
defer leaktest.AfterTest(t)()
5586
defer log.Scope(t).Close(t)

0 commit comments

Comments
 (0)