Repository navigation
Fix: prevent cross-project floating IP attach - #5177
Conversation
|
A tip: you can set the base of the PR to my branch so the diff will only show your commits, and then when mine merges it will automatically reset the base on this PR to main. |
| ) { | ||
| fip_selector.project = project; | ||
| } | ||
|
|
There was a problem hiding this comment.
Can this even happen? Is this about the case where floating IP is specified by name but there is no project, but instance is given by ID, so we can infer the project from that, and then we give that project to the floating IP as well?
This is subtle and a preference, but even though we're bending over backwards in my PR to be flexible, I think this bit is actually too accommodating because it allows the user to violate a contract that's enforced for every other endpoint to my knowledge — if you specify the resource by name (the primary resource for the endpoint, in this case the floating IP) you need to include the project. Even though we can technically infer it from the instance ID of the post body, I don't think we should. I think you should get rid of this if and let floating_ip_lookup error. That also has the advantage of letting you get rid of the mut, which freaks me out in general.
But back to "can this happen?" — I think this whole if might be ruled out by the floating_ip_lookup call in the match above — I think it will error there if the floating IP is by name and there's no project.
There was a problem hiding this comment.
You're right, that should not be possible (and we should not allow it). The main intent of this PR was initially to catch a double name lookup that could happen on FIP [name+ project] + Instance [ID] with the FIP attach saga, but I mistakenly tunnelled on 'always having a valid FIP selector' while building out the surrounding logic.
I think looking at it now we should make the FIP lookup unconditional outside of the top level match: I expect any other resources will need it, too.
There was a problem hiding this comment.
Sure, that makes sense.
There was a problem hiding this comment.
This looks considerably cleaner now, thanks!
This PR ensures that attached FIPs have the same project ID as their target instance, and prevents double lookup of a FIP in some circumstances. Depends on #5173.
b9bd8be to
570921b
Compare
Plumbing through the `authz::FloatingIp` all the way from here makes this logic considerably cleaner, as it turns out.
| (NameOrId::Name(_), None) => { | ||
| Some(authz_project.id().into()) | ||
| } | ||
| }; |
There was a problem hiding this comment.
Much cleaner! And actually... we don't even need to match on fip_selector.project anymore — we always know the project ID. And the comment can be shrunk. There's a lot less to explain.
let instance_selector = params::InstanceSelector {
project: match &target.parent {
NameOrId::Id(_) => None,
NameOrId::Name(_) => Some(authz_project.id().into()),
},
instance: target.parent,
};There was a problem hiding this comment.
Fantastic; done.
david-crespo
left a comment
There was a problem hiding this comment.
This looks great. Since you're already in the zone, how about eliminating this bit where we pass an external API params type into datastore? It looks like it only needs the IP (optional) and the name of the floating IP. Passing the name by itself would be slightly strange — when I tried to fix this I got hung up deciding what the args to the function should be.
Done: I've just destructured the |
This PR ensures that attached FIPs have the same project ID as their target instance, and prevents double lookup of a FIP in the
FIP [name + project] + Instance [ID]attach case.