Skip to content

Commit 61d5edc

Browse files
fix(restore): restore auth and service levels
As documented in https://opensource.docs.scylladb.com/master/cql/describe-schema.html#required-permissions, schema restoration should be performed with superuser permissions. Fixes #3869 Fixes #3875
1 parent a0100a4 commit 61d5edc

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

pkg/service/restore/helper_integration_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func newTestHelper(t *testing.T, srcHosts, dstHosts []string) *testHelper {
108108
user := randomizedName("helper_user_")
109109
pass := randomizedName("helper_pass_")
110110

111-
dropNonSuperUsers(t, dstCluster.rootSession)
111+
dropNonCassandraUsers(t, dstCluster.rootSession)
112112
createUser(t, dstCluster.rootSession, user, pass)
113113

114114
return &testHelper{
@@ -378,14 +378,14 @@ func filteredTables(t *testing.T, s gocqlx.Session, filter []string) []string {
378378
return out
379379
}
380380

381-
func dropNonSuperUsers(t *testing.T, s gocqlx.Session) {
381+
func dropNonCassandraUsers(t *testing.T, s gocqlx.Session) {
382382
var (
383383
name string
384384
super bool
385385
)
386386
iter := s.Query("LIST USERS", nil).Iter()
387387
for iter.Scan(&name, &super) {
388-
if !super {
388+
if name != "cassandra" {
389389
if err := s.ExecStmt(fmt.Sprintf("DROP USER '%s'", name)); err != nil {
390390
t.Fatal(errors.Wrapf(err, "drop user %s", name))
391391
}
@@ -434,7 +434,7 @@ func grantRestoreTablesPermissions(t *testing.T, s gocqlx.Session, restoredTable
434434
}
435435

436436
func grantRestoreSchemaPermissions(t *testing.T, s gocqlx.Session, user string) {
437-
ExecStmt(t, s, "GRANT CREATE ON ALL KEYSPACES TO "+user)
437+
ExecStmt(t, s, fmt.Sprintf("ALTER USER %s SUPERUSER", user))
438438
}
439439

440440
func validateCompleteProgress(t *testing.T, pr Progress, tables []table) {

pkg/service/restore/schema_worker.go

-7
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,6 @@ func (w *schemaWorker) restoreFromSchemaFile(ctx context.Context) error {
146146

147147
var createdKs []string
148148
for _, row := range *w.describedSchema {
149-
if row.Keyspace == "" {
150-
// Scylla 6.3 added roles and service levels to the output of
151-
// DESC SCHEMA WITH INTERNALS (https://github.com/scylladb/scylladb/pull/20168).
152-
// Those entities do not live in any particular keyspace, so that's how we identify them.
153-
// We are skipping them until we properly support their restoration.
154-
continue
155-
}
156149
if row.Keyspace == "system_replicated_keys" {
157150
// See https://github.com/scylladb/scylla-enterprise/issues/4168
158151
continue

pkg/service/restore/service_restore_integration_test.go

+7-18
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ func smokeRestore(t *testing.T, target Target, keyspace string, loadCnt, loadSiz
731731
}
732732

733733
// Restore should be performed on user with limited permissions
734-
dropNonSuperUsers(t, dstSession)
734+
dropNonCassandraUsers(t, dstSession)
735735
createUser(t, dstSession, user, "pass")
736736
dstH = newRestoreTestHelper(t, mgrSession, cfg, target.Location[0], nil, user, "pass")
737737

@@ -802,7 +802,7 @@ func restoreWithAgentRestart(t *testing.T, target Target, keyspace string, loadC
802802
}
803803

804804
// Restore should be performed on user with limited permissions
805-
dropNonSuperUsers(t, dstSession)
805+
dropNonCassandraUsers(t, dstSession)
806806
createUser(t, dstSession, user, "pass")
807807
dstH = newRestoreTestHelper(t, mgrSession, cfg, target.Location[0], nil, user, "pass")
808808

@@ -910,7 +910,7 @@ func restoreWithResume(t *testing.T, target Target, keyspace string, loadCnt, lo
910910
}
911911

912912
// Restore should be performed on user with limited permissions
913-
dropNonSuperUsers(t, dstSession)
913+
dropNonCassandraUsers(t, dstSession)
914914
createUser(t, dstSession, user, "pass")
915915
dstH = newRestoreTestHelper(t, mgrSession, cfg, target.Location[0], nil, user, "pass")
916916

@@ -1118,11 +1118,6 @@ func restoreWithVersions(t *testing.T, target Target, keyspace string, loadCnt,
11181118
// This also allows us to test scenario with mixed ID type SSTables.
11191119
srcH.Hrt.SetRespInterceptor(newRenameSnapshotSSTablesRespInterceptor(srcH.Client, srcSession, halfUUIDToIntIDGen()))
11201120

1121-
// Restore should be performed on user with limited permissions
1122-
//dropNonSuperUsers(t, dstSession)
1123-
//createUser(t, dstSession, user, "pass")
1124-
//dstH = newRestoreTestHelper(t, mgrSession, cfg, target.Location[0], nil, user, "pass")
1125-
11261121
if target.RestoreTables {
11271122
Print("Recreate schema on destination cluster")
11281123
WriteDataSecondClusterSchema(t, dstSession, keyspace, 0, 0)
@@ -1304,12 +1299,6 @@ func restoreWithVersions(t *testing.T, target Target, keyspace string, loadCnt,
13041299
Print("Restore 3-rd backup with versioned files")
13051300
target.SnapshotTag = tag3
13061301

1307-
if target.RestoreTables {
1308-
// grantRestoreTablesPermissions(t, dstSession, target.Keyspace, user)
1309-
} else {
1310-
// grantRestoreSchemaPermissions(t, dstSession, user)
1311-
}
1312-
13131302
if err = dstH.service.Restore(ctx, dstH.ClusterID, dstH.TaskID, dstH.RunID, dstH.targetToProperties(target)); err != nil {
13141303
t.Fatal(err)
13151304
}
@@ -1367,7 +1356,7 @@ func restoreViewCQLSchema(t *testing.T, target Target, keyspace string, loadCnt,
13671356
}
13681357

13691358
Print("When: Create Restore user")
1370-
dropNonSuperUsers(t, dstSession)
1359+
dropNonCassandraUsers(t, dstSession)
13711360
createUser(t, dstSession, user, "pass")
13721361
dstH = newRestoreTestHelper(t, mgrSession, cfg, target.Location[0], nil, user, "pass")
13731362

@@ -1459,7 +1448,7 @@ func restoreViewSSTableSchema(t *testing.T, schemaTarget, tablesTarget Target, k
14591448
dstH.skipImpossibleSchemaTest()
14601449

14611450
Print("When: Create Restore user")
1462-
dropNonSuperUsers(t, dstSession)
1451+
dropNonCassandraUsers(t, dstSession)
14631452
createUser(t, dstSession, user, "pass")
14641453
dstH = newRestoreTestHelper(t, mgrSession, cfg, schemaTarget.Location[0], nil, user, "pass")
14651454

@@ -1561,7 +1550,7 @@ func restoreAllTables(t *testing.T, schemaTarget, tablesTarget Target, keyspace
15611550
}
15621551

15631552
// Restore should be performed on user with limited permissions
1564-
dropNonSuperUsers(t, dstSession)
1553+
dropNonCassandraUsers(t, dstSession)
15651554
createUser(t, dstSession, user, "pass")
15661555
dstH = newRestoreTestHelper(t, mgrSession, cfg, schemaTarget.Location[0], nil, user, "pass")
15671556

@@ -1667,7 +1656,7 @@ func restoreAlternator(t *testing.T, schemaTarget, tablesTarget Target, testKeys
16671656
dstH.skipCQLSchemaTestAssumingSSTables()
16681657

16691658
// Restore should be performed on user with limited permissions
1670-
dropNonSuperUsers(t, dstSession)
1659+
dropNonCassandraUsers(t, dstSession)
16711660
createUser(t, dstSession, user, "pass")
16721661
dstH = newRestoreTestHelper(t, mgrSession, cfg, schemaTarget.Location[0], nil, user, "pass")
16731662

0 commit comments

Comments
 (0)