-
Notifications
You must be signed in to change notification settings - Fork 5.3k
build: migrate BoringSSL FIPS to genrule_repository. #5404
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| load(":genrule_cmd.bzl", "genrule_cmd") | ||
|
|
||
| cc_library( | ||
| name = "crypto", | ||
| srcs = [ | ||
| "crypto/libcrypto.a", | ||
| ], | ||
| hdrs = glob(["boringssl/include/openssl/*.h"]), | ||
| defines = ["BORINGSSL_FIPS"], | ||
| includes = ["boringssl/include"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "ssl", | ||
| srcs = [ | ||
| "ssl/libssl.a", | ||
| ], | ||
| hdrs = glob(["boringssl/include/openssl/*.h"]), | ||
| includes = ["boringssl/include"], | ||
| visibility = ["//visibility:public"], | ||
| deps = [":crypto"], | ||
| ) | ||
|
|
||
| genrule( | ||
| name = "build", | ||
| srcs = glob(["boringssl/**"]), | ||
| outs = [ | ||
| "crypto/libcrypto.a", | ||
| "ssl/libssl.a", | ||
| ], | ||
| cmd = genrule_cmd("@envoy//bazel/external:boringssl_fips.genrule_cmd"), | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # BoringSSL build as described in the Security Policy for BoringCrypto module (2018-10-25): | ||
| # https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp3318.pdf | ||
|
|
||
| # This works only on Linux-x86_64. | ||
| if [[ `uname` != "Linux" || `uname -m` != "x86_64" ]]; then | ||
| echo "ERROR: BoringSSL FIPS is currently supported only on Linux-x86_64." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Bazel magic. | ||
| ROOT=$$(dirname $(rootpath boringssl/BUILDING.md))/.. | ||
| pushd $$ROOT | ||
|
|
||
| # Build tools requirements: | ||
| # - Clang compiler version 6.0.1 (http://releases.llvm.org/download.html) | ||
| # - Go programming language version 1.10.3 (https://golang.org/dl/) | ||
| # - Ninja build system version 1.8.2 (https://github.com/ninja-build/ninja/releases) | ||
|
|
||
| # Override $$PATH for build tools, to avoid picking up anything else. | ||
| export PATH="$$(dirname `which cmake`):/usr/bin:/bin" | ||
|
|
||
| # Clang 6.0.1 | ||
| VERSION=6.0.1 | ||
| SHA256=7ea204ecd78c39154d72dfc0d4a79f7cce1b2264da2551bb2eef10e266d54d91 | ||
| PLATFORM="x86_64-linux-gnu-ubuntu-16.04" | ||
|
|
||
| curl -sLO https://releases.llvm.org/"$$VERSION"/clang+llvm-"$$VERSION"-"$$PLATFORM".tar.xz \ | ||
| && echo "$$SHA256" clang+llvm-"$$VERSION"-"$$PLATFORM".tar.xz | sha256sum --check | ||
| tar xf clang+llvm-"$$VERSION"-"$$PLATFORM".tar.xz | ||
|
|
||
| export HOME="$$PWD" | ||
| printf "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\n" > $${HOME}/toolchain | ||
| export PATH="$$PWD/clang+llvm-$$VERSION-$$PLATFORM/bin:$$PATH" | ||
|
|
||
| if [[ `clang --version | head -1 | awk '{print $$3}'` != "$$VERSION" ]]; then | ||
| echo "ERROR: Clang version doesn't match." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Go 1.10.3 | ||
| VERSION=1.10.3 | ||
| SHA256=fa1b0e45d3b647c252f51f5e1204aba049cde4af177ef9f2181f43004f901035 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't these be first class dependencies in Bazel rather than fetched in the script? This would allow more uniform treatment and centralization of dependencies in the repository locations file.. right now it's bit weird, since the boringssl FIPS library is there, but not a bunch of its implicit dependencies..
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about promoting those while moving the recipe to Promoting clang/go/ninja to Bazel dependencies is an incremental improvement that isn't as urgent and can be done later, IMHO. Having said that, those are specific versions of build tools required by the Security Policy for BoringSSL FIPS, so I'm not sure how much value there is in making them "visible" to Bazel and other dependencies.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The advantage of Bazel visibility is that it simplifies OSS compliance and security analysis by end users. Folks want to know what they are building and where it comes from. Can you file an issue and add a TODO? I agree this can be a future PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are build tools, and AFAIK, we don't track those anywhere (neither for Envoy itself, nor for other dependencies), so I'm not sure why BoringSSL FIPS should be an exception, and how it would help with the OSS compliance or security analysis. Furthermore, there are build tools (i.e. cmake, perl) used for BoringSSL builds, which we don't download (since Security Policy doesn't require specific version of those tools), so at best, we'd have incomplete list of build-time dependencies, which is IMHO more misleading than helpful. I can file an issue if you really want, but I don't see a reason to block this PR on it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need an issue. While these are build tools, some of them imply build-time link dependencies or generated code, e.g. the toolchain. We don't track this for Envoy proper, since we expect the outer build system to be tracking the environment's clang. Now we're adding an opaque toolchain to the mix. I think for go/cmake/perl, it's probably fine as is.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There: #5428. |
||
| PLATFORM="linux-amd64" | ||
|
|
||
| curl -sLO https://dl.google.com/go/go"$$VERSION"."$$PLATFORM".tar.gz \ | ||
| && echo "$$SHA256" go"$$VERSION"."$$PLATFORM".tar.gz | sha256sum --check | ||
| tar xf go"$$VERSION"."$$PLATFORM".tar.gz | ||
|
|
||
| export GOROOT="$$PWD/go" | ||
| export PATH="$$GOROOT/bin:$$PATH" | ||
|
|
||
| if [[ `go version | awk '{print $$3}'` != "go$$VERSION" ]]; then | ||
| echo "ERROR: Go version doesn't match." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Ninja 1.8.2 | ||
| VERSION=1.8.2 | ||
| SHA256=d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on how this will interact with #5049?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is build-time dependency (and a build system, at that), so I don't think there is any point in listing it as Envoy dependency. |
||
| PLATFORM="linux" | ||
|
|
||
| curl -sLO https://github.com/ninja-build/ninja/releases/download/v"$$VERSION"/ninja-"$$PLATFORM".zip \ | ||
| && echo "$$SHA256" ninja-"$$PLATFORM".zip | sha256sum --check | ||
| unzip ninja-"$$PLATFORM".zip | ||
|
|
||
| export PATH="$$PWD:$$PATH" | ||
|
|
||
| if [[ `ninja --version` != "$$VERSION" ]]; then | ||
| echo "ERROR: Ninja version doesn't match." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Clean after previous build. | ||
| rm -rf boringssl/build | ||
|
|
||
| # Build BoringSSL. | ||
| cd boringssl | ||
| mkdir build && cd build && cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=$${HOME}/toolchain -DFIPS=1 -DCMAKE_BUILD_TYPE=Release .. | ||
| ninja | ||
| ninja run_tests | ||
|
|
||
| # Verify correctness of the FIPS build. | ||
| if [[ `tool/bssl isfips` != "1" ]]; then | ||
| echo "ERROR: BoringSSL tool didn't report FIPS build." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Move compiled libraries to the expected destinations. | ||
| popd | ||
| mv $$ROOT/boringssl/build/crypto/libcrypto.a $(execpath crypto/libcrypto.a) | ||
| mv $$ROOT/boringssl/build/ssl/libssl.a $(execpath ssl/libssl.a) | ||
This file was deleted.
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.
FWIW, I think it would be ideal if we could use a consistent toolchain across the entire build. We've had issues in the past with string libraries and compiler/glibc couplings that would be simplified here. Can't we just mandate that the user actually builds under clang-6.0.1 if they want a real FIPS build?
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.
AFAIK, the issue that you're referring to is/was with linking against versions of libstdc++ that provide different ABIs, not using different compilers.
There are no issues with linking libraries produced using different toolchains (in fact, we're doing this already, since all prebuilt libraries are always built using gcc... same goes for the system libraries), and enforcing older toolchain on rest of the build is going to result in arguably "worse" binary, for no good reason, IMHO.
Yes, we could mandate that users build using clang-6.0.1, go-1.10.3 and ninja-1.8.2, and fail the build otherwise, but then we're only making things harder for the users.
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.
I don't see a strong reason to mandate users build using clang-6.0.1, go-1.10.3 and ninja-1.8.2, we might be able to skip download if existing toolchains matches the version we expected. It will make also make CI harder if we want FIPS build with different build image.
Btw, is it possible to use Bazel managed Go binary in a genrule?