Skip to contentSkip to conversation

refpolicy: patch for gpg-agent

PATCH Václav Ovsík 3 participants 9 messages Feb 20, 2008 – May 12, 2008 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,
I'm running HEAD refpolicy on Debian Sid, but this patch is not Debian-specific this time.
Having a copy of my std bash profile on the testing machine with a snippet (from gpg-agent man page):

    if test -f $HOME/.gpg-agent-info \
	     && kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info` 2>/dev/null
    then
	. $HOME/.gpg-agent-info
	export GPG_AGENT_INFO
	export SSH_AUTH_SOCK
	export SSH_AGENT_PID
    else
	eval `gpg-agent --daemon --write-env-file`
    fi

I got a number of denials for this snippet of commands.

1. Found a typo for permissions to create socket in the /tmp.
2. Added permission to send signal 0 by the user (see above).
3. Added permissions for writing agent info file into users home directory.

Regards

Signature · 1 line
Zito
modules/apps/gpg.if +10 -4
Index: policy/modules/apps/gpg.if
===================================================================
@@ -212,6 +212,12 @@
 	manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 	manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
+	# write ~/.gpg-agent-info (gpg-agent --write-env-file option)
+	allow $1_gpg_agent_t { $1_home_dir_t $1_home_t }:dir add_entry_dir_perms;
+	type_transition $1_gpg_agent_t $1_home_dir_t:file $1_home_t;
+	allow $1_gpg_agent_t $1_home_t:file create_file_perms;
+	allow $1_gpg_agent_t $1_home_t:file write_file_perms;
+
 	# allow gpg to connect to the gpg agent
 	stream_connect_pattern($1_gpg_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t,$1_gpg_agent_t)
 
@@ -219,11 +225,11 @@
 	ps_process_pattern($2,$1_gpg_agent_t)
 
 	# Allow the user shell to signal the gpg-agent program.
-	allow $2 $1_gpg_agent_t:process { signal sigkill };
+	allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
-	manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-	manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-	manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_sock_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	files_tmp_filetrans($1_gpg_agent_t, $1_gpg_agent_tmp_t, { file sock_file dir })
 
 	# Transition from the user domain to the derived domain.
#1 lore raw
Quoted 31 lines · Václav Ovsík

I'm running HEAD refpolicy on Debian Sid, but this patch is not Debian-specific this time.
Having a copy of my std bash profile on the testing machine with a snippet (from gpg-agent man page):

    if test -f $HOME/.gpg-agent-info \
             && kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info`
2>/dev/null
    then
        . $HOME/.gpg-agent-info
        export GPG_AGENT_INFO
        export SSH_AUTH_SOCK
        export SSH_AGENT_PID
    else
        eval `gpg-agent --daemon --write-env-file`
    fi

I got a number of denials for this snippet of commands.

1. Found a typo for permissions to create socket in the /tmp.
2. Added permission to send signal 0 by the user (see above).
3. Added permissions for writing agent info file into users home directory.

Index: policy/modules/apps/gpg.if
===================================================================

modules/apps/gpg.if (working copy) line 219

Quoted 8 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +5 -0
@@ -212,6 +212,12 @@
        manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
        manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
+       # write ~/.gpg-agent-info (gpg-agent --write-env-file option)
+       allow $1_gpg_agent_t { $1_home_dir_t $1_home_t }:dir add_entry_dir_perms;
+       type_transition $1_gpg_agent_t $1_home_dir_t:file $1_home_t;
+       allow $1_gpg_agent_t $1_home_t:file create_file_perms;
+       allow $1_gpg_agent_t $1_home_t:file write_file_perms;

I'm a little hesitant to add this unconditionally, I don't think we want gpg-agent to write out to general home dir content. Perhaps we should have a tunable, or a specific type for this.

Quoted 7 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +0 -0
        # allow gpg to connect to the gpg agent
        stream_connect_pattern($1_gpg_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t,$1_gpg_agent_t)
 
@@ -219,11 +225,11 @@
        ps_process_pattern($2,$1_gpg_agent_t)
 
        # Allow the user shell to signal the gpg-agent program.

