- 
                Notifications
    
You must be signed in to change notification settings  - Fork 108
 
[Ready for Review] Add HSTS (HTTP Strict Transport Security) support #3165
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
      
      
            Adam-D-Lewis
  wants to merge
  10
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
claude/review-issue-recommendation-011CUQHHYQUqEfW1yeydNdEQ
  
      
      
   
  
    
  
  
  
 
  
      
    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 8 commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      ddfccce
              
                Add built-in HSTS (HTTP Strict Transport Security) support
              
              
                claude d3ddfe5
              
                Use conservative HSTS max-age default for initial testing
              
              
                claude 51f08c5
              
                change default maxage to 300
              
              
                Adam-D-Lewis b73b035
              
                enable hsts by default for non local providers
              
              
                Adam-D-Lewis 907d74c
              
                Change whether HSTS is enabled by default to be based on cert type
              
              
                Adam-D-Lewis 9c0aba9
              
                update
              
              
                Adam-D-Lewis 0bcb5ef
              
                add missing tf vars, fix typo
              
              
                Adam-D-Lewis c3b26b9
              
                clean up comments, set default age to 1 year
              
              
                Adam-D-Lewis 818e0a7
              
                refactor
              
              
                Adam-D-Lewis 851fe94
              
                Merge branch 'main' into claude/review-issue-recommendation-011CUQHHY…
              
              
                Adam-D-Lewis 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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -145,7 +145,16 @@ class DnsProvider(schema.Base): | |
| auto_provision: Optional[bool] = False | ||
| 
     | 
||
| 
     | 
||
| class HSTS(schema.Base): | ||
| enabled: bool = True | ||
| # See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security | ||
| max_age: int = 31536000 | ||
| include_subdomains: bool = True | ||
| preload: bool = False | ||
| 
     | 
||
| 
     | 
||
| class Ingress(schema.Base): | ||
| hsts: Optional[HSTS] = None | ||
| terraform_overrides: Dict = {} | ||
| 
     | 
||
| 
     | 
||
| 
          
            
          
           | 
    @@ -203,6 +212,24 @@ def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]): | |
| cert_details["cloudflare-dns-api-token"] = os.environ.get( | ||
| "CLOUDFLARE_TOKEN" | ||
| ) | ||
| 
     | 
||
| # Initialize HSTS based on certificate type if not explicitly configured | ||
| hsts = self.config.ingress.hsts | ||
| if hsts is None: | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if hsts is not in config, then default to enabling it for lets-encrypt and existing certs, otherwise default to disabling it  | 
||
| # Only enable HSTS for valid certificates (lets-encrypt, existing) | ||
| # Do not enable for self-signed certs to avoid HSTS pinning issues during initial setup | ||
| is_valid_cert = cert_type in ["lets-encrypt", "existing"] | ||
| if is_valid_cert: | ||
| hsts = HSTS() | ||
| else: | ||
| hsts = HSTS(enabled=False) | ||
| 
     | 
||
| hsts_config = { | ||
| "hsts-enabled": hsts.enabled, | ||
| "hsts-max-age": hsts.max_age, | ||
| "hsts-include-subdomains": hsts.include_subdomains, | ||
| "hsts-preload": hsts.preload, | ||
| } | ||
| return { | ||
| **{ | ||
| "traefik-image": { | ||
| 
        
          
        
         | 
    @@ -217,6 +244,7 @@ def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]): | |
| **self.config.ingress.terraform_overrides, | ||
| }, | ||
| **cert_details, | ||
| **hsts_config, | ||
| } | ||
| 
     | 
||
| def set_outputs( | ||
| 
          
            
          
           | 
    ||
  
    
      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
    
  
  
    
              
        
          
  
    
      
          
            25 changes: 25 additions & 0 deletions
          
          25 
        
  src/_nebari/stages/kubernetes_ingress/template/modules/kubernetes/ingress/hsts-middleware.tf
  
  
      
      
   
        
      
      
    
  
    
      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,25 @@ | ||
| # HSTS (HTTP Strict Transport Security) Middleware | ||
| # | ||
| # Recovery: If HSTS causes issues, set max_age: 0 and redeploy. Users visit | ||
| # the site once over HTTPS and their browsers will immediately clear the policy. | ||
| # | ||
| resource "kubernetes_manifest" "hsts_middleware" { | ||
| count = var.hsts-enabled ? 1 : 0 | ||
| 
     | 
||
| manifest = { | ||
| apiVersion = "traefik.containo.us/v1alpha1" | ||
| kind = "Middleware" | ||
| metadata = { | ||
| name = "${var.name}-hsts" | ||
| namespace = var.namespace | ||
| } | ||
| spec = { | ||
| headers = { | ||
| stsSeconds = var.hsts-max-age | ||
| stsIncludeSubdomains = var.hsts-include-subdomains | ||
| stsPreload = var.hsts-preload | ||
| forceSTSheader = true | ||
| } | ||
| } | ||
| } | ||
| } | 
  
    
      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
    
  
  
    
              
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
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.
add hsts to nebari config on
nebari init ...if cert type is letsencrypt or existing