Une preuve de concept pour le partage de configuration Snap entre Snaps à l'aide des confdbs de configuration de Snapd.
Pour une démo simple, veuillez plutôt consulter ce référentiel.
Avertissement
Les Confdbs étaient auparavant appelés registres et aspects avant cela. Snapd, Snapcraft et le Store n'ont pas encore rattrapé ce changement de nom. Pour l'instant, remplacez chaque mention de "confdb" par "registry" et "confdbs" par "registries".
Note
Veuillez noter que l'ancien nom des registres était aspects , c'est pourquoi les snaps ont le préfixe aspects .
Pour installer ce PoC, exécutez simplement le script d'installation :
$ /bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/canonical/registries-poc/main/install.sh ) "
Acknowledging account/f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN assertion...
Acknowledging account-key/xkd_Y2ay5N2Uo14v_wsCtfVJYLAVbJgxbiKM8Ne4mZBflaROriZgk2nb5i9Oebum assertion...
Acknowledging network-confdb.assert assertion...
Installing aspects-poc-server...
aspects-poc-server (edge) 0.2 from Stephen Mwangi (st3v3nmw) installed
Installing aspects-poc-control...
aspects-poc-control (edge) 0.2 from Stephen Mwangi (st3v3nmw) installed
Installing aspects-poc-vpn...
aspects-poc-vpn (edge) 0.2 from Stephen Mwangi (st3v3nmw) installed
Installing aspects-poc-reporting...
aspects-poc-reporting (edge) 0.2 from Stephen Mwangi (st3v3nmw) installed
Assurez-vous d'avoir installé le PoC à l'aide du script d'installation ci-dessus. Le script doit installer le server
, le composant logiciel enfichable control
, le composant logiciel enfichable vpn
et le composant logiciel enfichable reporting
.
Tout doit fonctionner automatiquement et le composant logiciel enfichable control
doit contacter le serveur pour l'enregistrement. Une fois enregistrée, la vue confdb observe-device
devrait ressembler à ceci :
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/observe-device -d
{
"registered": 1719407517,
"uuid": "ca155b32-2472-4650-afb0-c6f967328afe"
}
Le composant logiciel enfichable control
définira également la configuration par défaut de l'appareil lors de son installation initiale :
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/control-interfaces config -d
{
"config": {
"eth0": {
"interface-type": "ethernet",
"ip-address": "172.16.0.3"
},
"wlan0": {
"interface-type": "wifi",
"ip-address": "192.168.0.104"
}
}
}
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/control-tunnel -d
{
"interface": "eth0",
"peers": [
"192.168.21.3",
"192.168.151.225",
"192.168.21.7"
]
}
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/control-telemetry -d
{
"monitor-packets-received": false,
"monitor-packets-sent": true,
"monitor-peers": true,
"sample-rate": 2
}
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/control-device -d
{
"server-url": "http://127.0.0.1:8000"
}
À partir de là, le snap control
s'exécutera toutes les minutes et simulera le flux de paquets sur chacune des interfaces ( config.{interface}.stats
). Vous pouvez le confirmer en vérifiant le démon du snap :
$ snap logs aspects-poc-control
systemd[1]: Starting snap.aspects-poc-control.daemon.service - Service for snap application aspects-poc-control.daemon...
aspects-poc-control.daemon[409009]: eth0: 9 packets ↑, 1 packets ↓
aspects-poc-control.daemon[409009]: wlan0: 5 packets ↑, 4 packets ↓
systemd[1]: snap.aspects-poc-control.daemon.service: Deactivated successfully.
systemd[1]: Finished snap.aspects-poc-control.daemon.service - Service for snap application aspects-poc-control.daemon.
systemd[1]: Starting snap.aspects-poc-control.daemon.service - Service for snap application aspects-poc-control.daemon...
aspects-poc-control.daemon[410059]: eth0: 7 packets ↑, 4 packets ↓
aspects-poc-control.daemon[410059]: wlan0: 2 packets ↑, 4 packets ↓
systemd[1]: snap.aspects-poc-control.daemon.service: Deactivated successfully.
systemd[1]: Finished snap.aspects-poc-control.daemon.service - Service for snap application aspects-poc-control.daemon.
Vous pouvez confirmer ces mises à jour en exécutant :
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/observe-interfaces packets-received
Key Value
packets-received.eth0 127
packets-received.wlan0 148
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/observe-interfaces packets-sent
Key Value
packets-sent.eth0 130
packets-sent.wlan0 131
Le vpn
Snap dispose d'un service qui s'exécute toutes les minutes pour simuler les modifications apportées au tunnel VPN. Cela se limite actuellement à la suppression et à l’ajout de nœuds homologues à l’extrémité opposée du tunnel. Chacune de ces actions a 10 % de chances de se produire.
Vous pouvez le confirmer en vérifiant le démon du snap :
$ snap logs aspects-poc-vpn
systemd[1]: snap.aspects-poc-vpn.daemon.service: Deactivated successfully.
systemd[1]: Finished snap.aspects-poc-vpn.daemon.service - Service for snap application aspects-poc-vpn.daemon.
systemd[1]: Starting snap.aspects-poc-vpn.daemon.service - Service for snap application aspects-poc-vpn.daemon...
aspects-poc-vpn.daemon[412358]: No changes to tunnel.
systemd[1]: snap.aspects-poc-vpn.daemon.service: Deactivated successfully.
systemd[1]: Finished snap.aspects-poc-vpn.daemon.service - Service for snap application aspects-poc-vpn.daemon.
systemd[1]: Starting snap.aspects-poc-vpn.daemon.service - Service for snap application aspects-poc-vpn.daemon...
aspects-poc-vpn.daemon[413769]: No changes to tunnel.
systemd[1]: snap.aspects-poc-vpn.daemon.service: Deactivated successfully.
systemd[1]: Finished snap.aspects-poc-vpn.daemon.service - Service for snap application aspects-poc-vpn.daemon.
Vous pouvez également consulter la vue confdb observe-tunnel
pour voir les pairs actuels :
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/observe-tunnel peers
[
"192.168.21.3",
"192.168.151.225",
"192.168.21.7"
]
Le reporting
snap dispose d'un service qui s'exécute toutes les minutes pour collecter des mesures sur l'état actuel du réseau. Les métriques collectées sont contrôlées par la vue confdb control-metrics
:
$ snap get f22PSauKuNkwQTM9Wz67ZCjNACuSjjhN/network/control-telemetry -d
{
"monitor-packets-received": false,
"monitor-packets-sent": true,
"monitor-peers": true,
"sample-rate": 2
}
Vous pouvez vérifier l'état du réseau en exécutant :
$ snap logs aspects-poc-reporting -n 25
aspects-poc-reporting.daemon[389998]: INFO:root:The network stats are:
aspects-poc-reporting.daemon[389998]: INFO:root: {'device-id': 'ca155b32-2472-4650-afb0-c6f967328afe',
aspects-poc-reporting.daemon[389998]: 'packets-sent': {'eth0': 137, 'wlan0': 141},
aspects-poc-reporting.daemon[389998]: 'tunnel-peers': ['192.168.21.3', '192.168.151.225', '192.168.21.7']}
aspects-poc-reporting.daemon[389998]: INFO:root:Next run in 30.00 seconds
aspects-poc-reporting.daemon[389998]: INFO:root:The network stats are:
aspects-poc-reporting.daemon[389998]: INFO:root: {'device-id': 'ca155b32-2472-4650-afb0-c6f967328afe',
aspects-poc-reporting.daemon[389998]: 'packets-sent': {'eth0': 137, 'wlan0': 141},
aspects-poc-reporting.daemon[389998]: 'tunnel-peers': ['192.168.21.3', '192.168.151.225', '192.168.21.7']}
aspects-poc-reporting.daemon[389998]: INFO:root:Next run in 30.00 seconds
aspects-poc-reporting.daemon[389998]: INFO:root:The network stats are:
aspects-poc-reporting.daemon[389998]: INFO:root: {'device-id': 'ca155b32-2472-4650-afb0-c6f967328afe',
aspects-poc-reporting.daemon[389998]: 'packets-sent': {'eth0': 138, 'wlan0': 150},
aspects-poc-reporting.daemon[389998]: 'tunnel-peers': ['192.168.21.3', '192.168.151.225', '192.168.21.7']}
aspects-poc-reporting.daemon[389998]: INFO:root:Next run in 30.00 seconds
aspects-poc-reporting.daemon[389998]: INFO:root:The network stats are:
aspects-poc-reporting.daemon[389998]: INFO:root: {'device-id': 'ca155b32-2472-4650-afb0-c6f967328afe',
aspects-poc-reporting.daemon[389998]: 'packets-sent': {'eth0': 138, 'wlan0': 150},
aspects-poc-reporting.daemon[389998]: 'tunnel-peers': ['192.168.21.3', '192.168.151.225', '192.168.21.7']}
aspects-poc-reporting.daemon[389998]: INFO:root:Next run in 30.00 seconds
aspects-poc-reporting.daemon[389998]: INFO:root:The network stats are:
aspects-poc-reporting.daemon[389998]: INFO:root: {'device-id': 'ca155b32-2472-4650-afb0-c6f967328afe',
aspects-poc-reporting.daemon[389998]: 'packets-sent': {'eth0': 145, 'wlan0': 154},
aspects-poc-reporting.daemon[389998]: 'tunnel-peers': ['192.168.21.3', '192.168.151.225', '192.168.21.7']}
aspects-poc-reporting.daemon[389998]: INFO:root:Next run in 30.00 seconds
Pendant que le serveur est en cours d'exécution (le composant logiciel enfichable correspondant a été installé), la documentation est disponible sur http://127.0.0.1:8000/docs.
Assurez-vous d'avoir installé le PoC à l'aide du script d'installation ci-dessus pour vous assurer que toutes les assertions sont reconnues et que les fonctionnalités expérimentales telles que confdbs sont activées.
Exécutez make
ou make all
pour créer tous les snaps en même temps ou exécutez les commandes suivantes pour les créer individuellement :
$ make control
Building control snap...
Generated snap metadata
Created snap package aspects-poc-control_0.2_amd64.snap
$ make reporting
Building reporting snap...
Generated snap metadata
Created snap package aspects-poc-reporting_0.2_amd64.snap
$ make server
Building server snap...
Generated snap metadata
Created snap package aspects-poc-server_0.2_amd64.snap
$ make vpn
Building vpn snap...
Generated snap metadata
Created snap package aspects-poc-vpn_0.2_amd64.snap
Pour utiliser les cibles make ci-dessous, assurez-vous que yq est installé. Vous pouvez l'installer en utilisant Homebrew ou en un clin d'œil :
$ brew install yq
$ snap install yq
Exécutez make install-all
pour installer tous les snaps en même temps ou exécutez les commandes suivantes pour les installer individuellement :
$ make install-server
Installing server snap...
aspects-poc-server 0.2 installed
$ make install-control
Installing control snap...
aspects-poc-control 0.2 installed
$ make install-vpn
Installing vpn snap...
aspects-poc-vpn 0.2 installed
$ make install-reporting
Installing reporting snap...
aspects-poc-reporting 0.2 installed