Skip to content

Fix direct download URL checks - #7693

Merged
yadvr merged 1 commit into
apache:4.18from
shapeblue:fix-direct-download-url-check-ca
Jul 6, 2023
Merged

Fix direct download URL checks#7693
yadvr merged 1 commit into
apache:4.18from
shapeblue:fix-direct-download-url-check-ca

Conversation

@nvazquez

Copy link
Copy Markdown
Contributor

Description

This PR fixes the URL check for direct downloads, in the case of HTTPS URLs the certificates were not loaded into the SSL context

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Tested on KVM with HTTPS, HTTP and metalink templates

@nvazquez

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 6341

@nvazquez

Copy link
Copy Markdown
ContributorAuthor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@nvazquez a [SF] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian Build Failed (tid-6870)

@kiranchavala

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@kiranchavala a [SF] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-6875)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 43331 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr7693-t6875-kvm-centos7.zip
Smoke tests completed. 101 look OK, 7 have errors, 0 did not run
Only failed and skipped tests results shown below:

TestResultTime (s)Test File
test_01_migrate_VM_and_root_volumeError77.66test_vm_life_cycle.py
test_02_migrate_VM_with_two_data_disksError58.57test_vm_life_cycle.py
test_10_attachAndDetach_isoError0.06test_vm_life_cycle.py
test_06_download_detached_volumeError301.86test_volumes.py
test_13_migrate_volume_and_change_offeringError125.80test_volumes.py
ContextSuite context=TestIpv6Vpc>:setupError0.00test_vpc_ipv6.py
ContextSuite context=TestVPCRedundancy>:setupError0.00test_vpc_redundant.py
ContextSuite context=TestVPCNics>:setupError0.00test_vpc_router_nics.py
ContextSuite context=TestRVPCSite2SiteVpn>:setupError0.00test_vpc_vpn.py
ContextSuite context=TestVPCSite2SiteVPNMultipleOptions>:setupError0.00test_vpc_vpn.py
ContextSuite context=TestVpcRemoteAccessVpn>:setupError0.00test_vpc_vpn.py
ContextSuite context=TestVpcSite2SiteVpn>:setupError0.00test_vpc_vpn.py
test_disable_oobm_ha_state_ineligibleError0.37test_hostha_kvm.py

@kiranchavalakiranchavala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Tested the issue with http, https and metalink template links and the directdownload link is working fine

Before the fix

2023-06-27 05:42:41,470 WARN [kvm.storage.KVMStorageProcessor] (agentRequest-Handler-5:null) (logid:96df14c1) Error downloading template 226 due to: Error on HTTPS request: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

After the fix

