Skip to content

Remote addresses are ignored #302

@riley206-pnnl

Description

@riley206-pnnl

I can look at how vctl handles connections all day but how is that the same as an agent connecting to a remote machine? Anyways, even if I did, it seems that the forward historian cant connect to a remote platform as is because of the bug below. Please correct me if im wrong.

The Bug in get_server_credentials():

File:

def get_server_credentials(address: Optional[str] = None) -> Credentials:

def get_server_credentials(address: Optional[str] = None) -> Credentials:
    # ...
    
    # ipc address must mean we are local so use @ symbol to mean so.
    if address is None or address.startswith('ipc'):
        address = "@"

    cred_path = Path(os.environ['VOLTTRON_HOME']).expanduser() / f"credentials_store/{PLATFORM}.json"
    return VolttronCredentials.load_from_file(cred_path)  # ⚠️ RETURNS HERE - LINE 148
    
    # ALL THE CODE BELOW NEVER EXECUTES (unreachable code after return)
    new_path = Path(os.environ['VOLTTRON_HOME']) / "known_hosts.json"
    # ... 40+ lines of code that never runs

The Problem:

  1. When you pass address="tcp://192.168.1.248:22917" (my other local volttron instance) (a remote address), the function ignores it
  2. On line 148, it immediately returns credentials from credentials_store/platform.json - which is the LOCAL platform's credentials
  3. All the code after line 148 is unreachable dead code - it never executes
  4. The function never checks known_hosts.json for the remote server's public key
  5. It returns the wrong serverkey - it gives you the LOCAL platform key instead of the REMOTE platform key

Where This Is Used:

File: zmq_core.py

@core_builder
class ZmqCoreBuilder(CoreBuilder):
    def build(self, *, context: AgentContext, owner: AbstractAgent = None) -> CoreLoop:
        # ...
        try:
            credstore = service_repo.resolve(CredentialsStore)
            server_creds = credstore.retrieve_credentials(identity=PLATFORM)
        except Unresolvable:
            server_creds = get_server_credentials()  # ⚠️ CALLS THE BROKEN FUNCTION
        
        return ZmqCore(owner=owner,
                       credentials=context.credentials,
                       address=context.address,
                       reconnect_interval=opts.reconnect_interval,
                       agent_uuid=opts.agent_uuid,
                       server_credentials=server_creds)  # ⚠️ WRONG CREDENTIALS PASSED

And in the ZmqCore.__init__:

def __init__(self, ..., server_credentials: Credentials = None, ...):
    # ...
    self.serverkey = server_credentials.publickey  # ⚠️ GETS LOCAL KEY INSTEAD OF REMOTE

What Should Happen:
The function should look up the remote address (tcp://192.168.1.248:22917) in known_hosts.json and return the public key of that remote server.

What Actually Happens:
It returns the credentials of the local platform, so when the agent tries to connect to the remote server, it uses the wrong serverkey and the authentication fails (or connects to the wrong place).

This is why we had to manually create RemoteAgent and pass server_credentials=PublicCredentials(identity='platform', publickey=serverkey) with the correct remote serverkey.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions