How to find peer `id` properly in `clever ng leave`?
Context
When a user joins a networkgroup, we add an external peer with an id. When he leaves, we delete the associated external peer.
As @Keruspe had proposed, it would be great to have a dedicated clever ng leave that allows the user to leave a networkgroup if something bad happened and the external peer hasn't been removed as planned.
Problem
The problem is that we do not have a way to find the id outside of the clever ng join command.
Remark: As discussed in ovd#27 (internal GitLab), we cannot use the host name to uniquely identify a peer.
Proposed solutions
I have different propositions, let me know what you think works best:
- We do like
wg-quickwhich stores a<name_of_wg_conf>.namefile somewhere which contains the name of the associated interface: We would have a<name_of_wg_conf>.idin/tmp/com.clever-cloud.com/networkgroupswhich would contain thepeer_idassociated to the computer. -
- ~~We get the computer's IP address (inside the VPN) from the WireGuard® configuration file.~~
- ~~We call the API to retrieve the peers list, and we search through it to find the
idof the external peer.~~
- ~~We create a new endpoint to the Networkgroups API which does the search from point 2., and which returns the
id.~~ - We let the user automate
idrecovery or we let them do it by hand (find themselves inclever ng peers list), but it remove the magic of it 🧙 -
- We take the private key from the WireGuard® configuration file (assuming it hasn't been deleted when something bad happened).
- We transform it to a public key.
- We add an endpoint to the Networkgroups API which allows removing a peer from its public key (and
ng_idof course).
With @moyowi, we rejected 2. and 3. for security reasons.
An example would be:
- Someone joins a networkgroup with IP address XXX.XXX.XXX.12
- They crash
- They are removed for some reason
- Someone else joins and gets the same IP address (we cycled through all adresses available for example)
- User 1 asks to be removed
- User 2 is removed instead
QED.
For now, we'll use the first option. If needed, we'll switch to option 5..
I just thought about something: If a user joins a networkgroup, has a problem, then joins it again, the <name_of_wg_conf>.id file will be overwritten.
I have two propositions in mind:
- Create a
<name_of_wg_conf>.idsfile instead, with onepeer_idby line. It would allow fast reading but needs appending text and doesn't easily allow removing only onepeer_id. - Create multiple
<name_of_wg_conf>-<random>.idfiles. It would be harder to find all thepeer_ids, but we would be able to delete them one by one more easily.
Since we don't need to delete peer_ids one by one, I would suggest option 1.. What do you think?
I'm just lurking, and i'm curious about all the files mentioned. Where are they stored? On clever-cloud instances, or on the machine running clever-tools?
It's not released yet, but we're talking about files on the machine running clever-tools. They will be stored in one's OS temporary folder (e.g. /tmp) and automatically deleted either by the OS or clever-tools.
We would have preferred not storing files, but unfortunately WireGuard®'s wg-quick command doesn't take in-memory files 😕
ah, so it's not possible to use file descriptors :-( but they're only used temporarily, just to call wg-quick and are not kept from run to run :relieved:
thanks for taking the time to indulge my curiosity!
Glad I could help 🙂
https://github.com/CleverCloud/clever-tools/issues/457#issuecomment-778221352
@Keruspe What's your thought on this?