Bug 1917879

Summary: Cannot sudo passwordless from staff_u/sysadm_u when using pam_ssh_agent_auth
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.3CC: apeetham, lvrabec, mmalik, pkoncity, plautrba, ssekidde, zpytela
Target Milestone: rcKeywords: Triaged
Target Release: 8.6   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.14.3-86.el8 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-10 15:14:56 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1778780    
Attachments:
Description Flags
SELinux denials gathered during testing of staff_u and sysadm_u users none

Description Renaud Métrich 2021-01-19 15:04:35 UTC
Description of problem:

After configuring pam_ssh_agent_auth to provide passwordless sudo through ssh agent, AVCs are preventing "sudo" from working:

-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
allow staff_sudo_t staff_t:unix_stream_socket connectto;
allow staff_sudo_t user_tmp_t:sock_file { getattr write };
allow sysadm_sudo_t sysadm_t:unix_stream_socket connectto;
allow sysadm_sudo_t user_tmp_t:sock_file write;
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

More generally, what is missing are these rules:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
allow staff_sudo_t staff_t:unix_stream_socket connectto;
allow sysadm_sudo_t sysadm_t:unix_stream_socket connectto;
allow auditadm_sudo_t auditadm_t:unix_stream_socket connectto;
allow dbadm_sudo_t dbadm_t:unix_stream_socket connectto;
allow secadm_sudo_t secadm_t:unix_stream_socket connectto;

allow sudodomain user_tmp_t:sock_file { getattr write };
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------


Version-Release number of selected component (if applicable):

selinux-policy-3.14.3-54.el8.noarch


How reproducible:

Always


Steps to Reproduce:
1. Install pam_ssh_agent_auth

  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
  # yum -y install pam_ssh_agent_auth
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

2. Configure passwordless sudo through ssh agent

  /etc/pam.d/sudo:
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
  auth       sufficient   pam_ssh_agent_auth.so file=~/.ssh/authorized_keys
  ...
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

  /etc/sudoers:
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
  Defaults    env_keep += "SSH_AUTH_SOCK"
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

3. Create "staff" and "sysadm" users

  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
  # useradd -Z staff_u -G wheel staff
  # echo "pass" | passwd --stdin staff
  # useradd -Z sysadm_u -G wheel sysadm
  # echo "pass" | passwd --stdin sysadm
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

4. Generate ssh key and install it

  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
  # ssh-keygen
  # ssh-copy-id staff@localhost
  # ssh-copy-id sysadm@localhost
  # semanage boolean -m ssh_sysadm_login --on
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

5. Finally start ssh-agent, ssh and sudo from the account

  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
  # ssh-agent; ssh-add
  # ssh -A staff@localhost
  $ sudo -i
  -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------


Actual results:

  [sudo] password for staff: 

Expected results:

  Password-less sudo

Comment 1 Renaud Métrich 2021-01-21 10:08:13 UTC
Additional missing rules:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
allow sudodomain user_tmp_t:sock_file { write getattr append open };
allow sudodomain ssh_agent_tmp_t:sock_file { write getattr append open };
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Comment 2 Milos Malik 2021-01-26 10:03:32 UTC
Created attachment 1750851 [details]
SELinux denials gathered during testing of staff_u and sysadm_u users

Comment 5 Zdenek Pytela 2021-12-22 12:42:12 UTC
I've submitted a Fedora PR to address the issue:
https://github.com/fedora-selinux/selinux-policy/pull/976

Comment 6 Zdenek Pytela 2021-12-23 16:48:44 UTC
To backport:
commit 901ac5314982f5600ef11691969b9af89aeba772
Author: Zdenek Pytela <zpytela>
Date:   Mon Dec 20 14:21:33 2021 +0100

    Allow userdomains use pam_ssh_agent_auth for passwordless sudo

    The pam_ssh_agent_auth module can be used for granting permissions based
    on SSH agent requests. When configured for using in the sudo pam module,
    it requires permissions for sudodomain to use the user socket file and
    stream connect to its corresponding userdomain.

    Resolves: rhbz#1917879

Comment 21 errata-xmlrpc 2022-05-10 15:14:56 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (selinux-policy bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:1995