lib/connections, lib/model, gui: Specify allowed networks per device (fixes #219)
This adds a new config AllowedNetworks per device, which when set should contain a list of network prefixes (192.168.0.0/126 etc) that are allowed for the given device. The connection service will not attempt connections to addresses outside of the given networks and incoming connections will be rejected as well. I've added the config to the normal device editor and shown it (when set) in the device summary on the main screen. There's a unit test for the IsAllowedNetwork method, I've done some manual sanity testing on top of that. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4073
This commit is contained in:
committed by
Audrius Butkevicius
parent
4253f22680
commit
c5e0c47989
@@ -133,16 +133,18 @@ func TestDeviceConfig(t *testing.T) {
|
||||
|
||||
expectedDevices := []DeviceConfiguration{
|
||||
{
|
||||
DeviceID: device1,
|
||||
Name: "node one",
|
||||
Addresses: []string{"tcp://a"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
DeviceID: device1,
|
||||
Name: "node one",
|
||||
Addresses: []string{"tcp://a"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
{
|
||||
DeviceID: device4,
|
||||
Name: "node two",
|
||||
Addresses: []string{"tcp://b"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
DeviceID: device4,
|
||||
Name: "node two",
|
||||
Addresses: []string{"tcp://b"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
}
|
||||
expectedDeviceIDs := []protocol.DeviceID{device1, device4}
|
||||
@@ -236,22 +238,26 @@ func TestDeviceAddressesDynamic(t *testing.T) {
|
||||
name, _ := os.Hostname()
|
||||
expected := map[protocol.DeviceID]DeviceConfiguration{
|
||||
device1: {
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"dynamic"},
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"dynamic"},
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device2: {
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"dynamic"},
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"dynamic"},
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device3: {
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"dynamic"},
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"dynamic"},
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device4: {
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -270,25 +276,29 @@ func TestDeviceCompression(t *testing.T) {
|
||||
name, _ := os.Hostname()
|
||||
expected := map[protocol.DeviceID]DeviceConfiguration{
|
||||
device1: {
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device2: {
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device3: {
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressNever,
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressNever,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device4: {
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -307,22 +317,26 @@ func TestDeviceAddressesStatic(t *testing.T) {
|
||||
name, _ := os.Hostname()
|
||||
expected := map[protocol.DeviceID]DeviceConfiguration{
|
||||
device1: {
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"tcp://192.0.2.1", "tcp://192.0.2.2"},
|
||||
DeviceID: device1,
|
||||
Addresses: []string{"tcp://192.0.2.1", "tcp://192.0.2.2"},
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device2: {
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"tcp://192.0.2.3:6070", "tcp://[2001:db8::42]:4242"},
|
||||
DeviceID: device2,
|
||||
Addresses: []string{"tcp://192.0.2.3:6070", "tcp://[2001:db8::42]:4242"},
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device3: {
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"tcp://[2001:db8::44]:4444", "tcp://192.0.2.4:6090"},
|
||||
DeviceID: device3,
|
||||
Addresses: []string{"tcp://[2001:db8::44]:4444", "tcp://192.0.2.4:6090"},
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
device4: {
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
DeviceID: device4,
|
||||
Name: name, // Set when auto created
|
||||
Addresses: []string{"dynamic"},
|
||||
Compression: protocol.CompressMetadata,
|
||||
AllowedNetworks: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user