-
Notifications
You must be signed in to change notification settings - Fork 165
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
fix(userspace/libsinsp): user id 0 or group id 0 default values #2177
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
900ec2a
fix(userspace/libsinsp): fixed uid 0 and gid 0 default values.
FedeDP d178abd
chore(userspace/libsinsp): added filtercheck user tests.
FedeDP 3cee60f
cleanup(userspace/libsinsp): clean up unused boolean flag in user gro…
FedeDP 451a3d9
fix(userspace/libsinsp): get_user() and get_loginuser() need differen…
FedeDP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* | ||
Copyright (C) 2024 The Falco Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
*/ | ||
|
||
#include <test/helpers/threads_helpers.h> | ||
|
||
TEST_F(sinsp_with_test_input, USER_FILTER_extract_from_existent_user_entry) { | ||
add_default_init_thread(); | ||
|
||
auto& thread = m_threads.front(); | ||
thread.uid = 1000; | ||
thread.gid = 1000; | ||
thread.loginuid = 0; | ||
|
||
open_inspector(); | ||
|
||
m_inspector.m_usergroup_manager.add_user("", INIT_TID, 1000, 1000, "foo", "/foo", "/bin/bash"); | ||
|
||
std::string path = "/home/file.txt"; | ||
int64_t fd = 3; | ||
|
||
auto evt = add_event_advance_ts(increasing_ts(), | ||
INIT_TID, | ||
PPME_SYSCALL_OPEN_E, | ||
fd, | ||
path.c_str(), | ||
(uint32_t)PPM_O_RDWR | PPM_O_CREAT, | ||
(uint32_t)0); | ||
ASSERT_EQ(get_field_as_string(evt, "user.uid"), "1000"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.loginuid"), "0"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.name"), "foo"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.homedir"), "/foo"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.shell"), "/bin/bash"); | ||
// Loginname default at root for 0 uid without an user entry in user group manager. | ||
ASSERT_EQ(get_field_as_string(evt, "user.loginname"), "root"); | ||
|
||
// Now remove the user | ||
m_inspector.m_usergroup_manager.rm_user("", 1000); | ||
ASSERT_EQ(get_field_as_string(evt, "user.uid"), "1000"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.loginuid"), "0"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.name"), "<NA>"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.homedir"), "<NA>"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.shell"), "<NA>"); | ||
// Loginname default at root for 0 uid without an user entry in user group manager. | ||
ASSERT_EQ(get_field_as_string(evt, "user.loginname"), "root"); | ||
|
||
// Add back a new user | ||
m_inspector.m_usergroup_manager.add_user("", INIT_TID, 1000, 1000, "bar", "/bar", "/bin/bash"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.uid"), "1000"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.loginuid"), "0"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.name"), "bar"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.homedir"), "/bar"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.shell"), "/bin/bash"); | ||
// Loginname default at root for 0 uid without an user entry in user group manager. | ||
ASSERT_EQ(get_field_as_string(evt, "user.loginname"), "root"); | ||
} | ||
|
||
TEST_F(sinsp_with_test_input, USER_FILTER_extract_from_default_user_entry) { | ||
add_default_init_thread(); | ||
|
||
open_inspector(); | ||
|
||
// The entry gets created when the inspector is opened and its threadtable created. | ||
// Since default thread uid is 0, the entry is created with "root" name and "/root" homedir. | ||
ASSERT_NE(m_inspector.m_usergroup_manager.get_user("", 0), nullptr); | ||
|
||
// remove the loaded "root" user to test defaults for uid 0 | ||
m_inspector.m_usergroup_manager.rm_user("", 0); | ||
ASSERT_EQ(m_inspector.m_usergroup_manager.get_user("", 0), nullptr); | ||
|
||
std::string path = "/home/file.txt"; | ||
int64_t fd = 3; | ||
|
||
auto evt = add_event_advance_ts(increasing_ts(), | ||
INIT_TID, | ||
PPME_SYSCALL_OPEN_E, | ||
fd, | ||
path.c_str(), | ||
(uint32_t)PPM_O_RDWR | PPM_O_CREAT, | ||
(uint32_t)0); | ||
|
||
// For non-existent entries whose uid is 0, "root" and "/root" | ||
// are automatically filled by threadinfo::get_user() method. | ||
ASSERT_EQ(get_field_as_string(evt, "user.uid"), "0"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.name"), "root"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.homedir"), "/root"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.shell"), "<NA>"); | ||
} | ||
|
||
TEST_F(sinsp_with_test_input, USER_FILTER_extract_from_existent_user_entry_without_metadata) { | ||
add_default_init_thread(); | ||
|
||
open_inspector(); | ||
|
||
// Creating the entry in the user group manager will override | ||
// the one created by the inspector threadtable initial load. | ||
// Since we set "" metadatas, we don't expect any metadata in the output fields. | ||
m_inspector.m_usergroup_manager.add_user("", INIT_TID, 0, 0, "", "", ""); | ||
|
||
std::string path = "/home/file.txt"; | ||
int64_t fd = 3; | ||
|
||
auto evt = add_event_advance_ts(increasing_ts(), | ||
INIT_TID, | ||
PPME_SYSCALL_OPEN_E, | ||
fd, | ||
path.c_str(), | ||
(uint32_t)PPM_O_RDWR | PPM_O_CREAT, | ||
(uint32_t)0); | ||
ASSERT_EQ(get_field_as_string(evt, "user.uid"), "0"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.name"), ""); | ||
ASSERT_EQ(get_field_as_string(evt, "user.homedir"), ""); | ||
ASSERT_EQ(get_field_as_string(evt, "user.shell"), ""); | ||
} | ||
|
||
TEST_F(sinsp_with_test_input, USER_FILTER_extract_from_loaded_user_entry) { | ||
add_default_init_thread(); | ||
|
||
open_inspector(); | ||
|
||
// Creating the entry in the user group manager will override | ||
// the one created by the inspector threadtable initial load. | ||
// Since we set **empty** metadata, we expect metadata to be loaded from the system. | ||
m_inspector.m_usergroup_manager.add_user("", INIT_TID, 0, 0, {}, {}, {}); | ||
|
||
std::string path = "/home/file.txt"; | ||
int64_t fd = 3; | ||
|
||
auto evt = add_event_advance_ts(increasing_ts(), | ||
INIT_TID, | ||
PPME_SYSCALL_OPEN_E, | ||
fd, | ||
path.c_str(), | ||
(uint32_t)PPM_O_RDWR | PPM_O_CREAT, | ||
(uint32_t)0); | ||
ASSERT_EQ(get_field_as_string(evt, "user.uid"), "0"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.name"), "root"); | ||
ASSERT_EQ(get_field_as_string(evt, "user.homedir"), "/root"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned up unused flag.