<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://coolscript.net/index.php?action=history&amp;feed=atom&amp;title=Grafana_Alloy%2C_Loki_and_SELinux</id>
	<title>Grafana Alloy, Loki and SELinux - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://coolscript.net/index.php?action=history&amp;feed=atom&amp;title=Grafana_Alloy%2C_Loki_and_SELinux"/>
	<link rel="alternate" type="text/html" href="https://coolscript.net/index.php?title=Grafana_Alloy,_Loki_and_SELinux&amp;action=history"/>
	<updated>2026-06-02T16:17:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://coolscript.net/index.php?title=Grafana_Alloy,_Loki_and_SELinux&amp;diff=1145&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;= Grafana Alloy, Loki and SELinux =  This article summarizes how to run Grafana Alloy on an SELinux-enabled Linux system, how to troubleshoot startup and access problems, and what to check when Alloy sends metrics to Mimir or logs to Loki.  == Scope ==  The main SELinux topics for Alloy are:  * execution of the Alloy binary * outbound network access to Mimir and Loki * reading local log files for Loki * reading the systemd journal for Loki * file ownership and runtime st...&quot;</title>
		<link rel="alternate" type="text/html" href="https://coolscript.net/index.php?title=Grafana_Alloy,_Loki_and_SELinux&amp;diff=1145&amp;oldid=prev"/>
		<updated>2026-04-20T14:24:11Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Grafana Alloy, Loki and SELinux =  This article summarizes how to run Grafana Alloy on an SELinux-enabled Linux system, how to troubleshoot startup and access problems, and what to check when Alloy sends metrics to Mimir or logs to Loki.  == Scope ==  The main SELinux topics for Alloy are:  * execution of the Alloy binary * outbound network access to Mimir and Loki * reading local log files for Loki * reading the systemd journal for Loki * file ownership and runtime st...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Grafana Alloy, Loki and SELinux =&lt;br /&gt;
&lt;br /&gt;
This article summarizes how to run Grafana Alloy on an SELinux-enabled Linux system, how to troubleshoot startup and access problems, and what to check when Alloy sends metrics to Mimir or logs to Loki.&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
&lt;br /&gt;
The main SELinux topics for Alloy are:&lt;br /&gt;
&lt;br /&gt;
* execution of the Alloy binary&lt;br /&gt;
* outbound network access to Mimir and Loki&lt;br /&gt;
* reading local log files for Loki&lt;br /&gt;
* reading the systemd journal for Loki&lt;br /&gt;
* file ownership and runtime state when Alloy runs as a restricted user&lt;br /&gt;
&lt;br /&gt;
== Key Lessons ==&lt;br /&gt;
&lt;br /&gt;
* The Alloy binary at `/usr/local/bin/alloy` must have a valid SELinux label such as `bin_t`.&lt;br /&gt;
* Do not use `SELinuxContext=` in the systemd unit.&lt;br /&gt;
* If cAdvisor is local, scrape `127.0.0.1:8080` instead of a hostname that may not resolve.&lt;br /&gt;
* If Alloy runs as a restricted user, it must be able to read the config and write its WAL.&lt;br /&gt;
* For Loki, SELinux usually matters more for reading log sources than for sending data to the Loki endpoint.&lt;br /&gt;
&lt;br /&gt;
== Installation Basics ==&lt;br /&gt;
&lt;br /&gt;
=== Binary ===&lt;br /&gt;
&lt;br /&gt;
Install Alloy here:&lt;br /&gt;
&lt;br /&gt;
 /usr/local/bin/alloy&lt;br /&gt;
&lt;br /&gt;
Check the SELinux label:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ls -lZ /usr/local/bin/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Expected type:&lt;br /&gt;
&lt;br /&gt;
 bin_t&lt;br /&gt;
&lt;br /&gt;
If the label is wrong, fix it:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 restorecon -v /usr/local/bin/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If that does not persist correctly, define the file context and relabel:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 semanage fcontext -a -t bin_t &amp;#039;/usr/local/bin/alloy&amp;#039;&lt;br /&gt;
 restorecon -v /usr/local/bin/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config ===&lt;br /&gt;
&lt;br /&gt;
Typical config location:&lt;br /&gt;
&lt;br /&gt;
 /etc/alloy/config.alloy&lt;br /&gt;
&lt;br /&gt;
=== Runtime Data ===&lt;br /&gt;
&lt;br /&gt;
Prefer runtime state under:&lt;br /&gt;
&lt;br /&gt;
 /var/lib/alloy&lt;br /&gt;
&lt;br /&gt;
Avoid keeping mutable runtime data under `/etc/alloy` when possible.&lt;br /&gt;
&lt;br /&gt;
== Systemd Unit ==&lt;br /&gt;
&lt;br /&gt;
Use a normal unit file. Do not set `SELinuxContext=`.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
 [Unit]&lt;br /&gt;
 Description=Grafana Alloy Service&lt;br /&gt;
 After=network.target&lt;br /&gt;
&lt;br /&gt;
 [Service]&lt;br /&gt;
 Type=simple&lt;br /&gt;
 ExecStart=/usr/local/bin/alloy run /etc/alloy/config.alloy&lt;br /&gt;
 WorkingDirectory=/etc/alloy&lt;br /&gt;
 Restart=always&lt;br /&gt;
 RestartSec=5&lt;br /&gt;
 User=root&lt;br /&gt;
 LimitNOFILE=65535&lt;br /&gt;
 StandardOutput=syslog&lt;br /&gt;
 StandardError=syslog&lt;br /&gt;
 SyslogIdentifier=alloy&lt;br /&gt;
 Environment=&amp;quot;test&amp;quot;&lt;br /&gt;
 Environment=&amp;quot;APP_NAME=test&amp;quot;&lt;br /&gt;
 Environment=&amp;quot;OrgID=anonymous&amp;quot;&lt;br /&gt;
 Environment=&amp;quot;PATH=/usr/local/bin:/usr/bin:/bin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 [Install]&lt;br /&gt;
 WantedBy=multi-user.target&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prometheus Scrape Example ==&lt;br /&gt;
&lt;br /&gt;
If cAdvisor runs locally, use:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
 prometheus.scrape &amp;quot;pan_cadvisor&amp;quot; {&lt;br /&gt;
   targets    = [{ __address__ = &amp;quot;127.0.0.1:8080&amp;quot;, client = sys.env(&amp;quot;CLIENT&amp;quot;) }]&lt;br /&gt;
   forward_to = [prometheus.remote_write.hosting.receiver]&lt;br /&gt;
 }&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This avoids hostname resolution problems such as failing to resolve `cadvisor`.&lt;br /&gt;
&lt;br /&gt;
== Common SELinux Problems ==&lt;br /&gt;
&lt;br /&gt;
=== 203/EXEC on startup ===&lt;br /&gt;
&lt;br /&gt;
Symptom:&lt;br /&gt;
&lt;br /&gt;
 Main process exited, code=exited, status=203/EXEC&lt;br /&gt;
&lt;br /&gt;
This usually means systemd could not execute the binary. A common cause is a wrong SELinux label on `/usr/local/bin/alloy`.&lt;br /&gt;
&lt;br /&gt;
Example bad label:&lt;br /&gt;
&lt;br /&gt;
 admin_home_t&lt;br /&gt;
&lt;br /&gt;
Check:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ls -lZ /usr/local/bin/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Fix:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 restorecon -v /usr/local/bin/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scrape fails with connect: permission denied ===&lt;br /&gt;
&lt;br /&gt;
Symptom:&lt;br /&gt;
&lt;br /&gt;
 Get &amp;quot;http://127.0.0.1:8080/metrics&amp;quot;: dial tcp 127.0.0.1:8080: connect: permission denied&lt;br /&gt;
&lt;br /&gt;
If `curl` works from the shell but Alloy cannot connect, SELinux may be blocking the Alloy process.&lt;br /&gt;
&lt;br /&gt;
Check denials:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ausearch -m AVC -ts recent&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If needed, generate and install a local policy:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ausearch -m AVC -c alloy --raw | audit2allow -M alloy_local&lt;br /&gt;
 semodule -i alloy_local.pp&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== WAL permission denied ===&lt;br /&gt;
&lt;br /&gt;
Symptom:&lt;br /&gt;
&lt;br /&gt;
 open data-alloy/prometheus.remote_write.hosting/wal/00000657: permission denied&lt;br /&gt;
&lt;br /&gt;
This typically happens after switching Alloy from `root` to a restricted user while the WAL directory is still owned by `root`.&lt;br /&gt;
&lt;br /&gt;
Immediate fix:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 chown -R alloy-user:alloy-user /etc/alloy/data-alloy&lt;br /&gt;
 chmod -R u+rwX /etc/alloy/data-alloy&lt;br /&gt;
 restorecon -Rv /etc/alloy/data-alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also ensure config readability:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 chown root:alloy-user /etc/alloy&lt;br /&gt;
 chmod 750 /etc/alloy&lt;br /&gt;
 chmod 640 /etc/alloy/config.alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Running Alloy as a Restricted User ==&lt;br /&gt;
&lt;br /&gt;
Create the user:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 useradd --system --no-create-home --shell /sbin/nologin alloy-user&lt;br /&gt;
 id alloy-user&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the service to:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
 User=alloy-user&lt;br /&gt;
 Group=alloy-user&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ensure:&lt;br /&gt;
&lt;br /&gt;
* `/usr/local/bin/alloy` is still labeled `bin_t`&lt;br /&gt;
* `/etc/alloy` is readable by `alloy-user`&lt;br /&gt;
* the WAL and runtime directories are writable by `alloy-user`&lt;br /&gt;
&lt;br /&gt;
Preferred runtime directory:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 mkdir -p /var/lib/alloy&lt;br /&gt;
 chown -R alloy-user:alloy-user /var/lib/alloy&lt;br /&gt;
 chmod 750 /var/lib/alloy&lt;br /&gt;
 restorecon -Rv /var/lib/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Returning Alloy to root ==&lt;br /&gt;
&lt;br /&gt;
Either set:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
 User=root&lt;br /&gt;
 Group=root&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or remove both lines entirely, since systemd defaults to `root`.&lt;br /&gt;
&lt;br /&gt;
If runtime directories were reassigned, give them back to root if needed:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 chown -R root:root /etc/alloy/data-alloy&lt;br /&gt;
 chown -R root:root /var/lib/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then reload and restart:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 systemctl daemon-reload&lt;br /&gt;
 systemctl restart alloy.service&lt;br /&gt;
 systemctl status alloy.service&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Loki and SELinux ==&lt;br /&gt;
&lt;br /&gt;
=== Sending data to Loki ===&lt;br /&gt;
&lt;br /&gt;
For the Loki endpoint, SELinux checks the outbound network connection from the Alloy process.&lt;br /&gt;
&lt;br /&gt;
If Alloy is running in `unconfined_service_t`, SELinux is usually not the main blocker for outbound HTTPS to Loki.&lt;br /&gt;
&lt;br /&gt;
Check the process context:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ps -eZ | grep alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example output:&lt;br /&gt;
&lt;br /&gt;
 system_u:system_r:unconfined_service_t:s0 539778 ? 00:00:16 alloy&lt;br /&gt;
&lt;br /&gt;
Important part:&lt;br /&gt;
&lt;br /&gt;
 unconfined_service_t&lt;br /&gt;
&lt;br /&gt;
This means the process is not tightly confined. In that case, failures to send to Loki are more likely to be caused by:&lt;br /&gt;
&lt;br /&gt;
* DNS problems&lt;br /&gt;
* TLS or certificate issues&lt;br /&gt;
* authentication problems&lt;br /&gt;
* proxy or firewall rules&lt;br /&gt;
* a wrong Loki URL&lt;br /&gt;
&lt;br /&gt;
Check for actual SELinux denials before changing policy:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ausearch -m AVC -ts recent&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a denial shows `name_connect`, a local policy module may be required.&lt;br /&gt;
&lt;br /&gt;
=== Reading plain log files for Loki ===&lt;br /&gt;
&lt;br /&gt;
This is the most common SELinux issue when adding Loki.&lt;br /&gt;
&lt;br /&gt;
Alloy must be able to:&lt;br /&gt;
&lt;br /&gt;
* traverse the parent directories&lt;br /&gt;
* open the file&lt;br /&gt;
* read the file&lt;br /&gt;
&lt;br /&gt;
Check labels:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ls -lZ /path/to/log-directory&lt;br /&gt;
 ls -lZ /path/to/logfile&lt;br /&gt;
 matchpathcon /path/to/logfile&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the file should behave like a regular log file, `var_log_t` is a common type.&lt;br /&gt;
&lt;br /&gt;
Quick test for one file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 chcon -t var_log_t /path/to/logfile&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Important:&lt;br /&gt;
&lt;br /&gt;
* `chcon` changes the current live label immediately&lt;br /&gt;
* `chcon` is usually not persistent&lt;br /&gt;
* `restorecon` may revert it later&lt;br /&gt;
&lt;br /&gt;
Preferred long-term fix for a custom log directory:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 semanage fcontext -a -t var_log_t &amp;#039;/path/to/log-directory(/.*)?&amp;#039;&lt;br /&gt;
 restorecon -Rv /path/to/log-directory&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reading the systemd journal ===&lt;br /&gt;
&lt;br /&gt;
If Alloy reads the journal, verify both OS permissions and SELinux access.&lt;br /&gt;
&lt;br /&gt;
Check:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 id alloy-user&lt;br /&gt;
 ls -lZ /var/log/journal&lt;br /&gt;
 ausearch -m AVC -ts recent&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If Alloy runs as a restricted user, journal group access may be needed:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 usermod -aG systemd-journal alloy-user&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Restart the service after changing group membership.&lt;br /&gt;
&lt;br /&gt;
=== Reading container logs ===&lt;br /&gt;
&lt;br /&gt;
If logs come from paths such as `/var/lib/docker/containers` or `/var/log/containers`, SELinux may be stricter because container paths often use special SELinux types.&lt;br /&gt;
&lt;br /&gt;
Check:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ls -lZ /var/lib/docker/containers&lt;br /&gt;
 ls -lZ /var/log/containers&lt;br /&gt;
 ausearch -m AVC -ts recent&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such cases, a local policy module may be required.&lt;br /&gt;
&lt;br /&gt;
== What `ps -eZ | grep alloy` tells you ==&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 system_u:system_r:unconfined_service_t:s0 539778 ? 00:00:16 alloy&lt;br /&gt;
&lt;br /&gt;
Meaning:&lt;br /&gt;
&lt;br /&gt;
* `system_u` = SELinux user&lt;br /&gt;
* `system_r` = SELinux role&lt;br /&gt;
* `unconfined_service_t` = SELinux type or process domain&lt;br /&gt;
* `s0` = SELinux level&lt;br /&gt;
&lt;br /&gt;
The most important field is the type. If Alloy runs as `unconfined_service_t`, SELinux is generally less restrictive for this process than for a tightly confined domain.&lt;br /&gt;
&lt;br /&gt;
== Useful SELinux Commands ==&lt;br /&gt;
&lt;br /&gt;
=== ls -lZ ===&lt;br /&gt;
&lt;br /&gt;
Shows the SELinux label of a file or directory.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ls -lZ /usr/local/bin/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== restorecon ===&lt;br /&gt;
&lt;br /&gt;
Restores the default label according to policy.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 restorecon -v /usr/local/bin/alloy&lt;br /&gt;
 restorecon -Rv /var/lib/alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== semanage ===&lt;br /&gt;
