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

move passwords from /etc/passwd to /etc/shadow #44

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

fischerling
Copy link
Contributor

Move the passwords from the world-readable file /etc/passwd into the shadow file and provide new functions in libc to access the passwords when running as uid 0.

TODO: In order for this separation to be effective. We need a proper way to set realistic permissions in the rootfs

  • Everything in / should be owned by uid=0
  • Everything in /home/user should be owned by uid=1000

Move the passwords from the world-readable file /etc/passwd into
the shadow file and provide new functions in libc to access the passwords
when running as uid 0.
@fischerling
Copy link
Contributor Author

In my fork of MentOS I have two separate non-root users alice and bob and I use a small shell script to set realistic permissions in the filesystem.
This is done by a cmake target mounting the root filesystem and running the script.

# MentOS is compatible with EXT2 filesystems. This targets set realistic
# permissions in the generated filesystem using the content of the `files` folder.
add_custom_target(filesystem_permissions
    COMMAND echo '============================================================================='
    COMMAND echo 'Fix root filesystem permissions...'
    COMMAND echo '============================================================================='
    COMMAND mkdir -p ${CMAKE_BINARY_DIR}/root
    COMMAND sudo fuse2fs ${CMAKE_BINARY_DIR}/rootfs.img ${CMAKE_BINARY_DIR}/root
    COMMAND sudo chown root:root -R ${CMAKE_BINARY_DIR}/root
    COMMAND sudo ${CMAKE_SOURCE_DIR}/scripts/fix_permissions.sh ${CMAKE_BINARY_DIR}/root
    COMMAND sudo umount ${CMAKE_BINARY_DIR}/root
    DEPENDS filesystem
)
#!/bin/sh

ROOT=$1

if [ -z "${ROOT}" ]
then
	echo "Usage: $0 <root>"
	exit 1
fi

# Set default permissions and file owner
chown root:root -R "${ROOT}"
sudo chmod -R u=rwX,go=rX -R "${ROOT}"

# Set security related permissions
sudo chmod 644 "${ROOT}"/etc/passwd
sudo chmod og-rwx "${ROOT}"/etc/shadow

# Set user permissions
sudo chown 1000:1000 -R "${ROOT}"/home/alice
sudo chown 1001:1001 -R "${ROOT}"/home/bob
sudo chmod -R u=rwX,go= -R "${ROOT}"/home/*

The problem with this approach is that it requires root permissions to mount the rootfs to modify its content.

Maybe we can come up with a better solution.
Something like using install(1) to copy all files into the build dir using the correct permissions.

@Galfurian
Copy link
Member

Galfurian commented Mar 4, 2024

I tried as much as possible to avoid using sudo throughout the project. This way it is possible for a student to run the code even on a University-owned computer, where they do not have admin rights.

I was thinking about a mid-way solution: distinguish between passwd and shadow, but store an encrypted password in shadow but without setting the typical linux rights on shadow. In a personal branch, I integrated a basic Data Encryption Standard (DES) algorithm in MentOS, and planned to encrypt the passwords in shadow at least.

What do you think?

I can think about how to properly set root and permissions in the future.

@Galfurian Galfurian merged commit 88bf849 into mentos-team:develop Mar 6, 2024
17 checks passed
@fischerling fischerling deleted the add-shadow-file branch March 14, 2024 17:49
@Galfurian Galfurian added the enhancement New feature or request label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants