SELinux-Refpolicy Archive on lore.kernel.org
 help / color / Atom feed
From: Chris PeBenito <pebenito@ieee.org>
To: russell@coker.com.au,
	"selinux-refpolicy@vger.kernel.org" 
	<selinux-refpolicy@vger.kernel.org>
Subject: Re: certbot patch
Date: Sun, 16 Feb 2020 10:32:33 -0500
Message-ID: <d9b9d1f3-2615-40a9-2eba-98542b0ddfda@ieee.org> (raw)
In-Reply-To: <3935693.2ZXyPmJE1a@xev>

On 2/11/20 10:08 PM, Russell Coker wrote:
> This patch against the git refpolicy adds a domain for the certbot client for
> letsencrypt.  This allows automatic renewal of certbot certificates.

Please inline the patch and add signed-off-by.

 > Index: refpolicy-2.20200209/policy/modules/services/certbot.fc
 > ===================================================================
 > --- /dev/null
 > +++ refpolicy-2.20200209/policy/modules/services/certbot.fc
 > @@ -0,0 +1,4 @@
 > +/usr/bin/certbot    -- 
gen_context(system_u:object_r:certbot_exec_t,s0)
 > +/usr/bin/letsencrypt    -- 
gen_context(system_u:object_r:certbot_exec_t,s0)
 > +/var/log/letsencrypt(/.*)? 
gen_context(system_u:object_r:certbot_log_t,s0)
 > +/var/lib/letsencrypt(/.*)? 
gen_context(system_u:object_r:certbot_var_lib_t,s0)
 > Index: refpolicy-2.20200209/policy/modules/services/certbot.if
 > ===================================================================
 > --- /dev/null
 > +++ refpolicy-2.20200209/policy/modules/services/certbot.if
 > @@ -0,0 +1,46 @@
 > +## <summary>SSL certificate requesting tool certbot AKA 
