From 69dd6922f6ce25e5b98471b14282b7834537431a Mon Sep 17 00:00:00 2001 From: Canina Automation Date: Wed, 28 Oct 2026 21:08:40 +0000 Subject: [PATCH] fix(stage): accept persisted ADMIN human role in maintenance --- backend/src/auth/public-author.spec.ts | 8 ++++++++ backend/src/common/guards/human-admin.guard.ts | 2 +- scripts/stage-author-bootstrap/ci.py | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/src/auth/public-author.spec.ts b/backend/src/auth/public-author.spec.ts index 2c97bf3d..49aeaf29 100644 --- a/backend/src/auth/public-author.spec.ts +++ b/backend/src/auth/public-author.spec.ts @@ -94,6 +94,14 @@ describe('Public authors are attribution only, never principals', () => { const ctx = { getHandler: () => null, getClass: () => null, switchToHttp: () => ({ getRequest: () => ({ user: author }) }) } as any; expect(() => guard.canActivate(ctx)).toThrow(ForbiddenException); }); + it.each(['Admin', 'ADMIN', 'SUPER_ADMIN'])('human admin guard accepts actual human role %s', role => { + const ctx = { switchToHttp: () => ({ getRequest: () => ({ user: { role } }) }) } as any; + expect(new HumanAdminGuard().canActivate(ctx)).toBe(true); + }); + it.each(['User_PetOwner', 'adminsuper', '', undefined])('human admin guard denies nonallowlisted role %s', role => { + const ctx = { switchToHttp: () => ({ getRequest: () => ({ user: { role } }) }) } as any; + expect(() => new HumanAdminGuard().canActivate(ctx)).toThrow(ForbiddenException); + }); it('human admin guard rejects author with admin role', () => { const ctx = { switchToHttp: () => ({ getRequest: () => ({ user: author }) }) } as any; expect(() => new HumanAdminGuard().canActivate(ctx)).toThrow(ForbiddenException); diff --git a/backend/src/common/guards/human-admin.guard.ts b/backend/src/common/guards/human-admin.guard.ts index e280b4d5..f3f884a7 100644 --- a/backend/src/common/guards/human-admin.guard.ts +++ b/backend/src/common/guards/human-admin.guard.ts @@ -10,7 +10,7 @@ import { export class HumanAdminGuard implements CanActivate { canActivate(context: ExecutionContext): boolean { const user = context.switchToHttp().getRequest().user; - if (!user || user.isPublicAuthor || user.isApiKey || !['Admin', 'SUPER_ADMIN'].includes(user.role)) + if (!user || user.isPublicAuthor || user.isApiKey || !['Admin', 'ADMIN', 'SUPER_ADMIN'].includes(user.role)) throw new ForbiddenException('Human administrator required'); return true; } diff --git a/scripts/stage-author-bootstrap/ci.py b/scripts/stage-author-bootstrap/ci.py index 627d97f1..085a7b9e 100644 --- a/scripts/stage-author-bootstrap/ci.py +++ b/scripts/stage-author-bootstrap/ci.py @@ -62,6 +62,12 @@ def run(env=os.environ, call=subprocess.run): database_info = json.loads(command(['docker', 'inspect', op.STAGE], capture_output=True).stdout)[0] op.check_identity(database_info) validate_runtime_url(values.get('DATABASE_URL', ''), database_info) + # Dedicated maintenance scope uses the independently verified canonical name. + # Preserve credentials, remove only the already validated default schema hint. + from urllib.parse import urlparse + runtime_url = urlparse(values['DATABASE_URL']) + credentials = runtime_url.netloc.rsplit('@', 1)[0] + '@' if '@' in runtime_url.netloc else '' + values['DATABASE_URL'] = runtime_url._replace(netloc=credentials + op.STAGE + ':5432', query='').geturl() if any('\n' in v or '\r' in v for v in values.values()): raise ValueError('Multiline env refused') live_env = evidence / 'stage.env' op.private_write(live_env, '\n'.join(k + '=' + v for k, v in values.items()).encode())