Commit Graph

426 Commits

Author SHA1 Message Date
Dmitriy Rabotyagov db284ddf93 Use replace module instead of lineinfile for disabling dynamic motd
Lineinfile module can manage only single occurance of line in the file,
while pam.d/sshd contains multiple occurances of pam_motd which
results in not disabling it fully.

In order to properly comment out/uncomment all occurances replace module
should be used instead.

Change-Id: I73babb2431d4fda5aa90d9a1e230c1796449c0fc
2024-01-29 16:26:16 +00:00
Dmitriy Rabotyagov b31cd46c18 Disable dynamic motd message
Right now default cloud images of Ubuntu does contain dynamic MOTD
by default, that takes around extra 0.4 sec for establishing connection.

Disabiling MOTD should improve responsivness of hosts and speedup
ansible execution as well.

With that we're keeping static MOTD that has no impact on connection
speed.

Change-Id: Iaf25f6f444055cefd60dd2e3b4d5579f2a6fcdb1
2023-10-26 11:15:46 +00:00
Dmitriy Rabotyagov db5c6f2d66 Fix linters and metadata
With update of ansible-lint to version >=6.0.0 a lot of new
linters were added, that enabled by default. In order to comply
with linter rules we're applying changes to the role.

With that we also update metdata to reflect current state.

Change-Id: I1920cd05ac5b4d32ad12bce42d9161a568f288b6
2023-07-17 14:25:21 +02:00
Dmitriy Rabotyagov 2c7889852c Remove warn argument for command/shell
Since ansible-core 2.14 you can't use warn as module argument.

Instead, noqa should be used to instruct ansible-lint to
supress alerts.

Change-Id: Ie448fa182db8c1c9f64744ea72f27f285aa64366
2023-06-30 15:05:50 +02:00
Dmitriy Rabotyagov aa1feb4527 Clean out SSH options we managing
With current behaviour we duplicate SSH options and don't care if same
thing is defined anywhere down the line.
With that change we change how options are defined - instead of the
template we use a list of mappings. With that
we can select and remove options that playbook supposed to manage.

With that we also keep playbook idempotency. As side effect we still
can have options duplicated but only if they have exact same value.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-openstack_hosts/+/840353
Change-Id: I140606f7e724fbe2a4f0b03f6a0501da7bdd5964
Closes-Bug: #1958649
2022-05-20 07:53:05 +00:00
Zuul 7626153a08 Merge "Refactor use of include_vars" 2022-01-12 14:23:14 +00:00
Jonathan Rosser 6007645fd7 Refactor use of include_vars
Use a first_found lookup instead of a with_first_found loop so that
the 'paths' parameter can be used.

This ensures that only vars from the role are included, and not vars
from a parent calling role. This can happen when a parent role has
a higher priority vars file available for inclusion than the role
it calls.

Change-Id: I078590020a98f0b5759f3de524753e01bb9c5597
2022-01-12 08:52:34 +00:00
Dmitriy Rabotyagov a82570f1a5 Use pipefail for shell module
It's not safe to run pipes without pipefail, but for some cases we
expect it to fail and working this around. In such case we ignore rule

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-tests/+/784751
Change-Id: I79a630ebe8ff54bc9f4600e1f3c0fda653cc4b71
2022-01-04 13:07:09 +00:00
Zuul 4ba0de970a Merge "Explicitly create clamav socket directory" 2021-11-03 12:57:39 +00:00
Dmitriy Rabotyagov 9d6a927d8c Explicitly create clamav socket directory
While most our supported distributions does create LocalSocket on their
own, it's not always the case and shouldn't be trusted that much.

Change-Id: I56851f56aa85108a4898ef99c48ac77c898ccb69
Closes-Bug: #1944564
2021-10-20 15:27:21 +03:00
Jonathan Rosser 480dd9d866 Remove references to unsupported operating systems
All references to Gentoo, SUSE, Debian stretch and Centos-7  are removed.
Conditional tasks, ternary operators and variables are simplified where possible
OS specific variables files are generalised where possible
Change-Id: Id3136a5eed068e317aa1a7b33a1149629dc76d77
2021-06-11 14:14:20 +00:00
codejubilee 9b3ea39df4 Added pam_auth_password to nullok check
Change-Id: I692241ce21e8bd8912b8d1ff5a261ae10d7da1f2
2021-04-12 22:39:31 +00:00
Dmitriy Rabotyagov e4b55822cf Extend timeout for RPM verification
For systems with many packages deployed or heavy loaded environments
rpm verification takes the way more time then 5 minutes ending up in
corrupted database of the rpm packages. So we set limit to 1 hour
and extending amount of retries to wait for result to match the async
timeout

