[ZSTAC-65483][4.8.38] Mask invalid userdata tag#4304
Conversation
Malformed userdata can break the sensitive-output masking path when Rest.maskSensitiveInfo is enabled. The handler now falls back to replacing the whole userdata token if YAML parsing fails, preserving query success without exposing plaintext. Constraint: ZStack 4.8.38 verification must run inside PR docker instead of host Maven Rejected: Return original tag on YAML parse failure | would keep plaintext userdata visible when masking is enabled Confidence: high Scope-risk: narrow Tested: Docker verify-case: mvn -pl compute,testlib -am -DskipTests -DskipJacoco=true install; mvn test -Dtest=org.zstack.test.userdata.TestUserdataTagOutputHandler -Dsurefire.useFile=false -DskipJacoco=true Not-tested: Full CI pipeline Resolves: ZSTAC-65483 Change-Id: Icd82dcc2f8ec8972e6b238f9e9a63186facfe1a3
概览在 变更内容userdata 脱敏异常处理与测试
估计代码审查难度🎯 2 (Simple) | ⏱️ ~10 minutes 小诗
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@test/src/test/java/org/zstack/test/userdata/TestUserdataTagOutputHandler.java`:
- Line 12: The test class `TestUserdataTagOutputHandler` does not follow the
naming convention which requires test classes to end with `Test` or `Case`
suffix. Rename the class from `TestUserdataTagOutputHandler` to
`UserdataTagOutputHandlerTest` and also rename the file accordingly from
`TestUserdataTagOutputHandler.java` to `UserdataTagOutputHandlerTest.java` to
maintain consistency with the coding guidelines and standard test naming
conventions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8a8e8df7-41aa-431a-b74a-740e38390784
📒 Files selected for processing (2)
compute/src/main/java/org/zstack/compute/vm/VmSystemTags.javatest/src/test/java/org/zstack/test/userdata/TestUserdataTagOutputHandler.java
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class TestUserdataTagOutputHandler { |
There was a problem hiding this comment.
测试类命名未满足约定后缀。
TestUserdataTagOutputHandler 未以 Test 或 Case 结尾,建议重命名为 UserdataTagOutputHandlerTest(并同步文件名),以保持测试命名一致性。
As per coding guidelines, “测试类需要以 Test 或 Case 结尾”。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@test/src/test/java/org/zstack/test/userdata/TestUserdataTagOutputHandler.java`
at line 12, The test class `TestUserdataTagOutputHandler` does not follow the
naming convention which requires test classes to end with `Test` or `Case`
suffix. Rename the class from `TestUserdataTagOutputHandler` to
`UserdataTagOutputHandlerTest` and also rename the file accordingly from
`TestUserdataTagOutputHandler.java` to `UserdataTagOutputHandlerTest.java` to
maintain consistency with the coding guidelines and standard test naming
conventions.
Source: Coding guidelines
Summary
Fix HTTP 500 when querying userdata system tags with
Rest.maskSensitiveInfoenabled and malformed userdata content.Root Cause
VmSystemTags.UserdataTagOutputHandlerdecoded userdata and parsed it as YAML without handling SnakeYAML runtime parse errors. If the userdata looked like cloud-config but had invalid indentation, the sensitive-output masking path threw during query response serialization.Change
*****when parsing fails, avoiding both the API 500 and plaintext exposure.chpasswd.liststructured masking.Verification
Ran in PR Docker through
scripts/verify-case-docker.sh:Result:
Risk
Scope is limited to userdata sensitive tag output masking. Full CI pending.
Resolves: ZSTAC-65483
sync from gitlab !10262