From e99294b69f2432eb5646b082230f56a08bc7ef2b Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Wed, 18 Nov 2026 14:34:47 -0500 Subject: [PATCH] Fix Console bulk domain suspend and history Fix two bugs in ConsoleBulkDomainAction: - Add runAsSuperuser() to ConsoleDomainActionType (returning true for SUSPEND and UNSUSPEND and false for DELETE) and pass it to EppController instead of user.getUserRoles().isAdmin(). Previously, DomainUpdateFlow rejected the server-only suspension statuses for non-admin FTE and SUPPORT_LEAD users who hold SUSPEND_DOMAIN. Superuser status is now driven solely by the action type, so DELETE never runs as superuser through the bulk domain action, even for admins. Superuser deletes, which bypass server statuses and can delete domains immediately, remain available through the nomulus CLI. - Prefix ConsoleUpdateHistory descriptions with '|' using ConsoleUpdateHistory.DESCRIPTION_SEPARATOR so bulk domain actions are returned by ConsoleHistoryDataAction's registrar history query and parsed properly in the Console history UI. - Add unit tests in ConsoleBulkDomainActionTest covering non-admin FTE and SUPPORT_LEAD suspend/unsuspend flows, permission enforcement, non-superuser DELETE for both admin and non-admin users, and ConsoleHistoryDataAction queries. BUG= http://b/586480958 --- .../domains/ConsoleBulkDomainAction.java | 15 +- .../ConsoleBulkDomainDeleteActionType.java | 10 +- .../ConsoleBulkDomainSuspendActionType.java | 10 +- .../ConsoleBulkDomainUnsuspendActionType.java | 10 +- .../domains/ConsoleDomainActionType.java | 8 + .../domains/ConsoleBulkDomainActionTest.java | 283 ++++++++++++++++-- 6 files changed, 303 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainAction.java b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainAction.java index 7de63e1999c..fb77d9e5a0f 100644 --- a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainAction.java +++ b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainAction.java @@ -102,10 +102,12 @@ protected void postHandler(User user) { checkPermission(user, registrarId, actionType.getNecessaryPermission()); + boolean isSuperuser = actionType.runAsSuperuser(); ImmutableMap result = domainList.domainList.stream() .collect( - toImmutableMap(d -> d, d -> executeEpp(actionType.getXmlContentsToRun(d), user))); + toImmutableMap( + d -> d, d -> executeEpp(actionType.getXmlContentsToRun(d), isSuperuser))); handleHistoryAdditions(result, actionType); // Front end should parse situations where only some commands worked consoleApiParams.response().setPayload(consoleApiParams.gson().toJson(result)); @@ -125,11 +127,16 @@ private void handleHistoryAdditions( e -> finishAndPersistConsoleUpdateHistory( new ConsoleUpdateHistory.Builder() - .setDescription(e.getKey()) + .setDescription( + String.format( + "%s%s%s", + registrarId, + ConsoleUpdateHistory.DESCRIPTION_SEPARATOR, + e.getKey())) .setType(actionType.getConsoleUpdateHistoryType())))); } - private ConsoleEppOutput executeEpp(String xml, User user) { + private ConsoleEppOutput executeEpp(String xml, boolean isSuperuser) { return ConsoleEppOutput.fromEppOutput( eppController.handleEppCommand( new StatelessRequestSessionMetadata( @@ -137,7 +144,7 @@ private ConsoleEppOutput executeEpp(String xml, User user) { new PasswordOnlyTransportCredentials(), EppRequestSource.CONSOLE, false, - user.getUserRoles().isAdmin(), + isSuperuser, xml.getBytes(UTF_8))); } diff --git a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainDeleteActionType.java b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainDeleteActionType.java index b42dbaa08cb..5d9c50c7218 100644 --- a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainDeleteActionType.java +++ b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainDeleteActionType.java @@ -22,7 +22,7 @@ public class ConsoleBulkDomainDeleteActionType extends ConsoleDomainActionType { private static final String DOMAIN_DELETE_XML = - """ +""" @@ -40,7 +40,8 @@ public class ConsoleBulkDomainDeleteActionType extends ConsoleDomainActionType { RegistryConsole -"""; +\ +"""; public ConsoleBulkDomainDeleteActionType(JsonElement jsonElement) { super(jsonElement); @@ -56,6 +57,11 @@ public ConsolePermission getNecessaryPermission() { return ConsolePermission.EXECUTE_EPP_COMMANDS; } + @Override + public boolean runAsSuperuser() { + return false; + } + @Override public ConsoleUpdateHistory.Type getConsoleUpdateHistoryType() { return ConsoleUpdateHistory.Type.DOMAIN_DELETE; diff --git a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainSuspendActionType.java b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainSuspendActionType.java index 71b56fe436b..3025ad728a1 100644 --- a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainSuspendActionType.java +++ b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainSuspendActionType.java @@ -22,7 +22,7 @@ public class ConsoleBulkDomainSuspendActionType extends ConsoleDomainActionType { private static final String DOMAIN_SUSPEND_XML = - """ +""" @@ -50,7 +50,8 @@ public class ConsoleBulkDomainSuspendActionType extends ConsoleDomainActionType RegistryConsole -"""; +\ +"""; public ConsoleBulkDomainSuspendActionType(JsonElement jsonElement) { super(jsonElement); @@ -66,6 +67,11 @@ public ConsolePermission getNecessaryPermission() { return ConsolePermission.SUSPEND_DOMAIN; } + @Override + public boolean runAsSuperuser() { + return true; + } + @Override public ConsoleUpdateHistory.Type getConsoleUpdateHistoryType() { return ConsoleUpdateHistory.Type.DOMAIN_SUSPEND; diff --git a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainUnsuspendActionType.java b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainUnsuspendActionType.java index 9ae158406ca..bbb72c0eb4f 100644 --- a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainUnsuspendActionType.java +++ b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleBulkDomainUnsuspendActionType.java @@ -22,7 +22,7 @@ public class ConsoleBulkDomainUnsuspendActionType extends ConsoleDomainActionType { private static final String DOMAIN_SUSPEND_XML = - """ +""" @@ -50,7 +50,8 @@ public class ConsoleBulkDomainUnsuspendActionType extends ConsoleDomainActionTyp RegistryConsole -"""; +\ +"""; public ConsoleBulkDomainUnsuspendActionType(JsonElement jsonElement) { super(jsonElement); @@ -66,6 +67,11 @@ public ConsolePermission getNecessaryPermission() { return ConsolePermission.SUSPEND_DOMAIN; } + @Override + public boolean runAsSuperuser() { + return true; + } + @Override public ConsoleUpdateHistory.Type getConsoleUpdateHistoryType() { return ConsoleUpdateHistory.Type.DOMAIN_UNSUSPEND; diff --git a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleDomainActionType.java b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleDomainActionType.java index f063bc31534..4025dd7623b 100644 --- a/core/src/main/java/google/registry/ui/server/console/domains/ConsoleDomainActionType.java +++ b/core/src/main/java/google/registry/ui/server/console/domains/ConsoleDomainActionType.java @@ -69,6 +69,14 @@ public String getXmlContentsToRun(String domainName) { /** Returns the permission necessary to successfully perform this action. */ public abstract ConsolePermission getNecessaryPermission(); + /** + * Returns whether the EPP command for this action runs with superuser privileges. + * + *