Change-Id: I30d29630214914bea99fc7fd66afa3218705d733
Closes-Bug: #1921292
2021-03-25 09:47:35 +02:00
Jonathan Rosser b9a9310d7c Use ansible_facts[] instead of fact variables
See https://github.com/ansible/ansible/issues/73654

Change-Id: I3dc2486a0666367d673b23403f2510c94c40eaf4
2021-03-10 16:54:58 +00:00
Zuul 087919c425 Merge "Make possible to avoid aide installation" 2021-02-12 10:33:08 +00:00
Jonathan Rosser b7b945b21e Exclude system directories (/sys, /proc, /dev) from the shosts file search
This halves the number of files examined by the find module on an ubuntu
focal system and nearly halves the runtime of the task on a ceph backed
VM.

Change-Id: I862351badc70fa091bebf55dd2910cccfa731ca2
2021-02-03 11:54:52 +00:00
Dmitriy Rabotyagov 180fc448eb Make possible to avoid aide installation
This patch adds variable `security_rhel7_enable_aide`. When it's False,
all AIDE related tasks would be ommited.

Change-Id: I64af348d9f49922ab51d8cd348d987df4263faa1
2021-02-02 14:12:10 +00:00
Jonathan Rosser c6703cd5e5 Fix linter errors
Work around the mutually incompatible W503 and W504.

Change-Id: I45d0ca8a911d9cf1af2df52a1cf911db817b13b3
2021-02-02 16:11:03 +02:00
Dmitriy Rabotyagov e1d8ec2211 Fix role to work with Jinja 2.7
By default Centos is shipped with Jinja 2.7.2 which do not have `in`
test. So we replace that logic with rejecting absent packages
and suggest that the rest of statuses are valid for
package installation.

Change-Id: Ibeb3aba5cccddc1af1f968c57bdc0be75e7f22d9
2020-04-29 07:32:44 +00:00
Ghanshyam Mann 83ac8bfd6d [ussuri][goal] Updates for python 2.7 drop
OpenStack is dropping the py2.7 support in ussuri cycle.

openstack-ansible repos only need updates on requirements
and tox file.

Complete discussion & schedule can be found in
- http://lists.openstack.org/pipermail/openstack-discuss/2019-October/010142.html
- https://etherpad.openstack.org/p/drop-python2-support

Ussuri Communtiy-wide goal:
https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html

Change-Id: Idf700e627b5c88059762690aec6dc3e3a345a39f
2020-04-03 21:18:52 +03:00
Dmitriy Rabotyagov 2093f503a6 Fix ignoring of packages in 'latest' state
Change-Id: I019ed9d87435a1ab6e0b7ae8624d85afd95db3ae
2019-12-19 14:10:26 +02:00
Zuul 87415a319b Merge "Splits STIG yum add/removes" 2019-11-21 11:53:49 +00:00
Khaled Elkhawaga ab430cfbff Replace deprecated apt parameter
Replace the deprecated "state: installed" parameter with "state: present" as
it's no longer supported in Ansible 2.9

Change-Id: I78c8595228f1aabded6cd23159c2a889738f3288
Signed-off-by: Khaled Elkhawaga <k.elkhawaga@gmail.com>
2019-11-20 19:59:43 +01:00
Jeff Albert 8db1a33cbf Splits STIG yum add/removes
In order to prevent RPM database corruption on the target hosts, this
change splits the STIG yum add/remove tasks into two separate plays.

Change-Id: I68751339d5b4cbfb61b8e3cf4ffbfeb47ea5fd76
Closes-Bug: #1851954
2019-11-09 11:35:42 -08:00
Bernd Müller 3b95e7fc03 changed disable dccp conf for preventing kernel messages
dccp_diag: Unknown symbol dccp_hashinfo (err 0)

https://access.redhat.com/solutions/2321691

$ cat /etc/modprobe.d/ansible-hardening-disable-dccp.conf
install dccp /bin/true
install dccp_diag /bin/true

Change-Id: I7441d71c52bdb4f215e1976d15e9282d9cd75139
Signed-off-by: Bernd Müller <mueller@b1-systems.de>
2019-10-21 13:18:03 +02:00
Logan V 00ad3500c8 Fix conditional cast to bool
While running the hardening role, I found that a small VM would
regularly crash ansible on the chrony configuration templating
task with "A worker was found in a dead state!". An ansible bug[0]
shows that this can be caused by jinja templating that is not casted
to the correct type.

After verifying the crash was reproducible 3-4 times in a row, this
crash stopped occuring once I started casting this variable to a bool.

I don't know if it is coincidence but it can't hurt to cast this
conditional regardless.

[0] https://github.com/ansible/ansible/issues/32554#issuecomment-382360908

Change-Id: Ie34de1808c807fd31099cc7d3d7b140ccfab64df
2019-03-15 23:01:45 -05:00
Jesse Pretorius f381cc02af Switch to using import_tasks for static inclusion
Using dynamic inclusion (include_tasks) should only be done
if the tasks to include are based on a conditional and there
is no expectation for the tag on the include task to be applied
to all included tasks. Using include_tasks for static inclusion
dramatically raises memory consumption. Using include_tasks also
breaks the ability to use a tag applied to the include.

In this patch we fix all inclusions to ensure that they are set
properly to dynamic or static inclusions where necessary.

We also remove the unnecessary leading whitespace in the main
task file.

Change-Id: Idff86d4a90d3309f0e9ae3b9f0559b37e25dc26f
Closes-Bug: #1800169
2019-01-08 11:54:21 +00:00
Mohammed Naser b792753b34 cleanup: use updated conditionals
This role made use of conditionals that still used filters, this
patch removes them all and switches them to the new system.

Change-Id: I7c68f4e5f7248aedd3cdae734aac6d97a8ce058b
2019-01-07 12:56:12 -05:00
Markos Chandras 8cef84567b Revert "file_perms: Skip rpm verification step for Leap 15"
This reverts commit 75e8b0f02a.

The openSUSE bug has been fixed so this workaround is not needed
anymore.

Change-Id: I7d8a93332d0ec925d97b64fc1052b1c3d621e066
2018-10-18 08:50:54 +01:00
Markos Chandras 75e8b0f02a file_perms: Skip rpm verification step for Leap 15
openSUSE Leap 15 has a bug in the sudo package and this test always
fails. As such, we need to skip it until the upstream bug is fixed.

Change-Id: Ifa6baa50d0e0c2e2cabba39ba101ef943f14d882
Link: https://bugzilla.suse.com/show_bug.cgi?id=1097643
2018-09-11 16:37:28 +01:00
Kevin Carter 111f48b2f6
Correct issue with ansible hardening and systemd
The systemd command does not have a stable api and can return different
codes when executed. This change converts the task to query the target
unit and disable it if it exists to a single systemd task using the
ansible module.

Closes-Bug: #1787048
Change-Id: I74c43839cd7d3a8620a0fb8e405fbc3f6a0f44d0
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-08-21 11:32:23 -05:00
Kevin Carter 1cafaf8cce Add option to skip sudoers NOPASSWD check
This change adds the option `security_sudoers_nopasswd_check_enable`
when running check "V-71947". This change allows users to skip this
check via ansible extra variable instead of having to skip tags. While
this change has a functional benifit in some environments, it is being
done with the primary intention of providing a better experience to
deploying running clouds where services like cloud-init may be present.

Change-Id: I0d0c95534ace0b00fa64c2f243ad91ce5844d85a
Closes-Bug: #1741225
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-07-31 03:18:27 +00:00
ZhijunWei ca8114438c Delete the unnecessary space
Change-Id: I776b0ac8b69ec1fdb0d7ef6402cfff52cf6b29fd
2018-07-17 16:54:03 -04:00
Jean-Philippe Evrard f07aba1662 Fix usage of "|" for tests
With the more recent versions of ansible, we should now use
"is" instead of the "|" sign for the tests.

This should fix it.

Change-Id: I8d78a2b4ba2a8746cbb809e4f8c9370abe211350
2018-07-12 16:58:21 +02:00
Zuul f22609a524 Merge "Ensure that comments are not counted" 2018-05-09 11:29:45 +00:00
Mohammed Naser 6cae2c1e46 Ensure that comments are not counted
With the previous grep, it was possible that any commented nameserver
entries would be counted.  This patch fixes that.

Change-Id: I9925cb9a71c1b58dcf12f70d8ce0872386732f06
Closes-Bug: #1768725
2018-05-08 12:19:02 -04:00
Christian Zunker 3c55999ce4 Use absolute path for aide binary in cronjob
/sbin is not included in the path for this cronjob, so use absolute path.

Change-Id: Idc11d83858a585041f7df2fe1657d20fd620a248
Closes-Bug: 1768726
2018-05-03 07:31:49 +02:00
Zuul 27965b5f02 Merge "Simplify SELinux check" 2018-03-15 15:02:32 +00:00
Zuul dc798c7979 Merge "Add check to ClamAV task to prevent simeltaneous content updates" 2018-03-08 00:42:32 +00:00
Major Hayden a10fae4fe1 Replace Fedora 26 with 27
Now that infra is moving from Fedora 26 to 27, we need to update
the role to reflect the changing support for Fedora releases.

Change-Id: Icce8fd7ee2f8c54e6eb33beec7af96c4d1d375d6
Signed-off-by: Major Hayden <major@mhtx.net>
2018-03-07 13:30:45 +00:00
Russell Tweed f1a52aad91 Add check to ClamAV task to prevent simeltaneous content updates
Check to see if a freshclam process is already running before kicking off another; attempting a second update will fail if one is already in progress.

Change-Id: Id5ab344c2408ba64c58612bab33c2ee98aeb97d5
Closes-Bug: 1730998
2018-03-07 09:36:37 +00:00
Major Hayden fcad8c23f5
Simplify SELinux check
The ansible_selinux variable is always populated with a 'status'
property, even if SELinux is not installed or configured. This
patch simplifies the check.

Change-Id: Ifddc385fc292ddb7d6c2758b199401c45de0f0f2
Signed-off-by: Major Hayden <major@mhtx.net>
2018-03-06 13:18:05 -06:00
Major Hayden 295ef13395
Move aide db when needed
The task that moves the aide database checks to see whether aide
was just initialized, but that task has a "changed_when: false" to
help with idempotency. That means that the database never gets
moved into place.

This patch changes the task to check whether the aide
initialization was skipped or not. If it wasn't skipped, then the
database will be moved.

Closes-Bug: 1745675
Change-Id: I2f186274cbff4b38706603a51429557057843e4e
2018-02-06 12:39:14 -06:00
Major Hayden 74c904247f
Use import/include_tasks
This patch uses the new import_tasks/include_tasks modules from
Ansible 2.1+ and removes some deprecation warnings from the
beginning of playbook runs.

Change-Id: I17d0a9bcb9964d666e140b832b6f2a26ff948d41
2018-01-18 10:03:25 -06:00
Markos Chandras 65dce4045a tasks: auth: Pass --unrestricted to Linux Grub2 entries
The password protection aims to only prevent users from editing the
menu entries not from booting the system altogether. Fedora is patching
the 10_linux file to use '--unrestricted' so all users can boot the
system. As such, we apply a similar patch to the rest of the distros.

Change-Id: I1390a330ea1f0b48e71fdcb548614d5582fffbd4
Link: http://pkgs.fedoraproject.org/cgit/rpms/grub2.git/tree/0109-Don-t-require-a-password-to-boot-entries-generated-b.patch
Link: https://www.gnu.org/software/grub/manual/grub/html_node/Authentication-and-authorisation.html#Authentication-and-authorisation
Closes-Bug: 1735709
2018-01-10 16:50:19 +00:00
Zuul 04365d3ec1 Merge "tasks: Add missing tags for async tasks" 2017-12-16 10:41:27 +00:00
Major Hayden c8a59a1c9a Remove old /etc/profile config block
When the openstack-ansible-security role became ansible-hardening,
a new config block was added to `/etc/profile` without removing
the original one with the openstack-ansible-security markers. This
causes errors on the command prompt since `TMOUT` is defined twice.

This patch removes the old config block using blockinfile.

Closes-Bug: 1736702
Change-Id: I2768182f5dde3368028a1a25af69db6ac7a75d9b
2017-12-15 20:05:02 +00:00
Markos Chandras d6ead42b8f tasks: Add missing tags for async tasks
When running the role using a specific tag (eg -t auth), some tasks
try to check the status of the async ones and they fail because the
async task was never executed due to missing the 'always' tag. We can
fix that by adding the missing tags to the async tasks.

For example,

TASK [ansible-hardening : Remove .shosts or shosts.equiv files]
******************************************************************************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "'job_result' is undefined"}

So we add the appropriate tags to the async tasks.

Change-Id: I24a23fb485f2269ae6f627533b3a725f6699d230
2017-12-13 12:55:43 +00:00
Markos Chandras a0810a9ca1 tasks: auth: Use standard Grub2 authentication mechanism
GRUB_PASSWORD is not understood by vanilla grub2 installations. As such,
we can use the recommended method by setting the superusers
environment variable and using the password_pbkdf2 command

Change-Id: I07df3decf5e70b85a7dc48b8a8d1ca86e8878d09
Link: https://www.gnu.org/software/grub/manual/grub/grub.html#Security
Closes-Bug: 1735709
2017-12-13 12:38:30 +00:00
Zuul c54fc86bfd Merge "Add scaffolding for contrib tasks" 2017-12-01 14:16:46 +00:00