influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
29.06k stars 3.56k forks source link

influxDB2.0 alpha - http custom base path #15721

Open steverweber opened 5 years ago

steverweber commented 5 years ago

Trying to serve influxdb v2.0alpha through nginx proxy because I need to run multiple websites on the same host while admins only allow one port to be open 443.

https://dnsname/influxdb2

influxdb http page is referencing the root url path to load the site .js also noticed <base href="/"> is the url root.

is their some header that I should be passing upstream to influxdb so it knows to use a different basepath? or could an option be added to influxd so the base path can be custom?

Thanks!

<!doctype html>
<html>
<head><meta http-equiv="Content-type" content="text/html;charset=utf-8width=device-width,initial-scale=1" name="viewport"><title>InfluxDB 2.0</title><base href="/">
<link rel="shortcut icon" href="/favicon.ico"></head>
<body><div id="react-root" data-basepath=""></div>
<!-- want this to be something like: influxdb2/a02e0ac4f4.js  or a02e0ac4f4.js and use base href="/influxdb2/" -->
<script src="/a02e0ac4f4.js"></script>
</body></html>
steverweber commented 5 years ago

looking at the code git checkout v2.0.0-alpha.19 i see some env vars... but setting them didn't help.

systemd...

Environment="STATIC_PREFIX=/influxdb2/"
Environment="API_PREFIX=/influxdb2/"
Environment="BASE_PATH=/influxdb2/"
Environment="API_BASE_PATH=/influxdb2/"
ExecStart=/srv/influxd

also seems that the option is in Chronograf looking at the readme

./chronograf/README.md:Change the default root path of the Chronograf server with the `--basepath`

perhaps this should be made available on influxd --basepath=/influxdb2/

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

steverweber commented 4 years ago

please provide some feedback before closing. Thanks.

drdelambre commented 4 years ago

For the base path parameters.. those are for configuring the frontend during compilation to allow it to be run behind a proxy, so they're already baked in by the time the image is pushed to the registry. Here's an example dockerfile that I use when i want to expose the frontend on a different url, passing those environment variables as build ARGs:

FROM ubuntu:bionic AS base

RUN apt-get update -y && \
    apt-get install -y \
        nginx \
        build-essential \
        curl \
        git

FROM base AS repo
WORKDIR /repo

ARG STATIC_DIRECTORY
ARG BASE_PATH
ARG API_BASE_PATH

ENV PATH="/node/bin:${PATH}"
RUN mkdir /node && \
    curl -sL https://git.io/n-install | N_PREFIX=/node bash -s -- -q && \
    npm i -g yarn

RUN git clone git://github.com/influxdata/influxdb.git && \
    cd ./influxdb

WORKDIR /repo/influxdb/ui

# these are all run together as docker's caching mechanism
# makes big steps like yarn install expensive
RUN yarn install --production=false && \
    yarn generate && \
    INFLUXDB_SHA=remote $(npm bin)/webpack --config ./webpack.prod.ts --bail && \
    rm -rf ./node_modules

FROM base AS deploy
WORKDIR /repo
COPY --from=repo /repo/influxdb/ui/build /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/nginx.conf
RUN useradd --no-create-home nginx

CMD ["nginx", "-g", "daemon off;"]

