Skip to content

Add Secure attribute to session cookie - #3902

Merged
david-crespo merged 4 commits into
mainfrom
session-cookie-secure
Sep 7, 2023
Merged

david-crespo merged 4 commits into
mainfrom
session-cookie-secure

Conversation

@david-crespo

@david-crespo david-crespo commented Aug 18, 2023 •

Copy link
Copy Markdown
Contributor

We had a TODO item in the code pointing to #249, but no dedicated issue. The Secure attribute means the browser will only include the cookie with encrypted requests. This is a no-brainer table stakes kind of thing we must do. This was blocked on adding TLS to Nexus.

We use deployment.dropshot_external.tls to decide whether to include Secure so things will still work in non-TLS environments like local dev.

Because the tests do not run in a browser, I think they should be indifferent to the Secure attribute, but I'll find out when CI runs.

The browser ignores this on localhost, so for a simple local Nexus instance without TLS this shouldn't be a problem. However, if people are running Nexus without TLS for other test and dev setups, that might be a problem — the web console won't work. I think we could get around that by looking at the config value for deployment.dropshot_external.tls and only including Secure if it's true.

@david-crespo david-crespo changed the title Add Secure attribute to session cookie Add Secure attribute to session cookie Aug 18, 2023
@davepacheco

Copy link
Copy Markdown
Collaborator

This seems like a good change.

The browser ignores this on localhost, so for a simple local Nexus instance without TLS this shouldn't be a problem. However, if people are running Nexus without TLS for other test and dev setups, that might be a problem — the web console won't work. I think we could get around that by looking at the config value for deployment.dropshot_external.tls and only including Secure if it's true.

I think we might want to do this? I don't know about other people but I definitely do run Omicron that way. We could also lean into making even dev setups use TLS, but that requires a more real DNS setup that's a little tricky.

@david-crespo

Copy link
Copy Markdown
Contributor Author

Ok, I'll add the check for the config value. I agree local TLS is too much, at least for right now.

// browser expiration is mostly for convenience, as the API will
// reject requests with an expired session regardless
apictx.session_absolute_timeout(),
apictx.external_tls_enabled,

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.

I thought about having session_cookie_header_value take the whole apictx, but then the unit tests become less trivial, and it's nice for unit tests to be trivial.

Comment thread nexus/src/context.rs
/// registry of metric producers
pub producer_registry: ProducerRegistry,
/// TLS enabled on the external Dropshot server
pub external_tls_enabled: bool,

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.

It feels a little sad to clutter up the context with another config value, but I wasn't sure whether I should get the answer from nexus itself because of the Arc around it. A method on nexus would have to look something like this. @davepacheco?

pub async fn external_tls_enabled(&self) -> bool {
    let external_server = self.external_server.lock().unwrap().take();
    if let Some(server) = external_server {
        return server.using_tls();
    }
    false
}

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 think it's okay as-is. One advantage of what's here over that method impl is that if someone asks the question before we've started the external server for some reason, it will report what's configured (which seems right) rather than panicking.

It seems like Dropshot could use a method on the RequestContext for this. Then you could just check that in the handler.

@david-crespo
david-crespo enabled auto-merge (squash) September 7, 2023 20:02
@david-crespo
david-crespo merged commit 7468571 into main Sep 7, 2023
@david-crespo
david-crespo deleted the session-cookie-secure branch September 7, 2023 20:51
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.

2 participants