After removing user, its ssh-keys are not removed together.
Description:
Consider we have a user in MikroTik that have public SSH keys (RSA or DSA) already imported. If we remove this user, its public SSH keys are kept in the system.
Maybe the expected behavior would be remove all public SSH keys together when removing the user.
Versions affected:
6.38.5(chr),6.39.1(mibspe),6.39.3(mibspe),6.40.1(mibspe)
How to reproduce:
- Create a user
- Import a public SSH key for this user
- Remove the user
- Verify that the public SSH keys were kept in the system
Detailed how to reproduce:
Create a user with the following command:
Code: Select all
/user add name=test group=read password=PASSWORD_HERE
Code: Select all
[admin@router] > /file print where name=teste.id_rsa.pub
# NAME TYPE SIZE CREATION-TIME
0 teste.id_rsa.pub ssh key 399 feb/08/2018 12:24:36
Code: Select all
/user ssh-keys import public-key-file=teste.id_rsa.pub user=test
Code: Select all
[admin@router] > /user print where name=test Flags: X - disabled
# NAME GROUP ADDRESS LAST-LOGGED-IN
0 test read
[admin@router] > /user ssh-keys print where user=test
Flags: R - RSA, D - DSA
# USER BITS KEY-OWNER
0 R test 2048 test@hostname
Code: Select all
/user remove test
Code: Select all
[admin@router] > /user print where name=test
Flags: X - disabled
# NAME GROUP ADDRESS LAST-LOGGED-IN
[admin@router] > /user ssh-keys print where user=test
Flags: R - RSA, D - DSA
# USER BITS KEY-OWNER
0 R test 2048 test@hostname
- It's a bug? Or its the expected behavior?
- What should be the desired behavior (philosophically speaking)?
Pros e cons
Cons
There are some arguments to keep the keys:
- If we remove an interface (like a VLAN), all IPs related to that interface are kept as invalid (they should be manually deleted after if you want);
- In Linux, when we remove a user, it's authorized keys remains in the system (if we did not ask the system to remove the user home).
Pros
But I really thinks the ssh keys should be removed on user removal. SSH keys are not a configuration, but an entry in the user database related to system security. I think all entries related to a given user should be removed together when this user was removed to keep the user database consistent.
Another argument to remove the keys is that if the user was added again, the old password will not work, but the old keys will be accepted. It may cause some security problems. Let me explain with an example. Consider that an employee was fired and its user was removed (but this public SSH keys were kept in the system). Years later, a new employee (who asked for the same username) was hired. When the new user is created (even if new SSH keys were imported), the old user (fired) will regain access to the router.
Even if we consider the example of the IP that remains after the interface was deleted, it's important to note that, if we recreate the interface (with the same name of the old one), the old IP will remain inactive (it will continue to reference an invalid interface).
Also, let's consider the example of the authorized_keys in Linux (that were kept in the user home after user removal). Even in this case, if we recreate the user years latter, the new user will probably receive a new UID/GID (different from the UID/GID of the old user). So, the old user will not automatically regain access to the system.