Skip to content

Commit

Permalink
lxd/network/network_utils: Check for project restrictions first
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Jan 24, 2025
1 parent 7795ebc commit 8cd98b6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lxd/network/network_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,11 @@ func ProxyParseAddr(data string) (*deviceConfig.ProxyAddress, error) {
func AllowedUplinkNetworks(s *state.State, projectConfig map[string]string) ([]string, error) {
var uplinkNetworkNames []string

// There are no allowed networks if project is restricted and restricted.networks.uplinks is not set.
if shared.IsTrue(projectConfig["restricted"]) && projectConfig["restricted.networks.uplinks"] == "" {
return []string{}, nil
}

err := s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
// Uplink networks are always from the default project.
networks, err := tx.GetCreatedNetworksByProject(ctx, api.ProjectDefaultName)
Expand Down Expand Up @@ -1490,11 +1495,6 @@ func AllowedUplinkNetworks(s *state.State, projectConfig map[string]string) ([]s

allowedUplinkNetworkNames := []string{}

// There are no allowed networks if restricted.networks.uplinks is not set.
if projectConfig["restricted.networks.uplinks"] == "" {
return allowedUplinkNetworkNames, nil
}

// Parse the allowed uplinks and return any that are present in the actual defined networks.
allowedRestrictedUplinks := shared.SplitNTrimSpace(projectConfig["restricted.networks.uplinks"], ",", -1, false)

Expand Down

0 comments on commit 8cd98b6

Please sign in to comment.