Skip to content

Store x.509 certs in CRDB, auto-load on boot, API for management - #2099

Merged
smklein merged 73 commits into
mainfrom
x509-in-crdb
Jan 20, 2023
Merged

smklein merged 73 commits into
mainfrom
x509-in-crdb

Conversation

@smklein

@smklein smklein commented Dec 29, 2022 •

Copy link
Copy Markdown
Collaborator
  • Removes x.509 cert from Nexus package
  • Transfers certificate to Nexus as a part of the "RSS handoff", if they are available
  • Nexus auto-loads certificate from CRDB when booting
  • Adds /system/certificates API to Nexus

TODO (remaining items postponed until after this PR):

  • Fix existing tests
  • When x.509 certs are updated via the API, should we refresh them?
    • Should we refresh neighboring Nexus servers too?
  • Tests for the API?
  • ... if we don't require Nexus to boot by scraping a CRDB cert, we could remove it from the package system right now?
  • Certificate validation on input?
    • ... but should we add more?
  • Adding a /system/... endpoint this way is surprisingly difficult. There are a ton of steps to keep track of... maybe I could document or improve this process?: [docs][nexus] Document the process for adding new endpoints #2101

Part of #1959

@smklein smklein changed the title X509 in crdb Store x.509 certs in CRDB, auto-load on boot, API for management Dec 29, 2022
smklein added a commit that referenced this pull request Dec 30, 2022
I've been committing to Omicron for a while, and even I forget all the
steps involved here.

I figured I'd write this down after going through the process on
#2099 - maybe this could
also serve as a discussion point for "are some of these steps more
complicated than they need to be?".
#[error("Certificate exists, but is empty")]
CertificateEmpty,

#[error("Failed to parse private key")]

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.

Is there anything useful in the openssl stack here (that'd be useful to put into the error message the way we do for BadCertificate)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I had a request to do roughly the opposite of this in #2099 (comment) - I don't have any way to parse the openssl stack, and I haven't validated that it wouldn't leak private key info.

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.

Okay, we can deal with that if we run into this failure mode in the wild.

Comment thread nexus/src/app/certificate.rs Resolved
/// server. This involves either:
/// - Creating a new HTTPS server if once does not exist
/// - Refreshing an existing HTTPS server if it already exists
/// - Tearing down an HTTPS server if no certificates exist

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.

You're right -- this is harder than I thought. I was thinking that we're creating one HTTPS server for each certificate, all on the same port, but of course that makes no sense.

I didn't (and don't) have a particular answer in mind.

My intuition is that there's no good reason to allow external API requests to remove the last certificate because I can't think of a reason to do that and it seems like it would result in nobody but Oxide support being able to access the rack any more, and then likely only through the technician port. Fixing that isn't necessarily an MVP blocker or a blocker for this PR.

I also imagine operators wanting a way to test a new certificate without risk to existing end users, in which case they might need better tools for promotion/activation like you said, but I definitely wouldn't say that's an MVP thing.

// Lookup x509 certificates which might be stored in CRDB, specifically
// for launching the Nexus service.
//
// We only grab one certificate (see: the "limit" argument) because

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.

I had missed before that we're just grabbing an arbitrary one here. What do you think of using limit 2 and warning if we find more than one? That way if support is asked to debug a cert-related problem, we can see if there was more than one configured when the server went to configure its cert.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in ed84be6

# Oxide API: configuration file for test suite
#

# Avoid conflicting with other ports during HTTPS tests

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.

To be more specific, I mean: why can't this use a regular dropshot config block with a bind port of 0? I guess that's because what you said that we need to know the port before the HTTPS server is running? (Does that also mean you can't use 0 in the production config here?)

This isn't that important. I ask because when the TLS server was just another item in the dropshot_external array, that meant you could adjust its config (e.g., request_body_max_bytes) the same way as anything else. With this change, the TLS server is sort of special and if we ever wanted to adjust its config, it seems like we'd have to invent an ad hoc structure for that. Again, not super important, I just figured I'd ask.

Comment thread nexus/src/app/mod.rs

/// Internal dropshot server
internal_server: Mutex<Option<DropshotServer>>,
internal_server: std::sync::Mutex<Option<DropshotServer>>,

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.

Why the change to std::sync? I think for Nexus it's dangerous to use a std::sync::Mutex in async code, since the program and environment are complicated enough that it's very hard to guarantee that we'll never block for a while with the lock held (and then block the executor). (If it's because of this section of the docs, there was a discussion in oxide-rust the other day concluding that that note is a bit confusing.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was requested that I make this change in #2099 (comment) ; @sunshowers , do you have strong opinions?

Comment thread nexus/types/src/external_api/shared.rs Outdated
/// This certificate is intended for the "Nexus" service.
///
/// This service acts as the main API point for accessing the Oxide rack.
Nexus,

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.

nit: I'd suggest we call this External or ExternalApi instead. I'm not sure operators should be aware of "Nexus", or that it's the external endpoint (it might not always be! if we add a load balancer in the future). Plus, these certs are used for only one of Nexus's servers (not the internal API).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 1b46c9b

@davepacheco davepacheco left a comment

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.

Forgot to hit "approve". I'm cool with deferring all the items I mentioned.

@smklein
smklein merged commit 5f240cb into main Jan 20, 2023
@smklein
smklein deleted the x509-in-crdb branch January 20, 2023 21:31
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