Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cyber-sandbox-creator
Manage
Activity
Members
Labels
Plan
Issues
10
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MUNI-KYPO-CSC
cyber-sandbox-creator
Commits
785dfc35
Commit
785dfc35
authored
4 years ago
by
Attila Farkas
Browse files
Options
Downloads
Patches
Plain Diff
add connection to Internet through border router
parent
e9b32d22
No related branches found
No related tags found
1 merge request
!7
Resolve Refactoring
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/ansible_generator.py
+10
-4
10 additions, 4 deletions
modules/ansible_generator.py
templates/br
+35
-35
35 additions, 35 deletions
templates/br
with
45 additions
and
39 deletions
modules/ansible_generator.py
+
10
−
4
View file @
785dfc35
...
...
@@ -2,9 +2,10 @@
from
modules.file_manager
import
generate_file
,
copy_template_file
from
modules.ansible_vars_generator
import
generate_ansible_vars
from
conf.border_router
import
BORDER_ROUTER_NAME
def
_create_config_playbooks
(
input_definitions
):
def
_create_config_playbooks
(
input_definitions
,
flags
):
"""
Generate playbooks and roles for basic device configuration.
"""
copy_template_file
(
"
device_configuration
"
,
"
base_provisioning/device_configuration.yml
"
)
...
...
@@ -17,8 +18,13 @@ def _create_config_playbooks(input_definitions):
"
base_provisioning/roles/routers/tasks/main.yml
"
)
for
device
in
input_definitions
[
"
hosts
"
]
+
input_definitions
[
"
routers
"
]:
copy_template_file
(
"
separate_devices
"
,
"
base_provisioning/roles/
"
+
device
[
"
name
"
]
+
"
/tasks/main.yml
"
)
if
"
border_router
"
in
flags
and
flags
[
"
border_router
"
]
and
\
device
[
"
name
"
]
==
BORDER_ROUTER_NAME
:
copy_template_file
(
"
br
"
,
"
base_provisioning/roles/
"
+
device
[
"
name
"
]
+
"
/tasks/main.yml
"
)
else
:
copy_template_file
(
"
separate_devices
"
,
"
base_provisioning/roles/
"
+
device
[
"
name
"
]
+
"
/tasks/main.yml
"
)
def
_create_user_playbooks
(
input_definitions
):
...
...
@@ -49,5 +55,5 @@ def generate_playbooks(input_definitions, flags):
:param flags: command line input flags
"""
generate_ansible_vars
(
input_definitions
,
flags
)
_create_config_playbooks
(
input_definitions
)
_create_config_playbooks
(
input_definitions
,
flags
)
_create_user_playbooks
(
input_definitions
)
This diff is collapsed.
Click to expand it.
templates/br
+
35
−
35
View file @
785dfc35
---
# Configuration f
or
the border router
# Configuration
o
f the border router
- name: Enable IP forwarding
copy:
dest: "/etc/sysctl.conf"
content: "net.ipv4.ip_forward=1"
- name: Restarting procps service
command: /etc/init.d/procps restart
{% for host in hosts %}
- name: Add {{ host.host_name }} alias
lineinfile:
path: /etc/hosts
line: {{ host.host_ip }} {{ host.host_name }}
{% endfor %}
{% for router in routers %}
- name: Add {{ router.router_name }} alias
- name: Adding aliases
loop: "{{ aliases | dict2items }}"
lineinfile:
path: /etc/hosts
line: {{ router.router_ip }} {{ router.router_name }}
{% endfor %}
{% for target_cidr, router_ip in br_routes.items() %}
- name: Add routing to network {{ target_cidr }}
command: route add -net {{ target_cidr }} gw {{ router_ip }} eth1
{% endfor %}
- name: Add postrouting
# ssh connection fails without async after execution of iptables commands
shell: "sleep 2 && sudo iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source {{ border_router_public_ip }}"
async: 1
poll: 0
{# name: Save postrouting rule #}
{# command: su -c 'iptables-save > /etc/iptables.rules' #}
line: "{{ item.value }} {{ item.key }}"
- name: Set up nondefault routes
include_role:
name: interface
vars:
interface_ip: "{{ route.interface_ip }}"
interface_routes:
- gateway: "{{ route.gateway }}"
network: "{{ route.network }}"
mask: "{{ route.netmask }}"
loop: "{{ routings.simple }}"
loop_control:
loop_var: route
- name: Set up default route
include_role:
name: interface
vars:
interface_ip: "{{ route.interface_ip }}"
interface_default_gateway: "{{ route.gateway }}"
loop: "{{ routings.default }}"
loop_control:
loop_var: route
- name: Set up postrouting
iptables:
table: nat
chain: POSTROUTING
out_interface: "{{ ansible_default_ipv4.interface }}"
jump: SNAT
to_source: "{{ ansible_default_ipv4.address }}"
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment