-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2271: Implement encrypted push and pull/bud/from using encrypted images r=rhatdan a=lumjjb <!-- Thanks for sending a pull request! Please make sure you've read and understood our contributing guidelines (https://github.com/containers/buildah/blob/master/CONTRIBUTING.md) as well as ensuring that all your commits are signed with `git commit -s`. --> #### What type of PR is this? <!-- Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. Uncomment only one `/kind <>` line, hit enter to put that in a new line, and remove leading whitespace from that line: --> /kind feature #### What this PR does / why we need it: This PR introduces the ability to encrypt an OCI container image when pushing, and also allows the use of encrypted OCI container images when building a Dockerfile or pulling an encrypted image from the registry. This is the initial implementation idea. There are a few more things that I am working on right now before taking out of DRAFT, but would like some feedback on the general idea. TODO in progress by me: - Remove ufave/cli and some additional imports which are not necessary from upstream ocicrypt lirbary - Add tests #### How to verify it ``` # Create keypair vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ openssl genrsa -out mykey.pem 1024 Generating RSA private key, 1024 bit long modulus (2 primes) ...........+++++ .......+++++ e is 65537 (0x010001) vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ openssl rsa -in mykey.pem -pubout > mykey.pub writing RSA key # Encrypt an image to local registry vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah images REPOSITORY TAG IMAGE ID CREATED SIZE vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah pull docker://docker.io/library/nginx:latest Getting image source signatures Copying blob ffadbd415ab7 done Copying blob c499e6d256d6 done Copying blob 74cda408e262 done Copying config ed21b7a8ae done Writing manifest to image destination Storing signatures ed21b7a8aee9cc677df6d7f38a641fa0e3c05f65592c592c9f28c42b3dd89291 vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f91d02361eae registry:2.7.1 "/entrypoint.sh /etc…" 4 months ago Up 2 days 0.0.0.0:5000->5000/tcp registry vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah push --tls-verify=false --encryption-key jwe:./mykey.pub docker.io/library/nginx:latest docker://localhost:5000/test_enc_img Getting image source signatures Copying blob d37eecb5b769 done Copying blob 99134ec7f247 done Copying blob c3a984abe8a8 done Copying config 3f9bb7a003 done Writing manifest to image destination Storing signatures # Try pulling encrypted image without key vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah pull --tls-verify=false docker://localhost:5000/test_enc_img Getting image source signatures Getting image source signatures Getting image source signatures Getting image source signatures while pulling "docker://localhost:5000/test_enc_img" as "localhost:5000/test_enc_img": Error decrypting layer sha256:ae69626ca4b44e82dce805f5f7be5272c5651bd75e19aa38ec2f5ef78986f3ff: missing private key needed for decryption ERRO exit status 1 # Try pulling encrypted image with key vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah pull --tls-verify=false --decryption-key ./mykey.pem docker://localhost:5000/test_enc_img Getting image source signatures Copying blob ae69626ca4b4 done Copying blob de5dd0ed1059 done Copying blob 4071791f0baf done Copying config 3f9bb7a003 done Writing manifest to image destination Storing signatures 3f9bb7a003b412bc186a8437e2d2246f42a6bb7488458585948e50be00a9037d # Cleanup vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah rmi --all -f ed21b7a8aee9cc677df6d7f38a641fa0e3c05f65592c592c9f28c42b3dd89291 3f9bb7a003b412bc186a8437e2d2246f42a6bb7488458585948e50be00a9037d # Create dockerfile that uses encrypted image vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ vi enc_dockerfile/Dockerfile vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ cat enc_dockerfile/Dockerfile FROM localhost:5000/test_enc_img # buildah bud without key vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah bud --tls-verify=false ./enc_dockerfile/ STEP 1: FROM localhost:5000/test_enc_img Getting image source signatures Getting image source signatures Getting image source signatures Getting image source signatures error creating build container: Error decrypting layer sha256:ae69626ca4b44e82dce805f5f7be5272c5651bd75e19aa38ec2f5ef78986f3ff: missing private key needed for decryption ERRO exit status 1 # buildah bud with key vagrant@ubuntu-bionic:~/go/src/github.com/containers/buildah$ ./buildah bud --tls-verify=false --decryption-key ./mykey.pem ./enc_dockerfile/ STEP 1: FROM localhost:5000/test_enc_img Getting image source signatures Copying blob ae69626ca4b4 done Copying blob 4071791f0baf done Copying blob de5dd0ed1059 done Copying config 3f9bb7a003 done Writing manifest to image destination Storing signatures STEP 2: COMMIT --> 3f9bb7a003b 3f9bb7a003b412bc186a8437e2d2246f42a6bb7488458585948e50be00a9037d ``` #### Which issue(s) this PR fixes: <!-- Automatically closes linked issue when PR is merged. Uncomment the following comment block and include the issue number or None on one line. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`, or `None`. --> None #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? Yes - it provides a new flag for `buildah push` with `--encryption-key` - it provides a new flag for `buildah pull` with `--decryption-key` - it provides a new flag for `buildah bud` with `--decryption-key` <!-- If no, just write `None` in the release-note block below. If yes, a release note is required: Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required". For more information on release notes please follow the kubernetes model: https://git.k8s.io/community/contributors/guide/release-notes.md --> ```release-note ``` Co-authored-by: Brandon Lum <lumjjb@gmail.com>
- Loading branch information
Showing
30 changed files
with
634 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.