-
Notifications
You must be signed in to change notification settings - Fork 9
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
New guide on container security best practices #156
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
98e45c1
- New guide on container security best practices
riverma 5242e10
Addressed some feedback: added filtering levels for CVEs
riverma 7a7ef1e
Feedback incorporated
riverma 4af98ae
Merge branch 'issue-155' of github.com:NASA-AMMOS/slim into issue-155
riverma 7903d1d
Recommending grype instead of docker scout
riverma ed4b54a
Better explanations
riverma 05b82fb
Less controversial language
riverma 45ac6d5
OGC to OCI
riverma e822388
Acknowledgements
riverma ae2c38a
Renamed best practice directory
riverma 2687593
Added link to grype page
riverma 6aa9388
Merging latest main changes
riverma 9004fa5
Wording updates from PR review
riverma a08d08a
Fixed typo in pre-commit message
riverma 427bdcc
Not checking DB updates for speed and better info for developer runni…
riverma 0be593d
Better language
riverma 20ab000
Reworded to be container-centric; running scan at push stage
riverma 93199f3
Clarified local dir scan and ensure pre-commit scans only upon push
riverma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
docs/guides/software-lifecycle/security/container-security/.pre-commit-config.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- repo: local | ||
hooks: | ||
- id: docker-scout-cve-scan | ||
name: Docker Scout CVE Scan | ||
entry: python -c "import subprocess; import sys; result=subprocess.run(['docker', 'scout', 'cves', 'fs://.', '--only-severity', 'critical', '--exit-code']); sys.exit(result.returncode)" | ||
language: system |
130 changes: 130 additions & 0 deletions
130
docs/guides/software-lifecycle/security/container-security/README.mdx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import CodeBlock from '@theme/CodeBlock'; | ||
import PreCommitConfigSource from '!!raw-loader!./.pre-commit-config.yml'; | ||
import DependabotSource from '!!raw-loader!./dependabot.yml'; | ||
|
||
# Container Security | ||
|
||
<pre align="center">Comprehensive guide to scanning container images for security vulnerabilities using pre-commit hooks and automated repository scanning tools.</pre> | ||
|
||
![banner-image](/img/container-security-screen.png) | ||
|
||
## Introduction | ||
|
||
**Background**: Container security is crucial for ensuring that your applications and services run in a secure environment. Containers encapsulate software and dependencies, providing consistency across environments. However, they also carry the risk of vulnerabilities within the base images or dependencies. This guide will help you establish a secure environment by implementing proactive vulnerability scanning. By using pre-commit hooks and repository-level automated scanning, you'll be able to identify security issues early, before they impact production. | ||
|
||
**Use Cases**: | ||
- Running vulnerability scans for all containers at the development stage | ||
- Ensuring that base images used in CI/CD pipelines are free from known vulnerabilities | ||
riverma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Automating container vulnerability scans in repositories hosting container images | ||
|
||
--- | ||
|
||
## Prerequisites | ||
**Software:** | ||
- Docker containers | ||
riverma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `pre-commit` framework | ||
- Docker Hub or GitHub Dependabot | ||
|
||
**Skills:** | ||
- Basic understanding of Git hooks and Docker commands | ||
- Familiarity with YAML files for pre-commit configuration | ||
|
||
--- | ||
|
||
## Quick Start | ||
|
||
**Run a local scan of your container's repository (folder containing the Dockerfile)** | ||
|
||
``` | ||
docker scout cves fs://. | ||
``` | ||
|
||
**⬇️ [.pre-commit-config.yml](.pre-commit-config.yml)** | ||
|
||
Download the file above to access the pre-commit configuration file, which includes an example hook for Docker Scout vulnerability scanning. The file should be placed within your local Git repository. You'll want to ensure you have the [pre-commit](https://pre-commit.com) framework installed. | ||
riverma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
**⬇️ [dependabot.yml](dependabot.yml)** | ||
|
||
Download the file above to access the recommended `dependabot.yml` file, which configures a GitHub dependabot deployment to perform Docker vulnerability scanning. The file should be placed within `.github/dependabot.yml`. You'll want to ensure you have dependabot configured - see our [GitHub Security Best Practices](/docs/guides/software-lifecycle/security/github-security/README.md) guide for details. | ||
|
||
--- | ||
|
||
## Step-by-Step Guide | ||
|
||
### Step 1: Setup Automated Local Scanning of Container Vulnerabilities | ||
|
||
1. Ensure you have `docker` installed and the `scout` plugin. See [this quickstart](https://docs.docker.com/scout/quickstart/#step-2-enable-docker-scout) from Docker's documentation. | ||
|
||
`docker scout` | ||
|
||
2. Login to DockerHub to enable scout (required) | ||
|
||
``` | ||
docker login | ||
``` | ||
|
||
3. Perform a scan of the local repository for CVES (vulnerabilities) | ||
|
||
``` | ||
docker scout cves fs://. | ||
``` | ||
|
||
NOTE: you can use the `--only-severity critical` to limit scanning to just specific criticality levels. [See options documentation here](https://docs.docker.com/reference/cli/docker/scout/cves/#options). | ||
|
||
### Step 2: Setup Automated Local Scanning of Container Vulnerabilities | ||
|
||
⚠️ NOTE: we only recommend installing this pre-commit hook if you've already scanned your repository and eliminated vulnerabilities first. See Step 1. | ||
|
||
1. Install the pre-commit framework via Python: | ||
```bash | ||
pip install pre-commit | ||
``` | ||
2. Initialize pre-commit in your repository: | ||
```bash | ||
pre-commit install | ||
``` | ||
3. Create a `.pre-commit-config.yaml` file in the root directory of your Git repository with the following content (note we suggest only scanning for critical vulnerabilities to reduce developer overhead): | ||
<CodeBlock language="yaml">{PreCommitConfigSource}</CodeBlock> | ||
|
||
NOTE: you'll need a DockerHub account to run the `docker scout` tool. Note that this command will compare a local scan's results with Docker's database. [More information about Docker Scout is available here](https://docs.docker.com/scout/quickstart/). | ||
|
||
### Step 3: Set Up Automated Repository Scanning | ||
- **Docker Hub**: | ||
- Push your images to Docker Hub, where automatic scans are enabled by default. | ||
|
||
- **GitHub**: | ||
- Leverage Dependabot to perform automated scans of containers (Docker) at a prescribed schedule. | ||
- Example `.github/dependabot.yml` file contents: | ||
<CodeBlock language="yaml">{DependabotSource}</CodeBlock> | ||
|
||
--- | ||
|
||
## Frequently Asked Questions (FAQ) | ||
|
||
**Q: What happens if the pre-commit scan finds vulnerabilities?** | ||
|
||
A: The pre-commit hook will prevent you from committing your changes until vulnerabilities are resolved. The scan is configured to only alert for `critical` vulnerabilities by default to be less obtrusive. You can disable the plugin via `SKIP=docker-scout-cve-scan git commit ...` | ||
|
||
**Q: What if I want to skip the pre-commit scan temporarily?** | ||
|
||
A: Use the `--no-verify` flag with the `git commit` command to bypass the hook, though this is not recommended. | ||
|
||
**Q: Is it possible to run vulnerability scans without pre-commit hooks?** | ||
|
||
A: Yes, you can incorporate scans into your CI/CD pipeline or use repository scanning tools like Docker Hub or Dependabot, though this poses the risk of having code pushed to other developers that may be vulnerable. | ||
|
||
--- | ||
|
||
## Credits | ||
|
||
**Authorship**: | ||
- [Rishi Verma](https://www.github.com/riverma) | ||
|
||
**Acknowledgements**: | ||
* OPERA SDS Project for implementation guidance | ||
|
||
--- | ||
|
||
## Feedback and Contributions | ||
|
||
We welcome feedback and contributions to help improve and grow this guide. Please see our [contribution guidelines](https://nasa-ammos.github.io/slim/docs/contribute/contributing/). |
8 changes: 8 additions & 0 deletions
8
docs/guides/software-lifecycle/security/container-security/dependabot.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "docker" | ||
directory: "/" | ||
schedule: | ||
interval: 'daily' | ||
labels: | ||
- 'dependencies' |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
riverma marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6525,6 +6525,14 @@ [email protected]: | |
iconv-lite "0.4.24" | ||
unpipe "1.0.0" | ||
|
||
raw-loader@^4.0.2: | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-4.0.2.tgz#1aac6b7d1ad1501e66efdac1522c73e59a584eb6" | ||
integrity sha512-ZnScIV3ag9A4wPX/ZayxL/jZH+euYb6FcUinPcgiQW0+UBtEv0O6Q3lGd3cqJ+GHH+rksEv3Pj99oxJ3u3VIKA== | ||
dependencies: | ||
loader-utils "^2.0.0" | ||
schema-utils "^3.0.0" | ||
|
||
[email protected], rc@^1.2.8: | ||
version "1.2.8" | ||
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hi @riverma explicit mention of Docker in the title is probably necessary. Reasoning; there are many (OCI-compliant) alternatives to Docker which could also be scanned for security vulnerabilities.
That is unless you want to broaden the scope of this best practice outside of Docker. Just food for thought :)
Nice work.
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.
Hey @lewismc - great observation! I was wanting to keep this guide title general so that we could support content for the Docker alternatives as well down-the-line.
That being said (and we could get feedback from @NASA-AMMOS/slim-community here too) - which other containers should we support within this guide? By that I mean: which other container technologies are actually being used by your projects right now or will be in aspiration? True to the SLIM philosophy - we tend to make guides that are targeted towards solutions / technology by our community members, and as the community grows, we iterate and expand the scope. (CC @NASA-AMMOS/slim-community-member-leads)
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.
The Open Container Initiative (OCI) is a standard started and promoted by Docker, amongst others. Many on Lab are now using Podman, which reports to be OCI-compliant, in place of Docker. In fact, I believe it is mandated going forward on AWS for some teams. Here is more information on Podman origins.
Thinking off-the-grid, what about making it an OCI-compliant container security guide?
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.
Hi @lewismc @jpl-jengelke - thought about your suggestions, discussed a bit with @lylebarner and ended up swapping to the grype toolkit, which is OGC compliant and not Docker specific. Moreover, it can scan non-containers as well.