Day 02: Debugging Service Level Permission Issues
Forensic Mental Map: Debugging Linux Service Permissions
When a service like Jenkins fails silently or logs are empty, follow this structured exclusion process to find the “blocker.”
Phase 1: The Identity Check (Linux Filesystem)
Goal: Prove the service user has basic OS-level access.
- Check Ownership: Does the user own the target directory?
ls -ld /var/log/jenkins
- Check Permissions: Is the directory writable (755 or 775)?
ls -l /var/log/jenkins
- The “Impersonation” Test: Can the user manually create a file?
sudo -u jenkins touch /var/log/jenkins/test.txt- If this fails, the fix is:
chown -R jenkins:jenkins /var/log/jenkins
Phase 2: The “Silent” Barrier (Systemd Sandboxing)
Goal: Check if Systemd is restricting the process beyond standard OS permissions.
- Inspect Restrictions: Look for security “sandboxing” flags.
systemctl cat jenkins | grep -E "Protect|ReadWrite|Private"
- Evaluate Flags:
ProtectSystem=full/strict: Prevents writing to system directories.ReadWritePaths=: If this list exists, the service cannot write anywhere else.
- The “Tackle”: Add your path to the allowed list in your override:
ReadWritePaths=/var/log/jenkins/
Phase 3: The “Invisible Wall” (Security Policies)
Goal: Identify blocks from Mandatory Access Control (SELinux/AppArmor).
- Check Enforcement: Is a security module active?
getenforce(Should return Enforcing or Permissive)
- Audit Logs: Check for “denied” messages the app didn’t see.
sudo ausearch -m avc -ts recent
- The “Isolation” Test: Temporarily disable the wall.
sudo setenforce 0- If the log starts working, the fix is:
sudo restorecon -Rv /var/log/jenkins
Phase 4: The “Forensic” Start (Manual Execution)
Goal: Bypass the service manager to see “raw” error output.
- Extract Command: Find exactly what command Systemd runs.
systemctl show jenkins -p ExecStart
- Manual Run: Run that exact command as the
jenkinsuser.sudo -u jenkins /usr/bin/java -jar ...
- Analyze Trace: Watch the terminal for “Java Stack Traces” or “Access Denied” errors that
journalctlmight have missed.
Phase 5: The Application Logic (Config vs. Reality)
Goal: Ensure the app is actually trying to write where you think it is.
- Path Verification: Does the path in
override.confmatch the physical folder? - Buffering: Is the app holding data in memory?
- Tackle: Trigger 20+ web requests to force a buffer flush.
Jenkins Administration & Linux Package Management Summary
1. Package Management (DNF vs. YUM)
- The Transition: DNF is the modern successor to YUM, offering superior dependency resolution (via
libsolv) and performance. On modern systems, theyumcommand is typically a symlink todnf. - Repository Logic: Repositories host the software and metadata, while GPG keys serve as a “tamper-proof seal” to verify package authenticity.
- Source Lists: Unlike the single
sources.listin Debian/Ubuntu, RPM-based systems use individual.repofiles located in/etc/yum.repos.d/.
2. Jenkins Installation & Configuration
- The Workflow: Installation requires adding the official repo, importing the GPG key, installing Java (the runtime engine), and finally installing the Jenkins package.
- Service Defaults: Jenkins runs under a dedicated
jenkinsuser and defaults to port 8080. - Critical Paths:
- Data:
/var/lib/jenkins - Logs:
/var/log/jenkins
- Data:
3. The “Golden Rule” of Customization: Overrides
- Avoid Direct Edits: Never modify
/usr/lib/systemd/system/jenkins.servicedirectly; these changes are lost during updates. - Use Overrides: Utilize
sudo systemctl edit jenkinsto create drop-in configurations. - Syntax Matters: Custom variables (e.g.,
JENKINS_PORT,JENKINS_ENABLE_ACCESS_LOG) must be placed under a[Service]header to be recognized. - Activation: Always run
sudo systemctl daemon-reloadand restart the service to apply changes.
4. Troubleshooting & The Forensic Mindset
- Validation vs. Raw Text:
systemctl cat: Displays the raw text on disk (useful for checking syntax).systemctl show: Displays what the system has actually “parsed” and accepted.
- The Forensic Mental Map:
- Ownership: Verify directory owners via
ls -ld. - Impersonation: Test write permissions with
sudo -u jenkins touch <file>. - Visibility: Check if SELinux is blocking access using
getenforce(test withsetenforce 0). - Raw Output: Run the Java startup command manually as the
jenkinsuser to see “silent” errors missed byjournalctl.
- Ownership: Verify directory owners via
5. Access Logging
- Activation: Setting
JENKINS_ENABLE_ACCESS_LOG=truegenerates anaccess_logfor HTTP traffic. - Empty Logs: If the log is empty, it usually indicates a lack of traffic to the port or that the output is currently buffered in memory.