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

[ipa-4-6] too-restrictive mask checks #2894

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions ipaserver/install/installutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,3 +1642,14 @@ def default_subject_base(realm_name):

def default_ca_subject_dn(subject_base):
return DN(('CN', 'Certificate Authority'), subject_base)


def validate_mask():
try:
mask = os.umask(0)
finally:
os.umask(mask)
mask_str = None
if mask & 0b111101101 > 0:
mask_str = "{:04o}".format(mask)
return mask_str
12 changes: 11 additions & 1 deletion ipaserver/install/server/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from ipaserver.install.installutils import (
IPA_MODULES, BadHostError, get_fqdn, get_server_ip_address,
is_ipa_configured, load_pkcs12, read_password, verify_fqdn,
update_hosts_file)
update_hosts_file, validate_mask)

if six.PY3:
unicode = str
Expand Down Expand Up @@ -311,6 +311,16 @@ def install_check(installer):
tasks.check_ipv6_stack_enabled()
tasks.check_selinux_status()

mask_str = validate_mask()
if mask_str:
print("Unexpected system mask: %s, expected 0022" % mask_str)
if installer.interactive:
if not user_input("Do you want to continue anyway?", True):
raise ScriptError(
"Unexpected system mask: %s" % mask_str)
else:
raise ScriptError("Unexpected system mask: %s" % mask_str)

if options.master_password:
msg = ("WARNING:\noption '-P/--master-password' is deprecated. "
"KDC master password of sufficient strength is autogenerated "
Expand Down
8 changes: 7 additions & 1 deletion ipaserver/install/server/replicainstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
installutils, kra, krbinstance,
ntpinstance, otpdinstance, custodiainstance, service)
from ipaserver.install.installutils import (
create_replica_config, ReplicaConfig, load_pkcs12, is_ipa_configured)
create_replica_config, ReplicaConfig, load_pkcs12, is_ipa_configured,
validate_mask)
from ipaserver.install.replication import (
ReplicationManager, replica_conn_check)
import SSSDConfig
Expand Down Expand Up @@ -575,6 +576,11 @@ def common_check(no_ntp):
tasks.check_ipv6_stack_enabled()
tasks.check_selinux_status()

mask_str = validate_mask()
if mask_str:
raise ScriptError(
"Unexpected system mask: %s, expected 0022" % mask_str)

if is_ipa_configured():
raise ScriptError(
"IPA server is already configured on this system.\n"
Expand Down
46 changes: 46 additions & 0 deletions ipatests/test_integration/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,49 @@ def test_reserved_ip_as_forwarder(self):
exp_str = ("Invalid IP Address 0.0.0.0: cannot use IANA reserved "
"IP address 0.0.0.0")
assert exp_str in cmd.stdout_text


class TestMaskInstall(IntegrationTest):
""" Test master and replica installation with wrong mask

This test checks that master/replica installation fails (expectedly) if
mask > 022.

related ticket: https://pagure.io/freeipa/issue/7193
"""

num_replicas = 0

@classmethod
def install(cls, mh):
super(TestMaskInstall, cls).install(mh)
cls.bashrc_file = cls.master.get_file_contents('/root/.bashrc')

def test_install_master(self):
self.master.run_command('echo "umask 0027" >> /root/.bashrc')
result = self.master.run_command(['umask'])
assert '0027' in result.stdout_text

cmd = tasks.install_master(
self.master, setup_dns=False, raiseonerr=False
)
exp_str = ("Unexpected system mask")
assert (exp_str in cmd.stderr_text and cmd.returncode != 0)

def test_install_replica(self):
result = self.master.run_command(['umask'])
assert '0027' in result.stdout_text

cmd = self.master.run_command([
'ipa-replica-install', '-w', self.master.config.admin_password,
'-n', self.master.domain.name, '-r', self.master.domain.realm,
'--server', 'dummy_master.%s' % self.master.domain.name,
'-U'], raiseonerr=False
)
exp_str = ("Unexpected system mask")
assert (exp_str in cmd.stderr_text and cmd.returncode != 0)

def test_files_ownership_and_permission_teardown(self):
""" Method to restore the default bashrc contents"""
if self.bashrc_file is not None:
self.master.put_file_contents('/root/.bashrc', self.bashrc_file)