Skip to content

Commit 7a00054

Browse files
rjrudinSameeraPriyathamTadikonda
authored andcommitted
DHFPROD-4558: Changing order of deploying PPs and QRs
See comments/assertions for why this is being done.
1 parent 61bd4dd commit 7a00054

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

marklogic-data-hub/src/main/java/com/marklogic/hub/dhs/DhsDeployer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,16 @@ protected List<Command> buildCommandsForDeveloper(HubConfig hubConfig) {
185185
commands.add(new LoadSchemasCommand());
186186
commands.add(new DeployScheduledTasksCommand());
187187

188-
commands.add(new DeployProtectedPathsCommand());
188+
/**
189+
* Have run into an odd problem where when a user without the "security" role deploys QRs immediately after
190+
* deploying PPs, the PPs don't work. Deploying PPs immediately after QRs does result in the PPs working. Or,
191+
* deploying QRs some amount of time after deploying PPs works as well. So in this context, PPs are deployed
192+
* after everything else is done, and QRs are deployed first based on the default sort order of the command.
193+
*/
194+
DeployProtectedPathsCommand pathsCommand = new DeployProtectedPathsCommand();
195+
pathsCommand.setExecuteSortOrder(Integer.MAX_VALUE);
196+
commands.add(pathsCommand);
197+
189198
commands.add(new DeployHubQueryRolesetsCommand());
190199

191200
return commands;

marklogic-data-hub/src/main/resources/hub-internal-config/security/roles/data-hub-developer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,41 @@
2828
"action": "http://marklogic.com/xdmp/privileges/create-trigger",
2929
"kind": "execute"
3030
},
31+
{
32+
"privilege-name": "database-node-query-rolesets",
33+
"action": "http://marklogic.com/xdmp/privileges/database-node-query-rolesets",
34+
"kind": "execute"
35+
},
3136
{
3237
"privilege-name": "get-system-logs",
3338
"action": "http://marklogic.com/xdmp/privileges/logs/system",
3439
"kind": "execute"
3540
},
41+
{
42+
"privilege-name": "node-query-rolesets",
43+
"action": "http://marklogic.com/xdmp/privileges/node-query-rolesets",
44+
"kind": "execute"
45+
},
46+
{
47+
"privilege-name": "path-add-permissions",
48+
"action": "http://marklogic.com/xdmp/privileges/path-add-permissions",
49+
"kind": "execute"
50+
},
51+
{
52+
"privilege-name": "path-get-permissions",
53+
"action": "http://marklogic.com/xdmp/privileges/path-get-permissions",
54+
"kind": "execute"
55+
},
56+
{
57+
"privilege-name": "path-remove-permissions",
58+
"action": "http://marklogic.com/xdmp/privileges/path-remove-permissions",
59+
"kind": "execute"
60+
},
61+
{
62+
"privilege-name": "path-set-permissions",
63+
"action": "http://marklogic.com/xdmp/privileges/path-set-permissions",
64+
"kind": "execute"
65+
},
3666
{
3767
"privilege-name": "protect-path",
3868
"action": "http://marklogic.com/xdmp/privileges/protect-path",
@@ -57,6 +87,11 @@
5787
"privilege-name": "temporal-admin",
5888
"action": "http://marklogic.com/xdmp/privileges/temporal-admin",
5989
"kind": "execute"
90+
},
91+
{
92+
"privilege-name": "unprotect-path",
93+
"action": "http://marklogic.com/xdmp/privileges/unprotect-path",
94+
"kind": "execute"
6095
}
6196
]
6297
}

marklogic-data-hub/src/test/java/com/marklogic/hub/dhs/DeployAsDeveloperTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import com.marklogic.hub.DatabaseKind;
1919
import com.marklogic.hub.HubConfig;
2020
import com.marklogic.hub.HubTestBase;
21-
import com.marklogic.hub.dhs.installer.deploy.DeployHubQueryRolesetsCommand;
2221
import com.marklogic.hub.deploy.commands.LoadUserArtifactsCommand;
2322
import com.marklogic.hub.deploy.commands.LoadUserModulesCommand;
23+
import com.marklogic.hub.dhs.installer.deploy.DeployHubQueryRolesetsCommand;
2424
import com.marklogic.hub.impl.HubConfigImpl;
2525
import com.marklogic.hub.impl.HubProjectImpl;
2626
import org.junit.jupiter.api.BeforeEach;
@@ -172,7 +172,6 @@ public void buildCommandList() {
172172
List<Command> commands = new DhsDeployer().buildCommandsForDeveloper(hubConfig);
173173
Collections.sort(commands, Comparator.comparing(Command::getExecuteSortOrder));
174174
int index = 0;
175-
assertTrue(commands.get(index++) instanceof DeployProtectedPathsCommand);
176175
assertTrue(commands.get(index++) instanceof DeployHubQueryRolesetsCommand);
177176
assertTrue(commands.get(index++) instanceof DeployOtherDatabasesCommand);
178177
assertTrue(commands.get(index++) instanceof LoadSchemasCommand);
@@ -185,16 +184,22 @@ public void buildCommandList() {
185184
assertTrue(commands.get(index++) instanceof DeployAlertConfigsCommand);
186185
assertTrue(commands.get(index++) instanceof DeployAlertActionsCommand);
187186
assertTrue(commands.get(index++) instanceof DeployAlertRulesCommand);
187+
assertTrue(commands.get(index++) instanceof DeployProtectedPathsCommand);
188188
assertEquals(13, commands.size(),
189189
"As of ML 10.0-3, the granular privilege for indexes doesn't seem to work with XML payloads. " +
190190
"Bug https://bugtrack.marklogic.com/54231 has been created to track that. Thus, " +
191191
"DeployDatabaseFieldCommand cannot be included and ml-config/database-fields/final-database.xml " +
192192
"cannot be processed.");
193193

194-
DeployOtherDatabasesCommand dodc = (DeployOtherDatabasesCommand) commands.get(2);
194+
DeployOtherDatabasesCommand dodc = (DeployOtherDatabasesCommand) commands.get(1);
195195
ResourceFilenameFilter filter = (ResourceFilenameFilter) dodc.getResourceFilenameFilter();
196196
assertEquals("(staging|final|job)-database.json", filter.getIncludePattern().pattern(),
197197
"DHS users aren't allowed to create their own databases, so the command for deploying databases is restricted " +
198198
"to only updating the 3 known databases");
199+
200+
DeployProtectedPathsCommand pathsCommand = (DeployProtectedPathsCommand) commands.get(commands.size() - 1);
201+
assertEquals(Integer.MAX_VALUE, pathsCommand.getExecuteSortOrder(),
202+
"The PPs command is executed last to avoid the timing issue that occurs when a user without the 'security' " +
203+
"role deploys PPs and then QRs immediately afterwards");
199204
}
200205
}