with just a simple nginx config in ./nginx.conf that hosts the files in `/usr/share/nginx/html' as your desired path:

  server {
    listen [::]:80;
    listen 80;

    server_name _;

    # Path for static files
    root /usr/share/nginx/html;

    location / {
      try_files $uri /index.html;
    }
  }
kwinkel commented 4 years ago

Rebuilding the UI with a variable seems not to be a solution. Setting an environment variable to override the base href and/or taking this from the request X-Forwarded-Prefix would be necessary to run influxdb2 behind a proxy with a subdirectory.

CLKBlu3 commented 4 years ago

Having a similar issue. I did follow https://gist.github.com/mvadu/5fbb7f5676ce31f2b1e6 from an older version to try setting up things. However, it only loads the login page at http://mydomain.com/influxdb/, which doesn't work.

My setup is: (relevant parts only) nginx.conf:

upstream influxdb {
        server localhost:8086;
        keepalive 10;
    }
    #check the referer to identify requests originated by Influx UI
    map $http_referer $proxyloc {   
        ~*influx influxdb;
    }

    #Influx Web API end points
    map $request_uri $backend { 
        ~*query influxdb;
        ~*write influxdb;
        ~*ping  influxdb;
    }

server conf:

[...]
location / {
        if ($backend) {
            return 302 /$backend/$request_uri;
        }

        if ($proxyloc) {
            return 302 /$proxyloc/$uri;
        }
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location /influxdb/ {

        proxy_pass     http://localhost:8086/;
        proxy_set_header   Host         $http_host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
[...]

As said, my current configuration seems to load the login page fine, but it's unfunctional as it doesn't allow me access it.

Note: I use the docker container for influxdb2.0 beta from https://quay.io/repository/influxdb/influxdb?tag=2.0.0-beta&tab=tags

cappelaere commented 4 years ago

Similar issue! Grrrrrr!

lephisto commented 3 years ago

Is there any progress on this? I would really like to put Influx 2 OSS behind a reversproxy.

nikosamus commented 3 years ago

Same happening here, can't reverse proxy Influx 2.0. Even after many hours trying with apache html proxy for rewriting urls I can't get it working.

CLKBlu3 commented 3 years ago

For people that had the same issue I did (commented a few months ago). We managed to make it work by using subdomains. So if you have a domain (we got our certs with Certbot), I can recommend trying this. We registered ours as mysubdomain.mydomain.com (sample name, obviously) This way, all the paths should work, since we do not have a "custom" base path as we used to, but instead have a new "root" path that can match influxdb's ones without messing our configuration.

Sample nginx configuration:

server {
        server_name     mysubdomain.mydomain.com;

        location / {

                #access_log /var/log/nginx/influx-access.log influx buffer=1024 flush=5m;
                proxy_pass         http://localhost:xxxx/;
                proxy_set_header   Host                 $http_host;
                proxy_set_header   X-Real-IP            $remote_addr;
                proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysubdomain.mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mysubdomain.mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
[...] # Other conf stuff
steverweber commented 3 years ago

seems the only solution to date is recompiling the source code because the path is baked in. workarounds:

Guess i'll just continue to ignore the influx UI and use the CLI for the odd admin task. Grafana runing under a custom base url is working out well for viewing data and setting alerts.

YassineElbouchaibi commented 3 years ago

Having the same issue... I just spent about 4 hours on it before finding this thread... For now I think I'll have to go with subdomain as no matter how I mess with the nginx config even if I get some web pages to load, some network requests just won't...

monsdar commented 3 years ago

Chiming in to put a bit more weight onto this issue. I've also just stumbled across this issue when trying to find a solution for the past hours. I wonder why this isn't troublesome for more people, using a reverse proxy with a custom subpath seems to be kind of a standard.

ondrej-ivanko commented 3 years ago

Spend few days on this issue. So far it seems unresolvable without using subdomain for host based filtering in Ingress.

I needed to use InfluxDB UI behing nginx reverse proxy. With only one ingress-controller for the whole cluster. Turns out path based routing is possible with rewrite-target annotation in Ingress resource. But the Influx UI does not display at all. What ultimately cancelled any effort to use Ingress was that <base href="/"> thing, which doused any effort for us to use Ingress.

We would welcome any customization of base_href path, possibly via helm chart as we're using that for deployment.

One option could be to separate INFLUXD_HTTP_BIND_ADDRESS responsibility to server as address to InfluxDB API. And some other ENV_VAR would be responsible for settings path for Influx UI. It would have to be customizable via helm chart as well.

gvasanka commented 3 years ago

Having the same issue, spent almost a day finding a solution with trying out different configs. finally, I am here :)

Turns out path based routing is possible with rewrite-target annotation in Ingress resource. But the Influx UI does not display at all.

@ondrej-ivanko I hope what you mean is, you could access the influx DB API endpoints(write and query) using the path-based routing approach. but no luck in accessing UI.

If that's true can you share the working config with rewrite-target annotation?

ondrej-ivanko commented 3 years ago

@gvasanka I can't confirm that accessing API endpoints with rewrite-target annotation will work, as I haven't tried it. I don't see any reason, why it shouldn't work though.

If that's true can you share the working config with rewrite-target annotation?

Our company decided to abandon the effort to use Ingress controller. We just use port-forwarding of Influx pod for accessing UI.

gvasanka commented 3 years ago

@ondrej-ivanko Thank you very much for your answer.

I was able to get access to influxDb 2 API with the below Ingress config. Posting it here for other's usage in case somebody struggling.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: influx-ingress-test
spec:
  rules:
  -  http:
      paths:
      - backend:
          serviceName: influxdb-release
          servicePort: 8086
        path: /influx(/|$)(.*)

But still no luck in getting access to the web.

ecospecifier commented 3 years ago

How is this not receiving more attention? Please can we get acknowledgement of the issue and get ENV access to set the base path like grafana has or appending to request url like even simple containers like adminer has. Apologies if I sound crass but having this hardcoded in is ridiculous. Running behind a reverse proxy nginx is something many people do and having to setup a subdomain just to workaround a HARDCODED base url is really silly.

Please try and give us some real commitment on this guys!

RavilN commented 3 years ago

I have a similar issue!

jjriggs commented 3 years ago

Would like to also add my complaint to this thread. Grafana has a root_url parameter you can set in the config file. As far as I can tell, that is not the case with InfluxDB. Very frustrating that there appears to be no way for it to reside behind a reverse proxy without a subdomain.

ingaa85 commented 3 years ago

I would also need this feature, as i dont want to use a second subdomain for this.

UnKnoWn-Consortium commented 3 years ago

From the commit that updates the UI version, it appears the UI releases are downloaded at build time and get bundled into the final go build. FYI: https://github.com/influxdata/influxdb/pull/21564/files

In that UI release bundle, <base href="/"> is already set. I think we should open a mirrored issue at the UI repo too.

TravisDuck999 commented 3 years ago

Having the same problem here, really thought it would be a simple setting to change when I started this.

Would love to see this updated, has anyone had any luck ?

Keviinplz commented 3 years ago

any update on this? :(

ecospecifier commented 3 years ago

Also checking back to see if there is any update on this, seems not.

thomas725 commented 3 years ago

Just stumbled upon this problem too. Hopefully this will be addressed soon.

cavepopo commented 3 years ago

Just spent one day trying to make this work and ended here.

+1 for this custom param !

nbejansen commented 3 years ago

+1

mattp0 commented 3 years ago

Still a problem and I am still hopeful for a solution. Wanted to also add that Grafana supports proxy auth and it would be nice if influx2.0 could be setup for SSO via a tool like vouch proxy.

h3po commented 3 years ago

+1

kuchosauronad0 commented 3 years ago

+1 I don't need the UI; just the API would be fine

klelifo commented 3 years ago

I am also trying to get the Influxdb v2 WebGUI to work behind an Apache web-proxy.

So far I have the a configuration which kinda works:

See my current configuration below.

   <Proxy balancer://influxcluster>
        BalancerMember http://10.27.xx.xx:8086 route=influx
        ProxySet lbmethod=byrequests
    </Proxy>

    <Location /influx>
        ProxyPass         balancer://influxcluster
        ProxyPassReverse  balancer://influxcluster

        AddOutputFilterByType SUBSTITUTE text/javascript text/html text/css application/json
        SubstituteMaxLineLength 10m
        Substitute "s#(href|src|path|a\.p)=(\"|\')\.?/#$1=$2/influx/#q"
        Substitute "s#(\'|\"|\`|\})(/api|/signin|/health|/metrics|/debug)#$1/influx$2#q"
    </Location>

BUT after successful login the influx GUI shows me: "404 Bummer! We couldn't find the page you were looking for" I have a feeling it has something to do with how the used JS framework resolves its pages.

Does anybody have an idea what I am missing?

rawtaz commented 3 years ago

I understand that those of us using (or as in my case, trying out) InfluxDB for free shouldn't be demanding anything, and that's fine. But it's quite hard to fathom how this incredibly silly issue has been open for two years without any of the core developers (or similar) just going "oh heck, let's just add a parameter for this" (or even just commenting at all). I can't imagine this would be complicated to do for them. :eyes:

IngoDbg commented 3 years ago

+1

nicko170 commented 2 years ago

+1

zychu312 commented 2 years ago

+1

Knud3 commented 2 years ago

Please, stop these "+1" and other non-content messages. It does not help anyone or this case. Just unnecessary clutter in the comment feed.

If you want to get notifications click "Subscribe". If you have the same problem and like to get it fixed, add a reaction to the first message.

MatthiasWerning commented 2 years ago

We would also like to run the InfluxDB UI behind a reverse proxy using Ingress, since a subdomain based approach is not feasible in our architecture. I tried to get the UI running using @steverweber approach with the referer filtering in nginx.

I got it working for the login screen and authentication using the API, but now I'm stuck at the internal React based routing. The only issue is not even just the base tag in the index.html but also all React routes which also begin with / altogether.

Btw if you're trying this solution as well, you also have to rewrite the session cookie path from /api to another path which could also pose a security issue by allowing other applications on your host to read the session cookie. You also gotta return a 307, since 302 does not preserve the original HTTP method (POST will turn into GET and thus auth will fail).

This issue is now open for 1.5 years and unfortunately there seems to be no feasible and not super hacky solution to use InfluxDB UI under a specific sub-path.

morix-gao commented 2 years ago

+1

1naboki1 commented 2 years ago

I cant see the point why this feature is not available - even as OSS. Marketingwise its like preventing users too see our logo....

+1

DonCamillo72 commented 2 years ago

Comparable tools like grafana or node-red offer this possibility. That would also be desirable for InfluxDB 2.x.

+1

SungulaGit commented 2 years ago

+1

Bluefries commented 2 years ago

Please give as a way to specify custom paths, not only subdomains as we also can't make it work with our architecture

realies commented 2 years ago

bump

mstrauch07 commented 2 years ago

FYI: this "issue" is not resolved by only doing <base href="/">, because I tried the following (nginx) in order to host the frontend under domain.tld/influx2/*:

        sub_filter '<base href="/">' '<base href="./">';
        sub_filter_once on;

or

        sub_filter '<base href="/">' '<base href="/influx2/">';
        sub_filter 'src="/' 'src="/influx2/';
        sub_filter 'href="/' 'href="/influx2/';
        sub_filter_once on;

This will take care that the initial script loads (1) but this script loads another script, obviously without the desired path (2):

image

So currently there is no way around custom building I guess. Sadly ... 😭

SaswatPadhi commented 2 years ago

There are 46 comments on this thread and over a hundred +1's if we add them up.

Please comment as to why this issue is marked as wontfix (but is still left open?!)

memetb commented 1 year ago

I have a hacked nginx configuration as follows that does it almost all, however I need someone to push it passed to touchdown line with regards to the front end.

The following configuration indirects the backend entirely (as far as the server is concerned, the front end calls look exactly as though they were coming from /).

It also solves most of the front end (I can browser-debug and see the api calls being made and correctly fetching data - including logging in correctly).

It also injects into the process.env.* values as referenced here in an attempt to make routing "just work". I can confirm via browser-debug that the values are present at the render call for the root.

Unfortunately, I still get a 404 on the ui. I am hoping this is something minor in the frontend, and that I just need to specify a different process.env value.

I would appreciate any frontend devs to chime in if they have any insights.

upstream influx {
    server 10.0.0.5:8086;
}

map $http_referer $munged_referer {
        "~^(?<prefix>.*)/influx(?<suffix>.*)$" $prefix$suffix;
}

server {
        listen 80;

        location ~ ^/signin(.*) {
                # this may or may not be necessary if the base path injection for the webpack makes a difference
                rewrite ^/signin(.*)$ /influx/signin$1 last;
        }

        location = /influx/env.js {
                # webpack process.env.* injection
                add_header Content-Type application/javascript;
                return 200 "var prefix='/influx/'; process = {'env' : {'STATIC_PREFIX':prefix,'API_PREFIX':prefix, 'BASE_PATH': prefix, 'API_BASE_PATH':prefix}};";
        }

        location = /influx {
                proxy_pass http://influx$1;
                proxy_redirect off;

                # inject environment for front-end webpack
                sub_filter '</head>' '<script type="text/javascript" src="/influx/env.js"></script></head>';

                # inject relative path to html root
                sub_filter 'href="/' 'href="/influx/';
                sub_filter 'src="/' 'src="/influx/';
                sub_filter_types text/css text/javascript application/javascript application/json;
                sub_filter_once off;
        }

        location ~ ^/influx(.*) {
                proxy_pass http://influx$1;
                proxy_redirect off;

                # tricks to make the server completely unaware of the redirection
                proxy_set_header Host $host;
                proxy_set_header Referer $munged_referer;
                proxy_cookie_path / /influx/;

                # rewrite API endpoint advertisments
                sub_filter '/api/v2' '/influx/api/v2';

                # rewrite endpoints which seem to be hard-coded in js. We also could url rewrite them as we do for login...
                sub_filter '/health' '/influx/health';
                sub_filter '"/logout' '"/influx/logout';

                sub_filter_types text/css text/javascript application/javascript application/json;
                sub_filter_once off;
        }

        location / {
                  # ...
        }
}
elyancorrea commented 1 year ago

+1

DennisGeisse commented 1 year ago

+1

depermana12 commented 1 year ago

+1