Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API security improvements #1075

Open
3 tasks done
Tbaile opened this issue Feb 11, 2025 · 5 comments
Open
3 tasks done

API security improvements #1075

Tbaile opened this issue Feb 11, 2025 · 5 comments
Labels
verified All test cases were verified successfully

Comments

@Tbaile
Copy link
Contributor

Tbaile commented Feb 11, 2025

Due to upcoming NIS2 regulations, several changes are needed to strengthen up the backend of NethSecurity.
Even if there are no evident security issues, the following changes are the first steps towards a more robust and bulletproof backend:

Most of this work has been addressed in these repos:

While the work is mostly done, needs to be distilled from said branches and thoroughly tested.

@Tbaile Tbaile added this to the NethSecurity 8.5 milestone Feb 11, 2025
@github-project-automation github-project-automation bot moved this to ToDo 🕐 in NethSecurity Feb 11, 2025
@Tbaile Tbaile moved this from ToDo 🕐 to In Progress 🛠 in NethSecurity Feb 12, 2025
@Tbaile Tbaile self-assigned this Feb 12, 2025
@Tbaile
Copy link
Contributor Author

Tbaile commented Feb 12, 2025

24.10.0-ns.1.4.99-alpha1-4-gda2a652

QA:

  • Check that you cannot change user password without filling the old one (this need to be checked even with CLI)
  • Ensure that adding SSH keys and deleting them works
  • Check that file generated from adding keys (/etc/dropbear/authorized_keys) has the correct permissions (600 and owned by root:root)
  • Using the API, ensure no additional command can be called except the listed above and the ns. functions. For example try to call file write.

@cotosso
Copy link
Contributor

cotosso commented Feb 26, 2025

1. Check that you cannot change user password without filling the old one (this need to be checked even with CLI)

Verified (UI only)
Old password is written in log, I suggest to avoid storing passwords (even old ones) in logs.

Feb 25 17:08:45 NSec8-VM nethsecurity-api[5416]: nethsecurity_api 2025/02/25 17:08:45 middleware.go:169: [INFO][AUTH] authorization success for user root. POST /api/ubus/call {"path":"ns.account","method":"set-password","payload":{"old_password":"Nethesis,5678","username":"root","password":"XXX"}}
Feb 25 17:08:46 NSec8-VM passwd: password for root changed by root

2. Ensure that adding SSH keys and deleting them works

Verified
The public key is logged during the add and delete phases, but this shouldn't represent an issue.

3. Check that file generated from adding keys (/etc/dropbear/authorized_keys) has the correct permissions (600 and owned by root:root)

Verified

root@NethSec:~# ll /etc/dropbear/authorized_keys 
-rw-------    1 root     root           400 Feb 26 18:09 /etc/dropbear/authorized_keys

@gsanchietti gsanchietti self-assigned this Mar 3, 2025
@gsanchietti
Copy link
Member

Test case 1, partially failed.
The user can't change its own password using the ns.account API if he does not provide the current password.
But he can do it by using the ns.users API:

 echo '{"name":"giacomo","description":"Giacomo Rossi","password":"Giacomo,1234","database":"main","extra":{},"id":"ns_e2afde54"}' | /usr/libexec/rpcd/ns.users call edit-local-user

Possible fix: disable UI and API access to user page for non-root users (alert: this will prevent a correct workflow for all adminsusers!)

@gsanchietti
Copy link
Member

Test case 4 verified:

curl 'https://192.168.100.238/api/ubus/call'   -H 'Accept: application/json, text/plain, */*'   -H 'Accept-Language: en-US,en;q=0.6'   -H 'Authorization: Bearer xxx' -H 'Content-Type: application/json' --data-raw '{"path":"uci","method":"set","payload":{"config":"rpcd"}}'   --insecure
{"code":500,"data":"exit status 2","message":"ubus call action failed"}

@gsanchietti gsanchietti added verified All test cases were verified successfully and removed testing Packages are available from testing repositories labels Mar 3, 2025
@gsanchietti gsanchietti removed their assignment Mar 3, 2025
@nethbot nethbot moved this from Testing to Verified in NethSecurity Mar 3, 2025
@gsanchietti
Copy link
Member

I'm setting the issue as verified, since behavior found in test case 1 is out of scope for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
verified All test cases were verified successfully
Projects
Status: Verified
Development

No branches or pull requests

3 participants