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

scratch for checkout, frontend, productcatalog and shipping #2512

Merged
merged 9 commits into from
Apr 29, 2024

Conversation

mathieu-benoit
Copy link
Contributor

@mathieu-benoit mathieu-benoit commented Apr 28, 2024

scratch for the final image for checkout, frontend, productcatalog and shipping.

Objectives for the Golang apps:

  • Improve the security posture (surface of attack reduced) with the container images (no busybox)
  • Improve the maintenance with CVEs on final container images based on alpine previously
  • Improve build time
  • Inspire others to build safer and more secure containe image by default

Addressing #693 for the Golang apps.

Associated resources for the inspiration and for the guidance:

The size is reduced:

For checkoutservice it's 8MB saved on disk:

checkoutservice    scratch   40aaa763fe97   17 minutes ago   21.1MB
checkoutservice    latest    a818e09cb797   58 minutes ago   29.1MB

For frontend it's 15.7 MB saved on disk:

frontend    scratch   34d8788e6d94   8 seconds ago    28.1MB
frontend    latest    cf73fd27f3fc   14 minutes ago   43.8MB

The number of packages is reduced:

With a tool like syft we could see that all the unnecessary/unsecured packages have been removed.

For checkoutservice, from 57 packages we are now at 40 packages, here are the ones removed:

alpine-baselayout                                                            3.4.3-r2                            apk          
alpine-baselayout-data                                                       3.4.3-r2                            apk          
alpine-keys                                                                  2.4-r1                              apk          
apk-tools                                                                    2.14.0-r5                           apk          
busybox                                                                      1.36.1-r15                          apk          
busybox-binsh                                                                1.36.1-r15                          apk          
ca-certificates                                                              20240226-r0                         apk          
ca-certificates-bundle                                                       20230506-r0                         apk

For frontend, from 82 packages we are now at 48 packages, here are the ones removed:

alpine-baselayout                                                            3.4.3-r2                            apk          
alpine-baselayout-data                                                       3.4.3-r2                            apk          
alpine-keys                                                                  2.4-r1                              apk          
apk-tools                                                                    2.14.0-r5                           apk          
bind-libs                                                                    9.18.24-r1                          apk          
bind-tools                                                                   9.18.24-r1                          apk          
busybox                                                                      1.36.1-r15                          apk          
busybox-binsh                                                                1.36.1-r15                          apk          
busybox-extras                                                               1.36.1-r15                          apk          
ca-certificates                                                              20240226-r0                         apk          
ca-certificates-bundle                                                       20230506-r0                         apk              
fstrm                                                                        0.6.1-r4                            apk            
json-c                                                                       0.17-r0                             apk          
keyutils-libs                                                                1.6.3-r3                            apk          
krb5-conf                                                                    1.0-r2                              apk          
krb5-libs                                                                    1.21.2-r0                           apk          
libc-utils                                                                   0.7.2-r5                            apk          
libcom_err                                                                   1.47.0-r5                           apk          
libcrypto3                                                                   3.1.4-r5                            apk          
libssl3                                                                      3.1.4-r5                            apk          
libuv                                                                        1.47.0-r0                           apk          
libverto                                                                     0.3.2-r2                            apk          
libxml2                                                                      2.11.7-r0                           apk          
mii-tool                                                                     2.10-r3                             apk          
musl                                                                         1.2.4_git20230717-r4                apk          
musl-utils                                                                   1.2.4_git20230717-r4                apk          
net-tools                                                                    2.10-r3                             apk          
nghttp2-libs                                                                 1.58.0-r0                           apk          
protobuf-c                                                                   1.4.1-r7                            apk          
scanelf                                                                      1.3.7-r2                            apk          
ssl_client                                                                   1.36.1-r15                          apk           
xz-libs                                                                      5.4.5-r0                            apk          
zlib                                                                         1.3.1-r0                            apk

On these now missing packages, that's avoiding/removing any CVEs debt/fatigue on them.

Important notes: removing busybox/wget is a great improvement on a security standpoint, nobody can do docker exec or kubectl exec on them.

The number of CVEs is reduced:

With a tool like trivy we could see that the alpine based one has currently 2 CVEs:

checkoutservice:latest (alpine 3.19.1)
======================================
Total: 2 (UNKNOWN: 0, LOW: 2, MEDIUM: 0, HIGH: 0, CRITICAL: 0)

