Skip to content

Commit

Permalink
feat(tofs): switch to tofs
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed May 20, 2019
1 parent 7d4a642 commit c05019a
Show file tree
Hide file tree
Showing 26 changed files with 589 additions and 300 deletions.
68 changes: 68 additions & 0 deletions test/integration/ufw/controls/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
control 'UFW configuration' do

title 'Test UFW configuration'

describe directory('/etc/ufw') do
it { should exist }
end

describe file('/etc/ufw/ufw.conf') do
its('content') { should include 'ENABLED=' }
its('content') { should include 'LOGLEVEL=' }
end

describe command('ufw status verbose | grep Status') do
its('exit_status') { should eq 0 }
its('stdout') { should match /active/ }
end

describe command('ufw status verbose | grep Logging') do
its('exit_status') { should eq 0 }
its('stdout') { should match /low/ }
end

describe command('ufw status | grep MySQL') do
its('exit_status') { should eq 0 }
its('stdout') { should match /ALLOW/ }
end

describe command('ufw status | grep Postgresql') do
its('exit_status') { should eq 0 }
its('stdout') { should match /LIMIT/ }
end

describe command('ufw status | grep SSH223') do
its('exit_status') { should eq 0 }
its('stdout') { should match /DENY/ }
end

describe command('ufw status | grep 10.0.0.0') do
its('exit_status') { should eq 0 }
its('stdout') { should match /DENY/ }
end

describe command('ufw status | grep 22/tcp') do
its('exit_status') { should eq 0 }
its('stdout') { should match /LIMIT/ }
end

describe command('ufw status | grep 80/tcp') do
its('exit_status') { should eq 0 }
its('stdout') { should match /DENY/ }
end

describe command('ufw status | grep 443/tcp') do
its('exit_status') { should eq 0 }
its('stdout') { should match /ALLOW/ }
end

describe command('ufw status | grep 10.0.0.1') do
its('exit_status') { should eq 0 }
its('stdout') { should match /DENY/ }
end

describe command('ufw status | grep 10.0.0.2') do
its('exit_status') { should eq 0 }
its('stdout') { should match /DENY/ }
end
end
7 changes: 7 additions & 0 deletions test/integration/ufw/controls/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
control 'UFW package' do
title 'should be installed'

describe package('ufw') do
it { should be_installed }
end
end
71 changes: 0 additions & 71 deletions test/integration/ufw/controls/ufw.rb

This file was deleted.

