Backup of docker instance failed to authenticate
pihomeserver opened this issue · 10 comments
Hi
Trying to use the backup tool with a docker instance but it fails due to an error in the authentication (API key is just for testing)
- I created an admin API token in the UI
- Tested successfully the curl command
chris@ci-dev:~$ curl -H "Authorization: Bearer eyJrIjoiRWp4S3RGa25Wd0hJRXBDNExCaE9CcDE2RWhhSXlpU0MiLCJuIjoiQmFja3VwIiwiaWQiOjF9" http://192.168.31.200:3000/api/dashboards/home
{"meta":{"isHome":true,"canSave":false,"canEdit":true,"canAdmin":false,"canStar":false,"slug":"","url":"","expires":"0001-01-01T00:00:00Z","created":"0001-01-01T00:00:00Z","updated":"0001-01-01T00:00:00Z","updatedBy":"","createdBy":"","version":0,"hasAcl":false,"isFolder":false,"folderId":0,"folderTitle":"General","folderUrl":"","provisioned":false,"provisionedExternalId":""},"dashboard":{"links":[],"panels":[{"datasource":null,"gridPos":{"h":3,"w":24,"x":0,"y":0},"id":1,"title":"","transparent":false,"type":"welcome"},{"datasource":null,"folderId":0,"gridPos":{"h":15,"w":12,"x":0,"y":4},"headings":true,"id":3,"limit":30,"links":[],"options":{},"query":"","recent":true,"search":false,"starred":true,"tags":[],"title":"Dashboards","type":"dashlist"},{"datasource":null,"gridPos":{"h":15,"w":12,"x":12,"y":4},"id":4,"links":[],"options":{"feedUrl":"https://grafana.com/blog/news.xml"},"title":"Latest from the blog","type":"news"},{"gridPos":{"h":9,"w":24,"x":0,"y":3},"id":123123,"type":"gettingstarted"}],"schemaVersion":22,"tags":[],"templating":{"list":[]},"time":{"from":"now-6h","to":"now"},"timepicker":{"hidden":true,"refresh_intervals":["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],"time_options":["5m","15m","1h","6h","12h","24h","2d","7d","30d"],"type":"timepicker"},"timezone":"browser","title":"Home"}}
- created the configuration file
{
"general": {
"debug": true,
"backup_dir": "_OUTPUT_",
"verify_ssl": false,
"pretty_print": true
},
"grafana": {
"url": "http://localhost:3000",
"token": "eyJrIjoiRWp4S3RGa25Wd0hJRXBDNExCaE9CcDE2RWhhSXlpU0MiLCJuIjoiQmFja3VwIiwiaWQiOjF9",
"search_api_limit": 5000
}
}
- call the script
chris@ci-dev:~$ .local/bin/grafana-backup save
/usr/lib/python3/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
RequestsDependencyWarning)
grafana health: http://localhost:3000/api/health
[DEBUG] resp status: 200
[DEBUG] resp body: {'commit': '2489dc4d3a', 'database': 'ok', 'version': '7.3.3'}
grafana auth check: http://localhost:3000/api/auth/keys
[DEBUG] resp status: 401
[DEBUG] resp body: {'message': 'Invalid Basic Auth Header'}
########################################
server status is not ok: {'message': 'Invalid Basic Auth Header'}
Using
- Grafana v7.3.3 (2489dc4d3a) in a docker container
- Python 3.7.3
- OS is Debian in a VM on Mac OS
You use curl testing http://192.168.31.200:3000
.
But configuration is http://localhost:3000
.
Is http://192.168.31.200:3000
the same Grafana as http://localhost:3000
?
Many thanks
Yes it. I tried both in the json file. Same result for curl. Same issue for the script
Can you please try installing inside a virtual environment @pihomeserver?
sudo apt install python3-virtualenv
git clone https://github.com/ysde/grafana-backup-tool.git
cd grafana-backup-tool
virtualenv -p $(which python3) venv
source venv/bin/activate
pip install .
grafana-backup save
Same issue. I add to adapt your step-by-step suggestion with python3 -m virtualenv -p $(which python3) venv
Then the result :
chris@ci-dev:~/grafana-backup-tool$ python3 -m virtualenv -p $(which python3) venv
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
/usr/lib/python3/dist-packages/virtualenv.py:1090: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /home/chris/grafana-backup-tool/venv/bin/python3
Also creating executable in /home/chris/grafana-backup-tool/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
chris@ci-dev:~/grafana-backup-tool$ source venv/bin/activate
(venv) chris@ci-dev:~/grafana-backup-tool$ pip install .
Processing /home/chris/grafana-backup-tool
Collecting boto3
Downloading boto3-1.16.41-py2.py3-none-any.whl (130 kB)
|████████████████████████████████| 130 kB 4.2 MB/s
Collecting botocore<1.20.0,>=1.19.41
Downloading botocore-1.19.41-py2.py3-none-any.whl (7.1 MB)
|████████████████████████████████| 7.1 MB 8.9 MB/s
Collecting jmespath<1.0.0,>=0.7.1
Using cached jmespath-0.10.0-py2.py3-none-any.whl (24 kB)
Collecting python-dateutil<3.0.0,>=2.1
Using cached python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting s3transfer<0.4.0,>=0.3.0
Using cached s3transfer-0.3.3-py2.py3-none-any.whl (69 kB)
Collecting six>=1.5
Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting urllib3<1.27,>=1.25.4
Using cached urllib3-1.26.2-py2.py3-none-any.whl (136 kB)
Collecting docopt
Downloading docopt-0.6.2.tar.gz (25 kB)
Collecting requests
Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Collecting chardet<5,>=3.0.2
Using cached chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting idna<3,>=2.5
Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Building wheels for collected packages: grafana-backup, docopt
Building wheel for grafana-backup (setup.py) ... done
Created wheel for grafana-backup: filename=grafana_backup-1.1.5-py3-none-any.whl size=25278 sha256=95f1983e750c5cf77b903678f1a26ea1181ae2dedf11926e2fe49046798f358f
Stored in directory: /home/chris/.cache/pip/wheels/a1/a7/b5/97e6b8ffb50c3d2a42f0c0405a4f1df08c8cc980077879bdb8
Building wheel for docopt (setup.py) ... done
Created wheel for docopt: filename=docopt-0.6.2-py2.py3-none-any.whl size=13705 sha256=89807fb7bab536743212727d2ebf5bc7259fca95dda7dff71c226cfd761ad1fb
Stored in directory: /home/chris/.cache/pip/wheels/72/b0/3f/1d95f96ff986c7dfffe46ce2be4062f38ebd04b506c77c81b9
Successfully built grafana-backup docopt
Installing collected packages: six, urllib3, python-dateutil, jmespath, botocore, s3transfer, idna, chardet, certifi, requests, docopt, boto3, grafana-backup
Successfully installed boto3-1.16.41 botocore-1.19.41 certifi-2020.12.5 chardet-4.0.0 docopt-0.6.2 grafana-backup-1.1.5 idna-2.10 jmespath-0.10.0 python-dateutil-2.8.1 requests-2.25.1 s3transfer-0.3.3 six-1.15.0 urllib3-1.26.2
(venv) chris@ci-dev:~/grafana-backup-tool$ mv ../grafana-backup.json .
(venv) chris@ci-dev:~/grafana-backup-tool$ grafana-backup save
grafana health: http://localhost:3000/api/health
[DEBUG] resp status: 200
[DEBUG] resp body: {'commit': '2489dc4d3a', 'database': 'ok', 'version': '7.3.3'}
grafana auth check: http://localhost:3000/api/auth/keys
[DEBUG] resp status: 401
[DEBUG] resp body: {'message': 'Unauthorized'}
########################################
server status is not ok: {'message': 'Unauthorized'}
(venv) chris@ci-dev:~/grafana-backup-tool$
different message, you are now getting Unauthorized
instead of Invalid Basic Auth Header'
Oups yes
By the way the sh script works like a charm
can you try removing the config file rm ~/.grafana-backup.json
and test using ENV vars only
export GRAFANA_URL=http://localhost:3000
export GRAFANA_TOKEN='<token>'
grafana-backup save
@acjohnson it works with ENV vars !
@acjohnson it works with ENV vars !
Good to know. I believe there is something wrong with your config file even though the contents of it that you posted in the OP looked good to me...
Thank you for the prompt support !