modules/apps/gpg.if (working copy) line 233

Quoted 10 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +4 -4
-       allow $2 $1_gpg_agent_t:process { signal sigkill };
+       allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
-       manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-       manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-       manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+       manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+       manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+       manage_sock_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
        files_tmp_filetrans($1_gpg_agent_t, $1_gpg_agent_tmp_t, { file sock_file dir })

This isn't a typo, the user domain should still be able to manage gpg-agent's tmp files.

Signature · 10 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150



--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw

Hi,
sorry for a delay...

Quoted 35 lines · Christopher J. PeBenito
Quoted 34 lines · Václav Ovsík

I'm running HEAD refpolicy on Debian Sid, but this patch is not Debian-specific this time.
Having a copy of my std bash profile on the testing machine with a snippet (from gpg-agent man page):

    if test -f $HOME/.gpg-agent-info \
             && kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info`
2>/dev/null
    then
        . $HOME/.gpg-agent-info
        export GPG_AGENT_INFO
        export SSH_AUTH_SOCK
        export SSH_AGENT_PID
    else
        eval `gpg-agent --daemon --write-env-file`
    fi

I got a number of denials for this snippet of commands.

1. Found a typo for permissions to create socket in the /tmp.
2. Added permission to send signal 0 by the user (see above).
3. Added permissions for writing agent info file into users home directory.

Index: policy/modules/apps/gpg.if
===================================================================

modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +0 -0
@@ -212,6 +212,12 @@
        manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
        manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
Quoted 9 lines

modules/apps/gpg.if (working copy) line 219

Quoted 5 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +5 -0
+       # write ~/.gpg-agent-info (gpg-agent --write-env-file option)
+       allow $1_gpg_agent_t { $1_home_dir_t $1_home_t }:dir add_entry_dir_perms;
+       type_transition $1_gpg_agent_t $1_home_dir_t:file $1_home_t;
+       allow $1_gpg_agent_t $1_home_t:file create_file_perms;
+       allow $1_gpg_agent_t $1_home_t:file write_file_perms;

I'm a little hesitant to add this unconditionally, I don't think we want gpg-agent to write out to general home dir content. Perhaps we should have a tunable, or a specific type for this.

I added this rules, so an example from gpg-agent manpage can work out-of-the-box. Adding a tunable (with the default to disallow) will not satisfy this. Maybe the later - specific type, but what security risk poses this rules?
I thought, that domain X_gpg_agent_t is very trusted domain, that manages my secret keys and should be shielded against the world around and not the opposite.

Quoted 10 lines
Quoted 10 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +1 -1
        # allow gpg to connect to the gpg agent
        stream_connect_pattern($1_gpg_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t,$1_gpg_agent_t)
 
@@ -219,11 +225,11 @@
        ps_process_pattern($2,$1_gpg_agent_t)
 
        # Allow the user shell to signal the gpg-agent program.
-       allow $2 $1_gpg_agent_t:process { signal sigkill };
+       allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
Quoted 10 lines

modules/apps/gpg.if (working copy) line 233

Quoted 7 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +3 -3
-       manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-       manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-       manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+       manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+       manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+       manage_sock_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
        files_tmp_filetrans($1_gpg_agent_t, $1_gpg_agent_tmp_t, { file sock_file dir })

This isn't a typo, the user domain should still be able to manage gpg-agent's tmp files.

Yes, you are right. I looked at ssh-agent rules just and considered it more or less equivalent to gpg-agent. Gpg-agent should do clean-up of its socket, but maybe some crash.

Ok, what about ssh-agent? Shoul be these rules for userdomain added for it too?

zito@sid:/tmp$ rm -rf ssh-*
audit(1206101398.028:16): avc:  denied  { write } for  pid=2155 comm="rm" name="ssh-IgYHrr2122" dev=sda1 ino=49168 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir
audit(1206101398.028:17): avc:  denied  { remove_name } for  pid=2155 comm="rm" name="agent.2122" dev=sda1 ino=49169 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir
audit(1206101398.028:18): avc:  denied  { unlink } for  pid=2155 comm="rm" name="agent.2122" dev=sda1 ino=49169 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=sock_file
audit(1206101398.028:19): avc:  denied  { rmdir } for  pid=2155 comm="rm" name="ssh-IgYHrr2122" dev=sda1 ino=49168 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir

Thanks for suggestions.
Regards

Signature · 1 line
Zito
modules/apps/gpg.if renamed from modules/apps/gpg.if.orig +14 -1
Index: policy/modules/apps/gpg.if
===================================================================
@@ -212,6 +212,12 @@
 	manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 	manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
+	# write ~/.gpg-agent-info (gpg-agent --write-env-file option)
+	allow $1_gpg_agent_t { $1_home_dir_t $1_home_t }:dir add_entry_dir_perms;
+	type_transition $1_gpg_agent_t $1_home_dir_t:file $1_home_t;
+	allow $1_gpg_agent_t $1_home_t:file create_file_perms;
+	allow $1_gpg_agent_t $1_home_t:file write_file_perms;
+
 	# allow gpg to connect to the gpg agent
 	stream_connect_pattern($1_gpg_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t,$1_gpg_agent_t)
 
@@ -219,11 +225,18 @@
 	ps_process_pattern($2,$1_gpg_agent_t)
 
 	# Allow the user shell to signal the gpg-agent program.
-	allow $2 $1_gpg_agent_t:process { signal sigkill };
+	allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
+	# Allow the user to manage gpg-agent tmp files (socket)
 	manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+
+	# Allow the gpg-agent to manage its tmp files (socket)
+	manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_sock_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+
 	files_tmp_filetrans($1_gpg_agent_t, $1_gpg_agent_tmp_t, { file sock_file dir })
 
 	# Transition from the user domain to the derived domain.
#3 lore raw
Quoted 44 lines · Václav Ovsík
Quoted 33 lines · Christopher J. PeBenito
Quoted 32 lines · Václav Ovsík

I'm running HEAD refpolicy on Debian Sid, but this patch is not Debian-specific this time.
Having a copy of my std bash profile on the testing machine with a snippet (from gpg-agent man page):

    if test -f $HOME/.gpg-agent-info \
             && kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info`
