Bug 2063353

Summary: semanage import fails with ValueError despite import starting with port -D to delete all first
Product: Red Hat Enterprise Linux 8 Reporter: James Hartsock <hartsjc>
Component: policycoreutilsAssignee: Vit Mojzis <vmojzis>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.5CC: dwalsh, lvrabec, mmalik, plautrba, rory586foster, ssekidde, vmojzis
Target Milestone: rcKeywords: AutoVerified, Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: policycoreutils-2.9-20.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 2108174 (view as bug list) Environment:
Last Closed: 2022-11-08 10:56:37 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2108174    

Description James Hartsock 2022-03-11 21:23:03 UTC
Description of problem:
  semanage import is able to import port rules fine as long as port isn't already defined.
  But if try run again (with port -D to delete all first) get error stating port is already defined.


Version-Release number of selected component (if applicable):
  # rpm -qf $(which semanage)
  policycoreutils-python-utils-2.9-16.el8.noarch


How reproducible:
  100%


Steps to Reproduce:
  1. Add custom port definition with semanage
  2. semanage export to file
  3. semanage import file from #2


Actual results:
  # semanage port -D
  # semanage port -a -t http_cache_port_t -r s0 -p tcp 3024

  # semanage export | grep -w port
  port -D
  port -a -t http_cache_port_t -r 's0' -p tcp 3024

  # echo -e "port -D\nport -a -t http_cache_port_t -r 's0' -p tcp 3024"  | semanage import
  ValueError: Port tcp/3024 already defined
  # echo $?
  1


Expected results:

  As the import has delete, it should not get "already defined" error.
  So expected result is should not have to manully delete them before doing import.

  # semanage port -D
  # echo -e "port -D\nport -a -t http_cache_port_t -r 's0' -p tcp 3024"  | semanage import
  # echo $?
  0


Additional info:
  Issue is present in fedora too (works first time, fails once defined)

  # rpm -qf $(which semanage)
  policycoreutils-python-utils-3.3-1.fc35.noarch
  # semanage port -D
  # echo -e "port -D\nport -a -t http_cache_port_t -r 's0' -p tcp 3024"  | semanage import
  # echo -e "port -D\nport -a -t http_cache_port_t -r 's0' -p tcp 3024"  | semanage import
  ValueError: Port tcp/3024 already defined



  Am able to run the delete and create that fails on import successfully on command line
  # semanage port -D ; semanage port -a -t http_cache_port_t -r s0 -p tcp 3024
  # echo $?
  0

Comment 13 errata-xmlrpc 2022-11-08 10:56:37 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (policycoreutils bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7805

Comment 14 rory586 2024-07-30 06:13:22 UTC Comment hidden (spam)