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

Change implementation of incoming-request.authority #2684

Closed
wants to merge 3 commits into from
Closed

Conversation

rylev
Copy link
Collaborator

@rylev rylev commented Jul 26, 2024

The guest will now see incoming-request.authority as whatever is set in the incoming request's Host header.

Previously we were relying on the definition of incoming-request.authority not being set by user input because outbound requests to the special self host would be ultimately directed towards whatever was in incoming-request.authority. Now, self requests are specifically defined (with scheme and authority) in the host. The implementation currently sets the self definition to be the same scheme as the incoming request and the authority is set to the listener address of the Spin web server.

@rylev rylev requested a review from lann July 26, 2024 09:06
@rylev
Copy link
Collaborator Author

rylev commented Jul 26, 2024

FYI: The CI failure is expected as this breaks one of the conformance tests. Once we're happy with the changes here, I will change the conformance test to match this behavior.

Copy link
Contributor

@tschneidereit tschneidereit left a comment

Choose a reason for hiding this comment

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

This looks good to me. I left a few in-line comments and suggestions, but they're all minor naming quibbles.

crates/trigger-http/src/lib.rs Outdated Show resolved Hide resolved
crates/trigger-http/src/lib.rs Outdated Show resolved Hide resolved
crates/trigger-http/src/wagi.rs Outdated Show resolved Hide resolved
) -> Result<Response<Body>>;
}

/// The definition of the `self` host for outbound requests.
#[derive(Clone)]
pub struct SelfRequestDefinition {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this perhaps be SelfRequestOrigin? "Definition" is pretty vague and I doubt future readers would have a reasonable intuition for what it stands for.

The origin concept of course technically includes the port, too; one way to address that would be to simply include it. But I think it'd also be fine to just add a comment saying that for our purposes that part is irrelevant, so left out.

Copy link
Collaborator

@lann lann Jul 26, 2024

Choose a reason for hiding this comment

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

Authority does include port, either explicitly or implicitly via scheme. This struct could also alternatively wrap (or be replaced by) a Uri, i.e. a "self base URI".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I renamed to SelfRequestOrigin and kept its fields (URI contains a lot of other stuff we don't need and I think it makes the code harder to read).

rylev added 3 commits July 29, 2024 11:50
Always rely on the `Host` header for authority incoming-reques.authority. To
determine where `self` requests should be routed, explicitly pass a
`self_authority` parameter which is set to the listening address.

Signed-off-by: Ryan Levick <[email protected]>
Signed-off-by: Ryan Levick <[email protected]>
builder = builder.header(*key, *value);
}

// TODO(rylev): convert body as well
Copy link
Collaborator

Choose a reason for hiding this comment

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

A TODO IN YOUR CODE?!? 🙂

/// The incoming request's URI is relative to the server, so we need to set the scheme and authority
fn set_req_uri(req: &mut Request<Body>, scheme: Scheme, addr: SocketAddr) -> Result<()> {
/// The incoming request's URI is relative to the server, so we need to set the scheme and authority.
/// The `Host` header is used to set the authority. This function will error if no `Host` header is
Copy link
Collaborator

Choose a reason for hiding this comment

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

The Host header is used to set the authority.

Should this also check the req.uri().authority()? I think it might be most correct to use either one, verifying that they are identical if both are present.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure that's right, based on hyperium/hyper#1612

@radu-matei
Copy link
Member

radu-matei commented Aug 15, 2024

Does this need another set of reviews, or is it good to merge?
Thanks!

Also, surfacing the test failure:

ailures:

---- request-shape ----
Failed assertion.
  stdout: Logging component stdio to ".spin/logs/"
  
  Serving http://127.0.0.1:49293/
  Available Routes:
    request-shape: http://127.0.0.1:49293/base/:path_segment/:path_end (wildcard)
  
error: test failed, to rerun pass `--test runtime`
  stderr: 
error: 1 target failed:
    `--test runtime`
Caused by:
      actual status 500 != expected status 200 - body: authority is not a valid SocketAddr
make: *** [test-runtime] Error 101

@rylev
Copy link
Collaborator Author

rylev commented Aug 16, 2024

We can land this whenever we feel comfortable with the breaking change.

One thought I had was that we'll need to bring these changes into the factors break. Instead of landing this in main, we could target the factors work so that this lands whenever factors does. Thoughts @radu-matei @lann?

@radu-matei
Copy link
Member

Given we know it's the right change, bringing it in together with the rest of the breaking changes from the factors work seems reasonable to me.

@rylev
Copy link
Collaborator Author

rylev commented Aug 27, 2024

Closing this in favor of the factors branch where #2723 was incorporated which addresses this issue.

@rylev rylev closed this Aug 27, 2024
@rylev rylev deleted the authority branch August 27, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants