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

[🐛 | Bug]: Organization bootstrap fails #8427

Closed
Landeers opened this issue Sep 18, 2024 · 5 comments
Closed

[🐛 | Bug]: Organization bootstrap fails #8427

Landeers opened this issue Sep 18, 2024 · 5 comments
Assignees
Labels
C-Bug Issue related to a bug

Comments

@Landeers
Copy link
Contributor

Landeers commented Sep 18, 2024

Parsec version tested on:

v3.0.0-rc.8

Platforms tested on:

Windows

Bug description:

On custom server while bootstrap (join organization with bootstrap link), client received an BootstrapOrganizationErrorInternal error

Relevant output:

Server capture on debug level
Capture d’écran 2024-09-18 094414

@Landeers Landeers added C-Bug Issue related to a bug B-Triage Blocker: The issue is awaiting triage labels Sep 18, 2024
@FirelightFlagboy FirelightFlagboy removed the B-Triage Blocker: The issue is awaiting triage label Sep 18, 2024
@FirelightFlagboy
Copy link
Contributor

Look if it's possible to inspect the header value Content-Type

@FirelightFlagboy
Copy link
Contributor

The status 415 correspond to BadContentTypeOrInvalidBodyOrUnknownCommand

BadContentTypeOrInvalidBodyOrUnknownCommand = 415

@FirelightFlagboy
Copy link
Contributor

It's returned by _handshake_abort_bad_content

That function is call during:

  • _parse_auth_headers_or_abort if Content-Type header is application/msgpack

    parsed = _parse_auth_headers_or_abort(
    headers=request.headers,
    raw_organization_id=raw_organization_id,
    with_authenticated_headers=False,
    with_invited_headers=False,
    with_sse_headers=False,
    expected_accept_type=None,
    expected_content_type=CONTENT_TYPE_MSGPACK,
    )

    if expected_content_type and headers.get("Content-Type") != expected_content_type:
    _handshake_abort_bad_content(api_version=settled_api_version)

  • If during the parsing of the anonymous command the exception ValueError is raised

    try:
    req = ANONYMOUS_CMDS_LOAD_FN[parsed.settled_api_version.version](body)
    except ValueError:
    _handshake_abort_bad_content(api_version=parsed.settled_api_version)

@FirelightFlagboy
Copy link
Contributor

FirelightFlagboy commented Sep 18, 2024

Look if it's possible to inspect the header value Content-Type

I've take a look about how to customize the access log provided by uvicorn

The issue encode/uvicorn#491 was a great help.

I was able to customize uvicorn with a custom access log format (see below)

diff --git a/server/parsec/asgi/__init__.py b/server/parsec/asgi/__init__.py
index 68ba698d3..66f6a2d42 100644
--- a/server/parsec/asgi/__init__.py
+++ b/server/parsec/asgi/__init__.py
@@ -1,6 +1,7 @@
 # Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
 from __future__ import annotations
 
+import copy
 from pathlib import Path
 
 import uvicorn
@@ -8,6 +9,7 @@ from fastapi import FastAPI, Request
 from fastapi.staticfiles import StaticFiles
 from fastapi.templating import Jinja2Templates
 from starlette.types import Receive, Scope, Send
+import uvicorn.config
 
 from parsec._version import __version__ as parsec_version
 from parsec.asgi.administration import administration_router
@@ -93,6 +95,12 @@ async def serve_parsec_asgi_app(
         v_major, _ = parsec_version.split(".", 1)
         # ex: parsec/3
         server_header = f"parsec/{v_major}"
+    log_config = copy.deepcopy(uvicorn.config.LOGGING_CONFIG)
+    # Eg: "INFO 127.0.0.1 - "GET /anonymous/foobar HTTP/1.1" 200"
+    log_config["formatters"]["access"]["fmt"] = (
+        'foobar %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s'
+    )
+
     # Note: Uvicorn comes with default values for incoming data size to
     # avoid DoS abuse, so just trust them on that ;-)
     config = uvicorn.Config(
@@ -107,6 +115,7 @@ async def serve_parsec_asgi_app(
         ssl_certfile=ssl_certfile,
         workers=workers,
         # TODO: configure access log format:
+        log_config=log_config,
         # Timestamp is added by the log processor configured in `parsec.logging`,
         # here we configure peer address + req line + rep status + rep body size + time
         # (e.g. "GET 88.0.12.52:54160 /foo 1.1 404 823o 12343ms")

Sadly, The log formatter don't have access to the request scope (HTTPScope) that contains the headers. Where are limited to client_addr, request_line and status_code (see uvicorn/logging.py::AccessFormatter)

@FirelightFlagboy FirelightFlagboy self-assigned this Sep 18, 2024
@FirelightFlagboy FirelightFlagboy linked a pull request Sep 19, 2024 that will close this issue
@mmmarcos
Copy link
Contributor

mmmarcos commented Oct 7, 2024

According to @Landeers this is no longer a blocking issue because a workaround was found for the reverse proxy redirects

FirelightFlagboy added a commit that referenced this issue Oct 8, 2024
Add a new option that configure the list of trusted address to parse the proxy headers from.
The parsing is handled by `uvicorn` which currently only support `x-forwarded-{for,proto}` headers.

Closes #8626, closes #8427
FirelightFlagboy added a commit that referenced this issue Oct 8, 2024
Add a new option that configure the list of trusted address to parse the proxy headers from.
The parsing is handled by `uvicorn` which currently only support `x-forwarded-{for,proto}` headers.

Closes #8626, closes #8427
FirelightFlagboy added a commit that referenced this issue Oct 8, 2024
Add a new option that configure the list of trusted address to parse the proxy headers from.
The parsing is handled by `uvicorn` which currently only support `x-forwarded-{for,proto}` headers.

Closes #8626, closes #8427
FirelightFlagboy added a commit that referenced this issue Oct 9, 2024
Add a new option that configure the list of trusted address to parse the proxy headers from.
The parsing is handled by `uvicorn` which currently only support `x-forwarded-{for,proto}` headers.

Closes #8626, closes #8427
FirelightFlagboy added a commit that referenced this issue Oct 9, 2024
Add a new option that configure the list of trusted address to parse the proxy headers from.
The parsing is handled by `uvicorn` which currently only support `x-forwarded-{for,proto}` headers.

Closes #8626, closes #8427

Co-authored-by: Marcos Medrano <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Oct 10, 2024
Add a new option that configure the list of trusted address to parse the proxy headers from.
The parsing is handled by `uvicorn` which currently only support `x-forwarded-{for,proto}` headers.

Closes #8626, closes #8427

Co-authored-by: Marcos Medrano <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug Issue related to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants