Skip to content

refactor: Distinguish semanage 'already exists' from real failures#126

Open
frostyardyeti[bot] wants to merge 1 commit intomainfrom
yeti/improve-25ea
Open

refactor: Distinguish semanage 'already exists' from real failures#126
frostyardyeti[bot] wants to merge 1 commit intomainfrom
yeti/improve-25ea

Conversation

@frostyardyeti
Copy link
Copy Markdown
Contributor

@frostyardyeti frostyardyeti Bot commented Mar 29, 2026

In internal/provision/provision.go:330-334, the semanage fcontext -a error is unconditionally swallowed with _ = err and a comment that it may mean 'already defined'. However, this also silences genuine failures like missing SELinux tools or permission denied errors. The fix is to check the command output/stderr for 'already defined' or 'already exists' and only suppress that specific case, returning the error for other failures.


Automated improvement by yeti improvement-identifier

The semanage fcontext error was unconditionally swallowed, silencing
genuine failures like missing SELinux tools or permission denied. Now
only suppress the error when the output contains 'already defined' or
'already exists', and return the error for all other failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bketelsen
Copy link
Copy Markdown
Contributor

need someone with SELinux to review/validate

@frostyardyeti
Copy link
Copy Markdown
Contributor Author

frostyardyeti Bot commented Mar 31, 2026

— Automated by Yeti —

No code changes needed. The review comment from @bketelsen is not requesting a code change — it's flagging that the PR needs validation from someone with SELinux experience before merging.

The change itself is straightforward and correct:

  • Before: semanage fcontext -a errors were unconditionally swallowed (_ = err), hiding real failures.
  • After: The error output is checked for "already defined" or "already exists" (the two known messages semanage emits for duplicate contexts). Only that specific case is suppressed; all other failures are properly returned.

This matches semanage's actual behavior — when a context rule already exists, it exits non-zero with a message containing "already defined" (older versions) or "already exists" (newer versions). The string check on the combined output is the standard way to distinguish this from genuine errors like missing tools or permission issues.

@frostyardyeti frostyardyeti Bot added the Ready Yeti has finished — needs human attention label Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready Yeti has finished — needs human attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant