nameko icon indicating copy to clipboard operation
nameko copied to clipboard

ClusterRpcProxy using default credentials even with given config

Open asciifaceman opened this issue 4 years ago • 4 comments

Please use the Discourse forum for support requests and questions.

Describe the bug Seemingly no matter what I do, ClusterRpcProxy uses the default guest:guest configuration.

    with ClusterRpcProxy(config={"AMQP_URI":"pyamqp://notguest:[email protected]"}) as rpc:
        result = rpc.stream_service.get(stream_id)
        return result, 200

results in

AMQPLAIN login refused: user 'guest' - invalid credentials
2020-07-26 03:15:34.787 [info] <0.7322.1> closing AMQP connection <0.7322.1> (172.25.0.1:60004 -> 172.25.0.2:5672)
2020-07-26 03:16:58.766 [info] <0.7505.1> accepting AMQP connection <0.7505.1> (172.25.0.1:60048 -> 172.25.0.2:5672)
2020-07-26 03:16:58.771 [error] <0.7505.1> Error on AMQP connection <0.7505.1> (172.25.0.1:60048 -> 172.25.0.2:5672, state: starting):
AMQPLAIN login refused: user 'guest' - invalid credentials

I have tried a series of variations of this (from instantiating the config different ways, with or without explicit definition) and have been unsuccessful.

Additionally, I was trying originally to use config.get() but it appears to not be set outside of a nameko run service context. This may just be an expected behavior I'm unaware of tho.

I have no issues so far using the nameko CLI to run the rpc calls manually, so config is working within the context of a nameko service.

To Reproduce

from flasgger import Swagger
from flask import Flask, jsonify, request
from nameko.rpc import RpcProxy
from nameko.standalone.rpc import ClusterRpcProxy

app = Flask(__name__)
Swagger(app)

@app.route('/stream/<stream_id>', methods=['GET'])
def get(stream_id):
    """Returns a single stream
    ---
    parameters:
        - name: stream_id
          in: path
          type: string
          required: true
    responses:
        200:
            description: A stream represented by json
    """

    config= {
        'AMQP_URI': 'pyamqp://user:[email protected]'
    }
    
    with ClusterRpcProxy(config) as rpc:
        result = rpc.stream_service.get(stream_id)
        return result, 200

app.run(debug=True)

Expected behavior For the RPC call to be made via ampq

Environment (please complete the following information):

  • Nameko version: 3.0.0rc8
  • Python version: Python 3.7.3
  • OS: Darwin Kernel Version 18.7.0 / 10.14.6 Mojave

Additional context

One example

127.0.0.1 - - [25/Jul/2020 20:27:35] "GET /stream/5f1cbdf1213b402266d9d0ca HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/asciifaceman/development/praetor/api.py", line 33, in get
    with ClusterRpcProxy(config={"AMQP_URI":"pyamqp://user:[email protected]"}) as rpc:    <<<<< Relevant
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/nameko/standalone/rpc.py", line 252, in __enter__
    return self.start()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/nameko/standalone/rpc.py", line 258, in start
    self.reply_listener.start()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/nameko/standalone/rpc.py", line 87, in start
    maybe_declare(self.queue, conn.channel())
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 289, in channel
    chan = self.transport.create_channel(self.connection)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 867, in connection
    max_retries=1, reraise_as_library_errors=False
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 445, in _ensure_connection
    callback, timeout=timeout
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/utils/functional.py", line 344, in retry_over_time
    return fun(*args, **kwargs)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 874, in _connection_factory
    self._connection = self._establish_connection()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 809, in _establish_connection
    conn = self.transport.establish_connection()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/transport/pyamqp.py", line 130, in establish_connection
    conn.connect()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 320, in connect
    self.drain_events(timeout=self.connect_timeout)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 508, in drain_events
    while not self.blocking_read(timeout):
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 514, in blocking_read
    return self.on_inbound_frame(frame)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/method_framing.py", line 55, in on_frame
    callback(channel, method_sig, buf, None)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 521, in on_inbound_method
    method_sig, payload, content,
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/abstract_channel.py", line 145, in dispatch_method
    listener(*args)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 651, in _on_close
    (class_id, method_id), ConnectionError)
amqp.exceptions.AccessRefused: (0, 0): (403) ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN. For details see the broker logfile.

Another example

127.0.0.1 - - [25/Jul/2020 21:09:59] "GET /stream/5f1cbdf1213b402266d9d0ca HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 2464, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 2450, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1867, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/asciifaceman/development/praetor/api.py", line 34, in get
    with ClusterRpcProxy(config) as rpc:   <<<<< Relevant
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/nameko/standalone/rpc.py", line 252, in __enter__
    return self.start()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/nameko/standalone/rpc.py", line 258, in start
    self.reply_listener.start()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/nameko/standalone/rpc.py", line 87, in start
    maybe_declare(self.queue, conn.channel())
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 289, in channel
    chan = self.transport.create_channel(self.connection)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 867, in connection
    max_retries=1, reraise_as_library_errors=False
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 445, in _ensure_connection
    callback, timeout=timeout
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/utils/functional.py", line 344, in retry_over_time
    return fun(*args, **kwargs)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 874, in _connection_factory
    self._connection = self._establish_connection()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/connection.py", line 809, in _establish_connection
    conn = self.transport.establish_connection()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/kombu/transport/pyamqp.py", line 130, in establish_connection
    conn.connect()
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 320, in connect
    self.drain_events(timeout=self.connect_timeout)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 508, in drain_events
    while not self.blocking_read(timeout):
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 514, in blocking_read
    return self.on_inbound_frame(frame)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/method_framing.py", line 55, in on_frame
    callback(channel, method_sig, buf, None)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 521, in on_inbound_method
    method_sig, payload, content,
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/abstract_channel.py", line 145, in dispatch_method
    listener(*args)
  File "/Users/asciifaceman/development/praetor/venv/lib/python3.7/site-packages/amqp/connection.py", line 651, in _on_close
    (class_id, method_id), ConnectionError)
amqp.exceptions.AccessRefused: (0, 0): (403) ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN. For details see the broker logfile.

asciifaceman avatar Jul 26 '20 04:07 asciifaceman

Note: I know I Could set up the API to be a service as well as is demonstrated in your examples repo, but I wanted to see how well it would operate in an event loop since I plan on interfacing with the rpc endpoints within a task scheduler that would be self-determining and not API bound (this was just the first step in testing it outside of the context of a service)

asciifaceman avatar Jul 26 '20 04:07 asciifaceman

resolved: https://github.com/nameko/nameko/issues/687#issuecomment-663938776

This should be documented in https://nameko.readthedocs.io/en/stable/built_in_extensions.html?highlight=standalone#rpc

asciifaceman avatar Jul 26 '20 05:07 asciifaceman

I think this is a bug and this needs to be fixed. Had spend half a day troubleshooting when I deploy into the server (eg: not using localhost) I tot our application has dev/prod parity issue. I switch back to 2.12.x official release instead of release candidates.

chewfred avatar Aug 06 '20 05:08 chewfred

I'm unfortunately on the RC for new features :\

asciifaceman avatar Aug 06 '20 06:08 asciifaceman