Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Create consumer cert & key, when chown failed #3466

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/subscription_manager/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,24 @@ def write(self) -> None:

# Set proper access permission to the key
if os.getuid() == 0 and rhsm_group is not None:
os.chown(self.keypath(), 0, rhsm_group.gr_gid)
# Changing of owner can fail due to e.g. SELinux. When this
# operation fails, then we should only write error message,
# and we should create consumer cert.pem too
try:
os.chown(self.keypath(), 0, rhsm_group.gr_gid)
except OSError as err:
log.error(f"Unable to chown permissions of {self.keypath()}: {err}")
Comment on lines +130 to +136
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth to factorize this to a small helper, as it is used in two places

os.chmod(self.keypath(), managerlib.ID_CERT_PERMS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Expected permissions for identity certificates:
ID_CERT_PERMS: int = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP

considering ID_CERT_PERMS also makes this group-readable: shouldn't this chmod() be done only if the chown() succeeds?


with open(self.certpath(), "w") as cert_file:
cert_file.write(self.cert)

# Set proper permission to consumer certificate
if os.getuid() == 0 and rhsm_group is not None:
os.chown(self.certpath(), 0, rhsm_group.gr_gid)
try:
os.chown(self.certpath(), 0, rhsm_group.gr_gid)
except OSError as err:
log.error(f"Unable to chown permissions of {self.certpath()}: {err}")
os.chmod(self.certpath(), managerlib.ID_CERT_PERMS)

def delete(self) -> None:
Expand Down
Loading