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

Checking server user permissions to use sudo #1442

Open
wants to merge 46 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ed83810
Username if whoami returns an error
lunardunno Mar 1, 2025
aafb72b
Update check_user_in_sudo.sh
lunardunno Mar 1, 2025
8ff09ef
Cases have been changed and added.
lunardunno Mar 1, 2025
3a180cb
Serves errors have been changed and added.
lunardunno Mar 1, 2025
5919e2f
Return ServerPacketManagerError
lunardunno Mar 1, 2025
90e25e9
Added errors handling
lunardunno Mar 1, 2025
fd06f8a
Update translations
lunardunno Mar 1, 2025
a97535a
Merge branch 'sudo_permissions' of https://github.com/amnezia-vpn/amn…
lunardunno Mar 1, 2025
b401c53
Myanmar translation update
lunardunno Mar 1, 2025
74e40cd
Update for my_MM.ts
lunardunno Mar 1, 2025
bf2fafb
checking for not allowed
lunardunno Mar 2, 2025
8dfa238
Removed "not allowed"
lunardunno Mar 3, 2025
0932f50
Removed nested launch
lunardunno Mar 3, 2025
e0ad25b
Returned nested launch
lunardunno Mar 3, 2025
78c74e6
All checks with sudo
lunardunno Mar 3, 2025
69e18ed
Moved removing timestamp sudo
lunardunno Mar 3, 2025
fea5a86
Checking the user directory
lunardunno Mar 3, 2025
1570647
Polishing
lunardunno Mar 3, 2025
a01bfc7
changing detection order
lunardunno Mar 8, 2025
1b47294
Merge branch 'dev' into sudo_permissions
lunardunno Mar 8, 2025
f3a0b06
Packet to Package
lunardunno Mar 8, 2025
efc76a0
chore: bump version (#1463)
albexk Mar 9, 2025
b2af2e4
fix for sh (#1462)
lunardunno Mar 9, 2025
9ffb075
Username if whoami returns an error
lunardunno Mar 1, 2025
fbdb931
Update check_user_in_sudo.sh
lunardunno Mar 1, 2025
1c47e97
Cases have been changed and added.
lunardunno Mar 1, 2025
1cca857
Serves errors have been changed and added.
lunardunno Mar 1, 2025
da966ce
Return ServerPacketManagerError
lunardunno Mar 1, 2025
a950cf3
Update translations
lunardunno Mar 1, 2025
a55084e
Added errors handling
lunardunno Mar 1, 2025
f47d10e
Myanmar translation update
lunardunno Mar 1, 2025
bec8770
Update for my_MM.ts
lunardunno Mar 1, 2025
383ba69
checking for not allowed
lunardunno Mar 2, 2025
b81d350
Removed "not allowed"
lunardunno Mar 3, 2025
c9dd16c
Removed nested launch
lunardunno Mar 3, 2025
0125688
Returned nested launch
lunardunno Mar 3, 2025
35e0c8e
All checks with sudo
lunardunno Mar 3, 2025
93946aa
Moved removing timestamp sudo
lunardunno Mar 3, 2025
23936fd
Checking the user directory
lunardunno Mar 3, 2025
f3b6787
Polishing
lunardunno Mar 3, 2025
ed4c02c
changing detection order
lunardunno Mar 8, 2025
b69113a
Merge branch 'sudo_permissions' of https://github.com/amnezia-vpn/amn…
lunardunno Mar 9, 2025
b20f982
Undoing unintended changes
lunardunno Mar 9, 2025
a57424e
Undoing unintended change
lunardunno Mar 9, 2025
797e339
not allowed to use sudo
lunardunno Mar 10, 2025
19eb6a2
Capital letters in the error
lunardunno Mar 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions client/core/controllers/serverController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,6 @@ ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credential

ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, DockerContainer container)
{
if (credentials.userName == "root") {
return ErrorCode::NoError;
}

QString stdOut;
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
stdOut += data + "\n";
Expand All @@ -774,8 +770,16 @@ ErrorCode ServerController::isUserInSudo(const ServerCredentials &credentials, D
const QString scriptData = amnezia::scriptData(SharedScriptType::check_user_in_sudo);
ErrorCode error = runScript(credentials, replaceVars(scriptData, genVarsForScript(credentials)), cbReadStdOut, cbReadStdErr);

if (!stdOut.contains("sudo"))
if (credentials.userName != "root" && !stdOut.contains("sudo") && !stdOut.contains("wheel"))
return ErrorCode::ServerUserNotInSudo;
if (credentials.userName != "root" && stdOut.contains("sudo:") && !stdOut.contains("uname:") && stdOut.contains("not found"))
return ErrorCode::SudoPackageIsNotPreinstalled;
if (stdOut.contains("can't cd to") || stdOut.contains("Permission denied") || stdOut.contains("No such file or directory"))
return ErrorCode::ServerUserDirectoryNotAccessible;
if (stdOut.contains("sudoers"))
return ErrorCode::ServerUserNotAllowedInSudoers;
if (stdOut.contains("password is required"))
return ErrorCode::ServerUserPasswordRequired;

return error;
}
Expand Down
4 changes: 4 additions & 0 deletions client/core/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace amnezia
ServerCancelInstallation = 204,
ServerUserNotInSudo = 205,
ServerPacketManagerError = 206,
SudoPackageIsNotPreinstalled = 207,
ServerUserDirectoryNotAccessible = 208,
ServerUserNotAllowedInSudoers = 209,
ServerUserPasswordRequired = 210,

// Ssh connection errors
SshRequestDeniedError = 300,
Expand Down
8 changes: 6 additions & 2 deletions client/core/errorstrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ QString errorString(ErrorCode code) {
case(ErrorCode::ServerContainerMissingError): errorMessage = QObject::tr("Server error: Docker container missing"); break;
case(ErrorCode::ServerDockerFailedError): errorMessage = QObject::tr("Server error: Docker failed"); break;
case(ErrorCode::ServerCancelInstallation): errorMessage = QObject::tr("Installation canceled by user"); break;
case(ErrorCode::ServerUserNotInSudo): errorMessage = QObject::tr("The user does not have permission to use sudo"); break;
case(ErrorCode::ServerPacketManagerError): errorMessage = QObject::tr("Server error: Packet manager error"); break;
case(ErrorCode::ServerUserNotInSudo): errorMessage = QObject::tr("The user is not a member of the sudo group"); break;
case(ErrorCode::ServerPacketManagerError): errorMessage = QObject::tr("Server error: Package manager error"); break;
case(ErrorCode::SudoPackageIsNotPreinstalled): errorMessage = QObject::tr("The sudo package is not pre-installed"); break;
case(ErrorCode::ServerUserDirectoryNotAccessible): errorMessage = QObject::tr("The server user's home directory is not accessible"); break;
case(ErrorCode::ServerUserNotAllowedInSudoers): errorMessage = QObject::tr("Action not allowed in sudoers"); break;
case(ErrorCode::ServerUserPasswordRequired): errorMessage = QObject::tr("The user's password is required"); break;

// Libssh errors
case(ErrorCode::SshRequestDeniedError): errorMessage = QObject::tr("SSH request was denied"); break;
Expand Down
15 changes: 13 additions & 2 deletions client/server_scripts/check_user_in_sudo.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
CUR_USER=$(whoami);\
groups $CUR_USER
if which apt-get > /dev/null 2>&1; then pm=$(which apt-get); opt="--version";\
elif which dnf > /dev/null 2>&1; then pm=$(which dnf); opt="--version";\
elif which yum > /dev/null 2>&1; then pm=$(which yum); opt="--version";\
elif which pacman > /dev/null 2>&1; then pm=$(which pacman); opt="--version";\
else pm="uname"; opt="-a";\
fi;\
CUR_USER=$(whoami 2>/dev/null || echo ~ | sed 's/.*\///');\
echo $LANG | grep -qE '^(en_US.UTF-8|C.UTF-8|C)$' || export LC_ALL=C;\
sudo -K;\
cd ~;\
if [ "$CUR_USER" = "root" ] || ( groups "$CUR_USER" | grep -E '\<(sudo|wheel)\>' ); then \
sudo -nu $CUR_USER $pm $opt > /dev/null; sudo -n $pm $opt > /dev/null;\
fi
2 changes: 1 addition & 1 deletion client/server_scripts/prepare_host.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CUR_USER=$(whoami);\
CUR_USER=$(whoami 2>/dev/null || echo ~ | sed 's/.*\///');\
sudo mkdir -p $DOCKERFILE_FOLDER;\
sudo chown $CUR_USER $DOCKERFILE_FOLDER;\
if ! sudo docker network ls | grep -q amnezia-dns-net; then sudo docker network create \
Expand Down
6 changes: 3 additions & 3 deletions client/translations/amneziavpn_ar_EG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3334,8 +3334,8 @@ Already installed containers were found on the server. All installed containers
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>ليس لدي المستخدم الصلحيات لأستخدام sudo</translation>
<source>The user is not a member of the sudo group</source>
<translation>المستخدم ليس عضوًا في مجموعة sudo</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="26"/>
Expand Down Expand Up @@ -3399,7 +3399,7 @@ Already installed containers were found on the server. All installed containers
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<source>Server error: Package manager error</source>
<translation>خطأ في الخادم: خطأ في مدير الحزم</translation>
</message>
<message>
Expand Down
8 changes: 4 additions & 4 deletions client/translations/amneziavpn_fa_IR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3468,8 +3468,8 @@ It&apos;s okay as long as it&apos;s from someone you trust.</source>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>The user does not have permission to use sudo</translation>
<source>The user is not a member of the sudo group</source>
<translation>کاربر عضو گروه sudo نیست</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="26"/>
Expand Down Expand Up @@ -3590,8 +3590,8 @@ It&apos;s okay as long as it&apos;s from someone you trust.</source>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<translation>Server error: Packet manager error</translation>
<source>Server error: Package manager error</source>
<translation>خطای سرور: خطای مدیر بسته</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="34"/>
Expand Down
8 changes: 4 additions & 4 deletions client/translations/amneziavpn_hi_IN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3434,13 +3434,13 @@ Already installed containers were found on the server. All installed containers
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>उपयोगकर्ता के पास sudo का उपयोग करने की अनुमति नहीं है</translation>
<source>The user is not a member of the sudo group</source>
<translation>उपयोगकर्ता sudo समूह का सदस्य नहीं है</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<translation>सर्वर त्रुटि: पैकेट प्रबंधक त्रुटि</translation>
<source>Server error: Package manager error</source>
<translation>सर्वर त्रुटि: पैकेज प्रबंधक त्रुटि</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="26"/>
Expand Down
8 changes: 4 additions & 4 deletions client/translations/amneziavpn_my_MM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3330,8 +3330,8 @@ Already installed containers were found on the server. All installed containers
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>ဤအသုံးပြုသူသည် sudo ကိုအသုံးပြုရန်ခွင့်ပြုချက်မရှိပါ</translation>
<source>The user is not a member of the sudo group</source>
<translation>ဤအသုံးပြုသူသည် sudo အုပ်စု၏အဖွဲ့ဝင်မဟုတ်ပါ</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="26"/>
Expand Down Expand Up @@ -3395,8 +3395,8 @@ Already installed containers were found on the server. All installed containers
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<translation>ဆာဗာ မှားယွင်းမှု: Packet Manager မှားယွင်းမှု</translation>
<source>Server error: Package manager error</source>
<translation>ဆာဗာ အမှား- Package manager အမှား</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="34"/>
Expand Down
6 changes: 3 additions & 3 deletions client/translations/amneziavpn_ru_RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3604,12 +3604,12 @@ and will not be shared or disclosed to the Amnezia or any third parties</source>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>У пользователя нет прав на использование sudo</translation>
<source>The user is not a member of the sudo group</source>
<translation>Пользователь не входит в группу sudo</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<source>Server error: Package manager error</source>
<translation>Ошибка сервера: ошибка менеджера пакетов</translation>
</message>
<message>
Expand Down
8 changes: 4 additions & 4 deletions client/translations/amneziavpn_uk_UA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3700,13 +3700,13 @@ and will not be shared or disclosed to the Amnezia or any third parties</source>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>The user does not have permission to use sudo</translation>
<source>The user is not a member of the sudo group</source>
<translation>Користувач не входить до групи sudo</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<translation type="unfinished"></translation>
<source>Server error: Package manager error</source>
<translation>Помилка сервера: помилка менеджера пакетів</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="26"/>
Expand Down
6 changes: 3 additions & 3 deletions client/translations/amneziavpn_ur_PK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3433,8 +3433,8 @@ Already installed containers were found on the server. All installed containers
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>صارف کو sudo استعمال کرنے کی اجازت نہیں ہے</translation>
<source>The user is not a member of the sudo group</source>
<translation>صارف sudo گروپ کا رکن نہیں ہے</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="26"/>
Expand Down Expand Up @@ -3498,7 +3498,7 @@ Already installed containers were found on the server. All installed containers
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<source>Server error: Package manager error</source>
<translation>سرور خطا: پیکیج منیجر خطا</translation>
</message>
<message>
Expand Down
8 changes: 4 additions & 4 deletions client/translations/amneziavpn_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3675,13 +3675,13 @@ and will not be shared or disclosed to the Amnezia or any third parties</source>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="22"/>
<source>The user does not have permission to use sudo</source>
<translation>用户没有root权限</translation>
<source>The user is not a member of the sudo group</source>
<translation>用户不是 sudo 组的成员</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="23"/>
<source>Server error: Packet manager error</source>
<translation type="unfinished"></translation>
<source>Server error: Package manager error</source>
<translation>服务器错误:包管理器错误</translation>
</message>
<message>
<location filename="../core/errorstrings.cpp" line="26"/>
Expand Down
Loading