mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-11-01 18:46:54 +08:00
@ -1134,9 +1134,9 @@ CMD [ "node", "dist/app.js" ]
|
||||
|
||||
## ![✔] 8.4. Use .dockerignore to prevent leaking secrets
|
||||
|
||||
**TL;DR**: Include a .dockerignore file that filters out common secret files and development artifacts. By doing so, you might prevent secrets from leaking into the image. As a bonus the build time will significantly decrease. Also, ensure not to copy all files recursively rather explicitly choose what should be copied to Docker
|
||||
**TL;DR**: Include a `.dockerignore` file that filters out common secret files and development artifacts. By doing so, you might prevent secrets from leaking into the image. As a bonus the build time will significantly decrease. Also, ensure not to copy all files recursively rather explicitly choose what should be copied to Docker
|
||||
|
||||
**Otherwise**: Common personal secret files like .env, .aws and .npmrc will be shared with anybody with access to the image (e.g. Docker repository)
|
||||
**Otherwise**: Common personal secret files like `.env`, `.aws` and `.npmrc` will be shared with anybody with access to the image (e.g. Docker repository)
|
||||
|
||||
🔗 [**Read More: Use .dockerignore**](/sections/docker/docker-ignore.md)
|
||||
|
||||
@ -1144,7 +1144,7 @@ CMD [ "node", "dist/app.js" ]
|
||||
|
||||
## ![✔] 8.5. Clean-up dependencies before production
|
||||
|
||||
**TL;DR:** Although DevDependencies are sometimes needed during the build and test life-cycle, eventually the image that is shipped to production should be minimal and clean from development dependencies. Doing so guarantees that only necessary code is shipped and the amount of potential attacks (i.e. attack surface) is minimized. When using multi stage build (see dedicated bullet) this can be achieved by installing all dependencies first and finally running `npm ci --production`
|
||||
**TL;DR:** Although Dev-Dependencies are sometimes needed during the build and test life-cycle, eventually the image that is shipped to production should be minimal and clean from development dependencies. Doing so guarantees that only necessary code is shipped and the amount of potential attacks (i.e. attack surface) is minimized. When using multi-stage build (see dedicated bullet) this can be achieved by installing all dependencies first and finally running `npm ci --production`
|
||||
|
||||
**Otherwise:** Many of the infamous npm security breaches were found within development packages (e.g. [eslint-scope](https://eslint.org/blog/2018/07/postmortem-for-malicious-package-publishes))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user