Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/xandikos.nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ server {
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Remote-User $remote_user;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://xandikos;
Expand Down
8 changes: 8 additions & 0 deletions xandikos/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,14 @@ def get_resource(self, relpath):
except KeyError:
return None

def set_principal(self, user):
principal = "/%s/" % user
Copy link
Owner

Choose a reason for hiding this comment

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

Ideally this path would be configurable, but we could leave that for a follow-up PR.

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean something like:

def set_principal(self, user, principal_path_prefix="/", principal_path_suffix="/"):
    principal = principal_path_prefix + user + principal_path_suffix

Copy link
Owner

Choose a reason for hiding this comment

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

Yep, exactly. Though we'd probably want those extra paths to come from a command-line argument/configuration file.

Copy link
Author

Choose a reason for hiding this comment

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

Can you explain SCRIPT_NAME?

Copy link
Owner

Choose a reason for hiding this comment

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

SCRIPT_NAME is a bit of a misnomer, but it's named after a similar variable in the CGI world - it's the bit of the path to Xandikos itself. If Xandikos is under https://foo.example.com/dav/, then SCRIPT_NAME would be /dav/.

if not self.get_resource(principal):
if os.getenv("AUTOCREATE"):
self.create_principal(
principal, create_defaults=True
)
self._mark_as_principal(principal)

class XandikosApp(webdav.WebDAVApp):
"""A wsgi App that provides a Xandikos web server."""
Expand Down
5 changes: 5 additions & 0 deletions xandikos/webdav.py
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,12 @@ def handle_wsgi_request(self, environ, start_response):
logging.debug('SCRIPT_NAME not set; assuming "".')
environ["SCRIPT_NAME"] = ""
request = WSGIRequest(environ)
remote_user = environ.get("HTTP_X_REMOTE_USER")
environ = {"SCRIPT_NAME": environ["SCRIPT_NAME"]}
if remote_user:
environ["REMOTE_USER"] = remote_user
self.backend.set_principal(remote_user)

try:
loop = asyncio.get_event_loop()
except RuntimeError:
Expand Down