Skip to content
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

[build] Check SHA sum of downloaded node package #7746

Merged
merged 4 commits into from
Oct 29, 2016

Conversation

ppisljar
Copy link
Member

@ppisljar ppisljar commented Jul 14, 2016

checks SHA checksum for downloaded node packages and throws error if cheksum doesnt match (after up to 3 retries).
--skip-node-download option can be passed to grunt task to skip download of node builds in case they were downloaded before. SHA verification still happens and throws an error in case it fails.

Fixes #7136
Fixes #7482

@ppisljar ppisljar changed the title Fix/7136 Fix/7136 - check SHA sum of downloaded node packages Jul 14, 2016
@ppisljar ppisljar changed the title Fix/7136 - check SHA sum of downloaded node packages Fix #7136 - check SHA sum of downloaded node package Jul 14, 2016
@@ -6,6 +6,7 @@ module.exports = function (grunt) {
'clean:build',
'clean:target',
'_build:downloadNodeBuilds:start',
'_build:downloadNodeBuilds:finish',
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason why we put downloadNodeBuilds:finish further down the build task is to allow other build tasks to occur while the binaries are downloading. I'm not opposed to blocking entirely on the downloadNodeBuilds task if that's necessary, but if it is, we should roll it all into a single task.

Copy link
Member Author

Choose a reason for hiding this comment

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

i think that download usually takes less than 1 minute and the rest of the build process takes around 10 minutes. so it doesn't feel right to wait for 10 minutes just to find out that my node binaries are corrupt. however we could put it a bit further down the line. in my opinion joining the tasks into one would be the cleanest solution (as download is usually fast).

let me know

Copy link
Contributor

Choose a reason for hiding this comment

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

Joining them works for me.

@Bargs
Copy link
Contributor

Bargs commented Jul 18, 2016

Haven't figured out exactly why yet, but sha checks are failing for me when I run a build.

map(platforms, start).nodeify(this.async());
getShaSums();
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we download the checksums first? This looks like a race condition waiting to happen. And I think ideally we'd pass them in as an argument rather than using a mutable variable in the closure.

@Bargs
Copy link
Contributor

Bargs commented Jul 18, 2016

Ah. So I think because the SHA check happens in the download function, it gets skipped the second time you run a build, even if it failed the first time (line 20 skips everything if the directory already exists). We should probably re-check the SHA every time a build is run, regardless of whether the binary was just downloaded, or pre-existing.

.on('end', () => {
return cb(null, content);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to get rid of a lot of the complexity by using wreck.get, like this:

    const resp = await fromNode(cb => {
      wreck.get(shaSumsUri, function (err, resp, payload) {
        console.log('in get');
        if (err) {
          return cb(err);
        }

        if (resp.statusCode !== 200) {
          return cb(new Error(`${shaSumsUri} failed with a ${resp.statusCode} response`));
        }

        cb(null, payload);
      });
    });

    resp.toString('utf8').split('\n').forEach(line => {
      let cells = line.split('  ');
      shaSums[cells[1]] = cells[0];
    });

@spalger
Copy link
Contributor

spalger commented Jul 21, 2016

jenkins, test it

@@ -93,6 +93,7 @@
"boom": "2.8.0",
"brace": "0.5.1",
"bunyan": "1.7.1",
"check-hash": "1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

1.0.1 is the latest.

@ppisljar
Copy link
Member Author

@Bargs my assumption was that if download was successful we don't need to check shasums the next time. shasum is only checked after download, if its correct archive is extracted and next time we don't need to check shasums. if download failed archive wont be extracted ... so it should be downloaded and checked again. why do you think it would be necesary to recheck shasums every time ?

@Bargs
Copy link
Contributor

Bargs commented Jul 25, 2016

@ppisljar this line skips everything if the platform directory exists. Running the build twice, it will always succeed the second time because the bad downloads still exist in that directory and their SHA isn't rechecked. So I think we should either re-check them or re-download them every time.

@ppisljar
Copy link
Member Author

i was under wrong assumption that folder will only exist in case download was successful (content extracted). i added code which will remove folder in case download failed. this way it should be redownloaded next time, but wont be redownloading in case download was successful (so we don't unnecessarily slow down the build + we can build while offline once packages have been downloaded)

@epixa
Copy link
Contributor

epixa commented Jul 26, 2016

Honestly, I think it's safer to check the shasum each time regardless of download. The build process is how we create production quality release candidates, so the process should be resilient to outside factors. It shouldn't be possible for me to manually add a file to the node binary directory and have the build process bundle it up.

In other words, assumptions like "well, there's a file where it is suppose to be so I assume we're good" are not cautious enough when it comes to creating official releases.

@ppisljar
Copy link
Member Author

ok, so i try to do this now:

  • check if files are already there, if not start download
  • once files are downloaded (or have been there already) do a shasum check
  • if shasum check is succesfull extract archives (everytime)
  • if shasum check has failed i delete the folder and throw error (next time archieve will be redownloaded)

does this sound ok ?

@epixa
Copy link
Contributor

epixa commented Jul 26, 2016

Works for me

@epixa
Copy link
Contributor

epixa commented Oct 29, 2016

@ppisljar Just a few more things:

  1. Can you rename --skip-download to --skip-node-download?
  2. There's still a let that should be a const: https://github.com/elastic/kibana/pull/7746/files#diff-021efbed7c1f8b71b2ed5c3e72084880R19
  3. When I do skip downloading, it should log a message that says as much rather than displaying nothing at all.
  4. If I elect to skip downloading, then the only thing that should happen is the sha verification of all downloads. If any sha is incorrect, the task should simply error rather than trying to reconcile it by redownloading it. The task doesn't need to be self healing - you either have all valid node binaries or you must not skip downloading.

@epixa
Copy link
Contributor

epixa commented Oct 29, 2016

Assuming that build goes green, LGTM

Can you update the PR description with more information about this change before merging? Specifically, describe the new skip-node-download argument and that sha verification happens regardless of whether you skip downloads or not.

@ppisljar
Copy link
Member Author

jenkins, test this

@ppisljar ppisljar merged commit 9b5a96e into elastic:master Oct 29, 2016
elastic-jasper added a commit that referenced this pull request Oct 29, 2016
Backports PR #7746

**Commit 1:**
fix #7136 - check SHA of downloaded node binaries

* Original sha: 955972b
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-07-11T19:17:08Z

**Commit 2:**
only skipping download if --skip-download cli argument is present

* Original sha: 325e172
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-07T10:54:23Z

**Commit 3:**
updating log messages based on epixas comments

* Original sha: 20b5c4d
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:24:55Z

**Commit 4:**
updating based on courts review

* Original sha: 78c124c
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-10-29T14:44:43Z
elastic-jasper added a commit that referenced this pull request Oct 29, 2016
Backports PR #7746

**Commit 1:**
fix #7136 - check SHA of downloaded node binaries

* Original sha: 955972b
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-07-11T19:17:08Z

**Commit 2:**
only skipping download if --skip-download cli argument is present

* Original sha: 325e172
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-07T10:54:23Z

**Commit 3:**
updating log messages based on epixas comments

* Original sha: 20b5c4d
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:24:55Z

**Commit 4:**
updating based on courts review

* Original sha: 78c124c
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-10-29T14:44:43Z
@ppisljar ppisljar deleted the fix/7136 branch October 29, 2016 15:13
ppisljar pushed a commit that referenced this pull request Oct 29, 2016
Backports PR #7746

**Commit 1:**
fix #7136 - check SHA of downloaded node binaries

* Original sha: 955972b
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-07-11T19:17:08Z

**Commit 2:**
only skipping download if --skip-download cli argument is present

* Original sha: 325e172
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-07T10:54:23Z

**Commit 3:**
updating log messages based on epixas comments

* Original sha: 20b5c4d
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:24:55Z

**Commit 4:**
updating based on courts review

* Original sha: 78c124c
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-10-29T14:44:43Z
epixa pushed a commit that referenced this pull request Oct 29, 2016
Backports PR #7746

**Commit 1:**
fix #7136 - check SHA of downloaded node binaries

* Original sha: 955972b
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-07-11T19:17:08Z

**Commit 2:**
only skipping download if --skip-download cli argument is present

* Original sha: 325e172
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-07T10:54:23Z

**Commit 3:**
updating log messages based on epixas comments

* Original sha: 20b5c4d
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:24:55Z

**Commit 4:**
updating based on courts review

* Original sha: 78c124c
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-10-29T14:44:43Z
nreese pushed a commit to nreese/kibana that referenced this pull request Nov 10, 2016
* fix elastic#7136 - check SHA of downloaded node binaries
* skips download if --skip-node-download cli argument is present
@epixa epixa added v5.1.1 and removed v5.1.0 labels Dec 8, 2016
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
Backports PR elastic#7746

**Commit 1:**
fix elastic#7136 - check SHA of downloaded node binaries

* Original sha: 955972b
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-07-11T19:17:08Z

**Commit 2:**
only skipping download if --skip-download cli argument is present

* Original sha: 325e172
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-07T10:54:23Z

**Commit 3:**
updating log messages based on epixas comments

* Original sha: 20b5c4d
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-09-23T06:24:55Z

**Commit 4:**
updating based on courts review

* Original sha: 78c124c
* Authored by ppisljar <peter.pisljar@gmail.com> on 2016-10-29T14:44:43Z

Former-commit-id: 8e22a9e
Sign up for free to 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.

4 participants