-
Notifications
You must be signed in to change notification settings - Fork 0
fix(portForwarding): serialize concurrent PF rule creation per VIP to prevent duplicates #3345
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
base: 5.5.6
Are you sure you want to change the base?
Changes from all commits
6b4521b
3b5bda3
80df074
a84a36e
f19223a
24d4f3b
f563992
6545350
76490a5
461e8a2
32e1e94
addec8c
26b8b1a
be53c72
e1dee9f
3bd062b
aaeaf39
f41558d
673be94
7f53f5a
72ce6ef
34bceb1
3e02188
799a84f
a82e14d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,10 @@ | |
| import org.zstack.header.storage.primary.PrimaryStorageInventory; | ||
| import org.zstack.utils.gson.JSONObjectUtil; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @Inventory(mappingVOClass = ExternalPrimaryStorageVO.class) | ||
|
|
@@ -59,6 +61,7 @@ public ExternalPrimaryStorageInventory(ExternalPrimaryStorageVO lvo) { | |
| super(lvo); | ||
| identity = lvo.getIdentity(); | ||
| config = JSONObjectUtil.toObject(lvo.getConfig(), LinkedHashMap.class); | ||
| desensitizeConfig(config); | ||
| addonInfo = JSONObjectUtil.toObject(lvo.getAddonInfo(), LinkedHashMap.class); | ||
| outputProtocols = lvo.getOutputProtocols().stream().map(PrimaryStorageOutputProtocolRefVO::getOutputProtocol).collect(Collectors.toList()); | ||
| defaultProtocol = lvo.getDefaultProtocol(); | ||
|
|
@@ -68,6 +71,35 @@ public static ExternalPrimaryStorageInventory valueOf(ExternalPrimaryStorageVO l | |
| return new ExternalPrimaryStorageInventory(lvo); | ||
| } | ||
|
|
||
| private static void desensitizeConfig(Map config) { | ||
| if (config == null) return; | ||
| desensitizeUrlList(config, "mdsUrls"); | ||
| desensitizeUrlList(config, "mdsInfos"); | ||
| } | ||
|
|
||
| private static void desensitizeUrlList(Map config, String key) { | ||
| Object urls = config.get(key); | ||
| if (urls instanceof List) { | ||
| List<String> desensitized = new ArrayList<>(); | ||
| for (Object url : (List) urls) { | ||
| desensitized.add(desensitizeUrl(String.valueOf(url))); | ||
| } | ||
| config.put(key, desensitized); | ||
| } | ||
| } | ||
|
|
||
| private static String desensitizeUrl(String url) { | ||
| int atIndex = url.lastIndexOf('@'); | ||
| if (atIndex > 0) { | ||
| int schemeIndex = url.indexOf("://"); | ||
| if (schemeIndex >= 0 && schemeIndex < atIndex) { | ||
| return url.substring(0, schemeIndex + 3) + "***" + url.substring(atIndex); | ||
| } | ||
| return "***" + url.substring(atIndex); | ||
| } | ||
| return url; | ||
|
Comment on lines
+91
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check if the file exists and read the relevant lines
wc -l header/src/main/java/org/zstack/header/storage/addon/primary/ExternalPrimaryStorageInventory.javaRepository: MatheMatrix/zstack Length of output: 163 🏁 Script executed: # Read the file around lines 91-100
sed -n '85,105p' header/src/main/java/org/zstack/header/storage/addon/primary/ExternalPrimaryStorageInventory.javaRepository: MatheMatrix/zstack Length of output: 701 🏁 Script executed: # Search for existing URL desensitization/masking/sanitization tools
rg -n --type=java -i 'desensit|mask.*url|sanitize.*url|redact.*url' -C 3Repository: MatheMatrix/zstack Length of output: 13125 🏁 Script executed: # Search for any URL related utility classes
fd -e java -type f -exec rg -l 'url.*desensit|url.*mask|url.*sanitize|url.*redact' {} \;Repository: MatheMatrix/zstack Length of output: 232 🏁 Script executed: # Look at the OtlpExporterProvider implementation
sed -n '40,80p' core/src/main/java/org/zstack/core/telemetry/OtlpExporterProvider.javaRepository: MatheMatrix/zstack Length of output: 1473 🏁 Script executed: # Search for more details about how desensitizeUrl is actually used
rg -n 'desensitizeUrl|mdsUrls|mdsInfos' --type java -C 5 header/src/main/java/org/zstack/header/storage/addon/primary/ExternalPrimaryStorageInventory.javaRepository: MatheMatrix/zstack Length of output: 1118 🏁 Script executed: # Check if java.net.URI is used anywhere in the codebase for URL parsing
rg -n 'new URI|URI\(' --type java | head -20Repository: MatheMatrix/zstack Length of output: 2911 使用 URI 解析而非字符串位置判断来实现 URL 凭据脱敏。 当前基于 建议改用 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| public String getIdentity() { | ||
| return identity; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1075,6 +1075,13 @@ private void handle(APIGetFreeIpMsg msg) { | |
| } | ||
| limit -= freeIpInventorys.size(); | ||
| } | ||
|
|
||
| Set<ReservedIpRangeVO> reservedIpRanges = self.getReservedIpRanges(); | ||
| if (reservedIpRanges != null && !reservedIpRanges.isEmpty()) { | ||
| freeIpInventorys.removeIf(freeIp -> reservedIpRanges.stream().anyMatch( | ||
| r -> NetworkUtils.isInRange(freeIp.getIp(), r.getStartIp(), r.getEndIp()))); | ||
| } | ||
|
Comment on lines
+1078
to
+1083
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IP 版本不匹配可能导致异常 当前代码在比较 free IP 与 reserved IP range 时,未按 IP 版本过滤。若 free IP 是 IPv4 而 reserved range 是 IPv6(或相反), 参考同文件第 486-487 行的已有模式,应先按 IP 版本过滤 reserved ranges: 🔧 建议修复 Set<ReservedIpRangeVO> reservedIpRanges = self.getReservedIpRanges();
if (reservedIpRanges != null && !reservedIpRanges.isEmpty()) {
- freeIpInventorys.removeIf(freeIp -> reservedIpRanges.stream().anyMatch(
- r -> NetworkUtils.isInRange(freeIp.getIp(), r.getStartIp(), r.getEndIp())));
+ freeIpInventorys.removeIf(freeIp -> reservedIpRanges.stream()
+ .filter(r -> r.getIpVersion() == freeIp.getIpVersion())
+ .anyMatch(r -> NetworkUtils.isInRange(freeIp.getIp(), r.getStartIp(), r.getEndIp())));
}🤖 Prompt for AI Agents |
||
|
|
||
| reply.setInventories(freeIpInventorys); | ||
|
|
||
| bus.reply(msg, reply); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 233
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 5508
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1570
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 3666
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1588
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 232
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1031
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2399
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 10639
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 3013
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2045
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 44
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 44
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 44
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 44
mdsInfos是List<Map>结构,当前实现会丢失字段。当
mdsInfos序列化后作为List<LinkedHashMap>存储在 config 中时,String.valueOf(map)会将 Map 对象转换成字符串表示(如{username=..., password=..., addr=...}),导致原有结构丢失,整项被替换为单一字符串。需要区分处理mdsUrls(List<String>)和mdsInfos(List<Map>),对 Map 类型的列表项保留结构并逐个脱敏其敏感字段。🔧 参考修复方式(需根据实际字段名调整)
private static void desensitizeUrlList(Map config, String key) { Object urls = config.get(key); if (urls instanceof List) { - List<String> desensitized = new ArrayList<>(); + List<Object> desensitized = new ArrayList<>(); for (Object url : (List) urls) { - desensitized.add(desensitizeUrl(String.valueOf(url))); + if (url instanceof Map) { + Map itemMap = new LinkedHashMap((Map) url); + if (itemMap.containsKey("username")) { + String username = String.valueOf(itemMap.get("username")); + itemMap.put("username", desensitizeUrl(username + "@dummy").substring(3)); + } + if (itemMap.containsKey("password")) { + itemMap.put("password", "***"); + } + desensitized.add(itemMap); + } else { + desensitized.add(desensitizeUrl(String.valueOf(url))); + } } config.put(key, desensitized); } }📝 Committable suggestion
🤖 Prompt for AI Agents