49 changes: 49 additions & 0 deletions ufw/config/applications.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- set sls_enable_service = tplroot ~ '.service.enable' %}
{%- set sls_reload_service = tplroot ~ '.service.reload' %}
{%- from tplroot ~ "/map.jinja" import ufw with context %}
include:
- {{ sls_package_install }}
- {{ sls_enable_service }}
- {{ sls_reload_service }}
# Applications
{%- for app_name, app_details in ufw.get('applications', {}).items() %}
{%- set from_addr_raw = app_details.get('from_addr', [None]) %}
{%- set from_addrs = [from_addr_raw] if from_addr_raw is string else from_addr_raw %}
{%- for from_addr in from_addrs %}
{%- set deny = app_details.get('deny', None) %}
{%- set limit = app_details.get('limit', None) %}
{%- set method = 'deny' if deny else ('limit' if limit else 'allow') %}
{%- set to_addr = app_details.get('to_addr', None) %}
{%- set comment = app_details.get('comment', None) %}
{%- if from_addr is not none %}
ufw-app-{{method}}-{{app_name}}-{{from_addr}}:
{%- else %}
ufw-app-{{method}}-{{app_name}}:
{%- endif %}
ufw.{{method}}:
- app: '"{{app_name}}"'
{%- if from_addr is not none %}
- from_addr: {{from_addr}}
{%- endif %}
{%- if to_addr is not none %}
- to_addr: {{to_addr}}
{%- endif %}
{%- if comment is not none %}
- comment: '"{{comment}}"'
{%- endif %}
- listen_in:
- cmd: reload-ufw
{%- endfor %}
{%- endfor %}
49 changes: 49 additions & 0 deletions ufw/config/file.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- from tplroot ~ "/map.jinja" import ufw with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
include:
- {{ sls_package_install }}
ufw-default-file-file-managed:
file.managed:
- name: {{ ufw.default_file }}
- user: root
- group: root
- template: jinja
- source: {{ files_switch(['ufw.default.tmpl', 'ufw.default.tmpl.jinja'],
lookup='ufw-default-file-file-managed'
)
}}
- require:
- sls: {{ sls_package_install }}
- context:
ufw_settings: {{ ufw.settings | json }}
ufw-sysctl-file-file-managed:
file.managed:
- name: {{ ufw.sysctl_file }}
- user: root
- group: root
- template: jinja
- source: {{ files_switch(['ufw.sysctl.tmpl', 'ufw.sysctl.tmpl.jinja'],
lookup='ufw-sysctl-file-file-managed'
)
}}
- require:
- sls: {{ sls_package_install }}
- context:
ufw_sysctl: {{ ufw.sysctl | json }}
/etc/ufw/applications.d:
file.recurse:
- user: root
- group: root
- file_mode: 644
- clean: False
- source: salt://ufw/files/applications.d
9 changes: 9 additions & 0 deletions ufw/config/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .file
- .services
- .applications
- .interfaces
- .open
29 changes: 29 additions & 0 deletions ufw/config/interfaces.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- set sls_enable_service = tplroot ~ '.service.enable' %}
{%- set sls_reload_service = tplroot ~ '.service.reload' %}
{%- from tplroot ~ "/map.jinja" import ufw with context %}
include:
- {{ sls_package_install }}
- {{ sls_enable_service }}
- {{ sls_reload_service }}
# Interfaces
{%- for interface_name, interface_details in ufw.get('interfaces', {}).items() %}
{%- set comment = interface_details.get('comment', None) %}
ufw-interface-{{interface_name}}:
ufw.allowed:
- interface: {{interface_name}}
{%- if comment is not none %}
- comment: '"{{comment}}"'
{%- endif %}
- listen_in:
- cmd: reload-ufw
{%- endfor %}
29 changes: 29 additions & 0 deletions ufw/config/open.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- set sls_enable_service = tplroot ~ '.service.enable' %}
{%- set sls_reload_service = tplroot ~ '.service.reload' %}
{%- from tplroot ~ "/map.jinja" import ufw with context %}
include:
- {{ sls_package_install }}
- {{ sls_enable_service }}
- {{ sls_reload_service }}
# Open
{%- for open_addr, open_details in ufw.get('open', {}).items() %}
{%- set comment = open_details.get('comment', None) %}
ufw-open-{{open_addr}}:
ufw.allowed:
- from_addr: {{open_addr}}
{%- if comment is not none %}
- comment: '"{{comment}}"'
{%- endif %}
- listen_in:
- cmd: reload-ufw
{%- endfor %}
54 changes: 54 additions & 0 deletions ufw/config/services.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- set sls_enable_service = tplroot ~ '.service.enable' %}
{%- set sls_reload_service = tplroot ~ '.service.reload' %}
{%- from tplroot ~ "/map.jinja" import ufw with context %}
include:
- {{ sls_package_install }}
- {{ sls_enable_service }}
- {{ sls_reload_service }}
# Services
{%- for service_name, service_details in ufw.get('services', {}).items() %}
{%- set from_addr_raw = service_details.get('from_addr', [None]) %}
{%- set from_addrs = [from_addr_raw] if from_addr_raw is string else from_addr_raw %}
{%- for from_addr in from_addrs %}
{%- set protocol = service_details.get('protocol', None) %}
{%- set deny = service_details.get('deny', None) %}
{%- set limit = service_details.get('limit', None) %}
{%- set method = 'deny' if deny else ('limit' if limit else 'allow') %}
{%- set from_port = service_details.get('from_port', None) %}
{%- set to_addr = service_details.get('to_addr', None) %}
{%- set to_port = service_details.get('to_port', service_name) %}
{%- set comment = service_details.get('comment', None) %}
ufw-svc-{{method}}-{{service_name}}-{{from_addr}}:
ufw.{{method}}:
{%- if protocol is not none %}
- protocol: {{protocol}}
{%- endif %}
{%- if from_addr is not none %}
- from_addr: {{from_addr}}
{%- endif %}
{%- if from_port is not none %}
- from_port: "{{from_port}}"
{%- endif %}
{%- if to_addr is not none %}
- to_addr: {{to_addr}}
{%- endif %}
{%- if comment is not none %}
- comment: '"{{comment}}"'
{%- endif %}
- to_port: "{{to_port}}"
- listen_in:
- cmd: reload-ufw
{%- endfor %}
{%- endfor %}
19 changes: 17 additions & 2 deletions ufw/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
ufwmap:
pkg: ufw
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
ufw:
package: ufw
packages: []
service:
name: ufw
default_file: /etc/default/ufw
sysctl_file: /etc/ufw/sysctl.conf
enabled: false
settings: {}
sysctl: {}
services: {}
applications: {}
interfaces: {}
open: {}
Loading

0 comments on commit c05019a

Please sign in to comment.