Skip to content

Conversation

@stefanhengl
Copy link
Member

@stefanhengl stefanhengl commented Nov 28, 2022

With this change, webserver proxies request to <webserver>/indexserver/ to the unix domain socket at <index dir>/indexserver.socket. Since this is a Sourcegraph feature, we put the proxy handler in webserver behind a flag which is toggled off per default.

The motivation is to expose indexserver endpoints on webserver addresses, which in case of Sourcegraph, are easily accessible at runtime.

Test Plan

  • start webserver with flag --indexserver_proxy
  • start indexserver
  • inspect output from curl http://localhost:6070/indexserver/

With this change webserver proxies request to /indexserver/ to the unix
domain socket at `<index dir>/indexserver.socket`. Since this is a
Sourcegraph feature, we put the proxy behind a flag which is toggled off
per default.

The motivation is to expose indexserver endpoints on webserver
addressses, which in case of Sourcegraph, are easily accessible at
runtime.
@stefanhengl stefanhengl requested a review from a team November 28, 2022 11:42
log.Fatalf("failed to listen on socket: %s", err)
}
debug.Printf("serving HTTP on %s", socket)
log.Fatal(http.Serve(l, http.StripPrefix("/indexserver", mux)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that the prefix that you're stripping shouldn't be /indexserver/?

https://pkg.go.dev/net/http#StripPrefix

...The prefix must match exactly...

Copy link
Member

Choose a reason for hiding this comment

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

I'm not really sure why you are stripping the prefix as well? Is this done because this is the path that the zoekt-webserver will proxy? If

Copy link
Member Author

@stefanhengl stefanhengl Nov 29, 2022

Choose a reason for hiding this comment

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

Yes, we have to strip it somewhere, otherwise the paths won't match. I agree, webserver seems the more natural place to do it, so that indexserver doesn't need to know about how the proxy operates.

Regarding stripping "/indexserver/" vs "/indexserver":

I did some manual testing, the answer seems to depend on where we call StripPrefix

  • indexserver: only "/indexserver" works
  • webserver: both work

@ggilmore ggilmore requested a review from a team November 28, 2022 18:28
Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

/chefs-kiss

log.Fatalf("failed to listen on socket: %s", err)
}
debug.Printf("serving HTTP on %s", socket)
log.Fatal(http.Serve(l, http.StripPrefix("/indexserver", mux)))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not really sure why you are stripping the prefix as well? Is this done because this is the path that the zoekt-webserver will proxy? If

@stefanhengl
Copy link
Member Author

@ggilmore @keegancsmith I ran some experiments on kubernetes. The good news is that the socket communication between webserver and indexserver works. The bad news is that the default permissions 755 of the socket are not enough for webserver to write to it, probably because indexserver and webserver run with different users.

In the last commit of this PR I change the permissions of the socket to 777, see also the comment in the code. WDYT? Could this be a security issue?

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

To me this is the same as just using TCP if we could have a well defined port. IE its the same security model between the two containers:

  • we want them to communicate with each other
  • only those containers have the FS mounted.

@stefanhengl stefanhengl merged commit a9bdee9 into main Nov 29, 2022
@stefanhengl stefanhengl deleted the sh/socket branch November 29, 2022 14:00
stefanhengl added a commit that referenced this pull request Nov 30, 2022
This enables the proxy for Sourcegraph's webserver

See #487
stefanhengl added a commit that referenced this pull request Dec 1, 2022
This enables the proxy for Sourcegraph's webserver

See #487
stefanhengl added a commit to sourcegraph/sourcegraph-public-snapshot that referenced this pull request Dec 1, 2022
Relates to sourcegraph/zoekt#487

We set the new flag for local dev and server.
stefanhengl added a commit to sourcegraph/sourcegraph-public-snapshot that referenced this pull request Dec 2, 2022
Relates to sourcegraph/zoekt#487

We set the new flag for local dev and server.
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.

3 participants