This repository was archived by the owner on Dec 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 198
Dependency flag #177
Merged
Merged
Dependency flag #177
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
59a9c62
added proper dependency support
jcheroske 5ef2d87
fixing dependencies
jcheroske 86ee679
fixing dependencies
jcheroske f6f928f
fixing dependencies
jcheroske 75f912c
added dependency flag
jcheroske 54f689f
added dependency flag
jcheroske 1258f4f
added dependency flag
jcheroske e3575e5
renamed main_2 -> hardening, added default var
jcheroske b4014e6
Merge branch 'master' of github.com:dev-sec/ansible-ssh-hardening
jcheroske File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- name: restart sshd | ||
service: name={{ sshd_service_name }} state=restarted | ||
when: "(ssh_server_enabled|bool)" | ||
become: yes | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,4 @@ | ||
--- | ||
- name: Set OS dependent variables | ||
include_vars: '{{ item }}' | ||
with_first_found: | ||
- '{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml' | ||
- '{{ ansible_distribution }}.yml' | ||
- '{{ ansible_os_family }}_{{ ansible_distribution_major_version }}.yml' | ||
- '{{ ansible_os_family }}.yml' | ||
|
||
- name: get openssh-version | ||
shell: ssh -V 2>&1 | sed -r 's/.*_([0-9]*\.[0-9]).*/\1/g' | ||
args: | ||
executable: /bin/sh | ||
changed_when: false | ||
register: sshd_version | ||
check_mode: no | ||
|
||
- name: include tasks to create crypo-vars | ||
include_tasks: crypto.yml | ||
|
||
- name: create revoked_keys and set permissions to root/600 | ||
template: | ||
src: 'revoked_keys.j2' | ||
dest: '/etc/ssh/revoked_keys' | ||
mode: '0600' | ||
owner: '{{ ssh_owner }}' | ||
group: '{{ ssh_group }}' | ||
notify: restart sshd | ||
when: ssh_server_hardening | ||
|
||
- name: create sshd_config and set permissions to root/600 | ||
template: | ||
src: 'opensshd.conf.j2' | ||
dest: '/etc/ssh/sshd_config' | ||
mode: '0600' | ||
owner: '{{ ssh_owner }}' | ||
group: '{{ ssh_group }}' | ||
validate: '/usr/sbin/sshd -T -f %s' | ||
notify: restart sshd | ||
when: ssh_server_hardening | ||
|
||
- name: create ssh_config and set permissions to root/644 | ||
template: | ||
src: 'openssh.conf.j2' | ||
dest: '/etc/ssh/ssh_config' | ||
mode: '0644' | ||
owner: '{{ ssh_owner }}' | ||
group: '{{ ssh_group }}' | ||
when: ssh_client_hardening | ||
|
||
- name: Check if {{ sshd_moduli_file }} contains weak DH parameters | ||
shell: awk '$5 < {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }} | ||
register: sshd_register_moduli | ||
changed_when: false | ||
check_mode: no | ||
|
||
- name: remove all small primes | ||
shell: awk '$5 >= {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }} > {{ sshd_moduli_file }}.new ; | ||
[ -r {{ sshd_moduli_file }}.new -a -s {{ sshd_moduli_file }}.new ] && mv {{ sshd_moduli_file }}.new {{ sshd_moduli_file }} || true | ||
notify: restart sshd | ||
when: sshd_register_moduli.stdout | ||
|
||
- name: include tasks to setup ca keys and principals | ||
include_tasks: ca_keys_and_principals.yml | ||
when: ssh_trusted_user_ca_keys_file != '' | ||
|
||
- name: include tasks to setup 2FA | ||
include_tasks: 2fa.yml | ||
when: | ||
- ssh_use_pam | ||
- ssh_challengeresponseauthentication | ||
- ssh_google_auth | ||
|
||
- name: test to see if selinux is installed and running | ||
command: getenforce | ||
register: sestatus | ||
failed_when: false | ||
changed_when: false | ||
check_mode: no | ||
|
||
- name: include selinux specific tasks | ||
include_tasks: selinux.yml | ||
when: sestatus.rc == 0 | ||
- include_tasks: main_2.yml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you call this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Np |
||
when: ssh_hardening_enabled | default(true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the variable to the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
- name: Set OS dependent variables | ||
include_vars: '{{ item }}' | ||
with_first_found: | ||
- '{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml' | ||
- '{{ ansible_distribution }}.yml' | ||
- '{{ ansible_os_family }}_{{ ansible_distribution_major_version }}.yml' | ||
- '{{ ansible_os_family }}.yml' | ||
|
||
- name: get openssh-version | ||
shell: ssh -V 2>&1 | sed -r 's/.*_([0-9]*\.[0-9]).*/\1/g' | ||
args: | ||
executable: /bin/sh | ||
changed_when: false | ||
register: sshd_version | ||
check_mode: no | ||
|
||
- name: include tasks to create crypo-vars | ||
include_tasks: crypto.yml | ||
|
||
- name: create revoked_keys and set permissions to root/600 | ||
template: | ||
src: 'revoked_keys.j2' | ||
dest: '/etc/ssh/revoked_keys' | ||
mode: '0600' | ||
owner: '{{ ssh_owner }}' | ||
group: '{{ ssh_group }}' | ||
notify: restart sshd | ||
when: ssh_server_hardening | ||
|
||
- name: create sshd_config and set permissions to root/600 | ||
template: | ||
src: 'opensshd.conf.j2' | ||
dest: '/etc/ssh/sshd_config' | ||
mode: '0600' | ||
owner: '{{ ssh_owner }}' | ||
group: '{{ ssh_group }}' | ||
validate: '/usr/sbin/sshd -T -f %s' | ||
notify: restart sshd | ||
when: ssh_server_hardening | ||
|
||
- name: create ssh_config and set permissions to root/644 | ||
template: | ||
src: 'openssh.conf.j2' | ||
dest: '/etc/ssh/ssh_config' | ||
mode: '0644' | ||
owner: '{{ ssh_owner }}' | ||
group: '{{ ssh_group }}' | ||
when: ssh_client_hardening | ||
|
||
- name: Check if {{ sshd_moduli_file }} contains weak DH parameters | ||
shell: awk '$5 < {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }} | ||
register: sshd_register_moduli | ||
changed_when: false | ||
check_mode: no | ||
|
||
- name: remove all small primes | ||
shell: awk '$5 >= {{ sshd_moduli_minimum }}' {{ sshd_moduli_file }} > {{ sshd_moduli_file }}.new ; | ||
[ -r {{ sshd_moduli_file }}.new -a -s {{ sshd_moduli_file }}.new ] && mv {{ sshd_moduli_file }}.new {{ sshd_moduli_file }} || true | ||
notify: restart sshd | ||
when: sshd_register_moduli.stdout | ||
|
||
- name: include tasks to setup ca keys and principals | ||
include_tasks: ca_keys_and_principals.yml | ||
when: ssh_trusted_user_ca_keys_file != '' | ||
|
||
- name: include tasks to setup 2FA | ||
include_tasks: 2fa.yml | ||
when: | ||
- ssh_use_pam | ||
- ssh_challengeresponseauthentication | ||
- ssh_google_auth | ||
|
||
- name: test to see if selinux is installed and running | ||
command: getenforce | ||
register: sestatus | ||
failed_when: false | ||
changed_when: false | ||
check_mode: no | ||
|
||
- name: include selinux specific tasks | ||
include_tasks: selinux.yml | ||
when: sestatus.rc == 0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
become: yes
to the playbook fixes this, so I'd rather not have this here, as mentioned here: #81Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man, this is such a sucky bug. I don't want to run my roles as root, so I don't use
become: yes
at the playbook level. It's supposed to be fixed, so that you can do animport_role
and put thebecome: yes
on that, but it doesn't work correctly. I think it would work, if there were noinclude_role
calls between the import and the calling of the handler, but my implementation uses aninclude
. That's why I put thebecome
on the handler itself. I can take it off, but it means I'm still going to have to fork to get it working for me. Not a huge deal, but not ideal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Let's keep it in for now and see if someone's got a problem with it.