Skip to content

feat: add HSTSMaxAge, HSTSIncludeSubdomains, and configurable ciphers#232

Merged
gaborbk merged 10 commits into
canonical:masterfrom
tmerten:master
Feb 2, 2026
Merged

feat: add HSTSMaxAge, HSTSIncludeSubdomains, and configurable ciphers#232
gaborbk merged 10 commits into
canonical:masterfrom
tmerten:master

Conversation

@tmerten
Copy link
Copy Markdown
Contributor

@tmerten tmerten commented Jan 28, 2026

Description

Add settings for HSTSMaxAge and configurable ciphers.

Motivated by customer requests to the MAAS team.

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests
  • Independent change*
    • unsure what this means but it does impact the server and how it runs. It is independent from the functionality on the other hand.

Test instructions

It should be tested that

  • given TLS ciphers injected/used correctly by the webserver (also in unit test)
  • HSTS-max-age and HSTS-include-subdomains injected correctly if given (included in config test)
  • does everything work as before if those options are not applied in the YAML

Notes for code reviewers

Grill me, my first bigger code contribution in Go ;)

- adds HSTS middleware
- makes cipher suites configurable
  - TODO: instead of defining ciphers iterate over what go has
Make uppercase of HSTS and TLS consistent in
YAML and config.

Also add test with incorrect config to validate
that wrong cipher names are detected by config
parser.
not very clean yet, mostly generated and fixed
rough edges. Needs to be refactored dry
@tmerten
Copy link
Copy Markdown
Contributor Author

tmerten commented Jan 28, 2026

@slapcat : feel free to add your manual testing results or provide additional review.

@slapcat
Copy link
Copy Markdown
Contributor

slapcat commented Jan 28, 2026

LGTM! I confirmed everything still works without these options configured and that the HSTS headers appear in requests when configured.

Copy link
Copy Markdown

@gaborbk gaborbk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR! I have a few minor comments, otherwise looks great :)

Comment thread candidtest/candidtest.go
Comment thread cmd/candidsrv/main.go Outdated
Comment thread config/config.go Outdated
Comment thread cmd/candidsrv/main.go Outdated
Comment thread config/config.go Outdated
Comment thread config/config.go Outdated
Copy link
Copy Markdown
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but i'd suggest returning an error, when an error is returned from parseCipheSuites

Comment thread cmd/candidsrv/main.go Outdated
Comment thread config/config.go
cipherSuites, err := parseCipherSuites(c.TLSCipherSuites)
if err != nil {
logger.Errorf("cannot parse cipher suites: %s", err)
return nil
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure we don't want to return an error here? might be surprising to some that they set a set cipher suites that then isn't used, because one of them was misspelled. i propose returning an error so that the user can deal with it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO introducing an error here would mean introducing it above as well (when the certificate is created). I did not want to change too much of the existing code which is why I followed the pattern of returning nil in that case. That said, I'd like to get it going as is first. But I'm happy to follow up with something later.

Comment thread server_cipher_test.go Outdated
tmerten and others added 3 commits February 2, 2026 17:57
- brush up some comments
- remove commented code
- remove maxAge check in middleware
- make HSTS string constants, fix max-age format
- remove debug print statements in test
Co-authored-by: Gabor Borics-Kuerti <gabor.borics.kuerti@canonical.com>
@gaborbk gaborbk merged commit 32cd777 into canonical:master Feb 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants