- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3k
Improve Traefik secuity settings, add security documentation #2854
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
          
     Open
      
      
            jameswilliams1
  wants to merge
  7
  commits into
  cookiecutter:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
jameswilliams1:bugfix/2841-traefik-uses-weak-security-settings-by-default
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      da0a683
              
                configure traefik http security headers
              
              
                jameswilliams1 837c869
              
                run traefik as non-root user
              
              
                jameswilliams1 6442fb5
              
                fix production.py templating
              
              
                jameswilliams1 ff97a20
              
                add security documentation
              
              
                jameswilliams1 0c7cc38
              
                change django 3.1 docs to dev
              
              
                jameswilliams1 c9d67c3
              
                add commented out security settings if using docker
              
              
                jameswilliams1 88ce135
              
                bump traefik to v2.4
              
              
                jameswilliams1 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
  
    
      This file contains hidden or 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 | 
|---|---|---|
|  | @@ -215,3 +215,4 @@ tags | |
| .idea/ | ||
|  | ||
| .pytest_cache/ | ||
| .vscode/ | ||
  
    
      This file contains hidden or 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 hidden or 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 | 
|---|---|---|
|  | @@ -24,6 +24,7 @@ Contents: | |
| deployment-with-docker | ||
| docker-postgres-backups | ||
| websocket | ||
| security | ||
| faq | ||
| troubleshooting | ||
|  | ||
|  | ||
  
    
      This file contains hidden or 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,52 @@ | ||
| Security | ||
| ======== | ||
|  | ||
| .. index:: Security, Configuration, TLS, SSL, Encrpytion, Compatibility | ||
|  | ||
| Overview | ||
| -------- | ||
|  | ||
| There is a reasonable level of security for most use cases configured as standard in cookiecutter-django, as much as is possible without knowing the features of the website you are building. That being said, your security requirements may differ greatly; before any deployment **you should ensure the security of your website is appropriate for your use case**. As a starting point, you should check any security settings used in cookiecutter-django and see if they are right for you, also actioning any TODOs. A good place to start is `config/settings/production.py`_, as well as `compose/production/traefik/traefik.yml`_ if you are using Docker. Naturally if you collect sensitive data, or have reason to believe your site is at all likely be targeted by hackers, a complete security review before allowing any user access is a must. | ||
|  | ||
| .. _`config/settings/production.py`: https://github.com/pydanny/cookiecutter-django/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/config/settings/production.py | ||
| .. _`compose/production/traefik/traefik.yml`: https://github.com/pydanny/cookiecutter-django/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/compose/production/traefik/traefik.yml | ||
|  | ||
|  | ||
|  | ||
| Security Checklist | ||
| --------------------------------- | ||
| This list is by no means comprehensive, but is a good starting point for those less well-versed in website security: | ||
|  | ||
| - Run ``python manage.py check --deploy`` and ensure any issues listed are fixed (make sure you are checking the production settings by setting ``DJANGO_SETTINGS_MODULE=config.settings.production`` in the environment). Note: if you are using Docker, some settings flagged as missing by Django may be managed by Traefik's config. | ||
| - Test your SSL security `using SSL Labs`_, a full score may be overkill and will likely cause compatibility issues with older browsers, but try to action anything flagged in red. **Note**: full marks here does not necessarily make your website 'secure', this tool merely tests the strength of your TLS encryption settings. | ||
| - Check how your site stacks up against Mozilla's `Web Security Cheat Sheet`_. Again, completing everything listed here may be overkill but it is good as a reference. | ||
| - Consider creating a `Content Security Policy`_ for your site. In short, this is a HTTP header that instructs client browsers where they should load resources from (scripts, stylesheets etc.), and what web features should be enabled (inline HTML script and style tags, allowed domains for JavaScript AJAX fetches etc.). An ideal policy is to disable everything by default then just enable the features you use on your site. | ||
|  | ||
| .. _`using SSL Labs`: https://www.ssllabs.com/ssltest/ | ||
| .. _`Web Security Cheat Sheet`: https://infosec.mozilla.org/guidelines/web_security.html#web-security-cheat-sheet | ||
| .. _`Content Security Policy`: https://content-security-policy.com/ | ||
|  | ||
| Compatibility Issues | ||
| -------------------- | ||
| By default, cookiecutter-django uses security settings that may break compatibility with very old browsers. Before changing your settings to allow for these older browsers, consider asking your clients to update. There is a trade-off between security and compatibility, and weakening your security to support a minority of users can make things less safe for those who are up to date. | ||
|  | ||
| Some settings of note when using Docker (in `compose/production/traefik/traefik.yml`_): | ||
|  | ||
| - ``tls.options.default.minVersion: VersionTLS12``: `TLS 1.2 supported browsers`_ | ||
| - ``tls.options.default.sniStrict: true``: `SNI supported browsers`_ | ||
| - ``tls.options.default.cipherSuites``: only ECDHE ciphers are used, this will not work in old browsers. Internet Explorer <11 does not work and IE11 seems to only work on Windows 10. Edge is fine though, and is a better alternative for Windows users. | ||
|  | ||
| .. _`TLS 1.2 supported browsers`: https://caniuse.com/tls1-2 | ||
| .. _`SNI supported browsers`: https://caniuse.com/sni | ||
|  | ||
| Useful Links | ||
| ------------ | ||
| - `Django Deployment Checklist`_ | ||
| - `SSL and TLS Deployment Best Practices`_ | ||
| - `Content Security Policy (CSP) Quick Reference Guide`_ | ||
| - `Mozilla Web Security Cheat Sheet`_ | ||
|  | ||
| .. _`Django Deployment Checklist`: https://docs.djangoproject.com/en/dev/howto/deployment/checklist/ | ||
| .. _`SSL and TLS Deployment Best Practices`: https://github.com/ssllabs/research/wiki/SSL-and-TLS-Deployment-Best-Practices | ||
| .. _`Content Security Policy (CSP) Quick Reference Guide`: https://content-security-policy.com/ | ||
| .. _`Mozilla Web Security Cheat Sheet`: https://infosec.mozilla.org/guidelines/web_security.html#web-security-cheat-sheet | 
        
          
          
            26 changes: 21 additions & 5 deletions
          
          26 
        
  {{cookiecutter.project_slug}}/compose/production/traefik/Dockerfile
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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 | 
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| FROM traefik:v2.2.11 | ||
| RUN mkdir -p /etc/traefik/acme \ | ||
| && touch /etc/traefik/acme/acme.json \ | ||
| && chmod 600 /etc/traefik/acme/acme.json | ||
| COPY ./compose/production/traefik/traefik.yml /etc/traefik | ||
| FROM traefik:2.4 | ||
|  | ||
| WORKDIR /etc/traefik/ | ||
|  | ||
| RUN addgroup --system traefik \ | ||
| && adduser \ | ||
| --disabled-password \ | ||
| --gecos '' \ | ||
| --no-create-home \ | ||
| --ingroup traefik \ | ||
| traefik \ | ||
| && mkdir acme/ \ | ||
| && touch acme/acme.json \ | ||
| && chmod 0600 acme/acme.json \ | ||
| && chown -R traefik:traefik . | ||
|  | ||
| EXPOSE 8080/tcp 8443/tcp | ||
|  | ||
| VOLUME /etc/traefik/acme/ | ||
|  | ||
| USER traefik | 
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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
    
  
  
    
              
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.