<@U06PYTVAES1> - I've looked at your comments on <...
# proj-sdk
s
@calm-artist-7206 - I've looked at your comments on https://github.com/OpenHands/agent-sdk/pull/855 and I've reverted the change to state.py
state.py
doesn't save any secrets
Not even the LLM api key. The
_secrets_manager
is private and so will not be saved either.
event_service.py
is used by the agent server and saves secrets.
When using the agent server on its own (No App Server) This means that secrets are stored in plain text on the host machine. This is similar to V0 OSS where secrets are stored in plain text inside
secrets.json
. It is not secure, but even if we encrypted these values at rest it would mean we would also need to store the encryption key somewhere unencrypted - either that or we disable persistence unless the user has set up a master key in their environment and warn them of this - but usability and security are pulling in opposite directions When using the App Server... We attempt to reduce the scope of these threats by: • Secrets are stored in the database, not any file system connected to the app server. (In non single user environments this database is typically Postgres on a separate machine) • All Secrets stored in the database are encrypted at rest using a master key stored in the app server (Typically defined as an environment variable - this is the same as V0 SAAS except we settled on JWKS as the standard to make key rotation easier.) • Secrets passed to Agent Servers are typically instances of LookupSecret - they include a URL where the actual secret is available and a key which expires after 2 weeks (Configurable as an environment variable) - So the actual secrets are not persisted within the sandbox, nor are they available as environment variables. If there is ever a detected leak, historical secrets are safer. Threat Analysis... • When installed on a single user machine app server / agent server, if a malicious user gained read access to the host file system, they could read any persisted keys. (Or read the master key and use that to decrypt any keys.) • When using the app server, if a malicious user gained read access to the container file system they could read the git token for the selected repository only, and the user secrets - assuming they gained access to a conversation which is less than 2 weeks old. • When using the app server with a database on a separate machine, if a malicious user got access to a database dump they would also need to get the master key from the app server in order to decrypt the secrets.
c
To note, • when using the agent server on its own ◦ my main concern is not external attackers, it’s _user expectations_: storing secrets in conversation files is IMHO very error prone. One could always zip a conversation and attach it publicly, e.g. for us to debug an error! 😓 ▪︎ or show off a funny Sonnet blunder ◦ that risk multiplies immensely if it would be in every conversation ◦ this is true about
meta.json
too, I think
; the user just needs to use the server otherwise I don’t think we save it ◦ we need to store one copy and/or read it, it’s no different than any configuration file ◦ except we seem to need more files (then they really should be well defined, well named, and in a common expected place) ◦ e.g.
~/.openhands/secrets/
maybe; what we have now is a bit messier ◦ I do think we can integrate keyring sometime, but we still need a fallback (files), it’s fine with care Frankly, I am still to figure out • why we save metadata at all in V1 (probably because there are multiple conversations even in the agent-server, this is confusing a bit because it also exists in app server, in db) • and why it includes secrets (I don’t know this) TL;DR: We need to store secrets of more than one kind, and probably - apparently - in more than one file. I think we really should save them in one place, not per conversation. It’s one agent server, it works in a single workspace => multiple conversations in that space have the same secrets, right?
> We need to store secrets of more than one kind I’m looking into those for LLMs indirectly, in this PR on LLM Profiles: https://github.com/OpenHands/agent-sdk/pull/795
👀 1
s
It’s one agent server, it works in a single workspace => multiple conversations in that space have the same secrets, right?
At the moment, the secrets are tied to the conversation rather than the workspace. So in theory you could have a workspace that has 2 conversations working in the same workspace - one for github, one for gitlab. (Or 2 different github accounts.) I suppose we could attach secrets to the workspace instead and then say if you want different accounts use a different workspace - this seems safer
I do see your point about accidental leaks
c
Definitely safer IMO, and again, closer to user expectations
s
I think this is a good argument for porting the JWKS functionality back from the app server into the sdk
(Meaning we do encryption at rest, and it is not giving us anything against a malicious attacker with read access but it does help prevent accidental leaks)
This becomes less of an issue if we attach the secrets to the workspace though
At the moment I don't think the V1 agent is even aware of these secrets though
I haven't been able to get it to use them - I was gonna bug Xingyao / Calvin about it
c
In V0, we had a file
secrets.json
I think, they weren’t in the metadata file
s
Yes - to replicate this in V1 I think we would remove the secrets from the conversation state and add them to the Workspace
c
To clarify, my point about LLM Profiles is that they will clearly need to save LLM keys/AWS , because otherwise the user will not be able to load a profile
s
If they are attached to the workspace having them just assumed to be environment variables makes more sense
Part of the config
c
Another option could be to merge LLM secrets into
secrets
instead, and then we could eliminate multiple files. Single, clear file. If they are attached to the workspace… Definitely sounds better than to conversation, but does it mean the user could end up with more than one copy when they work on different projects, using LocalWorkspace successively?
s
If the Local workspaces use the same directory it may be expected that secrets are reused
c
Just to take a step back: I think we assumed so far that secrets serialization exists in agent-sdk only in order to send them over the wire. We could: • still try to hold on to that assumption • give it up, because conversation restore and/or llm profiles need save/read on disk a bit too badly. Let me stress-test this idea: if we try to hold on to the assumption: • For LLM profiles (which includes conversation restore/switch for local use) ◦ I do think it will become a major pain. We could actually handle it ourselves right now (because we use litellm proxy a lot, so a single key), but users won’t… ◦ however, end users are going to (we hope) use a client app, not the SDK directly ◦ … but we also hope it will be used by client developers, and then they’d need to make up their own configuration module, basically ◦ I’m not sure this is good, under this hypothesis I think we may want to consider again the idea of a minimal configuration package sitting between the SDK and “full” client apps => doable, painful -ish IMO • For conversation restore, with remote use: ◦ I’m sorry, I’m still confused here: why don’t we use Lookup mechanism on restore just as well as any other time? ◦ do we really need to save meta.json / custom secrets
s
why don’t we use Lookup mechanism on restore just as well as any other time?
The lookup mechanism still needs to know which URL to lookup, and the key to use. If this were attached to the workspace rather than the conversation it would make more sense, as we would probably simply read it from the environment variables
I start a conversation...
This starts a sandbox - I can find it with the search endpoint...
I can pause this sandbox...
And it stops the docker container...
(I can pause / resume from the docker console too)
When I resume, if I want my secrets to be restored, they need to have been saved inside the container
Either in the file system or the environment variables
c
Right, that makes sense, but no, they… don’t. I actually thought LookupSecret is for GitHub specific refresh, I wasn’t aware of doing some sort of a similar expiration for them. That’s good! Then no save, two env vars is enough
Well, I suppose that’s not the case for LLM keys, so outside “custom secrets”
> When I resume, if I want my secrets to be restored, they need to have been saved inside the container It’s late, and I’m dense anyway, sorry. We have two servers, app and agent. These are secrets necessary for the agent, before we restart the conversation. • maybe agent-server asks app ◦ idk, can we trust it • or app sends them to agent-server ◦ this seems no different than when we first sent them ◦ we first sent them via POST I thought (in start conversation) ◦ I get that something doesn’t work atm, but that’s surely fixable ◦ we don’t need them when docker initializes stuff, but a bit later It seems to me that we can send them from app-server to agent-server with, idk, the request we use to restart the conversation, or the first user message after restarting? Please do tell what I’m missing