Skip to content

Commit

Permalink
Make 'admin' the default role instead of 'edgedb'
Browse files Browse the repository at this point in the history
But if 'edgedb' does not exist and it is specified at login, treat it
as 'admin'.
  • Loading branch information
msullivan committed Nov 22, 2024
1 parent 5111a08 commit e4093eb
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion edb/buildmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# The merge conflict there is a nice reminder that you probably need
# to write a patch in edb/pgsql/patches.py, and then you should preserve
# the old value.
EDGEDB_CATALOG_VERSION = 2024_11_15_00_00
EDGEDB_CATALOG_VERSION = 2024_11_22_00_00
EDGEDB_MAJOR_VERSION = 6


Expand Down
3 changes: 2 additions & 1 deletion edb/schema/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# Maximum number of arguments supported by SQL functions.
MAX_FUNC_ARG_COUNT = 100

EDGEDB_SUPERUSER = 'edgedb'
EDGEDB_SUPERUSER = 'admin'
EDGEDB_OLD_SUPERUSER = 'edgedb'
EDGEDB_TEMPLATE_DB = '__edgedbtpl__'
EDGEDB_SYSTEM_DB = '__edgedbsys__'

Expand Down
1 change: 1 addition & 0 deletions edb/server/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
EDGEDB_REMOTE_COMPILER_PORT = 5660
EDGEDB_SUPERGROUP = 'edgedb_supergroup'
EDGEDB_SUPERUSER = s_def.EDGEDB_SUPERUSER
EDGEDB_OLD_SUPERUSER = s_def.EDGEDB_OLD_SUPERUSER
EDGEDB_TEMPLATE_DB = s_def.EDGEDB_TEMPLATE_DB
EDGEDB_OLD_DEFAULT_DB = 'edgedb'
EDGEDB_SUPERUSER_DB = 'main'
Expand Down
1 change: 1 addition & 0 deletions edb/server/protocol/binary.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ cdef class EdgeConnection(frontend.FrontendConnection):
f'missing required connection parameter in ClientHandshake '
f'message: "user"'
)
user = self.tenant.resolve_user_name(user)

database = params.get('database')
branch = params.get('branch')
Expand Down
1 change: 1 addition & 0 deletions edb/server/protocol/protocol.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ cdef class HttpProtocol:
request.authorization)
username, opt_password = auth_helpers.extract_http_user(
scheme, auth_payload, request.params)
username = self.tenant.resolve_user_name(username)

# Fetch the configured auth methods
authmethods = await self.tenant.get_auth_methods(
Expand Down
9 changes: 9 additions & 0 deletions edb/server/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,15 @@ def resolve_branch_name(
assert database is not None
return database

def resolve_user_name(self, user: str) -> str:
if (
user == defines.EDGEDB_OLD_SUPERUSER
and user not in self.get_roles()
):
return defines.EDGEDB_SUPERUSER
else:
return user

async def get_auth_methods(
self,
user: str,
Expand Down
2 changes: 1 addition & 1 deletion edb/testbase/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ async def __aenter__(self):
else:
password = secrets.token_urlsafe()
bootstrap_command = f"""\
ALTER ROLE edgedb {{
ALTER ROLE admin {{
SET password := '{password}';
}};
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ async def test_server_auth_jwt_1(self):

good_keys = [
[],
[("roles", ["edgedb"])],
[("roles", ["admin"])],
[("databases", ["main"])],
[("instances", ["localtest"])],
]
Expand All @@ -479,7 +479,7 @@ async def test_server_auth_jwt_1(self):
bad_keys = {
(("roles", ("bad-role",)),):
'secret key does not authorize access '
+ 'in role "edgedb"',
+ 'in role "admin"',
(("databases", ("bad-database",)),):
'secret key does not authorize access '
+ 'to database "main"',
Expand Down
8 changes: 4 additions & 4 deletions tests/test_server_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ async def test_server_only_bootstraps_once(self):
async with tb.start_edgedb_server(
data_dir=temp_dir,
default_auth_method=args.ServerAuthMethod.Scram,
bootstrap_command='ALTER ROLE edgedb SET password := "first";'
bootstrap_command='ALTER ROLE admin SET password := "first";'
) as sd:
con = await sd.connect(password='first')
try:
Expand All @@ -412,7 +412,7 @@ async def test_server_only_bootstraps_once(self):
async with tb.start_edgedb_server(
data_dir=temp_dir,
default_auth_method=args.ServerAuthMethod.Scram,
bootstrap_command='ALTER ROLE edgedb SET password := "second";'
bootstrap_command='ALTER ROLE admin SET password := "second";'
) as sd:
con = await sd.connect(password='first')
try:
Expand Down Expand Up @@ -509,7 +509,7 @@ async def test(pgdata_path, tenant):
databases = await con.query('SELECT sys::Branch.name')
self.assertEqual(set(databases), {'main', tenant})
roles = await con.query('SELECT sys::Role.name')
self.assertEqual(set(roles), {'edgedb', tenant})
self.assertEqual(set(roles), {'admin', tenant})
finally:
await con.aclose()

Expand Down Expand Up @@ -544,7 +544,7 @@ async def test(pgdata_path, tenant):
databases = await con.query('SELECT sys::Branch.name')
self.assertEqual(set(databases), {'main', tenant})
roles = await con.query('SELECT sys::Role.name')
self.assertEqual(set(roles), {'edgedb', tenant})
self.assertEqual(set(roles), {'admin', tenant})
finally:
await con.aclose()

Expand Down

0 comments on commit e4093eb

Please sign in to comment.