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 for MITRE issue #13 #17

Closed
wants to merge 13 commits into from
Closed
4 changes: 2 additions & 2 deletions .github/workflows/update-profile-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
ruby-version: "3.1"
- run: bundle install
- name: Regenerate current `profile.json`
run: |
Expand All @@ -30,4 +30,4 @@ jobs:
with:
commit_user_name: GitHub Actions
commit_user_email: [email protected]
commit_message: 'Updating profile.json in the repository'
commit_message: "Updating profile.json in the repository"
20 changes: 12 additions & 8 deletions .github/workflows/verify-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: EC2 Testing Matrix

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
Expand All @@ -12,10 +12,11 @@ jobs:
env:
CHEF_LICENSE: accept-silent
KITCHEN_LOCAL_YAML: kitchen.ec2.yml
SUDO_PASSWD: ${{ secrets.SAF_SUDO_PASSWORD }}
LC_ALL: "en_US.UTF-8"
strategy:
matrix:
suite: ['vanilla', 'hardened']
suite: ["vanilla", "hardened"]
fail-fast: false
steps:
- name: add needed packages
Expand All @@ -36,7 +37,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
ruby-version: "3.1"
- name: Disable ri and rdoc
run: 'echo "gem: --no-ri --no-rdoc" >> ~/.gemrc'
- run: bundle install
Expand All @@ -46,16 +47,19 @@ jobs:
- name: Lint the Inspec profile
run: bundle exec inspec check .
- name: Run kitchen test
run: bundle exec kitchen test --destroy=always ${{ matrix.suite }}-rhel-7 || true
run: bundle exec kitchen test --destroy=always ${{ matrix.suite }}-amazon2 || true
- name: Show the 'spec/results'
run: |
ls -alh ./spec/results
- name: Save Test Result JSON
uses: actions/upload-artifact@v3
with:
path: spec/results/
- name: Display our ${{ matrix.suite }} results summary
path: spec/results/*.json
- name: Display our Amazon 2 ${{ matrix.suite }} Results Summary
uses: mitre/saf_action@v1
with:
command_string: 'view summary -i spec/results/ec2_rhel-7_${{ matrix.suite }}.json'
command_string: "view summary -i spec/results/ec2_amazon2_${{ matrix.suite }}.json"
- name: Ensure the scan meets our ${{ matrix.suite }} results threshold
uses: mitre/saf_action@v1
with:
command_string: 'validate threshold -i spec/results/ec2_rhel-7_${{ matrix.suite }}.json -F ${{ matrix.suite }}.threshold.yml'
command_string: "validate threshold -i spec/results/ec2_amazon2_${{ matrix.suite }}.json -F ${{ matrix.suite }}.threshold.yml"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Vagrant Testing Matrix

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
Expand All @@ -13,9 +13,10 @@ jobs:
env:
CHEF_LICENSE: accept-silent
KITCHEN_LOCAL_YAML: kitchen.vagrant.yml
SUDO_PASSWD: ${{ secrets.SAF_SUDO_PASSWORD }}
strategy:
matrix:
suite: ['vanilla', 'hardened']
suite: ["vanilla", "hardened"]
fail-fast: false
steps:
- name: Add jq for output formatting
Expand All @@ -25,7 +26,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
ruby-version: "3.1"
- name: Disable ri and rdoc
run: 'echo "gem: --no-ri --no-rdoc" >> ~/.gemrc'
- name: ensure bundler up-to-date
Expand All @@ -37,16 +38,19 @@ jobs:
- name: Lint the Inspec profile
run: bundle exec inspec check .
- name: Run kitchen test
run: bundle exec kitchen test --destroy=always ${{ matrix.suite }}-rhel-7 || true
run: bundle exec kitchen test --destroy=always ${{ matrix.suite }}-amazon2 || true
- name: Show the 'spec/results'
run: |
ls -alh ./spec/results
- name: Save Test Result JSON
uses: actions/upload-artifact@v3
with:
path: spec/results/
path: spec/results/*.json
- name: Display our ${{ matrix.suite }} results summary
uses: mitre/saf_action@v1
with:
command_string: 'view summary -i spec/results/rhel-7_${{ matrix.suite }}.json'
command_string: "view summary -i spec/results/vagrant_amazon2_${{ matrix.suite }}.json"
- name: Ensure the scan meets our ${{ matrix.suite }} results threshold
uses: mitre/saf_action@v1
with:
command_string: 'validate threshold -i spec/results/rhel-7_${{ matrix.suite }}.json -F ${{ matrix.suite }}.threshold.yml'
command_string: "validate threshold -i spec/results/vagrant_amazon2_${{ matrix.suite }}.json -F ${{ matrix.suite }}.threshold.yml"
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'

gem 'inspec-bin'
gem 'inspec', '>=4.26'
gem 'inspec', '5.22.36'
gem 'kitchen-ec2'
gem 'kitchen-inspec'
gem 'kitchen-ansible'
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ __For the best security of the runner, always install on the runner the _latest

Latest versions and installation options are available at the [InSpec](http://inspec.io/) site.

### Sudo Password

The hardening configures the system to require a sudo password. You should set the sudo password you want via an Environment Variable as `SUDO_PASSWD` to test-kitchen can set it correctly.

The default is set to 'P@ssw0rd!' ***WHICH YOU NEED TO UPDATE***.

The GitHub Actions Set the sudo password they use via a shared secret.

## Tailoring to Your Environment

The following inputs may be configured in an inputs ".yml" file for the profile to run correctly for your specific environment. More information about InSpec inputs can be found in the [InSpec Profile Documentation](https://www.inspec.io/docs/reference/profiles/).
Expand Down
2 changes: 1 addition & 1 deletion controls/AMZL-02-710343.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end
else
describe command("grep -ir 'timestamp_timeout' /etc/sudoers /etc/sudoers.d").stdout.strip do
it { should match /^[^#].*Defaults timestamp_timeout=\d/ }
it { should match /^[^#].*Defaults\s*timestamp_timeout=\d/ }
it { should_not match /\n/ }
end
end
Expand Down
3 changes: 1 addition & 2 deletions controls/AMZL-02-740320.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
# convert it to an integer using to_i it will convert it to 0 and pass the
# <= client_alive_interval check. However, the control as a whole will still fail.
describe sshd_config do
its('ClientAliveInterval') { should be_between(1, input('client_alive_interval')) }
its('ClientAliveInterval') { should_not eq nil }
its('ClientAliveInterval.to_i') { should be_between(1, input('client_alive_interval')) }
end
end
end
1 change: 1 addition & 0 deletions fixed-audit-file-reload.json

Large diffs are not rendered by default.

34 changes: 14 additions & 20 deletions kitchen.ec2.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
---
platforms:
- name: rhel-7

driver:
name: ec2
aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] %>
user_data: ./user_data.sh
tags:
POC: <%= ENV['POC_TAG'] %>
security_group_ids: <%= ENV['SECURITY_GROUP_IDS'] %>
region: <%= ENV['AWS_REGION'] %>
subnet_id: <%= ENV['SUBNET_ID'] %>
instance_type: t2.large
#aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] %>
#user_data: ./user_data.sh
#tags:
# POC: <%= ENV['POC_TAG'] %>
# security_group_ids: <%= ENV['SECURITY_GROUP_IDS'] %>
# region: <%= ENV['AWS_REGION'] %>
# subnet_id: <%= ENV['SUBNET_ID'] %>
# instance_type: t2.large
associate_public_ip: true

transport:
name: ssh
username: <%= ENV['AWS_EC2_USER'] %>
ssh_key: <%= ENV['AWS_EC2_SSH_KEY'] %>
username: "ec2-user"
# ssh_key: <%= ENV['AWS_EC2_SSH_KEY'] %>
connection_timeout: 10
connection_retries: 5

Expand All @@ -31,17 +28,14 @@ verifier:
lifecycle:
post_create:
- remote: |
sudo yum -y install python3-pip
sudo python3 -m pip install --upgrade pip
sudo yum -y install git python3-pip
sudo python3 -m pip install --user --upgrade pip

pre_converge:
- remote: |
echo 'updating the ec2-user password'
sudo chpasswd <<<"ec2-user:<%= ENV['SUDO_PASSWD'] || 'P@ssw0rd!' %>"
echo "NOTICE - Updating the ec2-user to keep sudo working"
sudo chage -d $(( $( date +%s ) / 86400 )) ec2-user
echo "NOTICE - updating ec2-user sudo config"
sudo chmod 600 /etc/sudoers && sudo sed -i'' "/ec2-user/d" /etc/sudoers && sudo chmod 400 /etc/sudoers

transport:
name: ssh
#https://github.com/neillturner/kitchen-ansible/issues/295
max_ssh_sessions: 2
20 changes: 15 additions & 5 deletions kitchen.vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@ driver:
clipboard: "disabled"

platforms:
- name: rhel-7

- name: amazon2
driver:
box: generic/centos7

verifier:
input_files:
- ec2.inputs.yml
reporter:
- cli
- json:spec/results/vagrant_%{platform}_%{suite}.json

lifecycle:
post_create:
- remote: |
sudo yum -y install git python3-pip
sudo python3 -m pip install --user --upgrade pip
pre_converge:
- remote: |
echo "NOTICE - Installing needed packages"
sudo yum install -y bc bind-utils redhat-lsb-core vim
echo 'updating the ec2-user password'
sudo chpasswd <<<"ec2-user:<%= ENV['SUDO_PASSWD'] || 'P@ssw0rd!' %>"
echo "NOTICE - Updating the vagrant user to keep sudo working"
sudo chage -d $(( $( date +%s ) / 86400 )) vagrant
echo "NOTICE - Updating root passwd"
echo 'password' | sudo passwd --stdin root
echo "NOTICE - updating vagrant sudo config"
sudo chmod 600 /etc/sudoers && sudo sed -i'' "/vagrant/d" /etc/sudoers && sudo chmod 400 /etc/sudoers
sudo chmod 600 /etc/sudoers && sudo sed -i'' "/vagrant/d" /etc/sudoers && sudo chmod 400 /etc/sudoers
21 changes: 16 additions & 5 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ verifier:
reporter:
- cli
- json:spec/results/%{platform}_%{suite}.json
input_files:
- ec2.inputs.yml
inspec_tests:
- name: RedHat Enterprise Linux 7 STIG
- name: Amazon Linux 2 STIG
path: .
<% if ENV['INSPEC_CONTROL'] %>
controls:
- "<%= ENV['INSPEC_CONTROL'] %>"
<% end %>
load_plugins: true

provisioner:
Expand All @@ -30,13 +36,18 @@ provisioner:
- ANSIBLE_REMOTE_TEMP=$HOME/.ansible/tmp

platforms:
- name: rhel-7
- name: amazon2
# - name: amazon2023

suites:
- name: vanilla
provisioner:
playbook: spec/ansible/roles/ansible-role-rhel-vanilla.yml

playbook: spec/ansible/roles/ansible-role-al2-vanilla.yml
verifier:
sudo_password: <%= ENV['SUDO_PASSWD'] || 'P@ssw0rd!' %>

- name: hardened
provisioner:
playbook: spec/ansible/roles/ansible-role-rhel-hardened.yml
playbook: spec/ansible/roles/ansible-role-al2-hardened.yml
verifier:
sudo_password: <%= ENV['SUDO_PASSWD'] || 'P@ssw0rd!' %>
23 changes: 23 additions & 0 deletions spec/ansible/roles/ansible-role-al2-hardened.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- hosts:
- localhost
roles:
- roles/ansible-role-al2-vanilla
- roles/al2STIG
serial: 50
become: yes
vars:
# al2stig_bootloader_password_hash: 'changethispassword'
# al2stig_using_password_auth: false
DISA_STIG_AMZL_02_020022: false
tasks:
- name: Call the handler to reload audit rules
debug:
msg: 'reload audit rules'
changed_when: true
notify: reload audit rules # Notify the handler

handlers:
- name: reload audit rules
become: yes
shell: "augenrules --load"
7 changes: 7 additions & 0 deletions spec/ansible/roles/ansible-role-al2-vanilla.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts:
- localhost
roles:
- roles/ansible-role-al2-vanilla
serial: 50
become: yes
3 changes: 3 additions & 0 deletions spec/ansible/roles/ansible-role-al2-vanilla/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# defaults file for ansible-role-al2-stig-vanilla
ansible_python_interpreter: /usr/bin/python3
12 changes: 12 additions & 0 deletions spec/ansible/roles/ansible-role-al2-vanilla/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
galaxy_info:
author: Sai Pavan Marlakunta
description: Ansible Role for AL2 Vanilla install
company: MITRE
license: license Apache-2.0

min_ansible_version: "2.1"

platforms:
- name: Amazon Linux
versions:
- "2"
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- name: Upgrade all packages
yum:
name: '*'
ansible.builtin.yum:
name: "*"
state: latest
- name: Install required packages via yum
yum:
ansible.builtin.yum:
name:
- vim
- bc
- git
state: latest

- name: Install required packages via pip
pip:
ansible.builtin.pip:
name:
- jmespath
state: latest
tags:
- pip-task

10 changes: 10 additions & 0 deletions spec/ansible/roles/ansible-role-al2-vanilla/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Include sub-tasks
ansible.builtin.include_tasks: "{{ item }}"
with_first_found:
- files:
- _packages.yml
- _config.yml
skip: true

# https://stackoverflow.com/questions/28119521/ansible-include-task-only-if-file-exists
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
- hosts: localhost
remote_user: root
roles:
- ansible-role-rhel-stig-vanilla
- ansible-role-al2-stig-vanilla
Loading