gcgarner / IOTstack

docker stack for getting started on IOT on the Raspberry PI
GNU General Public License v3.0
1.5k stars 578 forks source link

Grafana default username and password is incorrect #185

Closed ronnyandre closed 4 years ago

ronnyandre commented 4 years ago

I did a fresh install of Grafana, but I am not able to log into Grafana, even though the default username and password is both set to "admin".

Reset password does not work as IOTstack does not have an email service.

Slyke commented 4 years ago

Hey @ronnyandre the project has been migrated over to: https://github.com/SensorsIot/IOTstack

But to answer your question, go into the grafana.env file and uncomment the lines that set the username and password if you haven't already tried. The env file will be in the /services/grafana/ directory, don't use the one in /.templates/grafana unless you plan to rebuild.

ronnyandre commented 4 years ago

I did set the username and password, and then ran docker-compose up -d. Still no luck.

Paraphraser commented 4 years ago

I have not hit a problem like this with Grafana but I did run into a problem in PiHole that sounds quite like this one. I explained what I had found in #73. Look for the comment starting with “I will tell you something else that is also quite intriguing...”. I can’t promise it will help but it may give some clues.

I also recall running into a problem with passing settings to InfluxDB which, now that I think about it, may be another example of the same problem. I am not sure whether I ever documented it in an issue. I’ll keep looking and add to this if I find it.

Paraphraser commented 4 years ago

I found what I was thinking of. It was a Discord reply but it turned out to be unrelated.

Paraphraser commented 4 years ago

This is the magic incantation:

$ docker exec -it grafana bash
# grafana-cli --homepath "/usr/share/grafana" admin reset-admin-password "admin"
# exit

By the way, my grafana.env has always had:

# [SECURITY]
#GF_SECURITY_ADMIN_USER=admin
#GF_SECURITY_ADMIN_PASSWORD=admin

In other words, those have always been commented-out. The first time I fired up Grafana from the web interface, it wanted “admin/admin” then prompted me to change the password.

I just reset the password to “admin” as explained above. I did not restart the container. I just reconnected to Grafana’s web UI and it took me through the same forced password change.

I suppose that it is possible that, if I had (1) reset the password to admin, (2) stopped the container (stop, not restart), (3) set a specific password in the environment file then (4) run “docker-compose up -d” to bring Grafana up again, then that password from the environment file might have been used. But I did not test that. It seems fairly obvious from the behaviour of the reset command that the password is stored in an SQLite database. Even if the environment file method works, I think it will only ever be a one-shot. It will never be a general method for password maintenance.

Paraphraser commented 4 years ago

Oh, the most likely reason why a fresh install did not work for you is because the password is almost certainly stored in “ ~/IOTstack/volumes/grafana/data/grafana.db”. You’d have to blow that away to get a truly clean install.

I was recently trying a full restore of a daily backup from my “live” RPi4 onto a “test” RPi4 and my Grafana password came along for the ride. I was surprised and pleased. The full restore actually worked really well. The only tricky bit was Influx. Every other container just fired up.

In fact, I confused the hell out of myself when I started seeing “live” data appear in the Influx databases on the test machine. I thought, “how can that be? All my Arduinos are logging to the live machine and don’t know about the test machine.” It turned out that instead of my Node-Red flows subscribing to “mosquitto” (as a host name on the Docker bridged network) I was using the fully qualified domain name of the live machine. So it was Node-Red on the test machine that had subscribed to the broker on the live machine. I felt like a twit when I finally figured it out but it certainly proved that restoring an IOTstack backup actually works. Works really well!

ronnyandre commented 4 years ago

Seems like the issue was as @Paraphraser mention. The changed admin password was stored in the grafana.db file. This file seems not to purge when reinstalling grafana.