cockroachdb / cockroachdb/cockroach

sql: parameter "role" cannot be changed

Open
#108,732 3 comments 0 reactions 0 assignees View on GitHub
A-sql-pgcompat C-bug T-sql-foundations
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Repro steps**
```
demo@127.0.0.1:26257/demoapp/movr> CREATE USER testuser;
CREATE ROLE

demo@127.0.0.1:26257/demoapp/movr> CREATE USER testuser2;
CREATE ROLE

demo@127.0.0.1:26257/demoapp/movr> ALTER ROLE testuser SET ROLE TO testuser2;
ERROR: parameter "role" cannot be changed
SQLSTATE: 55P02
```

**Expected behavior**

Login as postgres:
```
% psql postgres:
psql (15.4 (Homebrew))
Type "help" for help.

postgres=# CREATE USER testuser;
CREATE ROLE
postgres=# CREATE USER testuser2;
CREATE ROLE
postgres=# ALTER ROLE testuser SET ROLE TO testuser2;
ALTER ROLE
postgres=# GRANT ALL ON SCHEMA public TO testuser2;
GRANT
postgres=# GRANT testuser2 TO testuser; -- prevent WARNING: permission denied to set role "testuser2" when logging in as testuser
GRANT ROLE
```
Login as testuser:
```
% psql postgres --user testuser
psql (15.4 (Homebrew))
Type "help" for help.

postgres=> CREATE TABLE t();
CREATE TABLE
postgres=> SELECT * FROM pg_tables WHERE tablename = 't';
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
------------+-----------+------------+------------+------------+----------+-------------+-------------
public | t | testuser2 | | f | f | f | f
(1 row)
```
Logged in as testuser and created a table, but the table owner is testuser2 because of `ALTER ROLE testuser SET ROLE TO testuser2;`.

**Extra info**

Bug reported on community slack here https://cockroachdb.slack.com/archives/CP4D9LD5F/p1692037996226209?thread_ts=1692032413.645759&cid=CP4D9LD5F

Exists as of dc2c52da339a49405815860cbed511d364b7e146

Jira issue: CRDB-30615

Epic CRDB-60818

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.