Major Hayden f92f29d134 Set permissions on sshd host keys [+Docs]
This patch adds tasks to set permissions on sshd public/private host key
files.

Documentation is included.

Implements: blueprint security-rhel7-stig
Change-Id: I45480882035a4682a2ef5036a1663eddccc953c5
2016-12-09 13:44:24 +00:00

110 lines
2.8 KiB
YAML

---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Adding additional sshd configuration options is usually easy, but if a
# configuration file ends with certain configurations, like a "Match" stanza,
# we need a blank line to separate those configurations from the ones that
# are added by the security role. For that reason, we check for the existence
# of a marker line here and add a marker line to the file if it doesn't exist.
- name: Find first 'Match' line in sshd_config (if it exists)
shell: "grep '^Match' /etc/ssh/sshd_config || echo 'EOF'"
register: sshd_match_check
changed_when: False
check_mode: no
tags:
- always
- sshd
- name: Copy login warning banner
copy:
src: login_banner.txt
dest: "{{ security_sshd_banner_file }}"
owner: root
group: root
tags:
- high
- sshd
- RHEL-07-010040
- RHEL-07-040170
- name: Adjust ssh server configuration based on STIG requirements
blockinfile:
dest: /etc/ssh/sshd_config
state: present
marker: "# {mark} MANAGED BY OPENSTACK-ANSIBLE-SECURITY"
insertbefore: "{{ sshd_match_check.stdout_lines[0] }}"
validate: '/usr/sbin/sshd -T -f %s'
block: "{{ lookup('template', 'sshd_config_block.j2') }}"
notify:
- restart ssh
tags:
- high
- sshd
- RHEL-07-010270
- RHEL-07-010440
- RHEL-07-010441
- RHEL-07-010442
- RHEL-07-040110
- RHEL-07-040170
- RHEL-07-040190
- RHEL-07-040191
- RHEL-07-040301
- RHEL-07-040310
- RHEL-07-040332
- RHEL-07-040334
- RHEL-07-040334
- RHEL-07-040540
- RHEL-07-040590
- RHEL-07-040620
- RHEL-07-040690
- RHEL-07-040700
- RHEL-07-040670
- RHEL-07-040680
- name: Ensure sshd is running and enabled
service:
name: "{{ ssh_service }}"
state: started
enabled: yes
when:
- security_enable_sshd | bool
tags:
- medium
- sshd
- RHEL-07-040261
- name: Public host key files must have mode 0644 or less
file:
path: "{{ item }}"
mode: "u-xX,g-wxs,o-wxt"
with_fileglob:
- /etc/ssh/*.pub
tags:
- medium
- sshd
- RHEL-07-040640
- name: Private host key files must have mode 0600 or less
file:
path: "{{ item }}"
mode: "u-xX,g-rwxs,o-rwxt"
with_fileglob:
- /etc/ssh/*_key
tags:
- medium
- sshd
- RHEL-07-040650