perftools / xhgui

Web interface for XHProf profiling data can store data in MongoDB or PDO database
1.65k stars 342 forks source link

Can't auth with mongodb #420

Closed athoune closed 2 years ago

athoune commented 3 years ago

XHGui use https://github.com/alcaeus/mongo-php-adapter, and it says :

The authenticate method is not supported. To connect to a database with authentication, please supply the credentials using the connection string.

In https://github.com/perftools/xhgui/blob/99d2d88f70d4a54f4a161dece9b106c3eb72e349/src/ServiceProvider/MongoStorageProvider.php#L46 the MongoClient is configured without username/password.

I set auth in config.php as suggested here https://github.com/perftools/xhgui/blob/99d2d88f70d4a54f4a161dece9b106c3eb72e349/config/config.default.php#L30 but this error happens MongoDB\Driver\Exception\ServerException: command find requires authentication in /var/www/vendor/mongodb/mongodb/src/Operation/Find.php:280

Is it possible to uses mongodb with a username/password ?

glensc commented 3 years ago

🚧 Never link to branches, share a permalink 🚧

NOTE: edit your post and fix it with a permalink!

athoune commented 3 years ago

ok, it's more readable with permalinks, sorry.

athoune commented 3 years ago

I can authenticate with an ugly hack in config.php :

$mongo_hostname = getenv('XHGUI_MONGO_HOSTNAME') ?: '127.0.0.1';
$mongo_port = getenv('XHGUI_MONGO_PORT') ?: 27017;
$mongo_username = getenv('XHGUI_MONGO_USER') ?: 'xhprof';
$mongo_password = getenv('XHGUI_MONGO_PASSWORD') ?: 'pazzword';

return [
'db.host' => "mongodb://$mongo_username:$mongo_password@$mongo_hostname:$mongo_port",
// lots of config here
];
glensc commented 3 years ago

The point of permalinks is that links stay working if code is changed.

glensc commented 3 years ago

From this changeset:

I read that password should go under 'options'. Did you try that?

you seem to be using old db.host syntax, you should use new syntax that the PR introduced, and is present as an example in config as well: config/config.default.php.

athoune commented 3 years ago

hum, I mess something with too many moving parts, mongodb image changed its behavior. I didn't notice when user wasn't created in mongodb, and when I put username/password in the wrong place (outside 'options').

'mongodb' => [
        'options' => [
            'username' => getenv('XHGUI_MONGO_USER') ?: 'xhprof',
            'password' => getenv('XHGUI_MONGO_PASSWORD') ?: 'pazzword',
        ],
]

It works.

Sorry for the noise.

glensc commented 3 years ago

@athoune please close the issue if problem solved!

glensc commented 3 years ago

@athoune what you think can the 'username'/'password' filled by default with null or false, or that will break setups where authentication is not enabled?

I was thinking, that maybe setup to config/config.default.php:

'mongodb' => [
        'options' => [
            'username' => getenv('XHGUI_MONGO_USERNAME') ?: null,
            'password' => getenv('XHGUI_MONGO_PASSWORD') ?: null,
        ],
]
glensc commented 3 years ago

@athoune hallo?

athoune commented 3 years ago

Your patch is nice, thanks.

glensc commented 3 years ago

@athoune can you please answer the question I asked you?

glensc commented 3 years ago

@athoune?

glensc commented 3 years ago

@athoune where did you go?

please answer the question:

glensc commented 2 years ago

Pity, when the user wants something, the developer needs to respond, but when the developer wants contribution back the user disappears.