2>/dev/null
    then
        . $HOME/.gpg-agent-info
        export GPG_AGENT_INFO
        export SSH_AUTH_SOCK
        export SSH_AGENT_PID
    else
        eval `gpg-agent --daemon --write-env-file`
    fi

I got a number of denials for this snippet of commands.

1. Found a typo for permissions to create socket in the /tmp.
2. Added permission to send signal 0 by the user (see above).
3. Added permissions for writing agent info file into users home directory.

Index: policy/modules/apps/gpg.if
===================================================================

modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +0 -0
@@ -212,6 +212,12 @@
        manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
        manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
Quoted 9 lines

modules/apps/gpg.if (working copy) line 219

Quoted 5 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +5 -0
+       # write ~/.gpg-agent-info (gpg-agent --write-env-file option)
+       allow $1_gpg_agent_t { $1_home_dir_t $1_home_t }:dir add_entry_dir_perms;
+       type_transition $1_gpg_agent_t $1_home_dir_t:file $1_home_t;
+       allow $1_gpg_agent_t $1_home_t:file create_file_perms;
+       allow $1_gpg_agent_t $1_home_t:file write_file_perms;

I'm a little hesitant to add this unconditionally, I don't think we want gpg-agent to write out to general home dir content. Perhaps we should have a tunable, or a specific type for this.

Quoted 7 lines

I added this rules, so an example from gpg-agent manpage can work out-of-the-box. Adding a tunable (with the default to disallow) will not satisfy this. Maybe the later - specific type, but what security risk poses this rules?
I thought, that domain X_gpg_agent_t is very trusted domain, that manages my secret keys and should be shielded against the world around and not the opposite.

Its trusted for handling keys, not trusted for handling general content in the user's home directory. Remember that if the rules are made conditional, theres nothing stopping distros from making the tunable default to true.

Quoted 9 lines

