LINUXOR.SK ... open source notes ...

Proxy - squid-local.te (SELinux module)

category: solutionz/proxy · date: 2019-12-31 · updated: 2026-10-03 · author: LALA

Proxy Solution · Config document · referenced from SELinux and client trust

noteThe module allows the Squid domain to write files of the base type var_lib_t, that is, anywhere under /var/lib that has no more specific label; audit2allow warns about exactly that in the file. It is the blunt fix my note, filed under 2018, ends with; what became of it afterwards the note does not say. The check against the RHEL 7.5 policy package below shows it was not needed: restorecon -Rv /var/lib/ssl_db would have done. Do not copy it.

A local SELinux type-enforcement module for Squid's ssl_crtd helper. On RHEL 7.5 Squid refused to start with the message (ssl_crtd): Uninitialized SSL certificate database directory: /var/lib/ssl_db although the database had been initialised, because SELinux stopped the helper, which runs in the squid_t domain, from writing into /var/lib/ssl_db, a directory labelled var_lib_t. The file is what audit2allow generated from the collected audit messages; the commands that produced and installed it are in the Article.

ItemValue
Path on the server/etc/selinux/squid-local.te, with the compiled squid-local.pp beside it
Hostdc2-a-vcprx001, RHEL 7.5; the notes do not name the policy type
Generated withgrep squid /var/log/audit/audit.log piped into audit2allow -M squid-local, in /etc/selinux
Loaded withsemodule -i /etc/selinux/squid-local.pp
Also onthe notes show the module on datacenter 2 only; whether datacenter 1 and the lab needed it, they do not say

The file

ini
module squid-local 1.0;

require {
        type squid_t;
        type var_lib_t;
        class file { create getattr lock open read write };
        class dir { add_name write };
}

#============= squid_t ==============
allow squid_t var_lib_t:dir { add_name write };

#!!!! WARNING: 'var_lib_t' is a base type.
allow squid_t var_lib_t:file { create getattr lock open read write };

The file is as audit2allow printed it, including its own #============= and #!!!! WARNING comment lines; nothing was added or edited.

What the lines mean

LineMeaning
module squid-local 1.0;the module name, given with audit2allow -M squid-local, and its version
require { … }the types and object classes the rules below refer to, which must already exist in the loaded policy
type squid_t;the domain Squid runs in; as I understand it, ssl_crtd is started by Squid and stays in that domain, which is why the denials name squid_t and not a helper type
type var_lib_t;the label of /var/lib and of anything created under it without a more specific file context, such as the ssl_db directory that ssl_crtd -c created
allow squid_t var_lib_t:dir { add_name write };the domain may write to a var_lib_t directory and add entries to it: create the database files inside /var/lib/ssl_db
#!!!! WARNING: 'var_lib_t' is a base type.audit2allow points out that the rule below is wide: var_lib_t is not specific to Squid
allow squid_t var_lib_t:file { create getattr lock open read write };the domain may create, stat, lock, open, read and write files of that type, which is what the helper does with the certificate database

The module was not needed at all, as a check against the policy package of RHEL 7.5 shows (next section): the policy already labelled /var/lib/ssl_db as squid_cache_t, and the directory only carried var_lib_t because ssl_crtd -c created it from a root shell and nothing relabelled it. restorecon -Rv /var/lib/ssl_db would have been the whole fix. The module stays here as it was built and loaded; see SELinux and client trust.

Checked against selinux-policy, RHEL 7.5 to RHEL 10

As builtToday
/var/lib/ssl_db labelled var_lib_t, module allows squid_t to write var_lib_tThe RHEL 7.5 package selinux-policy-targeted-3.13.1-192.el7 already carried /var/lib/ssl_db(/.*)? system_u:object_r:squid_cache_t:s0 in its file_contexts (added upstream on 2017-03-28, "Label /var/lib/ssl_db as squid_cache_t"), and squid_t may manage squid_cache_t directories and files. The RHEL 7 squid RPM does not ship the directory, so ssl_crtd -c -s /var/lib/ssl_db run by root created it with the parent's var_lib_t. The fix was restorecon -Rv /var/lib/ssl_db; a custom module was not needed
audit2allow -M, semodule -iStill the tooling. Current policy packages are selinux-policy-targeted-38.1.86-1.el9 and 42.1.27-2.el10; the squid_cache_t context for /var/lib/ssl_db is in all current branches
/var/lib/ssl_db as the database pathSquid 4 and later default to /var/spool/squid/ssl_db on RHEL builds, which is squid_cache_t through the /var/spool/squid(/.*)? context, so a database created at the default path inherits the right label with no extra step
The "Uninitialized SSL certificate database directory" messageUnchanged in Squid 7.7 apart from the helper name; it is thrown whenever the helper cannot open the database's index file, so an SELinux denial produces the same text as a missing database

The label was there before the module was. The warning audit2allow wrote into the file was the hint, and ls -Z /var/lib/ssl_db next to matchpathcon /var/lib/ssl_db would have shown the difference between the label the directory had and the one the policy wanted.

← solutionz/proxy