┌────────────┬───────────────┬──────────┬────────┬───────────────────┬───────────────┬───────────────────────────────────────────────────────────┐
│  Library   │ Vulnerability │ Severity │ Status │ Installed Version │ Fixed Version │                           Title                           │
├────────────┼───────────────┼──────────┼────────┼───────────────────┼───────────────┼───────────────────────────────────────────────────────────┤
│ libcrypto3 │ CVE-2024-2511 │ LOW      │ fixed  │ 3.1.4-r5          │ 3.1.4-r6      │ openssl: Unbounded memory growth with session handling in │
│            │               │          │        │                   │               │ TLSv1.3                                                   │
│            │               │          │        │                   │               │ https://avd.aquasec.com/nvd/cve-2024-2511                 │
├────────────┤               │          │        │                   │               │                                                           │
│ libssl3    │               │          │        │                   │               │                                                           │
│            │               │          │        │                   │               │                                                           │
│            │               │          │        │                   │               │                                                           │
└────────────┴───────────────┴──────────┴────────┴───────────────────┴───────────────┴───────────────────────────────────────────────────────────┘

On the other end, the new one doesn't have any CVEs.

Also, based on the GKE Security Posture feature, for frontend, this will fix these 25 CVEs:
image

Tests:

Successfully tested:

@mathieu-benoit mathieu-benoit marked this pull request as draft April 28, 2024 14:31
@mathieu-benoit mathieu-benoit changed the title scratch for checkout, productcatalog and shipping scratch for checkout, frontend, productcatalog and shipping Apr 28, 2024
@mathieu-benoit mathieu-benoit marked this pull request as ready for review April 28, 2024 16:47
@mathieu-benoit
Copy link
Contributor Author

Ready for review, thanks!

@@ -13,8 +13,6 @@
# limitations under the License.

FROM golang:1.22.2-alpine@sha256:cdc86d9f363e8786845bea2040312b4efa321b828acdeb26f393faa864d887b0 as builder
RUN apk add --no-cache ca-certificates git
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question: Do you know why we can remove ca-certificates?

Copy link
Collaborator

@NimJay NimJay Apr 29, 2024

Choose a reason for hiding this comment

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

(It's not super clear to me why ca-certificates is needed in the first place. I assume it's to enable HTTPS (secure) communication during runtime.)

Original commit: 92eb76c

Copy link
Contributor Author

@mathieu-benoit mathieu-benoit Apr 29, 2024

Choose a reason for hiding this comment

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

Good question. This is for the build container (not the final). If I do syft golang:1.22.2-alpine, I see that ca-certificates is already in there apparently:

NAME                    VERSION               TYPE                        
alpine-baselayout       3.4.3-r2              apk                          
alpine-baselayout-data  3.4.3-r2              apk                          
alpine-keys             2.4-r1                apk                          
apk-tools               2.14.0-r5             apk                          
busybox                 1.36.1-r15            apk                          
busybox-binsh           1.36.1-r15            apk                          
ca-certificates         20230506-r0           apk                          
ca-certificates-bundle  20230506-r0           apk                          
cmd/addr2line           (devel)               go-module                    
cmd/asm                 (devel)               go-module                    
cmd/buildid             (devel)               go-module                    
cmd/cgo                 (devel)               go-module                    
cmd/compile             (devel)               go-module                    
cmd/covdata             (devel)               go-module                    
cmd/cover               (devel)               go-module                    
cmd/doc                 (devel)               go-module                    
cmd/fix                 (devel)               go-module                    
cmd/go                  (devel)               go-module                    
cmd/gofmt               (devel)               go-module                    
cmd/link                (devel)               go-module                    
cmd/nm                  (devel)               go-module                    
cmd/objdump             (devel)               go-module                    
cmd/pack                (devel)               go-module                    
cmd/pprof               (devel)               go-module                    
cmd/test2json           (devel)               go-module                    
cmd/trace               (devel)               go-module                    
cmd/vet                 (devel)               go-module                    
d3-pprof                2.0.0                 npm                          
go                      1.22.2                binary                       
libc-utils              0.7.2-r5              apk                          
libcrypto3              3.1.4-r5              apk                          
libssl3                 3.1.4-r5              apk                          
musl                    1.2.4_git20230717-r4  apk                          
musl-utils              1.2.4_git20230717-r4  apk                          
scanelf                 1.3.7-r2              apk                          
ssl_client              1.36.1-r15            apk                          
stdlib                  go1.22.2              go-module  (+18 duplicates)  
zlib                    1.3.1-r0              apk

Not sure why it was added in there at the first place though.

Copy link
Collaborator

@NimJay NimJay left a comment

Choose a reason for hiding this comment

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

Thanks so much for this, @mathieu-benoit! I highly appreciate the elaborate and clear pull-request description + links.
Just had a question before merging. :)

@NimJay NimJay merged commit 6d78542 into GoogleCloudPlatform:main Apr 29, 2024
6 checks passed
@mathieu-benoit mathieu-benoit deleted the scratch branch April 29, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants