Repository navigation
Isolate secrets to each module - #6601
Conversation
9593df3 to
e0d0a35
Compare
e0d0a35 to
d8b1908
Compare
ef78f23 to
2d91181
Compare
|
I haven't looked through this in depth yet, but I just did a quick test and found that the grpc client metadata ends up plumbed all the way through to where I think this offers a simpler route to implementing isolation based on the client ID since each module gets its own even within the context of a session. Just wondering if you tried out that route too. Just leaving this as a quick drive-by thought since I hit a timebox, will resume taking a look again later. |
Hm just one concern with this - if two modules call this at the same time, we'd edge merge, and only get one call to the ExecOp. So theoretically, a module without access to the secret, could get access to the result of a computation that required the secret (though it wouldn't actually leak the secret). The only way to avoid this would be to make sure we actually have different cache keys (e.g. by actually changing the secret access IDs). That's why I went this slightly more complex route, but maybe there's a clever way we could still make it work? Potentially we could inject an env var/similar to every ExecOp in a module, to force a different cache key cross modules, but that feels a bit overly extreme. |
I'm presuming we were going to update to use a stable id as prefix rather than client id, and at that point we'd have the same edge merge problem, right? I was thinking through the cases where this would be undesirable and realized that practically speaking, the "edge-merge" case is actually the same as re-use of a cached exec op. E.g. all the cases where it would be undesirable for an edge merge to happen can also happen if exec-ops from completely different sessions get de-duped due to local/remote cache hits. So I think this actually gets at a larger long-standing and pre-existing issue. Probably still be worth addressing as part of our changes here though. The only thing I can think of to completely squash this problem in all cases (edge merge, cache hits) would be to change the underlying secret ID (i.e. the one that is provided to LLB and used in
So trying to put everything together, we could:
WDYT @jedevc? I'm not opposed to any solution that works and handles all the cases; the above just feels simplest and most robust to me (if the theory works out in practice), but that's obviously subjective. |
Yes, we need a stable id. I was actually thinking that we could pick a "module id" as a stable id:
This is stable, should be pretty easy to propagate everywhere, but doesn't really provide isolation between generic nested sessions (though I'm not necessarily sure this is an issue, this is more obscure, and also expectations of security are much lower). Also, what's really cool about this is that we allow caches/edge-merges for secrets only inside the context of that module - other modules get different buildkit secret ids, so they can't collide.
This is potentially a pain 😢 Without this, we don't have a way to distinguish secrets from each other - and we can't even rely on session id here. If I return a
Ah, nit-pick, but this then changes secret value changes to always invalidate cache - it's a tiny issue, but if possible I'd like to preserve the current behavior.
I think I'm going to try the module "ID" as the secret prefix - it ticks all the required cases, and also addresses the things I mentioned above. Even though it is a bit more work, it shouldn't be that much trickier. I don't think I'm far away from getting this PR into a ready state, should be done this week, just need one more proper focus session. |
0d94a8c to
6445b56
Compare
There was a problem hiding this comment.
👀 so this seems to work like a stable ID per module...
@vito does it seem reasonable that this would stay somewhat stable between runs? If not, it doesn't have sufficient uniqueness guarantees, I can go and add a module ID somewhere, but I'd like to avoid doing all the extra special casing for that if possible.
There was a problem hiding this comment.
You should use m.Source.ID().Digest(), I setup source to be usable as a stable ID with the exact properties you described here. Was previously needed to detecting dependency loops, but that got refactored away recently, but I guess it will come in handy again here.
There was a problem hiding this comment.
perfect, awesome! Thanks, have updated to use that as well.
|
Think I've got most of the tests passing now (:crossed_fingers:). Should be ready for a more proper review :tada: |
Yeah I think this is important. Just keeping in mind that people might be using shortlived secrets (e.g. AWS access keys that expire after an hour), I think we'll definitely want to avoid cache busting on them. Which unfortunately makes things more difficult. |
I know this is what we've landed on in the past, but I'm not sure I agree with it anymore. It means that you can provide invalid credentials that happen to have the same secret name and the operation will "succeed" due to caching. Something about that feels deeply wrong. But:
|
Yeah the issue is we need to be able to distinguish between "I manually changed my secret and want that action to affect external state" and "my credentials are super secure and rotate all the time, but I would still like to enjoy caching." To me it's pretty bad if we end up in a state that doesn't allow frequent cred rotation and caching to coexist. But yeah this probably gets into higher level discussions re: state, deployments, and secret management in general. |
sipsma
left a comment
There was a problem hiding this comment.
Please double check my reasoning here, but I think there may still be a backdoor available via loadSecretFromID. Namely, even though the ID format and accessor are "opaque", it's not that hard for something malicious to derive those (i.e. figure out the accessor for another unrelated module in the same session) and construct an ID manually that's provided to loadSecretFromID and thus grant access to calling plaintext and/or using the secret in other API calls.
This is part of what I was getting at in this comment about more explicitly tracking what module should have access to what secret.
That's an option, but trying to think through less dramatic changes on top of the current PR (which like I said before, I'm not opposed to at all since I think it's workable):
- Somehow write a custom
loadSecretFromIDresolver rather than use the automatic one from dagql? cc @vito seems like something that should be possible but maybe not quite out-of-the-box yet? - (I had more ideas but as I wrote them out they didn't make sense and I hit a timebox, so just pressing submit on my comment for now 😅)
There was a problem hiding this comment.
nit: isn't it available already via client.Opt.Worker.Executor()?
Ok, so - I don't think there's an issue directly with I had a rather nice shower-thought about how to resolve this (have pushed it in the last commit). Essentially, we use the plaintext-digest and put that into the ID - if you use an This has a few fun properties:
However, one note - is it ok that the plaintext secret digest is part of the dagql graph? We take a lot of pains to keep the plaintext out of the graph, so I wonder if we need to do some other stuff to keep the plaintext secret digest out (but we can't just mark it as sensitive, otherwise the client never actually gets access to it, which is kind of the whole point). If we do have concerns about that, we could potentially do some other magic as well, and combine the plaintext digest with the client ID (which is fine to use here, since this doesn't affect the buildkit caching), and track the client ID that set each secret in the secret store (which lets us verify). |
There was a problem hiding this comment.
I genuinely can't see a legitimate reason for users calling this function manually - it exists purely as an implementation detail IMO (the only place I want it really is in tests, and we can do manual querybuilding there).
Is there a way that we can hide this from the generate graphql docs + all the SDKs? Seems related to #6714 (comment)
There was a problem hiding this comment.
This has actually come up before in the wild, not just an internal thing - it was added for the internal call, yes, but in my mind it was also adding an API feature that has been requested for a while:
- https://discord.com/channels/707636530424053791/1200099731045613598/1200099731045613598
- https://discord.com/channels/707636530424053791/1153455796164771920/1153455796164771920
- (I think more but the point has been made)
Does it still work without these arguments?
There was a problem hiding this comment.
Ah I think we can keep the function itself, but I think it shouldn't be possible to call with accessor/etc manually. I'd be happy with just making them hidden, but...
If we could just make it impossible to do so, then I don't think we'd even need the plaintext digest thing I introduced.
894c734 to
a5cac3e
Compare
Bit of a brain dump, sorry: It's a bit risky. The plaintext digest will be sent over the progress stream, all the way to the TUI and Cloud, and visible in tools like https://dagviz.fly.dev. Theoretically someone could just browse to one of your runs and grab the digest from there if they have access to it. It's an obtuse angle, but it exists. It's not a dead end; in principle add something lesser to the "sensitive" flag that means "include this in IDs but don't emit it in telemetry" rather than "forbid this value from ever entering into an ID." The only thing is then you'll have IDs that need to be mutated as they pass through the metrics pipeline, so their digests will differ from the ones that actually evaluate. Nothing will actually break atm, but it's kind of an uncomfortable feeling, and might close certain caching-related doors in the future - e.g. if we wanted to lean harder on IDs as a cache key, this would add an asymmetry between frontend/backend. But maybe we could burn that bridge when we get to it. FWIW a similar concept already exists where IDs can be marked Maybe we could change how 'sensitive' works and rather than forbidding it from going into the ID, we implement a mechanism for redacting values as they're sent through the progress stream? Footnotes
|
This does affect caching though, specifically of module functions themselves that accept secrets as args. The values of all args are part of the cache key for the exec-op underlying the function call. If the ID changes, that invalidates the execution of the function call.
To be clear, I'm not opposed to this since like I said before I now think it makes sense to always invalidate cache based on the value of the secret. It's also how the CLI currently sets the secret name anyways too (code). I think it's essentially a step closer to what I suggested here #6601 (comment)
The thing I'd want to avoid is just using the ClientID as you mentioned towards then end of the comment since that would break our plans to make functions fully cacheable across sessions in the near-ish future. |
Agh, sorry, I did understand this at some point, and then it slipped my mind.
I don't have super strong opinions on the idea of this, but. If the secret hash is sensitive, then we want to avoid it leaking anywhere outside of the current machine:
Since magicache will cache the inputs to functions, I'd really rather not include any hashed version of the password in there - any attacker with access to the cache (just like @vito's point above about dagviz/telemetry), can then perform an offline bruteforce attack - we then rely on the entropy of the secret to provide all the security, which just doesn't feel right. I can't see a way to be comfortable with potentially uploading secret hashes to caching services (it feels like a security incident just waiting to happen). I think the only approach left is to carefully track exactly how secrets are passed between modules, and then when accessing secrets, ensure that that module was passed that secret (either by return from a module that had access, or by argument called by a module that had access). This feels tricky though, since it also requires accounting for secrets that are then stored in custom objects. Given the time before the release, I'm tempted to simply go back to just the Even though it's possible for a malicious module to potentially extract secrets from other running modules, I'm not actually convinced this is the highest priority - if I can run code on a machine, I can definitely think of lots of other nasty things to do - especially since we have privileged nesting/execs. As-is, this PR at least prevents secrets from accidentally colliding over each other, so I think is still an improvement to take for v0.10.0 - there's clearly a lot of future work here. |
a5cac3e to
c50d558
Compare
Signed-off-by: Justin Chadwell <[email protected]>
Looks like I accidentally broke this. I don't really understand dagql super well, but what I think was happening was that we would re-evaluated the secret in the context of the new session, so passing secrets between sessions broke. The solution here seems to be to... pass the scope as part of the call to secret. Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
This keys secrets in the secret store using the scope and the name, in a unique+reproducible way, such that the scope remains secret. This is just an HMAC (but this isn't fully implemented yet). Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
c50d558 to
48c99c6
Compare
sipsma
left a comment
There was a problem hiding this comment.
Given the time before the release, I'm tempted to simply go back to just the
accessor- even though it can be leaked by knowing the ID (I wrote a test for this and pushed it, we can enable it later).Even though it's possible for a malicious module to potentially extract secrets from other running modules, I'm not actually convinced this is the highest priority - if I can run code on a machine, I can definitely think of lots of other nasty things to do - especially since we have privileged nesting/execs.
As-is, this PR at least prevents secrets from accidentally colliding over each other, so I think is still an improvement to take for v0.10.0 - there's clearly a lot of future work here.
Okay yeah I agree this is a big step in the right direction and makes sense given the time frames 👍 (preemptively approving so we can merge ASAP)
Original feature request:
To achieve this isolation, we keep the same global secret store, but ensure that each secret has a "scope" - this scope split the global secret store into lots of smaller stores.
Note, this is really quite a tricky puzzle, and the requirements become more fiddly as you lay them out:
DockerBuildAPI without explicit passingFoofunction call, but then try and access it inBar, is it still there or is it only valid per-call? If it's still there, then does it matter which module called me - and does that make for weird dependency state?We can tick all these boxes by doing the prefixing trick - we also need to explicitly handle the
DockerBuildfrontend case, so we protect against reading directly from there. The only question really, is what prefix to use. A couple ideas I had:A->XandB->Xcalls would have two separately scopedXsecret stores)TODO:
ExecOp/etc). We can use a custom gateway/frontend to protect against this.