2023-06-27 11:02:09,364 DEBUG [cloud.agent.Agent] (agentRequest-Handler-3:null) (logid:c6e0ab18) Processing command: org.apache.cloudstack.agent.directdownload.HttpsDirectDownloadCommand
2023-06-27 11:02:09,364 DEBUG [storage.resource.StorageSubsystemCommandHandlerBase] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing command HttpsDirectDownloadCommand: [{"url":"https://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora-projects/fedora/linux/releases/37/Cloud/x86_64/images/Fedora-Cloud-Base-37-1.7.x86_64.qcow2","templateId":204,"destData":{"origUrl":"https://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora-projects/fedora/linux/releases/37/Cloud/x86_64/images/Fedora-Cloud-Base-37-1.7.x86_64.qcow2","uuid":"0a5a5582-a6d2-4566-af24-206568bcf354","id":204,"format":"QCOW2","accountId":2,"hvm":true,"displayText":"fedora3","imageDataStore":{"org.apache.cloudstack.storage.to.PrimaryDataStoreTO":{"uuid":"3c9ef251-b75d-3d2b-88ee-0122246e9f7e","name":"pr7693-t6872-kvm-centos7-kvm-pri1","id":1,"poolType":"NetworkFilesystem","host":"10.0.32.4","path":"/acs/primary/pr7693-t6872-kvm-centos7/pr7693-t6872-kvm-centos7-kvm-pri1","port":2049,"url":"NetworkFilesystem://10.0.32.4/acs/primary/pr7693-t6872-kvm-centos7/pr7693-t6872-kvm-centos7-kvm-pri1/?ROLE=Primary&STOREUUID=3c9ef251-b75d-3d2b-88ee-0122246e9f7e","isManaged":false}},"name":"204-2-54b96105-91a3-3d81-a34f-85692f07c72a","size":5368709120,"hypervisorType":"KVM","bootable":false,"uniqueName":"204-2-54b96105-91a3-3d81-a34f-85692f07c72a","directDownload":true,"deployAsIs":false},"destPool":{"uuid":"3c9ef251-b75d-3d2b-88ee-0122246e9f7e","name":"pr7693-t6872-kvm-centos7-kvm-pri1","id":1,"poolType":"NetworkFilesystem","host":"10.0.32.4","path":"/acs/primary/pr7693-t6872-kvm-centos7/pr7693-t6872-kvm-centos7-kvm-pri1","port":2049,"url":"NetworkFilesystem://10.0.32.4/acs/primary/pr7693-t6872-kvm-centos7/pr7693-t6872-kvm-centos7-kvm-pri1/?ROLE=Primary&STOREUUID=3c9ef251-b75d-3d2b-88ee-0122246e9f7e","isManaged":false},"headers":{},"connectTimeout":5000,"soTimeout":5000,"connectionRequestTimeout":5000,"templateSize":5368709120,"format":"QCOW2","wait":10800,"bypassHostMaintenance":false}].
2023-06-27 11:02:09,364 DEBUG [kvm.storage.KVMStorageProcessor] (agentRequest-Handler-3:null) (logid:c6e0ab18) Verifying temporary location for downloading the template exists on the host
2023-06-27 11:02:10,542 DEBUG [kvm.storage.KVMStorageProcessor] (agentRequest-Handler-3:null) (logid:c6e0ab18) Checking for free space on the host for downloading the template with physical size: 492830720 and virtual size: 5368709120
2023-06-27 11:02:10,543 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing: /bin/bash -c df --output=avail /var/lib/libvirt/images -B 1 | tail -1
2023-06-27 11:02:10,546 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing while with timeout : 3600000
2023-06-27 11:02:10,558 DEBUG [kvm.storage.LibvirtStorageAdaptor] (agentRequest-Handler-3:null) (logid:c6e0ab18) Successfully refreshed pool 3c9ef251-b75d-3d2b-88ee-0122246e9f7e Capacity: (1.9990 TB) 2197949513728 Used: (1.4938 TB) 1642465329152 Available: (517.33 GB) 555484184576
2023-06-27 11:02:10,558 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing: /bin/bash -c sed -n '/keystore.passphrase/p' '/etc/cloudstack/agent/agent.properties' 2>/dev/null | sed 's/keystore.passphrase=//g' 2>/dev/null
2023-06-27 11:02:10,561 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing while with timeout : 3600000
2023-06-27 11:02:10,565 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Execution is successful.
2023-06-27 11:02:10,585 DEBUG [kvm.storage.KVMStorageProcessor] (agentRequest-Handler-3:null) (logid:c6e0ab18) Trying to download template
2023-06-27 11:02:11,677 INFO [direct.download.DirectTemplateDownloaderImpl] (agentRequest-Handler-3:null) (logid:c6e0ab18) Downloading template 204 from https://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora-projects/fedora/linux/releases/37/
Cloud/x86_64/images/Fedora-Cloud-Base-37-1.7.x86_64.qcow2 to: /var/lib/libvirt/images/template/2/204/Fedora-Cloud-Base-37-1.7.x86_64.qcow2
2023-06-27 11:03:54,376 INFO [direct.download.DirectTemplateDownloaderImpl] (agentRequest-Handler-3:null) (logid:c6e0ab18) No checksum provided, skipping checksum validation
2023-06-27 11:03:54,379 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing: /bin/bash -c file /var/lib/libvirt/images/template/2/204/Fedora-Cloud-Base-37-1.7.x86_64.qcow2 | awk -F' ' '{print $2}'
2023-06-27 11:03:54,382 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing while with timeout : 3600000
2023-06-27 11:03:54,388 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Execution is successful.
2023-06-27 11:03:54,389 DEBUG [utils.script.Script] (agentRequest-Handler-3:null) (logid:c6e0ab18) Executing: /bin/bash -c mv /var/lib/libvirt/images/template/2/204/Fedora-Cloud-Base-37-1.7.x86_64.qcow2 /mnt/3c9ef251-b75d-3d2b-88ee-0122246e9f7e/a76d363c-ba0f-47e3-bfd3-10448127ec1d

