Skip to content

Conversation

aerusso
Copy link
Contributor

@aerusso aerusso commented May 10, 2025

shadow access is tightly controlled, with separate types for the shadow files and the locks. This patch distinguishes the two by enumerating the backup filenames and lock file names in their associated file transition rules.

Prior to this, the overbroad file transition rules would cause various shadow-manipulating tools to create lock files with the incorrect shadow_t label.

@aerusso aerusso force-pushed the mrs/rework-auth-shadow branch from 09199c4 to 89766d5 Compare May 10, 2025 13:23
@aerusso
Copy link
Contributor Author

aerusso commented May 10, 2025

I adjusted the rw_files_pattern macro to allow searching /etc (etc_t), and I think that's causing the lint failure. Should I just have it grant the useless dir search permission for shadow_lock_t, and expect that the etc_t search permission is granted by some other rule?

files_etc_filetrans($1, shadow_lock_t, file, ".pwd.lock")
files_etc_filetrans($1, shadow_lock_t, file, "passwd.lock")
files_etc_filetrans($1, shadow_lock_t, file, "group.lock")
rw_files_pattern($1, etc_t, shadow_lock_t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try:
allow $1 shadow_lock_t:file rw_file_perms;

Probably already has enough permissions on etc_t directories.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated this change out into another patch and moved the filetrans logic to another macro, so this issue can be handled separately.

rw_files_pattern($1, shadow_lock_t, shadow_lock_t)
files_etc_filetrans($1, shadow_lock_t, file, ".pwd.lock")
files_etc_filetrans($1, shadow_lock_t, file, "passwd.lock")
files_etc_filetrans($1, shadow_lock_t, file, "group.lock")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these uses of 'files_etc_filetrans' belong in a new interface instead (something line auth_filetrans_shadow_lock). These give permission to transition on file creation, but not to actually create the file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and I did something similar for the other file transitions. Let me know if this is what you were thinking of/if it's what you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further consideration, I think we should keep the filetranses in the original interfaces and use ifelse, like systemd_tmpfilesd_managed:

ifelse(`$2',`',`
	files_etc_filetrans($1, shadow_lock_t, file, ".pwd.lock")
	[...]
',`
	refpolicywarn(`$0($*) second parameter is deprecated.')
	files_etc_filetrans($1, shadow_t, file, $2)
')

@dsugar100
Copy link
Contributor

With these changes have to tested changing a users' password (twice - due to files created after the first change)? And keep in mind that things behave differently in enforcing vs. permissive.

Comment on lines 722 to 723
auth_etc_filetrans_shadow($1, "shadow-")
auth_etc_filetrans_shadow($1, "gshadow-")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the existing auth_etc_filetrans_shadow instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I handled this slightly differently, but hopefully it addresses your concern.

@aerusso aerusso force-pushed the mrs/rework-auth-shadow branch from 89766d5 to 2333d1c Compare May 19, 2025 03:09
@aerusso
Copy link
Contributor Author

aerusso commented May 19, 2025

I've also included some dpkg-specific changes, but (despite running Debian) have not tested them. This is in the final patch, and is motivated by a a read of the update-passwd.c source file.

Copy link
Member

@pebenito pebenito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see existing open comment.

aerusso added 2 commits July 18, 2025 21:46
There are no directories labeled shadow_lock_t, and therefore is no
reason to grant dir:search on shadow_lock_t.

Signed-off-by: Antonio Enrico Russo <[email protected]>
shadow access is tightly controlled, with separate types for the shadow
files and the locks.  This patch distinguishes the two by enumerating
the backup filenames and lock file names in their associated file
transition rules.

Prior to this, the overbroad file transition rules would cause various
shadow-manipulating tools to create lock files with the incorrect
shadow_t label.

Signed-off-by: Antonio Enrico Russo <[email protected]>
@aerusso aerusso force-pushed the mrs/rework-auth-shadow branch from 2333d1c to 5ad8ee0 Compare July 19, 2025 03:54
@aerusso
Copy link
Contributor Author

aerusso commented Jul 19, 2025

I think this is in good shape, though there were a few points I was unclear on. Sorry if I'm being dense on those!

Comment on lines +884 to +891
ifelse(`$2',`',`
files_etc_filetrans($1, shadow_lock_t, file, ".pwd.lock")
files_etc_filetrans($1, shadow_lock_t, file, "passwd.lock")
files_etc_filetrans($1, shadow_lock_t, file, "group.lock")
',`
refpolicywarn(`$0($*) second parameter is deprecated.')
files_etc_filetrans($1, shadow_t, file, $2)
')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right idea, but I meant to put it in auth_etc_filetrans_shadow(), making the changes in the other files unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants