helm icon indicating copy to clipboard operation
helm copied to clipboard

Helm pull fails if pulling from a repository that redirects to another domain

Open wahabmk opened this issue 5 years ago • 4 comments

Output of helm version:

version.BuildInfo{Version:"v3.5.1", GitCommit:"32c22239423b3b4ba6706d450bd044baffdcf9e6", GitTreeState:"clean", GoVersion:"go1.15.7"}

Output of kubectl version: Not applicable.

Cloud Provider/Platform (AKS, GKE, Minikube etc.): Using AWS S3 to host Helm charts.

Background:

I have a Helm registry set up that uses Cloud storage (AWS S3 in this case) to store Helm charts. When the server receives a GET request for a chart, it responds with HTTP temporary redirect (307) with Location in the response header.

This works fine with curl:

$ curl -L https://172.31.33.149/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz -u $USER:$PASSWORD -o testchartA-0.1.0.tgz --cacert ca.crt  -v
*   Trying 172.31.33.149...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 172.31.33.149 (172.31.33.149) port 443 (#0)
* found 1 certificates in ca.crt
* found 552 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_ECDSA_AES_256_GCM_SHA384
* 	 server certificate verification OK
* 	 server certificate status verification SKIPPED
* error fetching CN from cert:The requested data were not available.
* 	 common name:  (matched)
* 	 server certificate expiration date OK
* 	 server certificate activation date OK
* 	 certificate public key: EC
* 	 certificate version: #3
* 	 subject: C=US,L=San Francisco,O=Docker,OU=Docker
* 	 start date: Tue, 02 Feb 2021 20:27:11 GMT
* 	 expire date: Wed, 02 Feb 2022 20:27:11 GMT
* 	 issuer: C=US,L=San Francisco,O=Docker,OU=Docker
* 	 compression: NULL
* ALPN, server accepted to use http/1.1
* Server auth using Basic with user 'admin'
> GET /charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz HTTP/1.1
> Host: 172.31.33.149
> Authorization: Basic YWRtaW46cGFzc3dvcmQxMjM0
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 307 Temporary Redirect
< Server: nginx/1.18.0
< Date: Thu, 04 Feb 2021 00:07:43 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 423
< Connection: keep-alive
< Cache-Control: max-age=0, no-cache
< Location: https://s3.ap-south-1.amazonaws.com/msrtest/msr/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWQUPBQZXRD2WG4UI%2F20210204%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20210204T000743Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=3462325a83301fe14d58b4018e721392ece3c3942038ff0a59d5c3fc7cafacc8
< Strict-Transport-Security: max-age=63072000; includeSubdomains
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self'; connect-src 'self'; font-src 'self'; object-src 'none'; media-src 'self'; form-action 'self'; frame-ancestors 'self';
< X-Replica-ID: 5b00d17a80d7
< 
* Ignoring the response-body
{ [423 bytes data]
100   423  100   423    0     0   2428      0 --:--:-- --:--:-- --:--:--  2445
* Connection #0 to host 172.31.33.149 left intact
* Issue another request to this URL: 'https://s3.ap-south-1.amazonaws.com/msrtest/msr/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWQUPBQZXRD2WG4UI%2F20210204%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20210204T000743Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=3462325a83301fe14d58b4018e721392ece3c3942038ff0a59d5c3fc7cafacc8'
*   Trying 52.219.66.105...
* Connected to s3.ap-south-1.amazonaws.com (52.219.66.105) port 443 (#1)
* found 1 certificates in ca.crt
* found 552 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
* 	 server certificate verification OK
* 	 server certificate status verification SKIPPED
* 	 common name: *.s3.ap-south-1.amazonaws.com (matched)
* 	 server certificate expiration date OK
* 	 server certificate activation date OK
* 	 certificate public key: RSA
* 	 certificate version: #3
* 	 subject: C=US,ST=Washington,L=Seattle,O=Amazon.com\, Inc.,CN=*.s3.ap-south-1.amazonaws.com
* 	 start date: Tue, 28 Jan 2020 00:00:00 GMT
* 	 expire date: Wed, 14 Apr 2021 12:00:00 GMT
* 	 issuer: C=US,O=DigiCert Inc,OU=www.digicert.com,CN=DigiCert Baltimore CA-2 G2
* 	 compression: NULL
* ALPN, server did not agree to a protocol
> GET /msrtest/msr/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWQUPBQZXRD2WG4UI%2F20210204%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20210204T000743Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=3462325a83301fe14d58b4018e721392ece3c3942038ff0a59d5c3fc7cafacc8 HTTP/1.1
> Host: s3.ap-south-1.amazonaws.com
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< x-amz-id-2: j/5HkfSTjZoHUsZEhOmMr6kWzhNBo2I3JgtDx+1q/ruFw9IKi6ucqE5/LASvwSArefYVO/Lt5Gw=
< x-amz-request-id: 141C6EDCE8E1DDE5
< Date: Thu, 04 Feb 2021 00:07:44 GMT
< Last-Modified: Tue, 02 Feb 2021 22:04:29 GMT
< ETag: "aba1fb259faa7143e33a5cd114331df2"
< Accept-Ranges: bytes
< Content-Type: application/octet-stream
< Content-Length: 3893
< Server: AmazonS3
< 
{ [3893 bytes data]
100  3893  100  3893    0     0  15912      0 --:--:-- --:--:-- --:--:-- 15912
* Connection #1 to host s3.ap-south-1.amazonaws.com left intact

The "x509: cannot validate certificate" problem: However, with helm pull, I receive the following error:

$ helm pull https://172.31.33.149/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz --username $USER --password $PASSWORD --ca-file ca.crt
Error: Get "https://s3.ap-south-1.amazonaws.com/msrtest/msr/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWQUPBQZXRD2WG4UI%2F20210204%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20210204T001553Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=bf14dff595678bba0cb575cb91510feed8977713be124da9146ef47416e400cf": x509: cannot validate certificate for 172.31.33.149 because it doesn't contain any IP SANs

After a little digging, the issue seems to be in the following section of HTTPGetter.httpClient() function: https://github.com/helm/helm/blob/46d80f68c11d8107b688b9c8299fa02bccba312f/pkg/getter/httpgetter.go#L98-L110

  • tlsConf.ServerName field is being set in line 108, which is used to specify SNI.
  • What's happening is that since the ServerName field is used to specify SNI, Golang's implementation for TLS uses it to verify cert against. This works fine for the 1st request to my server (172.31.33.149), but for the subsequent redirect to AWS S3, it still tries to verify the cert against the provided SNI (172.31.33.149) instead of s3.ap-south-1.amazonaws.com.
  • By default, Golang's HTTP client sets the SNI itself on a clone of the TLS config using the hostname from the request URL, so the ServerName field should not be set manually here.
  • tlsConf.BuildNameToCertificate() in line 102 is deprecated, so should be removed.

The "signed by unknown authority " problem: Once, I made the above changes and built a new helm binary, I received the following error:

$ helm pull https://172.31.33.149/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz --username $USER --password $PASSWORD --ca-file ca.crt
Error: Get "https://s3.ap-south-1.amazonaws.com/msrtest/msr/charts/admin/myrepo/testchartA/testchartA-0.1.0.tgz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAWQUPBQZXRD2WG4UI%2F20210204%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20210204T005427Z&X-Amz-Expires=1200&X-Amz-SignedHeaders=host&X-Amz-Signature=03d9c79728f4e37e121cd751bcb3b2991c486fc052b1014309afa2cd12997b52": x509: certificate signed by unknown authority

This is because the system cert pool is not loaded by default in line 59 in CertPoolFromFile func: https://github.com/helm/helm/blob/46d80f68c11d8107b688b9c8299fa02bccba312f/internal/tlsutil/tls.go#L50-L64

Created PR #9318 for the fix.

wahabmk avatar Feb 04 '21 01:02 wahabmk

This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

github-actions[bot] avatar May 07 '21 00:05 github-actions[bot]

Comment to keep it from getting stale

wahabmk avatar May 07 '21 00:05 wahabmk

This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

github-actions[bot] avatar Aug 06 '21 00:08 github-actions[bot]

Fixed by https://github.com/helm/helm/pull/9318

scottrigby avatar Apr 11 '25 20:04 scottrigby