@shwstpprshwstppr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Though the effective change/improvement is to load custom and system-trusted SSL certificates while checking accessibility and getting the size for a direct-download QCOW2 template, a lot of refactoring was needed to achieve that.

Tested with a HTTPS template URL and can see it getting registered without errors.

@weizhouapacheweizhouapache left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

@codecov

codecovBot commented Jun 28, 2023

Copy link
Copy Markdown

Codecov Report

Merging #7693 (eff5ce9) into 4.18 (985f0ec) will increase coverage by 0.00%.
The diff coverage is 0.00%.

@@ Coverage Diff @@## 4.18 #7693 +/- ##
=========================================
Coverage 13.00% 13.01% - Complexity 9013 9015 +2 
=========================================
Files 2719 2719 Lines 256854 256836 -18 Branches 40048 40045 -3 =========================================
+ Hits 33413 33418 +5 + Misses 219255 219231 -24 - Partials 4186 4187 +1 
Impacted FilesCoverage Δ
...r/kvm/resource/wrapper/LibvirtCheckUrlCommand.java22.22% <0.00%> (+8.88%)⬆️
...ud/hypervisor/kvm/storage/KVMStorageProcessor.java5.02% <0.00%> (+0.04%)⬆️
...n/java/com/cloud/storage/VolumeApiServiceImpl.java15.28% <0.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@yadvr
yadvr marked this pull request as ready for review June 30, 2023 14:36
@yadvr

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rohityadavcloud a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 6374

@yadvr

yadvr commented Jul 3, 2023

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@rohityadavcloud a [SF] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@yadvryadvr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM didn't test it, need to pass smoketests

@DaanHooglandDaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new files don't end with a new line. Can you add those?

}
}

private SSLContext getSSLContext() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are nested try statements in this method. I think it can do with some restructuring.

private SSLContext getSSLContext() {
try {
KeyStore customKeystore = KeyStore.getInstance("jks");
try (FileInputStream instream = new FileInputStream(new File("/etc/cloudstack/agent/cloud.jks"))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this move to a separate method?

KeyStore defaultKeystore = KeyStore.getInstance(KeyStore.getDefaultType());
String relativeCacertsPath = "/lib/security/cacerts".replace("/", File.separator);
String filename = System.getProperty("java.home") + relativeCacertsPath;
try (FileInputStream is = new FileInputStream(filename)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this load to a separate method as well?

return Iterables.getFirst(Iterables.filter(
Arrays.asList(factory.getTrustManagers()), X509TrustManager.class), null);
} catch (NoSuchAlgorithmException | KeyStoreException e) {
e.printStackTrace();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not logging, but error output?

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-6937)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 44508 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr7693-t6937-kvm-centos7.zip
Smoke tests completed. 107 look OK, 1 have errors, 0 did not run
Only failed and skipped tests results shown below:

TestResultTime (s)Test File
test_01_migrate_VM_and_root_volumeError79.71test_vm_life_cycle.py
test_02_migrate_VM_with_two_data_disksError53.34test_vm_life_cycle.py

@yadvr
yadvr merged commit c733a23 into apache:4.18Jul 6, 2023
@yadvr
yadvr deleted the fix-direct-download-url-check-ca branch July 6, 2023 08:17
@DaanHoogland

Copy link
Copy Markdown
Contributor

@rohityadavcloud , that was an premature merge. I have some comments out that should be addressed!

@DaanHoogland

Copy link
Copy Markdown
Contributor

@rohityadavcloud , that was an premature merge. I have some comments out that should be addressed!

cc @nvazquez

@weizhouapache

Copy link
Copy Markdown
Member

this could be fixed by #7923

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@nvazquez@blueorangutan@kiranchavala@yadvr@DaanHoogland@weizhouapache@shwstppr