-
Notifications
You must be signed in to change notification settings - Fork 20
Pass proxy from environment to jvm args #173
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
Conversation
It was reported that proxy setup from environment variables is not correctly recognized by jdtls. The jdtls startup python script now transforms those settings to JVM parameters. Fixes: konveyor#172 Signed-off-by: Marek Aufart <maufart@redhat.com>
WalkthroughAdded a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
jdtls-bin-override/jdtls.py (1)
113-117: Consider handling additional NO_PROXY separators.The current implementation converts comma-separated NO_PROXY values to pipe-separated format for Java. However, some environments use spaces, semicolons, or mixed separators in NO_PROXY. Consider normalizing these as well for broader compatibility.
Example enhancement:
# NO_PROXY / Non-proxy hosts no_proxy = os.environ.get('NO_PROXY') or os.environ.get('no_proxy') if no_proxy: - # Convert comma-separated list to pipe-separated for Java - no_proxy_hosts = no_proxy.replace(',', '|') + # Convert various separators to pipe-separated for Java + import re + no_proxy_hosts = re.sub(r'[,\s;]+', '|', no_proxy.strip()) jvm_args.append(f'-Dhttp.nonProxyHosts={no_proxy_hosts}')jdtls-bin-override/test_jdtls.py (1)
10-180: Excellent test coverage with comprehensive scenarios.The test suite covers all major cases including:
- Basic proxy configurations (HTTP/HTTPS with/without ports)
- Case sensitivity and precedence rules
- Authentication credentials
- NO_PROXY handling
- Edge cases (missing schemes, invalid URLs, empty values)
Consider adding test for special characters in credentials.
Proxy passwords may contain special characters that require URL encoding (e.g.,
@,:,/,?,%). Consider adding a test to verify these are handled correctly byurlparse.Example test to add:
def test_proxy_with_special_characters_in_password(self): """Test proxy with special characters in password.""" with patch.dict(os.environ, {'HTTP_PROXY': 'http://user:p@ss%2Fw0rd@proxy.example.com:8080'}, clear=True): result = get_proxy_jvm_args() assert '-Dhttp.proxyHost=proxy.example.com' in result assert '-Dhttp.proxyPort=8080' in result assert '-Dhttp.proxyUser=user' in result # urlparse should decode the password assert '-Dhttp.proxyPassword=p@ss/w0rd' in result
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
jdtls-bin-override/jdtls.py(3 hunks)jdtls-bin-override/test_jdtls.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
jdtls-bin-override/test_jdtls.py (1)
jdtls-bin-override/jdtls.py (1)
get_proxy_jvm_args(73-119)
🔇 Additional comments (4)
jdtls-bin-override/jdtls.py (3)
21-21: LGTM: Import added for proxy URL parsing.The
urlparseimport is correctly placed and necessary for parsing proxy environment variables.
155-155: LGTM: Proxy arguments correctly integrated into JVM startup.The proxy arguments are properly positioned between base JVM arguments and user-provided arguments, allowing users to override proxy settings if needed via
--jvm-arg.
89-92: Add documentation warning about proxy credential visibility in process listings.The concern is valid: proxy passwords in
jdtls.pylines 89-92 and 108-110 are passed as JVM arguments (-Dhttp.proxyPassword/-Dhttps.proxyPassword), making them visible in process listings. This follows Java's standard proxy configuration approach but represents a security trade-off in less trusted environments.Add a comment above the
get_proxy_jvm_args()function documenting this limitation, e.g.: "Note: proxy credentials are passed as JVM arguments and will be visible in process listings. This is Java's standard proxy configuration mechanism but consider alternatives in sensitive environments."jdtls-bin-override/test_jdtls.py (1)
1-8: LGTM: Test suite structure is well-organized.The test suite uses appropriate imports and follows pytest conventions with clear test class organization and descriptive docstrings.
|
|
||
| def test_proxy_without_scheme(self): | ||
| """Test proxy URL without scheme (should add default scheme).""" | ||
| with patch.dict(os.environ, {'HTTP_PROXY': 'proxy.example.com:8080'}, clear=True): |
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.
Supporting also proxy without scheme prefix (http:// or https:// based on variable it is read from).
|
@aufi I think this is good change, I do wonder if we could use: Furthermore, If this is run in a container in kantra, then we need to verify kantra sets the proxy env vars on the container or the provider config. Also I am pretty sure, that you should also change: https://github.com/konveyor/analyzer-lsp/blob/main/external-providers/java-external-provider/pkg/java_external_provider/provider.go#L386 as we no longer use the the python script. |
Proxy setting with `-Djava...Proxies=true` was placed in args after `jar` which was most likely ignored by JVM. Changing its order to ensure its understood correctly by JVM running jdtls. Replaces konveyor/java-analyzer-bundle#173 Fixes: konveyor#172 Signed-off-by: Marek Aufart <maufart@redhat.com>
|
Thanks for input @shawn-hurley! actually it looks args were passed correctly from analyzer's external java provider, just in wrong order, so JVM ignored it. Should be solved with konveyor/analyzer-lsp#978 |
Proxy setting with `-Djava...Proxies=true` was placed in args after `jar` which was most likely ignored by JVM. Changing its order to ensure its understood correctly by JVM running jdtls. Replaces konveyor/java-analyzer-bundle#173 Fixes: konveyor/java-analyzer-bundle#172 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed Java application launcher argument ordering to ensure system proxy settings are correctly applied before the application runs. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Marek Aufart <maufart@redhat.com>
Proxy setting with `-Djava...Proxies=true` was placed in args after `jar` which was most likely ignored by JVM. Changing its order to ensure its understood correctly by JVM running jdtls. Replaces konveyor/java-analyzer-bundle#173 Fixes: konveyor/java-analyzer-bundle#172 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed Java application launcher argument ordering to ensure system proxy settings are correctly applied before the application runs. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Marek Aufart <maufart@redhat.com> Signed-off-by: Cherry Picker <noreply@github.com>
Proxy setting with `-Djava...Proxies=true` was placed in args after `jar` which was most likely ignored by JVM. Changing its order to ensure its understood correctly by JVM running jdtls. Replaces konveyor/java-analyzer-bundle#173 Fixes: konveyor/java-analyzer-bundle#172 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed Java application launcher argument ordering to ensure system proxy settings are correctly applied before the application runs. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Marek Aufart <maufart@redhat.com> Signed-off-by: Cherry Picker <noreply@github.com> Signed-off-by: Marek Aufart <maufart@redhat.com> Signed-off-by: Cherry Picker <noreply@github.com> Co-authored-by: Marek Aufart <aufi.cz@gmail.com>
It was reported that proxy setup from environment variables is not correctly recognized by jdtls.
The jdtls startup python script now transforms those settings to JVM parameters.
Fixes: #172
Created mostly with claude code assistant.
Summary by CodeRabbit
Release Notes
New Features
Tests