Ok, what about ssh-agent? Shoul be these rules for userdomain added for it too?

zito@sid:/tmp$ rm -rf ssh-*
audit(1206101398.028:16): avc:  denied  { write } for  pid=2155 comm="rm" name="ssh-IgYHrr2122" dev=sda1 ino=49168 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir
audit(1206101398.028:17): avc:  denied  { remove_name } for  pid=2155 comm="rm" name="agent.2122" dev=sda1 ino=49169 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir
audit(1206101398.028:18): avc:  denied  { unlink } for  pid=2155 comm="rm" name="agent.2122" dev=sda1 ino=49169 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=sock_file
audit(1206101398.028:19): avc:  denied  { rmdir } for  pid=2155 comm="rm" name="ssh-IgYHrr2122" dev=sda1 ino=49168 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir

Yes, it seems reasonable to me.

Signature · 10 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150



--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw

Hi,
after a longer period of inactivity I'm back with a new try :)

Quoted 61 lines · Christopher J. PeBenito
Quoted 44 lines · Václav Ovsík
Quoted 33 lines · Christopher J. PeBenito
Quoted 32 lines · Václav Ovsík

I'm running HEAD refpolicy on Debian Sid, but this patch is not Debian-specific this time.
Having a copy of my std bash profile on the testing machine with a snippet (from gpg-agent man page):

    if test -f $HOME/.gpg-agent-info \
             && kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info`
2>/dev/null
    then
        . $HOME/.gpg-agent-info
        export GPG_AGENT_INFO
        export SSH_AUTH_SOCK
        export SSH_AGENT_PID
    else
        eval `gpg-agent --daemon --write-env-file`
    fi

I got a number of denials for this snippet of commands.

1. Found a typo for permissions to create socket in the /tmp.
2. Added permission to send signal 0 by the user (see above).
3. Added permissions for writing agent info file into users home directory.

Index: policy/modules/apps/gpg.if
===================================================================

modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +0 -0
@@ -212,6 +212,12 @@
        manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
        manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
Quoted 9 lines

modules/apps/gpg.if (working copy) line 219

Quoted 5 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +5 -0
+       # write ~/.gpg-agent-info (gpg-agent --write-env-file option)
+       allow $1_gpg_agent_t { $1_home_dir_t $1_home_t }:dir add_entry_dir_perms;
+       type_transition $1_gpg_agent_t $1_home_dir_t:file $1_home_t;
+       allow $1_gpg_agent_t $1_home_t:file create_file_perms;
+       allow $1_gpg_agent_t $1_home_t:file write_file_perms;

I'm a little hesitant to add this unconditionally, I don't think we want gpg-agent to write out to general home dir content. Perhaps we should have a tunable, or a specific type for this.

Quoted 7 lines

I added this rules, so an example from gpg-agent manpage can work out-of-the-box. Adding a tunable (with the default to disallow) will not satisfy this. Maybe the later - specific type, but what security risk poses this rules?
I thought, that domain X_gpg_agent_t is very trusted domain, that manages my secret keys and should be shielded against the world around and not the opposite.

Its trusted for handling keys, not trusted for handling general content in the user's home directory. Remember that if the rules are made conditional, theres nothing stopping distros from making the tunable default to true.

Quoted 3 lines

Ok, what about ssh-agent? Shoul be these rules for userdomain added for it too?

Quoted 13 lines
Quoted 6 lines
zito@sid:/tmp$ rm -rf ssh-*
audit(1206101398.028:16): avc:  denied  { write } for  pid=2155 comm="rm" name="ssh-IgYHrr2122" dev=sda1 ino=49168 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir
audit(1206101398.028:17): avc:  denied  { remove_name } for  pid=2155 comm="rm" name="agent.2122" dev=sda1 ino=49169 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir
audit(1206101398.028:18): avc:  denied  { unlink } for  pid=2155 comm="rm" name="agent.2122" dev=sda1 ino=49169 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=sock_file
audit(1206101398.028:19): avc:  denied  { rmdir } for  pid=2155 comm="rm" name="ssh-IgYHrr2122" dev=sda1 ino=49168 scontext=staff_u:staff_r:staff_t:s0 tcontext=system_u:object_r:sshd_tmp_t:s0 tclass=dir

Yes, it seems reasonable to me.

Signature · 3 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150

Another patch is attached with the specific type for home file (<ROLE>_gpg_agent_home_t). I hope, this is better than general write permission from the previous patch and without administrative overhead of tunable.

Allowed rules for userdomain on gpg-agent tmp files (socket) are contained, but I'm not completely certain this is needed. Gpg-agent creates socket while starting and cleans it up when exits. The socket file remains in /tmp only when gpg-agent is killed by SIGKILL, and there is probably no need to remove this stuff by the userdomain either. Tmpreaper/tmpwatch cron job should do cleanup. Although I hope including these rules for userdomain is harmless.

Concerning SSH...
After some investigation I found, that it is a bit more complicated. When I ssh into the host with agent forwarded, than socket is created by sshd and it has a context:

zito@bobek:~$ ssh -A sid  
zito@sid:~$ ls -lZa $SSH_AUTH_SOCK 
srwxr-xr-x 1 zito zito system_u:object_r:sshd_tmp_t:s0 0 Apr 15 14:34 /tmp/ssh-afqvGT1954/agent.1954

The socket of ssh agent started localy has context:

zito@sid:~$ eval `ssh-agent`
Agent pid 2097
zito@sid:~$ ls -laZ $SSH_AUTH_SOCK
srw------- 1 zito zito staff_u:object_r:staff_ssh_agent_tmp_t:s0 0 Apr 15 14:48 /tmp/ssh-LgmzMU2096/agent.2096

If you consider the userdomain rules needless, than gpg-agent-nouser is attached as addon patch.

Best Regards

Signature · 1 line
Zito
---
 policy/modules/apps/gpg.if |   19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
modules/apps/gpg.if renamed from modules/apps/gpg.if.orig +19 -1
Index: policy/modules/apps/gpg.if
===================================================================
@@ -56,6 +56,9 @@
 	type $1_gpg_agent_tmp_t;
 	files_tmp_file($1_gpg_agent_tmp_t)
 
+	type $1_gpg_agent_home_t;
+	userdom_user_home_content($1,$1_gpg_agent_home_t)
+
 	type $1_gpg_secret_t;
 	userdom_user_home_content($1,$1_gpg_secret_t)
 
@@ -212,6 +215,14 @@
 	manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 	manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
+	# write ~/.gpg-agent-info or a similar to the users home dir or subdir
+	# (gpg-agent --write-env-file option)
+	userdom_user_home_dir_filetrans($1,$1_gpg_agent_t,$1_gpg_agent_home_t,file)
+	userdom_user_home_content_filetrans($1,$1_gpg_agent_t,$1_gpg_agent_home_t,file)
+	allow $1_gpg_agent_t $1_gpg_agent_home_t : file { create_file_perms write_file_perms };
+	# the user can manage the gpg-agent-info file
+	allow $2 $1_gpg_agent_home_t:file manage_file_perms;
+
 	# allow gpg to connect to the gpg agent
 	stream_connect_pattern($1_gpg_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t,$1_gpg_agent_t)
 
@@ -219,11 +230,18 @@
 	ps_process_pattern($2,$1_gpg_agent_t)
 
 	# Allow the user shell to signal the gpg-agent program.
-	allow $2 $1_gpg_agent_t:process { signal sigkill };
+	allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
+	# Allow the user to manage gpg-agent tmp files (socket)
 	manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+
+	# Allow the gpg-agent to manage its tmp files (socket)
+	manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_sock_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+
 	files_tmp_filetrans($1_gpg_agent_t, $1_gpg_agent_tmp_t, { file sock_file dir })
 
 	# Transition from the user domain to the derived domain.
policy/modules/apps/gpg.if +0 -5
Index: refpolicy-svn/policy/modules/apps/gpg.if
===================================================================
@@ -232,11 +232,6 @@
 	# Allow the user shell to signal the gpg-agent program.
 	allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
-	# Allow the user to manage gpg-agent tmp files (socket)
-	manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-	manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-	manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-
 	# Allow the gpg-agent to manage its tmp files (socket)
 	manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
#5 lore raw

On Tue, Apr 15, 2008 at 03:26:02PM +0200, Václav Ovsík wrote:
...

Quoted 2 lines

Another patch is attached with the specific type for home file (<ROLE>_gpg_agent_home_t). I hope, this is better than general write

...

I forgot file context... The attached patch adds one for fixed filename `.gpg-agent-info'.

Best Regards

Signature · 1 line
Zito
modules/apps/gpg.fc renamed from modules/apps/gpg.fc.orig +1 -0
Index: policy/modules/apps/gpg.fc
===================================================================
@@ -1,4 +1,5 @@
 HOME_DIR/\.gnupg(/.+)?		gen_context(system_u:object_r:ROLE_gpg_secret_t,s0)
+HOME_DIR/\.gpg-agent-info	gen_context(system_u:object_r:ROLE_gpg_agent_home_t,s0)
 
 /usr/bin/gpg(2)?	--	gen_context(system_u:object_r:gpg_exec_t,s0)
 /usr/bin/gpg-agent	--	gen_context(system_u:object_r:gpg_agent_exec_t,s0)
#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 11 lines · Václav Ovsík

On Tue, Apr 15, 2008 at 03:26:02PM +0200, Václav Ovsík wrote:
...

Quoted 2 lines

Another patch is attached with the specific type for home file (<ROLE>_gpg_agent_home_t). I hope, this is better than general write

...

I forgot file context... The attached patch adds one for fixed filename `.gpg-agent-info'.

Best Regards

Current Fedora allows gpg_t to manage files in the homedirs, since it needs to be able to read/write files in the homedir. No reason to isolate it.

The reason for this patch being large is that Fedora no longer separates homedir labeling via Prefix, since this concept will not work in a distributed homedir environment.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkgQ0KsACgkQrlYvE4MpobM2nACgyRQmsFLZI5YtoCQrrzkEwCww 22QAoLtrkiJd6DJ+CfoS4M989pRr33y7
=/Sa0
-----END PGP SIGNATURE-----

From: [email protected]
To: [email protected]
CC: [email protected]
Subject: [PATCH] refpolicy: apps_gpg changes
--text follows this line--

policy/modules/apps/gpg.fc +4 -4
@@ -1,9 +1,9 @@
-HOME_DIR/\.gnupg(/.+)?		gen_context(system_u:object_r:ROLE_gpg_secret_t,s0)
+HOME_DIR/\.gnupg(/.+)?		gen_context(system_u:object_r:user_gpg_secret_t,s0)
 
-/usr/bin/gpg(2)?	--	gen_context(system_u:object_r:gpg_exec_t,s0)
+/usr/bin/gpg2?		--	gen_context(system_u:object_r:gpg_exec_t,s0)
 /usr/bin/gpg-agent	--	gen_context(system_u:object_r:gpg_agent_exec_t,s0)
 /usr/bin/kgpg		--	gen_context(system_u:object_r:gpg_exec_t,s0)
 /usr/bin/pinentry.*	--	gen_context(system_u:object_r:pinentry_exec_t,s0)
 
-/usr/lib/gnupg/.*	--	gen_context(system_u:object_r:gpg_exec_t,s0)
-/usr/lib/gnupg/gpgkeys.* --	gen_context(system_u:object_r:gpg_helper_exec_t,s0)
+/usr/lib(64)?/gnupg/.*	--	gen_context(system_u:object_r:gpg_exec_t,s0)
+/usr/lib(64)?/gnupg/gpgkeys.* --	gen_context(system_u:object_r:gpg_helper_exec_t,s0)
policy/modules/apps/gpg.if +40 -249

321 lines not on this page · raw message

policy/modules/apps/gpg.te +230 -4

245 lines not on this page · raw message

#7 lore raw
In reply to Václav Ovsík
Quoted 61 lines · Václav Ovsík

Hi,
after a longer period of inactivity I'm back with a new try :)

Quoted 57 lines · Christopher J. PeBenito
Quoted 44 lines · Václav Ovsík
Quoted 33 lines · Christopher J. PeBenito
Quoted 32 lines · Václav Ovsík

I'm running HEAD refpolicy on Debian Sid, but this patch is not Debian-specific this time.
Having a copy of my std bash profile on the testing machine with a snippet (from gpg-agent man page):

    if test -f $HOME/.gpg-agent-info \
             && kill -0 `cut -d: -f 2 $HOME/.gpg-agent-info`
2>/dev/null
    then
        . $HOME/.gpg-agent-info
        export GPG_AGENT_INFO
        export SSH_AUTH_SOCK
        export SSH_AGENT_PID
    else
        eval `gpg-agent --daemon --write-env-file`
    fi

I got a number of denials for this snippet of commands.

1. Found a typo for permissions to create socket in the /tmp.
2. Added permission to send signal 0 by the user (see above).
3. Added permissions for writing agent info file into users home directory.

Index: policy/modules/apps/gpg.if
===================================================================

modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +0 -0
@@ -212,6 +212,12 @@
        manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
        manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
Quoted 9 lines

modules/apps/gpg.if (working copy) line 219

Quoted 5 lines
modules/apps/gpg.if (working copy) renamed from modules/apps/gpg.if (revision 2617) +5 -0
+       # write ~/.gpg-agent-info (gpg-agent --write-env-file option)
+       allow $1_gpg_agent_t { $1_home_dir_t $1_home_t }:dir add_entry_dir_perms;
+       type_transition $1_gpg_agent_t $1_home_dir_t:file $1_home_t;
+       allow $1_gpg_agent_t $1_home_t:file create_file_perms;
+       allow $1_gpg_agent_t $1_home_t:file write_file_perms;

I'm a little hesitant to add this unconditionally, I don't think we want gpg-agent to write out to general home dir content. Perhaps we should have a tunable, or a specific type for this.

Quoted 7 lines

I added this rules, so an example from gpg-agent manpage can work out-of-the-box. Adding a tunable (with the default to disallow) will not satisfy this. Maybe the later - specific type, but what security risk poses this rules?
I thought, that domain X_gpg_agent_t is very trusted domain, that manages my secret keys and should be shielded against the world around and not the opposite.

Its trusted for handling keys, not trusted for handling general content in the user's home directory. Remember that if the rules are made conditional, theres nothing stopping distros from making the tunable default to true.

[...]

Quoted 5 lines

Another patch is attached with the specific type for home file (<ROLE>_gpg_agent_home_t). I hope, this is better than general write permission from the previous patch and without administrative overhead of tunable.

Quoted 7 lines

Allowed rules for userdomain on gpg-agent tmp files (socket) are contained, but I'm not completely certain this is needed. Gpg-agent creates socket while starting and cleans it up when exits. The socket file remains in /tmp only when gpg-agent is killed by SIGKILL, and there is probably no need to remove this stuff by the userdomain either. Tmpreaper/tmpwatch cron job should do cleanup. Although I hope including these rules for userdomain is harmless.

I've been kicking this one around in my head for a while since this doesn't seem clear cut. I think adding another type is too much for such a file, so I still think the best choice is to have a tunable that allows writing to $1_home_t files, as I suggested before.

Another suggestion that was made to me would be to use the same type used by the socket ($1_gpg_agent_tmp_t). I'm not convinced there actually a security equivalence, but if you can come up with a good argument, then I'm open to it. If that happens the type will have to be renamed since creating a *_tmp_t file in a user home directory is confusing.

Signature · 10 lines
Chris PeBenito
Tresys Technology, LLC
(410) 290-1411 x150



--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#8 lore raw

Hi,

On Thu, Apr 24, 2008 at 02:25:48PM -0400, Daniel J Walsh wrote:
...

Quoted 7 lines

Current Fedora allows gpg_t to manage files in the homedirs, since it needs to be able to read/write files in the homedir. No reason to isolate it.

The reason for this patch being large is that Fedora no longer separates homedir labeling via Prefix, since this concept will not work in a distributed homedir environment.

...

My patch was about gpg-agent (gpg_agent_t) and not gpg itself (gpg_t). Thanks for the Fedora gpg patch. It is quite big. I must keep the change small to be acceptable by Christopher :).

On Tue, May 06, 2008 at 01:33:35PM -0400, Christopher J. PeBenito wrote:
...

Quoted 4 lines

I've been kicking this one around in my head for a while since this doesn't seem clear cut. I think adding another type is too much for such a file, so I still think the best choice is to have a tunable that allows writing to $1_home_t files, as I suggested before.

OK. This time I attached a patch with a tunable (shared by all roles). The tunable (gpg_agent_manage_user_files) defaults to false. Maybe names should be corrected.

Quoted 6 lines

Another suggestion that was made to me would be to use the same type used by the socket ($1_gpg_agent_tmp_t). I'm not convinced there actually a security equivalence, but if you can come up with a good argument, then I'm open to it. If that happens the type will have to be renamed since creating a *_tmp_t file in a user home directory is confusing.

I hope the above will be sufficient. My original meaning was less tunables the better (less possibility to miss-configure something...) and therefore I wrote the patch without tunable first.

Best Regards

Signature · 1 line
Zito
modules/apps/gpg.if renamed from modules/apps/gpg.if.orig +17 -1
Index: policy/modules/apps/gpg.if
===================================================================
@@ -212,6 +212,15 @@
 	manage_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 	manage_lnk_files_pattern($1_gpg_agent_t,$1_gpg_secret_t,$1_gpg_secret_t)
 
+	tunable_policy(`gpg_agent_manage_user_files',`
+	    # write ~/.gpg-agent-info or a similar to the users home dir
+	    # or subdir (gpg-agent --write-env-file option)
+	    #
+	    userdom_user_home_dir_filetrans_user_home_content($1,$1_gpg_agent_t,file)
+	    userdom_manage_user_home_content_dirs($1,$1_gpg_agent_t)
+	    userdom_manage_user_home_content_files($1,$1_gpg_agent_t)
+	')
+
 	# allow gpg to connect to the gpg agent
 	stream_connect_pattern($1_gpg_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t,$1_gpg_agent_t)
 
