Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept user/password as arguments of make_direct_shard_connection #87

Open
pierlauro opened this issue Jul 19, 2022 · 0 comments
Open

Comments

@pierlauro
Copy link
Collaborator

pierlauro commented Jul 19, 2022

The function is currently opening a direct connection to a shard with an URI not including username and password. While this works for testing clusters with no authentication enabled, this causes error in production clusters.

For example, this error is thrown when trying to call splitVector through a direct connection:

Traceback (most recent call last):
--
File "defragment_sharded_collection.py", line 1078, in <module>
loop.run_until_complete(main(args))
File "/usr/lib64/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "defragment_sharded_collection.py", line 959, in main
await asyncio.gather(*tasks)
File "defragment_sharded_collection.py", line 938, in split_oversized_chunks
await coll.split_chunk(c, target_chunk_size_kb, conn)
File "defragment_sharded_collection.py", line 112, in split_chunk
}, codec_options=self.cluster.client.codec_options)
File "/usr/lib64/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib64/python3.7/site-packages/pymongo/database.py", line 734, in command
**kwargs,
File "/usr/local/lib64/python3.7/site-packages/pymongo/database.py", line 615, in _command
client=self.__client,
File "/usr/local/lib64/python3.7/site-packages/pymongo/pool.py", line 764, in command
exhaust_allowed=exhaust_allowed,
File "/usr/local/lib64/python3.7/site-packages/pymongo/network.py", line 164, in command
parse_write_concern_error=parse_write_concern_error,
File "/usr/local/lib64/python3.7/site-packages/pymongo/helpers.py", line 180, in _check_command_response
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: command splitVector requires authentication, full error: {'operationTime': Timestamp(1658204283, 1), 'ok': 0.0, 'errmsg': 'command splitVector requires authentication', 'code': 13, 'codeName': 'Unauthorized', 'lastCommittedOpTime': Timestamp(1658204283, 1), '$clusterTime': {'clusterTime': Timestamp(1658204271, 1), 'signature': xx'_MANUALLY_OMITTED_xx'
}}

A user hardcoded username and password and everything worked:

diff common.py common.py.bak
--
131c131
< uri = 'mongodb://mongoadmin:password@' + conn_parts[1]
—
> uri = 'mongodb://' + conn_parts[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant