Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factor-outbound-networking: Add support for client TLS #2703

Merged
merged 3 commits into from
Aug 12, 2024

Conversation

lann
Copy link
Collaborator

@lann lann commented Aug 1, 2024

Port the [[client_tls]] runtime config logic from spin-trigger to spin-factor-outbound-networking.

This rewords the keys used in that runtime config section, which is a breaking change but I think its less confusing and worth it given that ~no one is using it yet and it will be released with 3.0.

This also switch from using Authority to a plain string for hostnames. Using Authority was my idea but I realize now that it makes things awkward when trying to deal with port numbers, so I bailed out to just plain host: String, though still using Authority's parser to validate that string.

The rustls::ClientConfig derived from this runtime config is exposed to dependent factors via InstanceBuilder::component_tls_configs.

@lann lann force-pushed the factors-client-tls branch 2 times, most recently from f6692dc to 64ca67e Compare August 2, 2024 14:54
@lann lann marked this pull request as ready for review August 2, 2024 14:54
@lann lann force-pushed the factors-client-tls branch from 64ca67e to 8585f6d Compare August 2, 2024 15:31
@lann
Copy link
Collaborator Author

lann commented Aug 2, 2024

@rajatjindal FYI

@lann lann requested a review from rylev August 2, 2024 15:56
@lann
Copy link
Collaborator Author

lann commented Aug 2, 2024

@rylev I'll be particularly interested in your thoughts on the RuntimeConfig approach.

lann added 2 commits August 2, 2024 16:42
Signed-off-by: Lann Martin <lann.martin@fermyon.com>
Signed-off-by: Lann Martin <lann.martin@fermyon.com>
@lann lann force-pushed the factors-client-tls branch from 8585f6d to c7a7319 Compare August 2, 2024 20:43
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are copied from spin-trigger-http tests.

@lann lann mentioned this pull request Aug 2, 2024
Copy link
Collaborator

@rylev rylev left a comment

Choose a reason for hiding this comment

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

I've got lots of nits, but this looks good overall 🎉

crates/factor-outbound-networking/src/runtime_config.rs Outdated Show resolved Hide resolved
crates/factor-outbound-networking/src/runtime_config.rs Outdated Show resolved Hide resolved
crates/factor-outbound-networking/src/runtime_config.rs Outdated Show resolved Hide resolved
// Validate hostname
http::uri::Authority::from_str(host).with_context(|| format!("invalid TLS 'host' {host:?}"))?;
if host.contains(':') {
anyhow::bail!("invalid TLS 'host' {host:?}; ports not currently supported");
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not clear to me why ports aren't supported. What would happen if this check were removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The behavior didn't seem obvious enough to me to roll it into a refactor.

fn deserialize_hosts<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<String>, D::Error> {
let hosts = Vec::<String>::deserialize(deserializer)?;
for host in &hosts {
validate_host(host).map_err(serde::de::Error::custom)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're going to validate the host later, is there really a need for it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Validating here gives nice TOML errors.

Signed-off-by: Lann Martin <lann.martin@fermyon.com>
@lann lann merged commit faeba8b into spinframework:factors Aug 12, 2024
2 checks passed
@lann lann deleted the factors-client-tls branch August 12, 2024 17:28
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