@@ -219,11 +228,18 @@
 	ps_process_pattern($2,$1_gpg_agent_t)
 
 	# Allow the user shell to signal the gpg-agent program.
-	allow $2 $1_gpg_agent_t:process { signal sigkill };
+	allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
+	# Allow the user to manage gpg-agent tmp files (socket)
 	manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+
+	# Allow the gpg-agent to manage its tmp files (socket)
+	manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+	manage_sock_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
+
 	files_tmp_filetrans($1_gpg_agent_t, $1_gpg_agent_tmp_t, { file sock_file dir })
 
 	# Transition from the user domain to the derived domain.
modules/apps/gpg.te renamed from modules/apps/gpg.te.orig +7 -0
Index: policy/modules/apps/gpg.te
===================================================================
@@ -6,6 +6,13 @@
 # Declarations
 #
 
+## <desc>
+## <p>
+## Allow gpg-agent to manage user files.
+## </p>
+## </desc>
+gen_tunable(gpg_agent_manage_user_files,false)
+
 # Type for gpg or pgp executables.
 type gpg_exec_t;
 type gpg_helper_exec_t;
policy/modules/apps/gpg.if +0 -5
Index: refpolicy-svn/policy/modules/apps/gpg.if
===================================================================
@@ -230,11 +230,6 @@
 	# Allow the user shell to signal the gpg-agent program.
 	allow $2 $1_gpg_agent_t:process { signal sigkill signull };
 
-	# Allow the user to manage gpg-agent tmp files (socket)
-	manage_dirs_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-	manage_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-	manage_sock_files_pattern($2,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
-
 	# Allow the gpg-agent to manage its tmp files (socket)
 	manage_dirs_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)
 	manage_files_pattern($1_gpg_agent_t,$1_gpg_agent_tmp_t,$1_gpg_agent_tmp_t)