Skip to content

feat: Add TLS support for influxdb3#26246

Merged
mgattozzi merged 1 commit intomainfrom
mgattozzi/tls
Apr 10, 2025
Merged

feat: Add TLS support for influxdb3#26246
mgattozzi merged 1 commit intomainfrom
mgattozzi/tls

Conversation

@mgattozzi
Copy link
Copy Markdown
Contributor

This commit adds TLS support to influxdb3 and allows users to pass in a path to a key and cert file with the --tls-key and --tls-cert flags in the serve command. It also adds the ability for every command to specify a certificate authority for requests. This is mostly needed when the cert is self signed, but there are other use cases for this.

The big thing is that most of our tests now use TLS by default. Included are self signed certs for localhost and the the CA cert included in the commit. Since these are only used for testing this should be fine to include as they are not used in nor are they intended to be used in any production system. The expiry has been set for 365 days and the file perms are set to o600 like the original issue mentioned. The tests pass with this restriction.

I've verified that the API works via curl with the self signed certs as I did not need to pass in the -k option to bypass checking the certs were valid. The same goes for our tests. They use the rootCA.pem file to verify the self signed cert when connecting and reject it otherwise.

With this users can be confident that their queries are safely encrypted during transport.

Note that TLS works for both FlightSQL and our normal APIs.

Closes #25774

This commit adds TLS support to influxdb3 and allows users to pass in a
path to a key and cert file with the --tls-key and --tls-cert flags in
the serve command. It also adds the ability for every command to specify
a certificate authority for requests. This is mostly needed when the
cert is self signed, but there are other use cases for this.

The big thing is that most of our tests now use TLS by default. Included
are self signed certs for localhost and the the CA cert included in the
commit. Since these are *only* used for testing this should be fine to
include as they are not used in nor are they intended to be used in any
production system. The expiry has been set for 365 days and the file
perms are set to o600 like the original issue mentioned. The tests pass
with this restriction.

I've verified that the API works via curl with the self signed certs as
I did *not* need to pass in the -k option to bypass checking the certs
were valid. The same goes for our tests. They use the rootCA.pem file
to verify the self signed cert when connecting and reject it otherwise.

With this users can be confident that their queries are safely encrypted
during transport.

Note that TLS works for both FlightSQL and our normal APIs.

Closes #25774
@mgattozzi mgattozzi requested review from a team and jdstrand April 10, 2025 15:58
Copy link
Copy Markdown
Contributor

@jdstrand jdstrand left a comment

Choose a reason for hiding this comment

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

I'll let other review the implementation but I can say I don't see any issues:

  • uses rustls (via hyper-rustls create). This is a solid choice: has tls1.2 and higher support (ie, these are safe algorithms), potential for FIPS configuration, etc. We have (mostly) standardized on this in our rust code (a good thing)
  • supports a custom CA (good for testing, but also good for users that need it (eg, k8s, on-prem CA, etc))
  • able to specify a cert and private key via filenames (as opposed to S3 (good, can't be accidentally exposed via API))
  • has various tests that verify the functionality

Observations:

  • The test pem file has a time bomb:
    $ openssl x509 -in /tmp/pem -text -noout
            Validity
                Not Before: Apr  9 22:27:29 2025 GMT
                Not After : Apr  9 22:27:29 2026 GMT
    
    I suggest a much longer timeout or better yet, creating these dynamically. It would be nice to have expiration tests in the code too.
  • I might have missed them, but it would be good to add negative tests (eg, bad certs) if you haven't already. It would be nice to have a client try to downgrade to tls1.1 and fail, but that is probably overkill since hyper-rustls likely won't ever implement 1.1.
  • I might've missed them, but it would be good to ensure that non-TLS connections still work as expected.
  • It would be nice to be able to force only tls1.3 (customers will want it and hyper-rustls supports disabling 1.2), but this can be in a followup PR.

None of the observations are blockers from me, but it would be nice to add some of the tests if you haven't already.

@mgattozzi
Copy link
Copy Markdown
Contributor Author

I'm happy to open up some issues for follow up work in the coming week or so if there are no actual blockers, including dynamic cert gen etc.

@jdstrand
Copy link
Copy Markdown
Contributor

I'm happy to open up some issues for follow up work in the coming week or so if there are no actual blockers, including dynamic cert gen etc.

None from me; all my observations can come as followups.

Copy link
Copy Markdown
Contributor

@waynr waynr left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@jdstrand
Copy link
Copy Markdown
Contributor

jdstrand commented Apr 10, 2025

None from me; all my observations can come as followups.

One other thing for your list of followups which is likely tied to the config file work: having to specify the custom CA in the client commands (when using a custom CA) will be annoying for some. Honoring an env var or a config file option would be nice here.

@mgattozzi mgattozzi merged commit fe69793 into main Apr 10, 2025
12 checks passed
@mgattozzi mgattozzi deleted the mgattozzi/tls branch April 10, 2025 17:45
@jdstrand
Copy link
Copy Markdown
Contributor

Btw, thanks for getting this in! :)

mgattozzi added a commit that referenced this pull request Apr 16, 2025
This commit is a follow up to #26246 and adds env vars to all of the TLS
options in Core/Enterprise. This allows users to specify things like a
CA file so that they don't need to run every single command with it
specified. Same with the cert and key files. This is also nice for
letting users configure environments like a Docker container with an
env var rather than with command line args.

Closes #26253
mgattozzi added a commit that referenced this pull request Apr 17, 2025
This commit is a follow up to #26246 and generates test certs on the fly
for our test suite. In practice this will only need to be done once with
a fresh repo check out as the certs will expire long after anyone would
reasonably be working on this code in the year 4096! This could be
extended in the future to generate negative tls tests where the file
should be expired.

Closes #26254
mgattozzi added a commit that referenced this pull request Apr 21, 2025
This commit is a follow up to #26246 and generates test certs on the fly
for our test suite. In practice this will only need to be done once with
a fresh repo check out as the certs will expire long after anyone would
reasonably be working on this code in the year 4096! This could be
extended in the future to generate negative tls tests where the file
should be expired.

Closes #26254
hiltontj pushed a commit that referenced this pull request May 2, 2025
This commit is a follow up to #26246 and generates test certs on the fly
for our test suite. In practice this will only need to be done once with
a fresh repo check out as the certs will expire long after anyone would
reasonably be working on this code in the year 4096! This could be
extended in the future to generate negative tls tests where the file
should be expired.

Closes #26254
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.

[Feature Request] add TLS support

3 participants