Skip to content

Conversation

@Adam-D-Lewis
Copy link
Member

@Adam-D-Lewis Adam-D-Lewis commented Oct 23, 2025

Closes #3121
Docs Issue - nebari-dev/nebari-docs#605
We should add some stuff in the next release upgrade - #3168

Summary

This PR adds built-in HSTS (HTTP Strict Transport Security) configuration to Nebari's ingress layer.

  • Adds configurable HSTS middleware for Traefik
  • Applies HSTS headers to both websecure and minio entrypoints when enabled

If HSTS is unspecified, then it will be enabled for existing, and let's encrypt certs, but not enabled for self-signed or no cert.

Example Configuration

ingress:
  hsts:
    enabled: true
    max_age: 30 
    include_subdomains: true
    preload: false

This commit implements HSTS as a built-in Nebari feature, addressing
security compliance requirements mentioned in the related issue.

Changes:
- Add HSTS configuration schema to Ingress class with options for:
  - enabled: Toggle HSTS on/off (default: false)
  - max_age: HSTS max-age in seconds (default: 31536000 = 1 year)
  - include_subdomains: Include subdomains in policy (default: true)
  - preload: Enable HSTS preload (default: false)

- Create Traefik middleware resource for HSTS headers
  - Conditionally created based on hsts-enabled setting
  - Applies to both websecure (443) and minio (9080) entrypoints

- Update Traefik deployment to use HSTS middleware when enabled

Users can now enable HSTS in their nebari-config.yaml:
```yaml
ingress:
  hsts:
    enabled: true
    max_age: 31536000
    include_subdomains: true
    preload: false
```

This replaces the previous workaround of manually creating middleware
resources and using terraform_overrides.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Changed the default HSTS max-age from 31536000 (1 year) to 30 seconds
to allow safe initial testing of HSTS configuration.

Rationale:
- HSTS headers instruct browsers to remember HTTPS enforcement for the
  specified duration
- If misconfigured with a long max-age, users could be locked out until
  the duration expires
- A 30-second default allows administrators to validate the configuration
  works correctly before committing to a longer duration

Added detailed comments in:
- Python schema (__init__.py) explaining the conservative default
- Terraform variables (variables.tf) noting the production recommendation
- Middleware resource (hsts-middleware.tf) with example configuration

Users should increase max_age to production values (e.g., 31536000)
after validating their deployment works correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Adam-D-Lewis Adam-D-Lewis requested a review from a team as a code owner October 23, 2025 15:11
@Adam-D-Lewis Adam-D-Lewis requested review from dcmcand and marcelovilla and removed request for a team October 23, 2025 15:11
@Adam-D-Lewis Adam-D-Lewis marked this pull request as draft October 23, 2025 15:13
@Adam-D-Lewis Adam-D-Lewis changed the title Release 2025.10.1: HSTS support, K8s 1.32, and conda-store worker customization Add built-in HSTS (HTTP Strict Transport Security) support Oct 23, 2025
@Adam-D-Lewis Adam-D-Lewis marked this pull request as ready for review October 23, 2025 22:12
cert_type = config.get("certificate", {}).get(
"type", CertificateEnum.selfsigned.value
)
is_valid_cert = cert_type in [CertificateEnum.letsencrypt.value, "existing"]
Copy link
Member Author

@Adam-D-Lewis Adam-D-Lewis Oct 28, 2025

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


# Initialize HSTS based on certificate type if not explicitly configured
hsts = self.config.ingress.hsts
if hsts is None:
Copy link
Member Author

Choose a reason for hiding this comment

The 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

@Adam-D-Lewis Adam-D-Lewis changed the title Add built-in HSTS (HTTP Strict Transport Security) support [Ready for Review] Add built-in HSTS (HTTP Strict Transport Security) support Oct 28, 2025
@Adam-D-Lewis Adam-D-Lewis changed the title [Ready for Review] Add built-in HSTS (HTTP Strict Transport Security) support [Ready for Review] Add HSTS (HTTP Strict Transport Security) support Oct 28, 2025
@viniciusdc
Copy link
Contributor

This will be pushed to a minor release after this one is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New 🚦

Development

Successfully merging this pull request may close these issues.

[BUG] - Nebari should be sending HSTS headers

4 participants