marklogic-data-hub/src/test/java/com/marklogic/hub/security/DataHubDeveloperTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.marklogic.mgmt.SaveReceipt;
77
import com.marklogic.mgmt.api.database.Database;
88
import com.marklogic.mgmt.api.database.GeospatialElementIndex;
9+
import com.marklogic.mgmt.api.security.Role;
10+
import com.marklogic.mgmt.api.security.RolePrivilege;
911
import com.marklogic.mgmt.api.security.protectedpath.Permission;
1012
import com.marklogic.mgmt.api.security.protectedpath.ProtectedPath;
1113
import com.marklogic.mgmt.api.security.queryroleset.QueryRoleset;
@@ -16,6 +18,7 @@
1618
import com.marklogic.mgmt.resource.alert.AlertRuleManager;
1719
import com.marklogic.mgmt.resource.security.ProtectedPathManager;
1820
import com.marklogic.mgmt.resource.security.QueryRolesetManager;
21+
import com.marklogic.mgmt.resource.security.RoleManager;
1922
import com.marklogic.mgmt.resource.tasks.TaskManager;
2023
import com.marklogic.mgmt.resource.temporal.TemporalAxesManager;
2124
import com.marklogic.mgmt.resource.temporal.TemporalCollectionManager;
@@ -87,6 +90,8 @@ public void task9ConfigureBitemporal() throws IOException {
8790

8891
@Test
8992
public void task10CreateProtectedPaths() throws Exception {
93+
verifyRoleHasAllProtectedPathAndQueryRolesetPrivileges();
94+
9095
final String pathExpression = "/some/path";
9196
ProtectedPath path = new ProtectedPath(pathExpression);
9297
path.setPermission(Arrays.asList(new com.marklogic.mgmt.api.security.protectedpath.Permission("rest-reader", "read")));
@@ -116,6 +121,30 @@ public void task10CreateProtectedPaths() throws Exception {
116121
}
117122
}
118123

124+
private void verifyRoleHasAllProtectedPathAndQueryRolesetPrivileges() {
125+
Role role = resourceMapper.readResource(new RoleManager(adminUserClient).getPropertiesAsJson("data-hub-developer"), Role.class);
126+
List<RolePrivilege> privileges = role.getPrivilege();
127+
Arrays.asList("protect-path", "remove-path", "unprotect-path", "path-add-permissions", "path-get-permissions", "path-remove-permissions",
128+
"path-set-permissions", "add-query-rolesets", "remove-query-rolesets", "database-node-query-rolesets", "node-query-rolesets")
129+
.stream().forEach(privilegeName -> {
130+
131+
boolean found = false;
132+
for (RolePrivilege rp : privileges) {
133+
if (privilegeName.equals(rp.getPrivilegeName())) {
134+
found = true;
135+
break;
136+
}
137+
}
138+
assertTrue(found, "Did not find privilege: " + privilegeName + ". Due to the odd issue with protected paths " +
139+
"not working if query rolesets are deployed immediately after protected paths by a user without the " +
140+
"'security' role, all privileges related to PPs and QRs are granted to the data-hub-developer role to " +
141+
"minimize the chance of some other mysterious issue popping up. The Manage API appears to allow for " +
142+
"PPs to be deployed and deleted with just protect-path and remove-path, and for QRs to be deployed " +
143+
"and deleted with just add-query-rolesets and remove-query-rolesets, but we're granting all the privileges " +
144+
"just to be safe.");
145+
});
146+
}
147+
119148
@Test
120149
void task10CreateQueryRolesets() {
121150
final QueryRolesetManager mgr = new QueryRolesetManager(userWithRoleBeingTestedClient);

0 commit comments

Comments
 (0)