letsencrypt.</summary>
 > +
 > +########################################
 > +## <summary>
 > +##      Execute certbot/letsencrypt in the certbot
 > +##      domain.
 > +## </summary>
 > +## <param name="domain">
 > +##      <summary>
 > +##      Domain allowed to transition.
 > +##      </summary>
 > +## </param>
 > +#
 > +interface(`certbot_domtrans',`
 > +    gen_require(`
 > +        type certbot_t, certbot_exec_t;
 > +    ')
 > +
 > +    domtrans_pattern($1, certbot_exec_t, certbot_t)
 > +')
 > +
 > +########################################
 > +## <summary>
 > +##      Execute certbot/letsencrypt in the certbot
 > +##      domain, and allow the specified role
 > +##      the firstboot domain.
 > +## </summary>
 > +## <param name="role">
 > +##      <summary>
 > +##      Role allowed access.
 > +##      </summary>
 > +## </param>
 > +## <param name="domain">
 > +##      <summary>
 > +##      Domain allowed to transition.
 > +##      </summary>
 > +## </param>
 > +#
 > +interface(`certbot_run',`
 > +    gen_require(`
 > +        type certbot_t;
 > +    ')
 > +
 > +    certbot_domtrans($2)
 > +    role $1 types certbot_t;
 > +')
 > Index: refpolicy-2.20200209/policy/modules/services/certbot.te
 > ===================================================================
 > --- /dev/null
 > +++ refpolicy-2.20200209/policy/modules/services/certbot.te
 > @@ -0,0 +1,99 @@
 > +policy_module(certbot, 1.0.0)
 > +
 > +########################################
 > +#
 > +# Declarations
 > +#
 > +
 > +type certbot_t;
 > +type certbot_exec_t;
 > +init_daemon_domain(certbot_t, certbot_exec_t)
 > +
 > +type certbot_log_t;
 > +logging_log_file(certbot_log_t)
 > +
 > +type certbot_var_run_t;

Please rename to certbot_runtime_t.


 > +files_pid_file(certbot_var_run_t)
 > +
 > +type certbot_tmp_t;
 > +files_tmp_file(certbot_tmp_t)
 > +
 > +type certbot_tmpfs_t;
 > +files_tmpfs_file(certbot_tmpfs_t)
 > +
 > +type certbot_var_lib_t;
 > +files_type(certbot_var_lib_t)

I'm trying to get away from encoding the path into the type name. Please 
use certbot_lib_t or another name that makes more sense, if possible.


 > +########################################
 > +#
 > +# Local policy
 > +#
 > +
 > +allow certbot_t self:fifo_file { getattr ioctl read write };
 > +
 > +allow certbot_t self:capability { chown dac_override sys_resource };
 > +
 > +# this is for certbot to have write-exec memory, I know it is bad
 > +allow certbot_t self:process execmem;
 > +allow certbot_t certbot_tmp_t:file { map execute };
 > +allow certbot_t certbot_tmpfs_t:file { map execute };
 > +allow certbot_t certbot_var_run_t:file { map execute };
 > +
 > +kernel_search_fs_sysctls(certbot_t)
 > +
 > +allow certbot_t self:tcp_socket all_tcp_socket_perms;
 > +allow certbot_t self:netlink_route_socket create_netlink_socket_perms;
 > +corenet_tcp_bind_generic_node(certbot_t)
 > +corenet_tcp_connect_http_port(certbot_t)
 > +
 > +# bind to http port for standalone mode
 > +corenet_tcp_bind_http_port(certbot_t)
 > +
 > +allow certbot_t self:udp_socket all_udp_socket_perms;
 > +sysnet_read_config(certbot_t)
 > +files_read_etc_files(certbot_t)
 > +
 > +# for /usr/bin/x86_64-linux-gnu-gcc-8 why?
 > +corecmd_exec_bin(certbot_t)
 > +# for /usr/lib/gcc/x86_64-linux-gnu/8/collect2
 > +libs_exec_lib_files(certbot_t)
 > +
 > +libs_exec_ldconfig(certbot_t)
 > +
 > +apache_search_config(certbot_t)
 > +
 > +# for bin_t map
 > +corecmd_bin_entry_type(certbot_t)

There is a better interface that doesn't allow a bin_t entrypoint, 
corecmd_mmap_bin_files().


 > +miscfiles_read_localization(certbot_t)
 > +
 > +miscfiles_read_generic_certs(certbot_t)
 > +miscfiles_manage_generic_tls_privkey_dirs(certbot_t)
 > +miscfiles_manage_generic_tls_privkey_files(certbot_t)
 > +miscfiles_manage_generic_tls_privkey_lnk_files(certbot_t)
 > +
 > +manage_files_pattern(certbot_t, certbot_var_run_t, certbot_var_run_t)
 > +files_pid_filetrans(certbot_t, certbot_var_run_t, file)
 > +
 > +logging_search_logs(certbot_t)
 > +allow certbot_t certbot_log_t:dir manage_dir_perms;
 > +allow certbot_t certbot_log_t:file manage_file_perms;
 > +
 > +files_search_var_lib(certbot_t)
 > +manage_dirs_pattern(certbot_t, certbot_var_lib_t, certbot_var_lib_t)
 > +manage_files_pattern(certbot_t, certbot_var_lib_t, certbot_var_lib_t)
 > +
 > +manage_files_pattern(certbot_t, certbot_tmp_t, certbot_tmp_t)
 > +files_tmp_filetrans(certbot_t, certbot_tmp_t, { file })
 > +
 > +manage_files_pattern(certbot_t, certbot_tmpfs_t, certbot_tmpfs_t)
 > +fs_tmpfs_filetrans(certbot_t, certbot_tmpfs_t, { file })
 > +
 > +domain_use_interactive_fds(certbot_t)
 > +userdom_use_user_ptys(certbot_t)
 > +userdom_dontaudit_search_user_home_dirs(certbot_t)
 > +
 > +optional_policy(`
 > +    # for writing to webroot
 > +    apache_manage_sys_content(certbot_t)
 > +')

In general the style (line ordering) needs to be revised.


-- 
Chris PeBenito

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12  3:08 Russell Coker
2020-02-16 15:32 ` Chris PeBenito [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9b9d1f3-2615-40a9-2eba-98542b0ddfda@ieee.org \
    --to=pebenito@ieee.org \
    --cc=russell@coker.com.au \
    --cc=selinux-refpolicy@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

SELinux-Refpolicy Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/selinux-refpolicy/0 selinux-refpolicy/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 selinux-refpolicy selinux-refpolicy/ https://lore.kernel.org/selinux-refpolicy \
		selinux-refpolicy@vger.kernel.org
	public-inbox-index selinux-refpolicy

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.selinux-refpolicy


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git