This is evaluated only after {@link #getNecessaryPermission()} has been verified, and it + * applies to all users regardless of whether they are admins. + */ + public abstract boolean runAsSuperuser(); + /** Returns the type of history / audit logging object to save. */ public abstract ConsoleUpdateHistory.Type getConsoleUpdateHistoryType(); diff --git a/core/src/test/java/google/registry/ui/server/console/domains/ConsoleBulkDomainActionTest.java b/core/src/test/java/google/registry/ui/server/console/domains/ConsoleBulkDomainActionTest.java index e407bafc661..066185e2233 100644 --- a/core/src/test/java/google/registry/ui/server/console/domains/ConsoleBulkDomainActionTest.java +++ b/core/src/test/java/google/registry/ui/server/console/domains/ConsoleBulkDomainActionTest.java @@ -36,6 +36,7 @@ import google.registry.flows.EppController; import google.registry.flows.EppTestComponent; import google.registry.model.console.ConsoleUpdateHistory; +import google.registry.model.console.GlobalRole; import google.registry.model.console.RegistrarRole; import google.registry.model.console.User; import google.registry.model.console.UserRoles; @@ -47,6 +48,7 @@ import google.registry.testing.FakeResponse; import google.registry.ui.server.console.ConsoleActionBaseTestCase; import google.registry.ui.server.console.ConsoleApiParams; +import google.registry.ui.server.console.ConsoleHistoryDataAction; import java.util.Collections; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; @@ -101,7 +103,7 @@ void testSuccess_delete() { assertThat(loadByEntity(domain).getDeletionTime()).isEqualTo(plusDays(clock.now(), 35)); ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_DELETE); - assertThat(history.getDescription()).hasValue("example.tld"); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); } @Test @@ -122,7 +124,7 @@ void testSuccess_suspend() throws Exception { .containsAtLeastElementsIn(serverSuspensionStatuses); ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_SUSPEND); - assertThat(history.getDescription()).hasValue("example.tld"); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); } @Test @@ -145,7 +147,7 @@ void testSuccess_unsuspend() throws Exception { assertThat(loadByEntity(domain).getStatusValues()).containsNoneIn(serverSuspensionStatuses); ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_UNSUSPEND); - assertThat(history.getDescription()).hasValue("example.tld"); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); } @Test @@ -171,7 +173,7 @@ void testHalfSuccess_halfNonexistent() throws Exception { assertThat(loadByEntity(domain).getDeletionTime()).isEqualTo(plusDays(clock.now(), 35)); ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_DELETE); - assertThat(history.getDescription()).hasValue("example.tld"); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); } @Test @@ -261,25 +263,260 @@ void testFailure_nonexistentRegistrar() { assertThat(response.getStatus()).isEqualTo(SC_FORBIDDEN); } - // @ptkach - reenable with suspend change - // @Test - // void testFailure_suspend_nonAdmin() { - // ConsoleBulkDomainAction action = - // createAction( - // "SUSPEND", - // GSON.toJsonTree( - // ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", - // "test")), - // user); - // action.run(); - // assertThat(fakeResponse.getStatus()).isEqualTo(SC_OK); - // Map payload = - // GSON.fromJson(fakeResponse.getPayload(), new TypeToken<>() {}); - // assertThat(payload).containsKey("example.tld"); - // assertThat(payload.get("example.tld").responseCode()).isEqualTo(2004); - // assertThat(payload.get("example.tld").message()).contains("cannot be set by clients"); - // assertThat(loadByEntity(domain)).isEqualTo(domain); - // } + @Test + void testSuccess_suspend_nonAdminFte() { + User nonAdminFte = + persistResource( + new User.Builder() + .setEmailAddress("nonadmin-fte@example.com") + .setUserRoles( + new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).setIsAdmin(false).build()) + .build()); + assertThat(nonAdminFte.getUserRoles().isAdmin()).isFalse(); + persistResource( + domain.asBuilder().addStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED).build()); + + ConsoleBulkDomainAction action = + createAction( + "SUSPEND", + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "policy")), + nonAdminFte); + action.run(); + + assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()) + .isEqualTo( + """ + {"example.tld":{"message":"Command completed successfully","responseCode":1000}}\ + """); + assertThat(loadByEntity(domain).getStatusValues()) + .containsAtLeastElementsIn(serverSuspensionStatuses); + ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); + assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_SUSPEND); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); + assertThat(history.getActingUser().getEmailAddress()).isEqualTo("nonadmin-fte@example.com"); + } + + @Test + void testSuccess_unsuspend_nonAdminFte() { + User nonAdminFte = + persistResource( + new User.Builder() + .setEmailAddress("nonadmin-fte@example.com") + .setUserRoles( + new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).setIsAdmin(false).build()) + .build()); + persistResource(domain.asBuilder().addStatusValues(serverSuspensionStatuses).build()); + + ConsoleBulkDomainAction action = + createAction( + "UNSUSPEND", + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "cured")), + nonAdminFte); + action.run(); + + assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()) + .isEqualTo( + """ + {"example.tld":{"message":"Command completed successfully","responseCode":1000}}\ + """); + assertThat(loadByEntity(domain).getStatusValues()).containsNoneIn(serverSuspensionStatuses); + ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); + assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_UNSUSPEND); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); + assertThat(history.getActingUser().getEmailAddress()).isEqualTo("nonadmin-fte@example.com"); + } + + @Test + void testSuccess_suspend_nonAdminSupportLead() { + User supportLead = + persistResource( + new User.Builder() + .setEmailAddress("support-lead@example.com") + .setUserRoles( + new UserRoles.Builder() + .setGlobalRole(GlobalRole.SUPPORT_LEAD) + .setIsAdmin(false) + .build()) + .build()); + assertThat(supportLead.getUserRoles().isAdmin()).isFalse(); + + ConsoleBulkDomainAction action = + createAction( + "SUSPEND", + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "policy")), + supportLead); + action.run(); + + assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()) + .isEqualTo( + """ + {"example.tld":{"message":"Command completed successfully","responseCode":1000}}\ + """); + assertThat(loadByEntity(domain).getStatusValues()) + .containsAtLeastElementsIn(serverSuspensionStatuses); + ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); + assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_SUSPEND); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); + assertThat(history.getActingUser().getEmailAddress()).isEqualTo("support-lead@example.com"); + } + + @Test + void testSuccess_unsuspend_nonAdminSupportLead() { + User supportLead = + persistResource( + new User.Builder() + .setEmailAddress("support-lead@example.com") + .setUserRoles( + new UserRoles.Builder() + .setGlobalRole(GlobalRole.SUPPORT_LEAD) + .setIsAdmin(false) + .build()) + .build()); + persistResource(domain.asBuilder().addStatusValues(serverSuspensionStatuses).build()); + + ConsoleBulkDomainAction action = + createAction( + "UNSUSPEND", + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "cured")), + supportLead); + action.run(); + + assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()) + .isEqualTo( + """ + {"example.tld":{"message":"Command completed successfully","responseCode":1000}}\ + """); + assertThat(loadByEntity(domain).getStatusValues()).containsNoneIn(serverSuspensionStatuses); + ConsoleUpdateHistory history = loadSingleton(ConsoleUpdateHistory.class).get(); + assertThat(history.getType()).isEqualTo(ConsoleUpdateHistory.Type.DOMAIN_UNSUSPEND); + assertThat(history.getDescription()).hasValue("TheRegistrar|example.tld"); + assertThat(history.getActingUser().getEmailAddress()).isEqualTo("support-lead@example.com"); + } + + @Test + void testSuccess_historyQueryableByRegistrarId() { + User supportLead = + persistResource( + new User.Builder() + .setEmailAddress("support-lead@example.com") + .setUserRoles( + new UserRoles.Builder() + .setGlobalRole(GlobalRole.SUPPORT_LEAD) + .setIsAdmin(false) + .build()) + .build()); + createAction( + "SUSPEND", + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "policy")), + supportLead) + .run(); + assertThat(response.getStatus()).isEqualTo(SC_OK); + + ConsoleApiParams historyParams = + ConsoleApiParamsUtils.createFake(AuthResult.createUser(supportLead)); + when(historyParams.request().getMethod()).thenReturn("GET"); + FakeResponse historyResponse = (FakeResponse) historyParams.response(); + new ConsoleHistoryDataAction( + historyParams, "support@example.com", 500, "TheRegistrar", Optional.empty()) + .run(); + + assertThat(historyResponse.getStatus()).isEqualTo(SC_OK); + assertThat(historyResponse.getPayload()).contains("TheRegistrar|example.tld"); + assertThat(historyResponse.getPayload()).contains("DOMAIN_SUSPEND"); + } + + @Test + void testFailure_suspend_supportAgentForbidden() { + User supportAgent = + persistResource( + new User.Builder() + .setEmailAddress("support-agent@example.com") + .setUserRoles( + new UserRoles.Builder() + .setGlobalRole(GlobalRole.SUPPORT_AGENT) + .setIsAdmin(false) + .build()) + .build()); + JsonElement payload = + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "policy")); + + createAction("SUSPEND", payload, supportAgent).run(); + assertThat(response.getStatus()).isEqualTo(SC_FORBIDDEN); + + createAction("UNSUSPEND", payload, supportAgent).run(); + assertThat(response.getStatus()).isEqualTo(SC_FORBIDDEN); + } + + @Test + void testFailure_suspend_registrarTechContactForbidden() { + User techContact = + persistResource( + new User.Builder() + .setEmailAddress("tech@theregistrar.com") + .setUserRoles( + new UserRoles.Builder() + .setRegistrarRoles( + ImmutableMap.of("TheRegistrar", RegistrarRole.TECH_CONTACT)) + .build()) + .build()); + JsonElement payload = + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "policy")); + + createAction("SUSPEND", payload, techContact).run(); + assertThat(response.getStatus()).isEqualTo(SC_FORBIDDEN); + } + + @Test + void testFailure_delete_nonAdminDoesNotRunAsSuperuser() { + User supportLead = + persistResource( + new User.Builder() + .setEmailAddress("support-lead@example.com") + .setUserRoles( + new UserRoles.Builder() + .setGlobalRole(GlobalRole.SUPPORT_LEAD) + .setIsAdmin(false) + .build()) + .build()); + assertDeleteDoesNotBypassServerDeleteProhibited(supportLead); + } + + @Test + void testFailure_delete_adminDoesNotRunAsSuperuser() { + // Superuser deletes (which bypass server statuses and can delete immediately) are only + // available through the nomulus CLI, not through the bulk domain action, even for admins. + assertThat(fteUser.getUserRoles().isAdmin()).isTrue(); + assertDeleteDoesNotBypassServerDeleteProhibited(fteUser); + } + + private void assertDeleteDoesNotBypassServerDeleteProhibited(User user) { + Domain lockedDomain = + persistResource( + domain.asBuilder().addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED).build()); + + createAction( + "DELETE", + GSON.toJsonTree( + ImmutableMap.of("domainList", ImmutableList.of("example.tld"), "reason", "test")), + user) + .run(); + + assertThat(response.getStatus()).isEqualTo(SC_OK); + assertThat(response.getPayload()).contains("\"responseCode\":2304"); + assertThat(loadByEntity(lockedDomain)).isEqualTo(lockedDomain); + assertThat(loadSingleton(ConsoleUpdateHistory.class)).isEmpty(); + } private ConsoleBulkDomainAction createAction(String action, JsonElement payload) { return createAction("TheRegistrar", action, payload, fteUser, 500);