Lever-age / leverage

Empower citizens of Philadelphia to use campaign finance data when making informed decisions about who they donate to, who they support, and who they vote for.
http://leveragecampaignfinance.org/
20 stars 10 forks source link

Devise a solution to grant users in docker container. #37

Closed modpluz closed 6 years ago

modpluz commented 6 years ago

Right now, you have to manually copy the grant_users.sql file in the root directory into the /volumes directory before executing docker-compose up in a fresh setup.

@lottspot, offered to cleverly resolve this.

lottspot commented 6 years ago

I'm actually relabeling this as a bug because in addition to this quality of life addition (and probably more importantly) the grant_users.sql file has some problems with it which make it not work with the configuration in the docker environment.

lottspot commented 6 years ago

So we shouldn't actually need this-- I ran a clean docker-compose up without the grant_users.sql file, and the grants are already handled by the container configuration

james@lottbookpro ~/Repositories/leverage-devbackend (issue/leverage#62)
$ docker-compose up -d
Creating network "leverage-devbackend_default" with the default driver
Creating leverage-devbackend_db_1 ... done
Creating leverage-devbackend_api_1        ... done
Creating leverage-devbackend_phpmyadmin_1 ... done

james@lottbookpro ~/Repositories/leverage-devbackend (issue/leverage#62)
$ docker exec -ti leverage-devbackend_db_1 /bin/bash
root@0a757fc9111f:/# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show grants for leverage;
+--------------------------------------------------------+
| Grants for leverage@%                                  |
+--------------------------------------------------------+
| GRANT USAGE ON *.* TO 'leverage'@'%'                   |
| GRANT ALL PRIVILEGES ON `leverage`.* TO 'leverage'@'%' |
+--------------------------------------------------------+
2 rows in set (0.00 sec)

mysql>
james@lottbookpro ~/Repositories/leverage-devbackend (issue/leverage#62)
$ ls volumes/db/docker-entrypoint-initdb.d/
leverage_philly.sql leverage_philly.sql.old
lottspot commented 6 years ago

closed by https://github.com/Lever-age/leverage-devbackend/pull/1

modpluz commented 6 years ago

Yes, the interactive terminal works just fine.

However, when I try connecting to the API from the frontend, I get a 500 error and docker-compose logs shows the below;

leverage_db_1   | 2018-05-23T13:51:53.765734Z 4 [Note] Access denied for user 'leverage'@'172.25.0.4' (using password: YES)

Manually adding a GRANT for the mysql user "leverage'@'172.25.0.4" fixes the error above.

lottspot commented 6 years ago

emphasis on this part of my previous comment:

+--------------------------------------------------------+
| Grants for leverage@%                                  |
+--------------------------------------------------------+
| GRANT USAGE ON *.* TO 'leverage'@'%'                   |
| GRANT ALL PRIVILEGES ON `leverage`.* TO 'leverage'@'%' |
+--------------------------------------------------------+

The grants are already there for leverage@'%' by default. I'm not able to reproduce this problem in a fresh working environment with the latest DB dump. Can you jump into a MySQL shell before running the grant_users.sql script and see if show grants for leverage; returns the same for you as it did for me?

modpluz commented 6 years ago

Sorry, I failed to mention that I can see the grants for the leverage user (as per above). Which is why it doesn't make any logical sense why I'm still getting the "Access denied" error.

I'll look further into this on my side...and possibly re-open the issue if need be.