Skip to content

Commit bfb881a

Browse files
committed
Network: Tighten adoption filter
ListOSResourcesForAdoption only filtered by name. Resolve ProjectRef when set and include ProjectID in the list filter to prevent adopting a network from the wrong project with admin-scoped credentials.
1 parent 9545833 commit bfb881a

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

internal/controllers/network/actuator.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,32 @@ func (actuator networkActuator) GetOSResourceByID(ctx context.Context, id string
7272
}
7373

7474
func (actuator networkActuator) ListOSResourcesForAdoption(ctx context.Context, obj orcObjectPT) (iter.Seq2[*osResourceT, error], bool) {
75-
if obj.Spec.Resource == nil {
75+
resource := obj.Spec.Resource
76+
if resource == nil {
7677
return nil, false
7778
}
7879

79-
listOpts := networks.ListOpts{Name: getResourceName(obj)}
80+
// Resolve the project ID from ProjectRef if set. Without the project
81+
// ID, adoption with admin-scoped credentials could match a network
82+
// in the wrong project.
83+
var projectID string
84+
if resource.ProjectRef != nil {
85+
project, rs := dependency.FetchDependency(
86+
ctx, actuator.k8sClient, obj.Namespace, resource.ProjectRef, "Project",
87+
func(dep *orcv1alpha1.Project) bool {
88+
return orcv1alpha1.IsAvailable(dep) && dep.Status.ID != nil
89+
},
90+
)
91+
if needsReschedule, _ := rs.NeedsReschedule(); needsReschedule {
92+
return nil, false
93+
}
94+
projectID = ptr.Deref(project.Status.ID, "")
95+
}
96+
97+
listOpts := networks.ListOpts{
98+
Name: getResourceName(obj),
99+
ProjectID: projectID,
100+
}
80101
return actuator.osClient.ListNetwork(ctx, listOpts), true
81102
}
82103

0 commit comments

Comments
 (0)