threefoldtech / grid_deployment

Deploy a full Grid backend with docker-compose and snapshots
Apache License 2.0
2 stars 0 forks source link

[hub] tf-connect get wrong redirect #61

Closed coesensbert closed 3 months ago

coesensbert commented 3 months ago

https://github.com/threefoldtech/grid_deployment/tree/development/grid-hub

poc instance: https://hub.ninja.tf/

on deploying a hub with the above docker-compose there seem to be two issues:

${DOMAIN} is used as an environment variable so a user only has to supply it in a .env file: https://github.com/threefoldtech/grid_deployment/blob/development/grid-hub/.env#L8 https://github.com/threefoldtech/grid_deployment/blob/development/grid-hub/Caddyfile#L2 https://github.com/threefoldtech/grid_deployment/blob/development/grid-hub/config.py-example#L29 https://github.com/threefoldtech/grid_deployment/blob/development/grid-hub/config.py-example#L36

so it seems ${DOMAIN} is not interpreted as an env var somewhere.

if you navigate the https://hub.ninja.tf/ you will also find wrong url's like https://0-hub:5555/${DOMAIN} or https://0-hub:5555/login-method

If we remove the env vars from config.py and manually supply the hub.ninja.tf none of the above behavior changes.

maxux commented 3 months ago

Same as bootstrap, can you try without the header. But that should only fix 0-hub:5555 issue, not the ${DOMAIN} expanding.

maxux commented 3 months ago

On your batch of sed I don't see when you replace DOMAIN actually.

coesensbert commented 3 months ago

Great, that seems to resolve https://0-hub:5555/${DOMAIN}: https://github.com/threefoldtech/grid_deployment/commit/2ba40c32fc9046c705dd81b7258a33c7b851e97b

So now tf-connect also became the default login method, but after logging in we are indeed forwarded to https://https//hub.%7B$DOMAIN%7D/callback_threebot?signedAttempt=%7B%22signedAttempt%22%253A%229F5GM5ZxptKL4CccT3nkIw%252BkS..

seems that the second 'https://' came from the threebot appid so removed that one already: https://github.com/threefoldtech/grid_deployment/commit/355db6ba145d3b8849cf9d81c4400231f5d77d3b

Now the last issue is that the env var $DOMAIN is not picked up by the hub code: https://github.com/threefoldtech/grid_deployment/blob/development/grid-hub/config.py-example#L150

while it is there:

root@cfbdef14d874:/hub/src# printenv
HOSTNAME=cfbdef14d874
PWD=/hub/src
DOMAIN=ninja.tf
HOME=/root
..
coesensbert commented 3 months ago

On your batch of sed I don't see when you replace DOMAIN actually.

that is because for the grid backend, validator and snapshot generator we use an env var for the domain. This so a user only has to fill it in in the .env and be done (instructions = as simple as possible for the user). If here the user has to fill it in somewhere else, we deviate from this so prefer not to do that. So instead the domain is not replaced in the config, but the config file contains an env var that is shot into the container on deployment (based on the .env)

maxux commented 3 months ago

Hub code will never take DOMAIN from environment variable. It's inside the configuration file. You have to sed it with the environment variable. Using the environment variable is possible but that would require some changes in the code, it wasn't expected like that :/

maxux commented 3 months ago

User can only input it in the .env file but you'll need a wrapper which first read that, replace variable in config file then execute the python code. That small wrapper can be the entrypoint.

coesensbert commented 3 months ago

Hub code will never take DOMAIN from environment variable. It's inside the configuration file. You have to sed it with the environment variable. Using the environment variable is possible but that would require some changes in the code, it wasn't expected like that :/

in that case, in the install script can we take the variable from the .env and then sed it to the config.py ?

maxux commented 3 months ago

Yes, or only one time during install or on each run via a init wrapper. But looking for ${DOMAIN} inside each config field on code side would add some huge complexity otherwise :/

coesensbert commented 3 months ago

Yes, or only one time during install or on each run via a init wrapper. But looking for ${DOMAIN} inside each config field on code side would add some huge complexity otherwise :/

sure, if we can fix it via the wrapper in the install script it's ok. But no dev here, no idea to make a wrapper or get x out of file y. Could you assist?

maxux commented 3 months ago

A bash script can do wrapper job:

#!/bin/bash
source .env

sed -i "s#__DOMAIN__#${DOMAIN}#g" config.py

python3 flist-uploader.py

You can add as many sed you want to fill the config file.

Using sed -i does a inplace replacement, but you can sed from base file and write to the new config file as well:

sed "s#__DOMAIN__#${DOMAIN}#g" config-base.py > config.py

It's up to you to update source config file in order to put your placeholder there where you want :)

coesensbert commented 3 months ago

A bash script can do wrapper job:

#!/bin/bash
source .env

sed -i "s#__DOMAIN__#${DOMAIN}#g" config.py

python3 flist-uploader.py

You can add as many sed you want to fill the config file.

Using sed -i does a inplace replacement, but you can sed from base file and write to the new config file as well:

sed "s#__DOMAIN__#${DOMAIN}#g" config-base.py > config.py

It's up to you to update source config file in order to put your placeholder there where you want :)

thanks, this seems to work: https://github.com/threefoldtech/grid_deployment/commit/7a8de509cd47fefe73a7cae6b6276fc3cef5134d

whatever is provided in .env for DOMAIN is now sed'd into config-bootstrap.py without env var

coesensbert commented 3 months ago

and for the hub itself: https://github.com/threefoldtech/grid_deployment/commit/ff2408451f849cbbfdf8408e9b5ceb981f914cbe

coesensbert commented 3 months ago

resolved: https://hub.ninja.tf/