-
Notifications
You must be signed in to change notification settings - Fork 1
[RMZ-413] upgrade runner ACL lead to server error on ACL dataset management #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jreynard-code
merged 4 commits into
release/v3.1
from
JREY/RMZ-413-dataset-acl-modification-runner
Nov 21, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bcd1522
[RMZ-413] upgrade runner ACL lead to server error on ACL dataset mana…
jreynard-code 4d92061
Remove not necessary check on ownership in dataset deletion endpoint
jreynard-code 46a3bae
Upgrade cosmotech-api-common version from 0.3.2 to 0.3.3
jreynard-code 6c737eb
[RMZ-413] Fix after dev review
jreynard-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ import io.mockk.junit5.MockKExtension | |
| import io.mockk.mockk | ||
| import io.mockk.mockkStatic | ||
| import java.util.* | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import org.junit.jupiter.api.BeforeEach | ||
| import org.junit.jupiter.api.DynamicTest.dynamicTest | ||
|
|
@@ -2776,76 +2777,140 @@ class RunnerServiceRBACTest : CsmRedisTestBase() { | |
| } | ||
|
|
||
| @TestFactory | ||
| fun `test Dataset RBAC addRunnerAccessControl`() = | ||
| mapOf( | ||
| ROLE_VIEWER to true, | ||
| ROLE_EDITOR to true, | ||
| ROLE_VALIDATOR to true, | ||
| ROLE_USER to true, | ||
| ROLE_NONE to true, | ||
| ROLE_ADMIN to false, | ||
| fun `test Dataset RBAC modification when addRunnerAccessControl is called on a runner`() = | ||
| listOf( | ||
| ROLE_VIEWER, | ||
| ROLE_EDITOR, | ||
| ROLE_VALIDATOR, | ||
| ROLE_USER, | ||
| ROLE_NONE, | ||
| ROLE_ADMIN, | ||
| ) | ||
| .map { (role, shouldThrow) -> | ||
| dynamicTest("Test Dataset RBAC addRunnerAccessControl : $role") { | ||
| every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER | ||
| val connector = makeConnector() | ||
| val connectorSaved = connectorApiService.registerConnector(connector) | ||
| val organization = makeOrganizationWithRole(id = TEST_USER_MAIL, role = ROLE_ADMIN) | ||
| val organizationSaved = organizationApiService.registerOrganization(organization) | ||
| val dataset = | ||
| makeDataset(organizationSaved.id!!, connectorSaved, TEST_USER_MAIL, role) | ||
| var datasetSaved = datasetApiService.createDataset(organizationSaved.id!!, dataset) | ||
| datasetSaved = | ||
| datasetRepository.save( | ||
| datasetSaved.apply { ingestionStatus = Dataset.IngestionStatus.SUCCESS }) | ||
| every { datasetApiService.createSubDataset(any(), any(), any()) } returns datasetSaved | ||
| val solution = makeSolution(organizationSaved.id!!, TEST_USER_MAIL, ROLE_ADMIN) | ||
| val solutionSaved = | ||
| solutionApiService.createSolution(organizationSaved.id!!, solution) | ||
| val workspace = | ||
| makeWorkspaceWithRole( | ||
| organizationSaved.id!!, | ||
| solutionSaved.id!!, | ||
| id = TEST_USER_MAIL, | ||
| role = ROLE_ADMIN) | ||
| val workspaceSaved = | ||
| workspaceApiService.createWorkspace(organizationSaved.id!!, workspace) | ||
| val runner = | ||
| makeRunnerWithRole( | ||
| organizationSaved.id!!, | ||
| workspaceSaved.id!!, | ||
| solutionSaved.id!!, | ||
| mutableListOf(datasetSaved.id!!), | ||
| id = TEST_USER_MAIL, | ||
| role = ROLE_ADMIN) | ||
| val runnerSaved = | ||
| runnerApiService.createRunner(organizationSaved.id!!, workspaceSaved.id!!, runner) | ||
| every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL | ||
|
|
||
| if (shouldThrow) { | ||
| val exception = | ||
| assertThrows<CsmAccessForbiddenException> { | ||
| runnerApiService.addRunnerAccessControl( | ||
| .map { role -> | ||
| dynamicTest( | ||
| "Check Dataset RBAC modification " + | ||
| "when addRunnerAccessControl is called on a runner with role : $role") { | ||
| every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER | ||
| val connector = makeConnector() | ||
| val connectorSaved = connectorApiService.registerConnector(connector) | ||
| val organization = | ||
| makeOrganizationWithRole(id = TEST_USER_MAIL, role = ROLE_ADMIN) | ||
| val organizationSaved = organizationApiService.registerOrganization(organization) | ||
| val dataset = | ||
| makeDataset(organizationSaved.id!!, connectorSaved, TEST_USER_MAIL, role) | ||
| var datasetSaved = | ||
| datasetApiService.createDataset(organizationSaved.id!!, dataset) | ||
| datasetSaved = | ||
| datasetRepository.save( | ||
| datasetSaved.apply { ingestionStatus = Dataset.IngestionStatus.SUCCESS }) | ||
| every { datasetApiService.createSubDataset(any(), any(), any()) } returns | ||
| datasetSaved | ||
| val solution = makeSolution(organizationSaved.id!!, TEST_USER_MAIL, ROLE_ADMIN) | ||
| val solutionSaved = | ||
| solutionApiService.createSolution(organizationSaved.id!!, solution) | ||
| val workspace = | ||
| makeWorkspaceWithRole( | ||
| organizationSaved.id!!, | ||
| solutionSaved.id!!, | ||
| id = TEST_USER_MAIL, | ||
| role = ROLE_ADMIN) | ||
| val workspaceSaved = | ||
| workspaceApiService.createWorkspace(organizationSaved.id!!, workspace) | ||
| val runner = | ||
| makeRunnerWithRole( | ||
| organizationSaved.id!!, | ||
| workspaceSaved.id!!, | ||
| runnerSaved.id!!, | ||
| RunnerAccessControl("id", ROLE_ADMIN)) | ||
| } | ||
| assertEquals( | ||
| "RBAC ${datasetSaved.id!!} - User does not have permission $PERMISSION_WRITE_SECURITY", | ||
| exception.message) | ||
| } else { | ||
| assertDoesNotThrow { | ||
| runnerApiService.addRunnerAccessControl( | ||
| organizationSaved.id!!, | ||
| workspaceSaved.id!!, | ||
| runnerSaved.id!!, | ||
| RunnerAccessControl("id", ROLE_ADMIN)) | ||
| solutionSaved.id!!, | ||
| mutableListOf(datasetSaved.id!!), | ||
| id = TEST_USER_MAIL, | ||
| role = ROLE_ADMIN) | ||
| val runnerSaved = | ||
| runnerApiService.createRunner( | ||
| organizationSaved.id!!, workspaceSaved.id!!, runner) | ||
|
|
||
| assertDoesNotThrow { | ||
| assertEquals( | ||
| true, | ||
| datasetSaved.security | ||
| ?.accessControlList | ||
| ?.filter { datasetAccessControl -> | ||
| datasetAccessControl.id == TEST_USER_MAIL | ||
| } | ||
| ?.any { datasetAccessControl -> datasetAccessControl.role == role }) | ||
|
|
||
| runnerApiService.addRunnerAccessControl( | ||
| organizationSaved.id!!, | ||
| workspaceSaved.id!!, | ||
| runnerSaved.id!!, | ||
| RunnerAccessControl(TEST_USER_MAIL, ROLE_ADMIN)) | ||
|
|
||
| val datasetWithUpgradedACL = | ||
| datasetApiService.findDatasetById(organizationSaved.id!!, datasetSaved.id!!) | ||
| assertEquals( | ||
| true, | ||
| datasetWithUpgradedACL.security | ||
| ?.accessControlList | ||
| ?.filter { datasetAccessControl -> | ||
| datasetAccessControl.id == TEST_USER_MAIL | ||
| } | ||
| ?.any { datasetAccessControl -> datasetAccessControl.role == role }) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `test addRunnerAccessControl when called on a runner with an user that do not exist in Dataset RBAC`() { | ||
| every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER | ||
| val connector = makeConnector() | ||
| val connectorSaved = connectorApiService.registerConnector(connector) | ||
| val organization = makeOrganizationWithRole(id = TEST_USER_MAIL, role = ROLE_ADMIN) | ||
| val organizationSaved = organizationApiService.registerOrganization(organization) | ||
| val dataset = | ||
| makeDataset( | ||
| organizationSaved.id!!, connectorSaved, id = "[email protected]", role = ROLE_NONE) | ||
| var datasetSaved = datasetApiService.createDataset(organizationSaved.id!!, dataset) | ||
| datasetSaved = | ||
| datasetRepository.save( | ||
| datasetSaved.apply { ingestionStatus = Dataset.IngestionStatus.SUCCESS }) | ||
| every { datasetApiService.createSubDataset(any(), any(), any()) } returns datasetSaved | ||
|
|
||
| assertEquals( | ||
| false, | ||
| datasetSaved.security?.accessControlList?.any { datasetAccessControl -> | ||
| datasetAccessControl.id == TEST_USER_MAIL | ||
| }) | ||
|
|
||
| val solution = makeSolution(organizationSaved.id!!, TEST_USER_MAIL, ROLE_ADMIN) | ||
| val solutionSaved = solutionApiService.createSolution(organizationSaved.id!!, solution) | ||
| val workspace = | ||
| makeWorkspaceWithRole( | ||
| organizationSaved.id!!, solutionSaved.id!!, id = TEST_USER_MAIL, role = ROLE_ADMIN) | ||
| val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id!!, workspace) | ||
| val runner = | ||
| makeRunnerWithRole( | ||
| organizationSaved.id!!, | ||
| workspaceSaved.id!!, | ||
| solutionSaved.id!!, | ||
| mutableListOf(datasetSaved.id!!), | ||
| id = "[email protected]", | ||
| role = ROLE_ADMIN) | ||
| val runnerSaved = | ||
| runnerApiService.createRunner(organizationSaved.id!!, workspaceSaved.id!!, runner) | ||
|
|
||
| runnerApiService.addRunnerAccessControl( | ||
| organizationSaved.id!!, | ||
| workspaceSaved.id!!, | ||
| runnerSaved.id!!, | ||
| RunnerAccessControl(TEST_USER_MAIL, ROLE_ADMIN)) | ||
| val datasetWithUpgradedACL = | ||
| datasetApiService.findDatasetById(organizationSaved.id!!, datasetSaved.id!!) | ||
| assertEquals( | ||
| true, | ||
| datasetWithUpgradedACL.security?.accessControlList?.any { datasetAccessControl -> | ||
| datasetAccessControl.id == TEST_USER_MAIL | ||
| }) | ||
| } | ||
|
|
||
| @TestFactory | ||
| fun `test Solution RBAC addRunnerAccessControl`() = | ||
| mapOf( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.