├── .github
├── images
│ ├── screenshot.png
│ ├── screenshot_light.png
│ ├── screenshot_results.png
│ ├── screenshot_results_light.png
│ ├── screenshot_sbom_results.png
│ └── screenshot_sbom_results_light.png
└── workflows
│ ├── codeql-analysis.yml
│ └── easy_release.yml
├── .gitignore
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── client
├── .browserslistrc
├── .editorconfig
├── .env
├── .gitignore
├── .prettierrc.json
├── package-lock.json
├── package.json
├── public
│ ├── font
│ │ └── droplet.otf
│ ├── images
│ │ ├── tada.svg
│ │ ├── trivy.svg
│ │ └── trivy_logo.svg
│ ├── index.html
│ └── styles
│ │ └── fonts.css
├── src
│ ├── App.tsx
│ ├── ConfigureCreds.tsx
│ ├── DefaultDisplay.tsx
│ ├── ImageList.tsx
│ ├── Links.tsx
│ ├── Loading.tsx
│ ├── Metrics.tsx
│ ├── Pill.tsx
│ ├── SBOM.tsx
│ ├── Success.tsx
│ ├── TrivyVulnerability.tsx
│ ├── Vulns.tsx
│ ├── VulnsFilter.tsx
│ ├── Welcome.tsx
│ ├── globals.d.ts
│ ├── index.tsx
│ └── react-app-env.d.ts
├── tsconfig.json
└── yarn.lock
├── go.mod
├── go.sum
├── make.bat
├── metadata.json
├── metrics
├── Makefile
├── README.md
├── go.mod
├── go.sum
├── main.go
└── template.yaml
├── service
├── docker-compose.yaml
├── internal
│ ├── auth
│ │ └── validate.go
│ └── socket
│ │ ├── socket.go
│ │ ├── socket_darwin.go
│ │ ├── socket_linux.go
│ │ ├── socket_unix.go
│ │ ├── socket_unix_test.go
│ │ └── socket_windows.go
└── main.go
└── trivy.svg
/.github/images/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/be570083643124add79adda3c37a13f0997d060f/.github/images/screenshot.png
--------------------------------------------------------------------------------
/.github/images/screenshot_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/be570083643124add79adda3c37a13f0997d060f/.github/images/screenshot_light.png
--------------------------------------------------------------------------------
/.github/images/screenshot_results.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/be570083643124add79adda3c37a13f0997d060f/.github/images/screenshot_results.png
--------------------------------------------------------------------------------
/.github/images/screenshot_results_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/be570083643124add79adda3c37a13f0997d060f/.github/images/screenshot_results_light.png
--------------------------------------------------------------------------------
/.github/images/screenshot_sbom_results.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/be570083643124add79adda3c37a13f0997d060f/.github/images/screenshot_sbom_results.png
--------------------------------------------------------------------------------
/.github/images/screenshot_sbom_results_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/be570083643124add79adda3c37a13f0997d060f/.github/images/screenshot_sbom_results_light.png
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ main ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ main ]
20 | schedule:
21 | - cron: '29 13 * * 6'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'javascript' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support
38 |
39 | steps:
40 | - name: Checkout repository
41 | uses: actions/checkout@v3
42 |
43 | # Initializes the CodeQL tools for scanning.
44 | - name: Initialize CodeQL
45 | uses: github/codeql-action/init@v2
46 | with:
47 | languages: ${{ matrix.language }}
48 | # If you wish to specify custom queries, you can do so here or in a config file.
49 | # By default, queries listed here will override any specified in a config file.
50 | # Prefix the list here with "+" to use these queries and those in the config file.
51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
52 |
53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54 | # If this step fails, then you should remove it and run the build manually (see below)
55 | - name: Autobuild
56 | uses: github/codeql-action/autobuild@v2
57 |
58 | # ℹ️ Command-line programs to run using the OS shell.
59 | # 📚 https://git.io/JvXDl
60 |
61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62 | # and modify them (or add more) to build your code if your project
63 | # uses a compiled language
64 |
65 | #- run: |
66 | # make bootstrap
67 | # make release
68 |
69 | - name: Perform CodeQL Analysis
70 | uses: github/codeql-action/analyze@v2
71 |
--------------------------------------------------------------------------------
/.github/workflows/easy_release.yml:
--------------------------------------------------------------------------------
1 | name: Release extension
2 | on:
3 | push:
4 | tags:
5 | - "*"
6 |
7 | jobs:
8 | publish-extension:
9 | name: Build extension and push to dockerhub
10 | runs-on: ubuntu-latest
11 | steps:
12 | - name: Check out the repo
13 | uses: actions/checkout@v2
14 |
15 | - name: Set up QEMU
16 | id: qemu
17 | uses: docker/setup-qemu-action@v1
18 |
19 | - name: Login to DockerHub
20 | if: github.event_name != 'pull_request'
21 | uses: docker/login-action@v1
22 | with:
23 | username: ${{ secrets.DOCKERHUB_USER }}
24 | password: ${{ secrets.DOCKERHUB_TOKEN }}
25 |
26 | - name: Release extension
27 | run: TAG=${GITHUB_REF#refs/*/} make release-extension
28 | env:
29 | DOCKER_BUILDKIT: 1
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | ui/build/bundle.*
3 | metrics/.aws-sam
4 | metrics/samconfig.toml
5 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Build the UI
2 | FROM node:lts-alpine3.15 AS client-builder
3 | WORKDIR /app/client
4 |
5 | COPY client/package.json /app/client/package.json
6 | COPY client/yarn.lock /app/client/yarn.lock
7 |
8 | ARG TARGETARCH
9 | RUN yarn config set cache-folder /usr/local/share/.cache/yarn-${TARGETARCH}
10 | RUN --mount=type=cache,target=/usr/local/share/.cache/yarn-${TARGETARCH} yarn --network-timeout 1000000
11 |
12 | COPY client /app/client
13 | RUN --mount=type=cache,target=/usr/local/share/.cache/yarn-${TARGETARCH} yarn build --network-timeout 1000000
14 |
15 |
16 | # Build the service
17 | FROM golang:1.17-alpine AS service-builder
18 | ENV CGO_ENABLED=0
19 | RUN apk add --update make
20 | WORKDIR /plugin
21 | COPY . .
22 | RUN make bin
23 |
24 | # Bring it all together
25 | FROM alpine:3.15
26 | LABEL org.opencontainers.image.title="Aqua Trivy" \
27 | org.opencontainers.image.description="Run unlimited vulnerability scans against remote or locally stored images. Understand any security issues that may be present in images before you pull and use them." \
28 | org.opencontainers.image.vendor="Aqua Security Software" \
29 | com.docker.desktop.extension.api.version=">= 0.2.0" \
30 | com.docker.desktop.extension.icon="https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/main/trivy.svg" \
31 | com.docker.extension.publisher-url="https://trivy.dev" \
32 | com.docker.extension.screenshots="[{\"alt\": \"Trivy Dark Screenshot\", \"url\": \"https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/main/.github/images/screenshot.png\"},{\"alt\": \"Trivy light screenshot\", \"url\": \"https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/main/.github/images/screenshot_light.png\"}]" \
33 | com.docker.extension.detailed-description="
Free and Unlimited Vulnerability Scanning
Take control of your application security with Trivy
Trivy is the world’s most popular open source vulnerability and misconfiguration scanner. It is reliable, fast, extremely easy to use, and it works wherever you need it.
Scan locally stored images by choosing from the list
Scan remote images simply by entering the name in the search box
Filter by the severity of the vulnerability or optionally only show issues with fixes
" \
34 | com.docker.extension.additional-urls="[{\"title\":\"Trivy Website\",\"url\":\"https://trivy.dev/\"},{\"title\":\"Issues\",\"url\":\"https://github.com/aquasecurity/trivy/issues\"},{\"title\":\"Slack\",\"url\":\"https://slack.aquasec.com/\"}]" \
35 | com.docker.extension.category="security"
36 |
37 | COPY --from=client-builder /app/client/dist ui
38 | COPY --from=service-builder /plugin/bin/creds-service /
39 | COPY trivy.svg .
40 | COPY metadata.json .
41 | COPY service/docker-compose.yaml .
42 |
43 | CMD /creds-service
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2022 Aqua Security
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | IMAGE?=aquasec/trivy-docker-extension
2 | TAG?=latest
3 |
4 | BUILDER=buildx-multi-arch
5 |
6 | STATIC_FLAGS=CGO_ENABLED=0
7 | LDFLAGS="-s -w"
8 | GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
9 |
10 | .PHONY: bin
11 | bin: ## Build the binary for the current plarform
12 | @echo "$(INFO_COLOR)Building...$(NO_COLOR)"
13 | $(GO_BUILD) -o bin/creds-service ./service
14 |
15 | .PHONY: build-app
16 | build-app:
17 | @npm run-script build
18 |
19 | .PHONY: build-dev
20 | build-dev:
21 | @DOCKER_BUILDKIT=1 docker build -t trivy-docker-extension:development .
22 |
23 | .PHONY: deploy-dev
24 | deploy-dev: build-dev
25 | @docker extension rm trivy-docker-extension:development || true
26 | @docker extension install trivy-docker-extension:development
27 |
28 | .PHONY: dev-debug
29 | dev-debug:
30 | @docker extension dev debug trivy-docker-extension:development
31 |
32 | .PHONY: dev-reset
33 | dev-reset:
34 | @docker extension dev reset trivy-docker-extension:development
35 |
36 | .PHONY: remove-dev
37 | remove-dev:
38 | @docker extension rm trivy-docker-extension:development || true
39 |
40 | .PHONY: prepare-buildx
41 | prepare-buildx: ## Create buildx builder for multi-arch build, if not exists
42 | docker buildx inspect $(BUILDER) || docker buildx create --name=$(BUILDER) --driver=docker-container --driver-opt=network=host
43 |
44 | .PHONY: release-extension
45 | release-extension: prepare-buildx
46 | @docker buildx build --push --builder=$(BUILDER) --platform=linux/amd64,linux/arm64 --build-arg TAG=$(TAG) --tag=$(IMAGE):$(TAG) .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | 
3 |
4 | # Trivy Docker Extension
5 |
6 |
7 | ## What is this?
8 |
9 | Docker are adding the concept of `Extensions` to the Docker Desktop tool. This is an extension that allows the user to run Trivy and get pretty output in return.
10 |
11 | The user can either select from a drop down of local images or type the name of an image into the drop down.
12 |
13 | 
14 |
15 | 
16 |
17 |
18 | When you run the scan you'll get the results
19 |
20 | 
21 |
22 | 
23 |
24 | When you run the scan you can optionally get the results in SBOM format
25 |
26 | 
27 |
28 | 
29 |
30 | ## What is is made of?
31 |
32 | The extension runs in its own container with a web interface that calls into the Docker extension API. At a high level the flow is;
33 |
34 | 1. specify an image
35 | 2. create the trivy cache volume if it does not already exist
36 | 3. run aquasec/trivy against the image providing the volume for docker.sock and the cache volume
37 | 4. process the json results and render
38 |
39 | ### But what is it made of?
40 |
41 | The extension is React app leveraging Material UI components. The Docker extension team have provided theme support so we just use that for the look and feel.
42 |
43 | The source is all in `client/src` with the main component being [App.tsx](client/src/App.tsx). This has the core code for running the extension and loads all of the child components.
44 |
45 | The rest of the tsx files are detailed below
46 |
47 | | Component | Purpose |
48 | |-------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
49 | | [DefaultDisplay](client/src/DefaultDisplay.tsx) | After the landing page has been used to initiate the first scan the view switches to the default display with the logo and search box |
50 | | [ImageList](client/src/ImageList.tsx) | Provides the functionality for loading the images stored locally and autocomplete functionality |
51 | | [Links](client/src/Links.tsx) | Header links for github, docs and slack |
52 | | [Loading](client/src/Loading.tsx) | The spinner loading blackout shim |
53 | | [Pill](client/src/Pill.tsx) | Coloured badges to denote the severity of the vulnerability |
54 | | [Success](client/src/Success.tsx) | When the scan has no vulnerabilities this :tada: message is displayed |
55 | | [Vulns](client/src/Vulns.tsx) | Renders the Accordion "table" of results - this includes the [VulnsFilter](client/src/VulnsFilter.tsx) |
56 | | [VulnsFilter](client/src/VulnsFilter.tsx) | This control has the numbers of each severity and allows filtering the "table" of results |
57 | | [Welcome](client/src/Welcome.tsx) | The Landing page - has the Trivy description and the initial scan |
58 |
59 |
60 | In addition to these there is the [TrivyVulnerability](client/src/TrivyVulnerability.tsx) which provides a class to represent a vulnerability from the Json results.
61 |
62 | ## How do I get started?
63 |
64 | ### Prereqs
65 |
66 | You will need
67 |
68 | 1. Docker Desktop release that supports extensions (currently private repo)
69 | 2. Docker Extension binary release (currently private repo)
70 | 3. NPM installed
71 |
72 | ## Local Dev
73 |
74 | ### Deploy to local Docker Desktop
75 |
76 | To launch the extension into your Docker Desktop you'll need
77 |
78 | *Linux/Mac*
79 |
80 | ```bash
81 | make deploy-dev
82 | ```
83 |
84 | *Windows*
85 |
86 | ```bash
87 | make.bat deploy-dev
88 | ```
89 |
90 | ### Enable debugging in local Docker Desktop
91 |
92 | To launch the extension into your Docker Desktop you'll need
93 |
94 | *Linux/Mac*
95 |
96 | ```bash
97 | make dev-debug
98 | ```
99 |
100 | *Windows*
101 |
102 | ```bash
103 | make.bat dev-debug
104 | ```
105 |
106 | ### Disable debugging in local Docker Desktop
107 |
108 | To launch the extension into your Docker Desktop you'll need
109 |
110 | *Linux/Mac*
111 |
112 | ```bash
113 | make dev-reset
114 | ```
115 |
116 | *Windows*
117 |
118 | ```bash
119 | make.bat dev-reset
120 | ```
121 |
122 | ## CI Process
123 |
124 | A bit about the CI process - on a new tag a release will be built for `linux/amd64` and `linux/arm64` using `docker buildx` with the multi arch builder.
125 |
126 | The [release-extension target](Makefile) in the `Makefile` is fairly self explanatory and will push the new image.
127 |
128 | It's worth noting the installation of QEmu on the GitHub action worker so that it can build the `arm64` image - without that there are issues finding `glibc`.
129 |
--------------------------------------------------------------------------------
/client/.browserslistrc:
--------------------------------------------------------------------------------
1 | # This is automatically converted to a Chromium version
2 | # See: https://github.com/kilian/electron-to-chromium
3 |
4 | # One day, we could distribute a config package from pinata with a Chrome version derived by
5 | # feeding `require("electron").version` into an up-to-date `electron-to-chromium`.
6 | # https://github.com/browserslist/browserslist#shareable-configs
7 |
8 | Chrome 91
9 |
10 | # Ideally we'd do (at time of writing) "Electron 13.1.4", but the version of electron-to-chromium
11 | # in our dependency tree is a bit outdated
12 | # See https://github.com/Kilian/electron-to-chromium/blob/master/versions.js for full list
13 |
--------------------------------------------------------------------------------
/client/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | root = true
3 | end_of_line = lf
4 |
5 | indent_size = 2
6 | indent_style = space
7 |
--------------------------------------------------------------------------------
/client/.env:
--------------------------------------------------------------------------------
1 | BUILD_PATH=dist
2 | PUBLIC_URL=.
3 |
--------------------------------------------------------------------------------
/client/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 | /dist
14 |
15 | # misc
16 | .DS_Store
17 | .env.local
18 | .env.development.local
19 | .env.test.local
20 | .env.production.local
21 |
22 | npm-debug.log*
23 | yarn-debug.log*
24 | yarn-error.log*
25 |
26 | # Yarn-related
27 | .yarn/*
28 | !.yarn/patches
29 | !.yarn/releases
30 | !.yarn/plugins
31 | !.yarn/sdks
32 | !.yarn/versions
33 | .pnp.*
34 |
--------------------------------------------------------------------------------
/client/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "trailingComma": "all"
4 | }
5 |
--------------------------------------------------------------------------------
/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@aquasec/trivy-desktop-extension",
3 | "version": "0.3.0",
4 | "private": true,
5 | "scripts": {
6 | "start": "react-scripts start",
7 | "build": "react-scripts build"
8 | },
9 | "dependencies": {
10 | "@docker/docker-mui-theme": "^0.0.6",
11 | "@emotion/react": "^11.8.2",
12 | "@emotion/styled": "^11.8.1",
13 | "@mui/icons-material": "^5.5.1",
14 | "@mui/material": "^5.5.2",
15 | "@mui/system": "^5.5.2",
16 | "@types/react": "^17.0.0",
17 | "@types/react-dom": "^17.0.0",
18 | "react": "^17.0.2",
19 | "react-dom": "^17.0.2",
20 | "react-scripts": "5.0.0",
21 | "typescript": "^4.1.2"
22 | }
23 | }
--------------------------------------------------------------------------------
/client/public/font/droplet.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aquasecurity/trivy-docker-extension/be570083643124add79adda3c37a13f0997d060f/client/public/font/droplet.otf
--------------------------------------------------------------------------------
/client/public/images/tada.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/public/images/trivy.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/public/images/trivy_logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
150 |
--------------------------------------------------------------------------------
/client/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/client/public/styles/fonts.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: Droplet;
3 | src: url("../font/droplet.otf") format("opentype");
4 | }
5 |
--------------------------------------------------------------------------------
/client/src/App.tsx:
--------------------------------------------------------------------------------
1 | import { DockerMuiThemeProvider } from '@docker/docker-mui-theme';
2 | import { Box } from '@mui/material';
3 | import CssBaseline from '@mui/material/CssBaseline';
4 | import React from 'react';
5 | import { ConfigureCreds } from './ConfigureCreds';
6 |
7 | import { DefaultDisplay } from './DefaultDisplay';
8 | import { Loading } from './Loading';
9 | import { SBOM } from './SBOM';
10 | import { Success } from './Success';
11 | import { TrivyVulnerability } from './TrivyVulnerability';
12 | import { Vulns } from './Vulns';
13 | import { Welcome } from './Welcome';
14 | import { SendMetric } from './Metrics';
15 |
16 |
17 | export function App() {
18 | const [aquaKey, setAquaKey] = React.useState("");
19 | const [aquaSecret, setAquaSecret] = React.useState("");
20 | const [aquaCSPMUrl, setAquaCSPMUrl] = React.useState("");
21 |
22 | const [scanImage, setScanImage] = React.useState("");
23 | const [disableScan, setDisableScan] = React.useState(true);
24 | const [fixedOnly, setFixedOnly] = React.useState(true);
25 | const [uploadAqua, setUploadAqua] = React.useState(false);
26 | const [SBOMOutput, setSBOMOutput] = React.useState(false);
27 | const [SBOMContent, setSBOMContent] = React.useState("");
28 |
29 |
30 | const [showLoginBox, setShowLoginBox] = React.useState(false);
31 | const [showUploadAqua, setShowUploadAqua] = React.useState("none")
32 | const [showSBOM, setShowSBOM] = React.useState("none");
33 | const [showFilter, setShowFilter] = React.useState("none");
34 | const [showSuccess, setShowSuccess] = React.useState("none");
35 | const [showDefaultDisplay, setShowDefaultDisplay] = React.useState("none");
36 | const [showWelcome, setShowWelcome] = React.useState("flex");
37 |
38 | const [severityFilter, setSeverityFilter] = React.useState("all");
39 | const [all, setAll] = React.useState(0);
40 | const [critical, setCritical] = React.useState(0);
41 | const [high, setHigh] = React.useState(0);
42 | const [medium, setMedium] = React.useState(0);
43 | const [low, setLow] = React.useState(0);
44 | const [unknown, setUnknown] = React.useState(0);
45 |
46 | const [vulnerabilities, setVulnerabilities] = React.useState([]);
47 | const [allVulnerabilities, setAllVulnerabilities] = React.useState([]);
48 |
49 | const [loadingWait, setLoadingWait] = React.useState(false);
50 | const [loggedIn, setLoggedIn] = React.useState(false);
51 |
52 |
53 |
54 | const getSeverityOrdering = (severity: string): number => {
55 | switch (severity) {
56 | case "CRITICAL":
57 | return 0;
58 | case "HIGH":
59 | return 1;
60 | case "MEDIUM":
61 | return 2;
62 | case "LOW":
63 | return 3;
64 | case "UNKNOWN":
65 | return 4;
66 | default:
67 | return 5
68 | }
69 | };
70 |
71 | async function checkForCacheVolume() {
72 | var exists = false;
73 | await window.ddClient.docker.cli
74 | .exec("volume", [
75 | "inspect",
76 | "trivy-docker-extension-cache"
77 | ])
78 | .then((result: any) => {
79 | console.log(result);
80 | if (result.stdout !== "") {
81 | exists = true;
82 | }
83 | }).catch((err: Error) => {
84 | console.log(err);
85 | exists = false;
86 | });
87 | return exists;
88 | }
89 |
90 | async function createCacheVolume() {
91 | var success = true;
92 | await window.ddClient.docker.cli
93 | .exec("volume", ["create", "trivy-docker-extension-cache"])
94 | .then((result: any) => {
95 | if (result.stderr !== "") {
96 | success = false;
97 | }
98 | });
99 | return success;
100 | }
101 |
102 | async function triggerTrivy() {
103 | if (scanImage === "") {
104 | return;
105 | }
106 |
107 |
108 | resetUI();
109 | if (!(await checkForCacheVolume())) {
110 | await createCacheVolume().then((created) => {
111 | if (!created) {
112 | setLoadingWait(true);
113 | console.log("failed to create volume");
114 | return;
115 | }
116 | });
117 | window.ddClient.desktopUI.toast.warning(
118 | `Creating vulnerability cache volume on first run, populating this will cause a slight delay.`
119 | );
120 | }
121 |
122 | let stdout = "";
123 | let stderr = "";
124 | let commandParts: string[] = [
125 | "--rm",
126 | "-v",
127 | "/var/run/docker.sock:/var/run/docker.sock",
128 | "-v",
129 | "trivy-docker-extension-cache:/root/.cache"
130 | ];
131 |
132 | if (uploadAqua && !SBOMOutput) {
133 | commandParts.push("-e");
134 | commandParts.push("TRIVY_RUN_AS_PLUGIN=aqua");
135 | commandParts.push("-e");
136 | commandParts.push("AQUA_KEY=" + aquaKey);
137 | commandParts.push("-e");
138 | commandParts.push("AQUA_SECRET=" + aquaSecret);
139 | commandParts.push("-e");
140 | commandParts.push("CSPM_URL=" + aquaCSPMUrl);
141 | }
142 |
143 |
144 | commandParts.push("aquasec/trivy");
145 | commandParts.push("--quiet");
146 | commandParts.push("image")
147 | if (SBOMOutput) {
148 | commandParts.push("-f=cyclonedx")
149 | } else {
150 | commandParts.push("-f=json")
151 | }
152 |
153 | if (fixedOnly && !SBOMOutput) {
154 | commandParts.push("--ignore-unfixed");
155 | }
156 | commandParts.push(scanImage);
157 | ({ stdout, stderr } = await runTrivy(commandParts, stdout, stderr));
158 | }
159 |
160 | async function runTrivy(commandParts: string[], stdout: string, stderr: string) {
161 | SendMetric("trivy_scan_initiated", { imageName: scanImage });
162 | await window.ddClient.docker.cli.exec(
163 | "run", commandParts,
164 | {
165 | stream: {
166 | onOutput(data: any) {
167 | stdout += data.stdout;
168 | if (data.stderr) {
169 | stderr += data.stderr;
170 | }
171 | },
172 | onError(error: any) {
173 | window.ddClient.desktopUI.toast.error(
174 | `An error occurred while scanning ${scanImage}`
175 | );
176 | console.error(error);
177 | },
178 | onClose(exitCode: number) {
179 | setLoadingWait(false);
180 | setDisableScan(false);
181 | var res = { stdout: stdout, stderr: stderr };
182 | if (exitCode === 0) {
183 | if (uploadAqua && !SBOMOutput) {
184 | window.ddClient.desktopUI.toast.success(
185 | `Results successfully uploaded to Aqua`
186 | );
187 | }
188 | SendMetric("trivy_scan_succeeded", { imageName: scanImage });
189 | processResult(res);
190 | } else {
191 | SendMetric("trivy_scan_failed", { imageName: scanImage });
192 | window.ddClient.desktopUI.toast.error(
193 | `An error occurred while scanning ${scanImage}: ${res.stderr}`
194 | );
195 | }
196 | },
197 | },
198 | }
199 | );
200 | return { stdout, stderr };
201 | }
202 |
203 | const processResult = (res: any) => {
204 |
205 | let vulns = [];
206 | if (res.stderr !== "") {
207 | return;
208 | }
209 |
210 | let output = res.stdout;
211 |
212 | if (uploadAqua) {
213 | output = output.slice(output.indexOf('{'));
214 | }
215 |
216 | console.log(output);
217 | var results = JSON.parse(output);
218 |
219 | if (SBOMOutput) {
220 | setShowSBOM("block");
221 | setSBOMContent(results);
222 | return;
223 | }
224 |
225 |
226 |
227 | if (results.Results === undefined) {
228 | setVulnerabilities([]);
229 | setShowFilter("none");
230 | setShowSuccess("block");
231 | return;
232 | }
233 |
234 | let all = 0;
235 | let critical = 0;
236 | let high = 0;
237 | let medium = 0;
238 | let low = 0;
239 | let unknown = 0;
240 |
241 |
242 | for (let i = 0; i < results.Results.length; i++) {
243 | let r = results.Results[i];
244 | if (r.Vulnerabilities === undefined) {
245 | continue;
246 | }
247 | for (let j = 0; j < r.Vulnerabilities.length; j++) {
248 | let v = r.Vulnerabilities[j];
249 | vulns.push(new TrivyVulnerability(v));
250 | all += 1;
251 | switch (v.Severity) {
252 | case "CRITICAL":
253 | critical += 1;
254 | break;
255 | case "HIGH":
256 | high += 1;
257 | break;
258 | case "MEDIUM":
259 | medium += 1;
260 | break;
261 | case "LOW":
262 | low += 1;
263 | break;
264 | default:
265 | unknown += 1;
266 | }
267 | }
268 | }
269 |
270 | setAll(all);
271 | setCritical(critical);
272 | setHigh(high);
273 | setMedium(medium);
274 | setLow(low);
275 | setUnknown(unknown);
276 |
277 | vulns.sort((a, b) => {
278 | if (getSeverityOrdering(a.severity) === getSeverityOrdering(b.severity)) {
279 | return a.pkgName >= b.pkgName ? 1 : -1;
280 | }
281 | return getSeverityOrdering(a.severity) >= getSeverityOrdering(b.severity)
282 | ? 1
283 | : -1;
284 | });
285 |
286 | if (all === 0) {
287 | console.debug("No results, showing the success screen");
288 | setShowSuccess("block");
289 | setShowFilter("none");
290 | } else {
291 | setShowFilter("block");
292 | }
293 | setAllVulnerabilities(vulns);
294 | setVulnerabilities(vulns);
295 | }
296 |
297 | const runScan = () => {
298 | setLoadingWait(true);
299 | setShowDefaultDisplay("block");
300 | setShowWelcome("none");
301 | triggerTrivy();
302 | }
303 |
304 | const resetUI = () => {
305 | setAll(0);
306 | setCritical(0);
307 | setHigh(0);
308 | setMedium(0);
309 | setLow(0);
310 | setUnknown(0);
311 | setVulnerabilities([]);
312 | setShowSuccess("none");
313 | setShowSBOM("none");
314 | setShowFilter("none");
315 | }
316 |
317 | const triggerFilter = (e: React.MouseEvent, obj: string) => {
318 | setSeverityFilter(obj);
319 | if (obj === "all") {
320 | setVulnerabilities(allVulnerabilities);
321 | return;
322 | }
323 | const filtered = allVulnerabilities.filter((v) => v.severityClass === obj);
324 |
325 | setVulnerabilities(filtered);
326 | }
327 |
328 | const imageUpdated = () => {
329 | resetUI();
330 | }
331 |
332 | React.useEffect(() => {
333 | if (aquaKey !== "" && aquaSecret !== "") {
334 | setShowUploadAqua("");
335 | } else {
336 | setShowUploadAqua("none");
337 | }
338 | }, [aquaKey, aquaSecret]);
339 |
340 | React.useEffect(() => {
341 | window.ddClient.extension.vm.service.get("/credentials").then((value: any) => {
342 | setAquaKey(value.aqua_key);
343 | setAquaSecret(value.aqua_secret);
344 | setAquaCSPMUrl(value.aqua_cspm_url);
345 | if (value.aqua_key !== "" && value.aqua_secret !== "" && value.aqua_cspm_url !== "") {
346 | setLoggedIn(true);
347 | }
348 | }).catch((err: any) => {
349 | console.log(err);
350 | });
351 | SendMetric("trivy_extension_opened", {});
352 | }, []);
353 |
354 |
355 | return (
356 |
357 |
358 |
359 | {/* Entry point to the extension - large hero with description and scan box */}
360 |
372 |
373 |
391 | {/* Top level interaction point - hidden when the welcome screen is displayed */}
392 |
408 |
412 | {/* Table of vulnerabilities with the filter control included in this component */}
413 |
428 | {/* Component that is displayed when the scan completes without issue */}
429 |
433 | {/* Shim to block the screen when the scan is loading */}
434 |
437 |
438 |