Skip to content

Commit 937d66e

Browse files
authored
Merge pull request #150375 from souravcrl/blathers/backport-release-25.3-150105
release-25.3: sql: populate estimated_last_login_time for all authenticating users
2 parents c478f4a + edd218a commit 937d66e

File tree

10 files changed

+233
-143
lines changed

10 files changed

+233
-143
lines changed

pkg/backup/backup_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ func TestBackupRestoreSystemTables(t *testing.T) {
10651065
expectedFingerprints := map[string][][]string{}
10661066
err := crdb.ExecuteTx(ctx, conn, nil /* txopts */, func(tx *gosql.Tx) error {
10671067
for _, table := range tables {
1068-
rows, err := conn.Query("SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE system." + table)
1068+
rows, err := tx.Query("SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE system." + table)
10691069
if err != nil {
10701070
return err
10711071
}
@@ -1077,7 +1077,7 @@ func TestBackupRestoreSystemTables(t *testing.T) {
10771077
}
10781078
// Record the transaction's timestamp so we can take a backup at the
10791079
// same time.
1080-
return conn.QueryRow("SELECT cluster_logical_timestamp()").Scan(&backupAsOf)
1080+
return tx.QueryRow("SELECT cluster_logical_timestamp()").Scan(&backupAsOf)
10811081
})
10821082
if err != nil {
10831083
t.Fatal(err)

pkg/backup/full_cluster_backup_restore_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,29 +1189,29 @@ func TestFullClusterRestoreWithUserIDs(t *testing.T) {
11891189
sqlDB.Exec(t, `CREATE USER test2`)
11901190
sqlDB.Exec(t, `BACKUP INTO $1`, localFoo)
11911191

1192-
sqlDB.CheckQueryResults(t, `SELECT * FROM system.users ORDER BY user_id`, [][]string{
1193-
{"root", "", "false", "1", "NULL"},
1194-
{"admin", "", "true", "2", "NULL"},
1195-
{"test1", "NULL", "false", "100", "NULL"},
1196-
{"test2", "NULL", "false", "101", "NULL"},
1192+
sqlDB.CheckQueryResults(t, `SELECT username, "hashedPassword", "isRole", user_id FROM system.users ORDER BY user_id`, [][]string{
1193+
{"root", "", "false", "1"},
1194+
{"admin", "", "true", "2"},
1195+
{"test1", "NULL", "false", "100"},
1196+
{"test2", "NULL", "false", "101"},
11971197
})
11981198
// Ensure that the new backup succeeds.
11991199
sqlDBRestore.Exec(t, `RESTORE FROM LATEST IN $1`, localFoo)
12001200

1201-
sqlDBRestore.CheckQueryResults(t, `SELECT * FROM system.users ORDER BY user_id`, [][]string{
1202-
{"root", "", "false", "1", "NULL"},
1203-
{"admin", "", "true", "2", "NULL"},
1204-
{"test1", "NULL", "false", "100", "NULL"},
1205-
{"test2", "NULL", "false", "101", "NULL"},
1201+
sqlDBRestore.CheckQueryResults(t, `SELECT username, "hashedPassword", "isRole", user_id FROM system.users ORDER BY user_id`, [][]string{
1202+
{"root", "", "false", "1"},
1203+
{"admin", "", "true", "2"},
1204+
{"test1", "NULL", "false", "100"},
1205+
{"test2", "NULL", "false", "101"},
12061206
})
12071207

12081208
sqlDBRestore.Exec(t, `CREATE USER test3`)
12091209

1210-
sqlDBRestore.CheckQueryResults(t, `SELECT * FROM system.users ORDER BY user_id`, [][]string{
1211-
{"root", "", "false", "1", "NULL"},
1212-
{"admin", "", "true", "2", "NULL"},
1213-
{"test1", "NULL", "false", "100", "NULL"},
1214-
{"test2", "NULL", "false", "101", "NULL"},
1215-
{"test3", "NULL", "false", "102", "NULL"},
1210+
sqlDBRestore.CheckQueryResults(t, `SELECT username, "hashedPassword", "isRole", user_id FROM system.users ORDER BY user_id`, [][]string{
1211+
{"root", "", "false", "1"},
1212+
{"admin", "", "true", "2"},
1213+
{"test1", "NULL", "false", "100"},
1214+
{"test2", "NULL", "false", "101"},
1215+
{"test3", "NULL", "false", "102"},
12161216
})
12171217
}

pkg/backup/testdata/backup-restore/restore-mixed-version

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ CREATE DATABASE d;
66
USE d;
77
CREATE TABLE foo (i INT PRIMARY KEY, s STRING);
88
INSERT INTO foo VALUES (1, 'x'),(2,'y');
9+
CREATE ROLE testrole NOLOGIN;
10+
CREATE USER testuser WITH PASSWORD 'testpass';
11+
GRANT testrole TO testuser;
912
----
1013

1114
exec-sql
@@ -47,3 +50,15 @@ SELECT * FROM d.foo
4750
----
4851
1 x
4952
2 y
53+
54+
# Restore system users into the newer version cluster.
55+
exec-sql cluster=s2
56+
RESTORE SYSTEM USERS FROM LATEST IN 'nodelocal://1/full_cluster_backup/';
57+
----
58+
59+
# Verify the users were restored correctly.
60+
query-sql cluster=s2
61+
SELECT username, options, member_of FROM [SHOW ROLES] WHERE username IN ('testrole', 'testuser')
62+
----
63+
testrole {NOLOGIN} {}
64+
testuser {} {testrole}

pkg/ccl/multiregionccl/cold_start_latency_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestColdStartLatency(t *testing.T) {
4747
defer leaktest.AfterTest(t)()
4848
defer log.Scope(t).Close(t)
4949
skip.UnderDuress(t, "too slow")
50+
skip.WithIssue(t, 150251, "skipping as timeout settings causes #150105 to fail")
5051
// We'll need to make some per-node args to assign the different
5152
// KV nodes to different regions and AZs. We'll want to do it to
5253
// look somewhat like the real cluster topologies we have in mind.

pkg/sql/logictest/testdata/logic_test/drop_user

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,51 @@ statement ok
22
CREATE USER user1
33

44
skipif config local-mixed-25.2
5-
query TTTT colnames,rowsort
6-
SHOW USERS
5+
query TTT colnames,rowsort
6+
select username, options, member_of from [SHOW USERS]
77
----
8-
username options member_of estimated_last_login_time
9-
admin {} {} NULL
10-
root {} {admin} NULL
11-
testuser {} {} NULL
12-
user1 {} {} NULL
8+
username options member_of
9+
admin {} {}
10+
root {} {admin}
11+
testuser {} {}
12+
user1 {} {}
1313

1414
statement ok
1515
DROP USER user1
1616

1717
skipif config local-mixed-25.2
18-
query TTTT colnames,rowsort
19-
SHOW USERS
18+
query TTT colnames,rowsort
19+
select username, options, member_of from [SHOW USERS]
2020
----
21-
username options member_of estimated_last_login_time
22-
admin {} {} NULL
23-
root {} {admin} NULL
24-
testuser {} {} NULL
21+
username options member_of
22+
admin {} {}
23+
root {} {admin}
24+
testuser {} {}
2525

2626
statement ok
2727
CREATE USER user1
2828

2929
skipif config local-mixed-25.2
30-
query TTTT colnames,rowsort
31-
SHOW USERS
30+
query TTT colnames,rowsort
31+
select username, options, member_of from [SHOW USERS]
3232
----
33-
username options member_of estimated_last_login_time
34-
admin {} {} NULL
35-
root {} {admin} NULL
36-
testuser {} {} NULL
37-
user1 {} {} NULL
33+
username options member_of
34+
admin {} {}
35+
root {} {admin}
36+
testuser {} {}
37+
user1 {} {}
3838

3939
statement ok
4040
DROP USER USEr1
4141

4242
skipif config local-mixed-25.2
43-
query TTTT colnames,rowsort
44-
SHOW USERS
43+
query TTT colnames,rowsort
44+
select username, options, member_of from [SHOW USERS]
4545
----
46-
username options member_of estimated_last_login_time
47-
admin {} {} NULL
48-
root {} {admin} NULL
49-
testuser {} {} NULL
46+
username options member_of
47+
admin {} {}
48+
root {} {admin}
49+
testuser {} {}
5050

5151
statement error user "user1" does not exist
5252
DROP USER user1
@@ -88,45 +88,45 @@ statement ok
8888
CREATE USER user4
8989

9090
skipif config local-mixed-25.2
91-
query TTTT colnames,rowsort
92-
SHOW USERS
91+
query TTT colnames,rowsort
92+
select username, options, member_of from [SHOW USERS]
9393
----
94-
username options member_of estimated_last_login_time
95-
admin {} {} NULL
96-
root {} {admin} NULL
97-
testuser {} {} NULL
98-
user1 {} {} NULL
99-
user2 {} {} NULL
100-
user3 {} {} NULL
101-
user4 {} {} NULL
94+
username options member_of
95+
admin {} {}
96+
root {} {admin}
97+
testuser {} {}
98+
user1 {} {}
99+
user2 {} {}
100+
user3 {} {}
101+
user4 {} {}
102102

103103
statement ok
104104
DROP USER user1,user2
105105

106106
skipif config local-mixed-25.2
107-
query TTTT colnames,rowsort
108-
SHOW USERS
107+
query TTT colnames,rowsort
108+
select username, options, member_of from [SHOW USERS]
109109
----
110-
username options member_of estimated_last_login_time
111-
admin {} {} NULL
112-
root {} {admin} NULL
113-
testuser {} {} NULL
114-
user3 {} {} NULL
115-
user4 {} {} NULL
110+
username options member_of
111+
admin {} {}
112+
root {} {admin}
113+
testuser {} {}
114+
user3 {} {}
115+
user4 {} {}
116116

117117
statement error user "user1" does not exist
118118
DROP USER user1,user3
119119

120120
skipif config local-mixed-25.2
121-
query TTTT colnames,rowsort
122-
SHOW USERS
121+
query TTT colnames,rowsort
122+
select username, options, member_of from [SHOW USERS]
123123
----
124-
username options member_of estimated_last_login_time
125-
admin {} {} NULL
126-
root {} {admin} NULL
127-
testuser {} {} NULL
128-
user3 {} {} NULL
129-
user4 {} {} NULL
124+
username options member_of
125+
admin {} {}
126+
root {} {admin}
127+
testuser {} {}
128+
user3 {} {}
129+
user4 {} {}
130130

131131
statement ok
132132
CREATE USER user1
@@ -156,13 +156,13 @@ PREPARE du AS DROP USER user4;
156156
EXECUTE du
157157

158158
skipif config local-mixed-25.2
159-
query TTTT colnames,rowsort
160-
SHOW USERS
159+
query TTT colnames,rowsort
160+
select username, options, member_of from [SHOW USERS]
161161
----
162-
username options member_of estimated_last_login_time
163-
admin {} {} NULL
164-
root {} {admin} NULL
165-
testuser {} {} NULL
162+
username options member_of
163+
admin {} {}
164+
root {} {admin}
165+
testuser {} {}
166166

167167
user testuser
168168

pkg/sql/logictest/testdata/logic_test/role

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ statement ok
2525
CREATE ROLE myrole
2626

2727
skipif config local-mixed-25.2
28-
query TTTT colnames,rowsort
29-
SHOW ROLES
28+
query TTT colnames,rowsort
29+
select username, options, member_of from [SHOW ROLES]
3030
----
31-
username options member_of estimated_last_login_time
32-
admin {} {} NULL
33-
myrole {NOLOGIN} {} NULL
34-
root {} {admin} NULL
35-
testuser {} {} NULL
31+
username options member_of
32+
admin {} {}
33+
myrole {NOLOGIN} {}
34+
root {} {admin}
35+
testuser {} {}
3636

3737
statement error a role/user named myrole already exists
3838
CREATE ROLE myrole
@@ -56,26 +56,26 @@ statement error pq: cannot drop roles/users admin, myrole: grants still exist on
5656
DROP ROLE admin, myrole
5757

5858
skipif config local-mixed-25.2
59-
query TTTT colnames,rowsort
60-
SHOW ROLES
59+
query TTT colnames,rowsort
60+
select username, options, member_of from [SHOW ROLES]
6161
----
62-
username options member_of estimated_last_login_time
63-
admin {} {} NULL
64-
myrole {NOLOGIN} {} NULL
65-
root {} {admin} NULL
66-
testuser {} {} NULL
62+
username options member_of
63+
admin {} {}
64+
myrole {NOLOGIN} {}
65+
root {} {admin}
66+
testuser {} {}
6767

6868
statement ok
6969
DROP ROLE myrole
7070

7171
skipif config local-mixed-25.2
72-
query TTTT colnames,rowsort
73-
SHOW ROLES
72+
query TTT colnames,rowsort
73+
select username, options, member_of from [SHOW ROLES]
7474
----
75-
username options member_of estimated_last_login_time
76-
admin {} {} NULL
77-
root {} {admin} NULL
78-
testuser {} {} NULL
75+
username options member_of
76+
admin {} {}
77+
root {} {admin}
78+
testuser {} {}
7979

8080
statement error pq: role/user "myrole" does not exist
8181
DROP ROLE myrole
@@ -105,13 +105,13 @@ statement ok
105105
DROP ROLE rolea, roleb
106106

107107
skipif config local-mixed-25.2
108-
query TTTT colnames,rowsort
109-
SHOW ROLES
108+
query TTT colnames,rowsort
109+
select username, options, member_of from [SHOW ROLES]
110110
----
111-
username options member_of estimated_last_login_time
112-
admin {} {} NULL
113-
root {} {admin} NULL
114-
testuser {} {} NULL
111+
username options member_of
112+
admin {} {}
113+
root {} {admin}
114+
testuser {} {}
115115

116116
skipif config local-mixed-25.2
117117
query T noticetrace
@@ -502,16 +502,16 @@ admin root true
502502
roled testuser false
503503

504504
skipif config local-mixed-25.2
505-
query TTTT rowsort
506-
SHOW ROLES
507-
----
508-
admin {} {} NULL
509-
roleb {NOLOGIN} {} NULL
510-
roled {NOLOGIN} {} NULL
511-
rolee {NOLOGIN} {} NULL
512-
root {} {admin} NULL
513-
testuser {} {roled} NULL
514-
testuser2 {} {} NULL
505+
query TTT rowsort
506+
select username, options, member_of from [SHOW ROLES]
507+
----
508+
admin {} {}
509+
roleb {NOLOGIN} {}
510+
roled {NOLOGIN} {}
511+
rolee {NOLOGIN} {}
512+
root {} {admin}
513+
testuser {} {roled}
514+
testuser2 {} {}
515515

516516
statement ok
517517
DROP ROLE roleb

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ v CREATE VIEW public.v (
495495

496496

497497
skipif config local-mixed-25.2
498-
query TTTT colnames
499-
SELECT * FROM [SHOW USERS] ORDER BY 1
498+
query TTT colnames
499+
SELECT username,options,member_of FROM [SHOW USERS] ORDER BY 1
500500
----
501-
username options member_of estimated_last_login_time
502-
admin {} {} NULL
503-
root {} {admin} NULL
504-
testuser {} {} NULL
501+
username options member_of
502+
admin {} {}
503+
root {} {admin}
504+
testuser {} {}
505505

506506

507507
query TTTI colnames

0 commit comments

Comments
 (0)