fix: scope discovery update and delete by namespace (#6827) - #7007
Open
wy471x wants to merge 1 commit into
Open
Conversation
Add namespace_id predicates to the discovery update, updateSelective
and delete statements so that discovery configs can only be modified
within the caller's namespace. DiscoveryService#delete now validates
the namespace of the target discovery before processing, and the
DELETE /discovery/{discoveryId} endpoint requires a namespaceId
parameter and plugin edit/delete permissions.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary
Changes:
discovery-sqlmap.xml— addedAND namespace_id = #{namespaceId, jdbcType=VARCHAR}to the WHERE clauses ofupdate(:217),updateSelective(:248) anddelete(:254), so discovery mutations are scoped to the caller's namespace;deletenow takes(id, namespaceId)parameters.DiscoveryMapper.java:134—delete(String id)changed todelete(@Param("id") String id, @Param("namespaceId") String namespaceId).DiscoveryServiceImpl.java:192-206—deleteacceptsnamespaceIdand verifies the selectedDiscoveryDObelongs to the requested namespace before invoking the discovery processor, so cross-namespace ids produce no registry side effects (also fixes a potential NPE when the id does not exist); the mapper delete is then called with the scoped predicate.SelectorServiceImpl.java:332/ProxySelectorServiceImpl.java:184— internal cleanup paths passdiscoveryDO.getNamespaceId()(the DO is freshly loaded from DB, so the value is authoritative).DiscoveryController.java—DELETE /discovery/{discoveryId}now requires anamespaceIdrequest parameter (validated via@Existed(NamespaceMapper)); added@RequiresPermissions("system:plugin:edit")toinsertOrUpdateand@RequiresPermissions("system:plugin:delete")todelete, consistent with the Selector/Rule controllers.Test Cases:
DiscoveryMapperTest— H2 integration tests:delete/update/updateSelectivewith a mismatched namespace mutate 0 rows; with a matching namespace they mutate only the target row and leave the other namespace's row intact.DiscoveryServiceImplTest— delete succeeds in the matching namespace; throwsShenyuExceptionwith no processor/mapper side effects on namespace mismatch or when the discovery does not exist.Verification
./mvnw clean install -Dmaven.javadoc.skip=truepassed locally (JDK 21).DiscoveryMapperTest,DiscoveryServiceImplTest,SelectorServiceTest,ProxySelectorServiceTest).checkstyle:checkpassed.Note: the dashboard frontend (apache/shenyu-dashboard) currently calls
DELETE /discovery/{id}without anamespaceId; a follow-up in that repository is needed to pass the current namespace.close #6827
related pr: #596