&lt;br /&gt;
Defines persistent SELinux mappings, such as file contexts and port types.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 semanage fcontext -a -t bin_t &amp;#039;/usr/local/bin/alloy&amp;#039;&lt;br /&gt;
 semanage fcontext -a -t var_log_t &amp;#039;/path/to/log-directory(/.*)?&amp;#039;&lt;br /&gt;
 semanage port -l | grep 8080&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== semodule ===&lt;br /&gt;
&lt;br /&gt;
Installs and lists policy modules.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 semodule -i alloy_local.pp&lt;br /&gt;
 semodule -l | grep alloy&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ausearch ===&lt;br /&gt;
&lt;br /&gt;
Searches the audit log for SELinux denials.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ausearch -m AVC -ts recent&lt;br /&gt;
 ausearch -m AVC -c alloy --raw&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== getenforce and setenforce ===&lt;br /&gt;
&lt;br /&gt;
Show or temporarily change SELinux mode.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 getenforce&lt;br /&gt;
 setenforce 0&lt;br /&gt;
 setenforce 1&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use `setenforce 0` only as a temporary test.&lt;br /&gt;
&lt;br /&gt;
=== matchpathcon ===&lt;br /&gt;
&lt;br /&gt;
Shows the expected SELinux label for a path.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 matchpathcon /usr/local/bin/alloy&lt;br /&gt;
 matchpathcon /path/to/logfile&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== audit2allow ===&lt;br /&gt;
&lt;br /&gt;
Builds a local policy module from recorded denials.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
 ausearch -m AVC -c alloy --raw | audit2allow -M alloy_local&lt;br /&gt;
 semodule -i alloy_local.pp&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Review generated policy before using it in production.&lt;br /&gt;
&lt;br /&gt;
== Recommended Troubleshooting Flow ==&lt;br /&gt;
&lt;br /&gt;
# Verify SELinux mode:&lt;br /&gt;
#* `getenforce`&lt;br /&gt;
#* `sestatus`&lt;br /&gt;
# Verify the Alloy binary label:&lt;br /&gt;
#* `ls -lZ /usr/local/bin/alloy`&lt;br /&gt;
#* `matchpathcon /usr/local/bin/alloy`&lt;br /&gt;
# Fix labels if needed:&lt;br /&gt;
#* `restorecon -v /usr/local/bin/alloy`&lt;br /&gt;
#* or use `semanage fcontext` plus `restorecon`&lt;br /&gt;
# Check the running process context:&lt;br /&gt;
#* `ps -eZ | grep alloy`&lt;br /&gt;
# Reproduce the problem and inspect denials:&lt;br /&gt;
#* `ausearch -m AVC -ts recent`&lt;br /&gt;
# For Loki file collection, inspect the file and directory labels.&lt;br /&gt;
# For journald collection, check journal permissions and group membership.&lt;br /&gt;
# If required, generate and install a local policy module.&lt;br /&gt;
# Restart Alloy and verify logs.&lt;br /&gt;
&lt;br /&gt;
== Final Recommendations ==&lt;br /&gt;
&lt;br /&gt;
* Keep `/usr/local/bin/alloy` labeled as `bin_t`.&lt;br /&gt;
* Do not use `SELinuxContext=` in the systemd unit.&lt;br /&gt;
* Prefer `/var/lib/alloy` for runtime state.&lt;br /&gt;
* Use `127.0.0.1:8080` for a local cAdvisor target.&lt;br /&gt;
* For Loki, first focus on SELinux access to the log source, not only the Loki endpoint.&lt;br /&gt;
* Use `chcon` only for quick tests.&lt;br /&gt;
* Use `semanage fcontext` plus `restorecon` for persistent label fixes.&lt;br /&gt;
* Use `ausearch -m AVC -ts recent` before changing SELinux policy.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>