OpenSlides / openslides-manage-service

Manage service for OpenSlides 4+
MIT License
4 stars 13 forks source link

Error when using initial-data when communicating through traefik #187

Open funkyfuture opened 2 years ago

funkyfuture commented 2 years ago

i have a reachable OpenSlides instance, but when i execute the initial-data subcommand, i get an error:

$ curl https://openslides.example.org
<!DOCTYPE html><html lang="en"><head>
        <meta charset="utf-8">
        <title>OpenSlides</title>
        <base href="/">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noindex">
        <meta name="google" content="notranslate">
        <link rel="icon" type="image/x-icon" href="assets/img/favicon.png">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <link rel="manifest" href="manifest.webmanifest">
        <meta name="theme-color" content="#1976d2">
    <style>@charset "UTF-8";@font-face{font-family:OSFont;font-style:normal;font-display:swap;font-weight:400;src:url(fira-sans-latin-400.65c43bf52c7e766a.woff) format("woff")}@font-face{font-family:OSFont;font-style:italic;font-display:swap;font-weight:400;src:url(fira-sans-latin-400italic.9c4127481240eb33.woff) format("woff")}@font-face{font-family:OSFont;font-style:normal;font-display:swap;font-weight:500;src:url(fira-sans-latin-500.15b62b0d74930e62.woff) format("woff")}@font-face{font-family:OSFont;font-style:italic;font-display:swap;font-weight:500;src:url(fira-sans-latin-500italic.a0b8458b18c95c88.woff) format("woff")}*{font-family:OSFont,Fira Sans,Roboto,Arial,Helvetica,sans-serif}body{margin:0 auto;padding:0;line-height:1.5;font-size:14px}</style><link rel="stylesheet" href="styles.ebb81be3804fed8c.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.ebb81be3804fed8c.css"></noscript></head>
    <body class="openslides-light-theme">
        <os-root></os-root>
        <noscript>Please enable JavaScript to continue using this application.</noscript>
    <script src="runtime.8b5f6a24d9835303.js" type="module"></script><script src="polyfills.968451426b9442c4.js" type="module"></script><script src="scripts.7645c40ffe1e241e.js" defer></script><script src="main.d81b35707f758190.js" type="module"></script>

</body></html>
$ ./openslides initial-data -a openslides.example.org:443
Error: setting initial data: calling manage service (setting initial data): unexpected HTTP status code received from server: 502 (Bad Gateway); malformed header: missing HTTP content-type

as a sidenote, the README.md doesn't give any hint what the purpose and possible contents of this initial data would be, and hence i really can't assess whether this situation poses a problem.

addendum: i seems that this command would at least set the superadmin password as i can't login to the instance.

normanjaeckel commented 2 years ago

Hm. Do you run Openslides behind a self configured proxy? Please have a look which request comes in. Maybe your proxy does not forward the correct content-type header. The openslides tool uses GRPC to connect to the server, so the instance expects respective header (https://github.com/OpenSlides/OpenSlides/blob/main/proxy/caddy_base.json#L167).

funkyfuture commented 2 years ago

the proxy that we use informs about a 502 response by the service.

that's what Caddy / the proxy service is telling:

{
    "level": "error",
    "ts": 1659357956.5641763,
    "logger": "http.log.error",
    "msg": "net/http: HTTP/1.x transport connection broken: malformed HTTP response \"\\x00\\x00\\x06\\x04\\x00\\x00\\x00\\x00\\x00\\x00\\x05\\x00\\x00@\\x00\"",
    "request": {
        "remote_addr": "192.168.0.3:54710",
        "proto": "HTTP/1.1",
        "method": "POST",
        "host": "openslides.example.org:443",
        "uri": "/Manage/InitialData",
        "headers": {
            "User-Agent": [
                "grpc-go/1.45.0"
            ],
            "Content-Type": [
                "application/grpc"
            ],
            "X-Forwarded-Port": [
                "443"
            ],
            "X-Forwarded-Proto": [
                "https"
            ],
            "X-Forwarded-Server": [
                "6e13e21b3b77"
            ],
            "Authorization": [
                "xxx"
            ],
            "Grpc-Timeout": [
                "4925074u"
            ],
            "X-Forwarded-For": [
                "11.22.33.44"
            ],
            "X-Real-Ip": [
                "11.22.33.44"
            ],
            "Te": [
                "trailers"
            ],
            "X-Forwarded-Host": [
                "openslides.exmaple.org:443"
            ],
            "Accept-Encoding": [
                "gzip"
            ]
        }
    },
    "duration": 0.005011078,
    "status": 502,
    "err_id": "r6sa2evtm",
    "err_trace": "reverseproxy.statusError (reverseproxy.go:783)"
}

it shows that the content-type header is passed.

but nonetheless, the issue is caused by the employed reverse proxy traefik, it requires to specify a specific URL scheme for grpc services.

here's an imperfect snippet as reference for the proxy service that solves this:

services:
  proxy:
    labels:
      traefik.enable: "true"

      traefik.http.services.openslides-proxy.loadbalancer.server.port: "8000"
      traefik.http.routers.openslides.service: openslides-proxy
      traefik.http.routers.openslides.rule: Host(`openslides.example.org`)

      traefik.http.services.openslides-manage.loadbalancer.server.port: "8000"
      traefik.http.services.openslides-manage.loadbalancer.server.scheme: h2c
      traefik.http.routers.openslides-manage.service: openslides-manage
      traefik.http.routers.openslides-manage.rule: Host(`openslides.example.org`) && PathPrefix(`/Manage/`)

i'd like to keep this issue open until #186 is solved (or not), so that other users can find this information.