-
Notifications
You must be signed in to change notification settings - Fork 13
Description
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 runsThe Problem:
- When you pass
address="tcp://192.168.1.248:22917"(my other local volttron instance) (a remote address), the function ignores it - On line 148, it immediately returns credentials from
credentials_store/platform.json- which is the LOCAL platform's credentials - All the code after line 148 is unreachable dead code - it never executes
- The function never checks
known_hosts.jsonfor the remote server's public key - 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 PASSEDAnd in the ZmqCore.__init__:
def __init__(self, ..., server_credentials: Credentials = None, ...):
# ...
self.serverkey = server_credentials.publickey # ⚠️ GETS LOCAL KEY INSTEAD OF REMOTEWhat 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.