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

Ipsec endisable issue43 #44

Merged
merged 8 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tasks/ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

# definition:
# opn_ipsec:
# enable: 1
# enable: 1 # set to 0 to disable ipsec and explicit to 1 do enable a disabled ipsec service
# ipsec_asn: 1
# ipsec_chd: 1
# ... # other globalsettings like passthrough_networks, ...
# ikeids: # dict: ikeid is the key !
# 1:
# phase1: # dict
# descr: s2s ...
# #disabled: 1 # this way you can disable a entry without deleting it; a disabled entry must be enabled by explicitly setting disabled: 0
# iketype: ikev1
# interface: wan
# mode: main
Expand Down Expand Up @@ -59,6 +60,19 @@
- "{{ opn_ipsec | default({}) }}"
when:
- item.key != 'ikeids'
- not (item.key == 'enable' and item.value|int != 1)

- name: IPSec disable
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/ipsec/{{ item.key }}"
state: absent
pretty_print: true
with_dict:
- "{{ opn_ipsec | default({}) }}"
when:
- item.key == 'enable' and item.value|int != 1

- name: IPSec loop ikeids for phase1 ...
ansible.builtin.include_tasks: ipsecphase1.yml
Expand Down
13 changes: 13 additions & 0 deletions tasks/ipsecphase1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
- "{{ ipsecphasevar.phase1 | default({}) }}"
when:
- not item.key == 'encryption-algorithm'
- not (item.key == 'disabled' and item.value|int != 1)

- name: "IPSec ike phase1 for ikeid {{ ikeid }} enable"
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/ipsec/phase1[ikeid/text()='{{ ikeid }}']/{{ item.key }}"
state: absent
pretty_print: true
with_dict:
- "{{ ipsecphasevar.phase1 | default({}) }}"
when:
- item.key == 'disabled' and item.value|int != 1

- name: "IPSec ike phase1 encryption-algorithm for ikeid {{ ikeid }}"
delegate_to: localhost
Expand Down
2 changes: 1 addition & 1 deletion test/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ roles_path = ../../

host_key_checking = False

hash_behaviour = merge
#hash_behaviour = merge

#callbacks_enabled = profile_tasks
#stdout_callback = dense
1 change: 1 addition & 0 deletions test/ipsec-test1-expect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<system>
</system>
<ipsec>
<enable>1</enable>
<ipsec_asn>1</ipsec_asn>
<ipsec_chd>1</ipsec_chd>
<passthrough_networks>192.168.0.0/24</passthrough_networks>
Expand Down
2 changes: 1 addition & 1 deletion test/ipsec-test1.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
opn_ipsec:
#disabled: 0
enable: 1
ipsec_asn: 1
ipsec_chd: 1
passthrough_networks: "192.168.0.0/24"
Expand Down
112 changes: 112 additions & 0 deletions test/ipsec-testdisable-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<ipsec>
<ipsec_asn>1</ipsec_asn>
<ipsec_chd>1</ipsec_chd>
<passthrough_networks>192.168.0.0/24</passthrough_networks>
<phase1>
<ikeid>1</ikeid>
<descr>s2s test</descr>
<iketype>ikev1</iketype>
<interface>wan</interface>
<mode>main</mode>
<protocol>inet</protocol>
<myid_type>auto</myid_type>
<myid_data>localhost</myid_data>
<peerid_type>fqdn</peerid_type>
<peerid_data>fw02</peerid_data>
<lifetime>28800</lifetime>
<certref>61546da45fbc3</certref>
<caref>5ef9c5881c158</caref>
<authentication_method>rsasig</authentication_method>
<nat_traversal>on</nat_traversal>
<auto>start</auto>
<dhgroup>2</dhgroup>
<hash-algorithm>md5,sha1</hash-algorithm>
<private-key/>
<remote-gateway>fw02</remote-gateway>
<dpd_delay>10</dpd_delay>
<dpd_maxfail>5</dpd_maxfail>
<dpd_action>restart</dpd_action>
<encryption-algorithm>
<name>aes</name>
<keylen>256</keylen>
</encryption-algorithm>
<disabled>1</disabled>
</phase1>
<phase2>
<ikeid>1</ikeid>
<uniqid>eea1dcb2e051a</uniqid>
<disabled>1</disabled>
<mode>tunnel</mode>
<pfsgroup>2</pfsgroup>
<lifetime>3600</lifetime>
<protocol>esp</protocol>
<pinghost>10.0.0.1</pinghost>
<descr>10.0.0.0/12</descr>
<reqid>1</reqid>
<localid>
<type>lan</type>
</localid>
<remoteid>
<type>network</type>
<address>10.0.0.0</address>
<netbits>12</netbits>
</remoteid>
<encryption-algorithm-option>
<name>aes256</name>
</encryption-algorithm-option>
<hash-algorithm-option>hmac_sha1</hash-algorithm-option>
</phase2>
<phase2>
<ikeid>1</ikeid>
<uniqid>e471b7299c8c1</uniqid>
<mode>tunnel</mode>
<pfsgroup>2</pfsgroup>
<lifetime>3600</lifetime>
<protocol>esp</protocol>
<pinghost>10.128.0.1</pinghost>
<descr>10.128.0.0/12</descr>
<reqid>2</reqid>
<localid>
<type>lan</type>
</localid>
<remoteid>
<type>network</type>
<address>10.128.0.0</address>
<netbits>12</netbits>
</remoteid>
<encryption-algorithm-option>
<name>aes256</name>
</encryption-algorithm-option>
<hash-algorithm-option>hmac_sha1</hash-algorithm-option>
<disabled>1</disabled>
</phase2>
<phase2>
<ikeid>1</ikeid>
<uniqid>e98f78c414ece</uniqid>
<mode>tunnel</mode>
<pfsgroup>2</pfsgroup>
<lifetime>3600</lifetime>
<protocol>esp</protocol>
<pinghost>10.224.0.1</pinghost>
<descr>10.224.0.0/12</descr>
<reqid>3</reqid>
<localid>
<type>lan</type>
</localid>
<remoteid>
<type>network</type>
<address>10.224.0.0</address>
<netbits>12</netbits>
</remoteid>
<encryption-algorithm-option>
<name>aes256</name>
</encryption-algorithm-option>
<hash-algorithm-option>hmac_sha1</hash-algorithm-option>
<disabled>1</disabled>
</phase2>
</ipsec>
</opnsense>
110 changes: 110 additions & 0 deletions test/ipsec-testdisable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<ipsec>
<enable>1</enable>
<ipsec_asn>1</ipsec_asn>
<ipsec_chd>1</ipsec_chd>
<passthrough_networks>192.168.0.0/24</passthrough_networks>
<phase1>
<ikeid>1</ikeid>
<descr>s2s test</descr>
<iketype>ikev1</iketype>
<interface>wan</interface>
<mode>main</mode>
<protocol>inet</protocol>
<myid_type>auto</myid_type>
<myid_data>localhost</myid_data>
<peerid_type>fqdn</peerid_type>
<peerid_data>fw02</peerid_data>
<lifetime>28800</lifetime>
<certref>61546da45fbc3</certref>
<caref>5ef9c5881c158</caref>
<authentication_method>rsasig</authentication_method>
<nat_traversal>on</nat_traversal>
<auto>start</auto>
<dhgroup>2</dhgroup>
<hash-algorithm>md5,sha1</hash-algorithm>
<private-key/>
<remote-gateway>fw02</remote-gateway>
<dpd_delay>10</dpd_delay>
<dpd_maxfail>5</dpd_maxfail>
<dpd_action>restart</dpd_action>
<encryption-algorithm>
<name>aes</name>
<keylen>256</keylen>
</encryption-algorithm>
</phase1>
<phase2>
<ikeid>1</ikeid>
<uniqid>eea1dcb2e051a</uniqid>
<disabled>1</disabled>
<mode>tunnel</mode>
<pfsgroup>2</pfsgroup>
<lifetime>3600</lifetime>
<protocol>esp</protocol>
<pinghost>10.0.0.1</pinghost>
<descr>10.0.0.0/12</descr>
<reqid>1</reqid>
<localid>
<type>lan</type>
</localid>
<remoteid>
<type>network</type>
<address>10.0.0.0</address>
<netbits>12</netbits>
</remoteid>
<encryption-algorithm-option>
<name>aes256</name>
</encryption-algorithm-option>
<hash-algorithm-option>hmac_sha1</hash-algorithm-option>
</phase2>
<phase2>
<ikeid>1</ikeid>
<uniqid>e471b7299c8c1</uniqid>
<mode>tunnel</mode>
<pfsgroup>2</pfsgroup>
<lifetime>3600</lifetime>
<protocol>esp</protocol>
<pinghost>10.128.0.1</pinghost>
<descr>10.128.0.0/12</descr>
<reqid>2</reqid>
<localid>
<type>lan</type>
</localid>
<remoteid>
<type>network</type>
<address>10.128.0.0</address>
<netbits>12</netbits>
</remoteid>
<encryption-algorithm-option>
<name>aes256</name>
</encryption-algorithm-option>
<hash-algorithm-option>hmac_sha1</hash-algorithm-option>
</phase2>
<phase2>
<ikeid>1</ikeid>
<uniqid>e98f78c414ece</uniqid>
<mode>tunnel</mode>
<pfsgroup>2</pfsgroup>
<lifetime>3600</lifetime>
<protocol>esp</protocol>
<pinghost>10.224.0.1</pinghost>
<descr>10.224.0.0/12</descr>
<reqid>3</reqid>
<localid>
<type>lan</type>
</localid>
<remoteid>
<type>network</type>
<address>10.224.0.0</address>
<netbits>12</netbits>
</remoteid>
<encryption-algorithm-option>
<name>aes256</name>
</encryption-algorithm-option>
<hash-algorithm-option>hmac_sha1</hash-algorithm-option>
</phase2>
</ipsec>
</opnsense>
77 changes: 77 additions & 0 deletions test/ipsec-testdisable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
opn_ipsec:
enable: 0
ipsec_asn: 1
ipsec_chd: 1
passthrough_networks: "192.168.0.0/24"
ikeids: # key is the ikeid
1:
phase1:
disabled: 1
descr: s2s test
iketype: ikev1
interface: wan
mode: main
protocol: inet
myid_type: auto
myid_data: "{{ inventory_hostname }}"
peerid_type: fqdn
peerid_data: fw02
encryption-algorithm:
name: aes
keylen: 256
lifetime: 28800
certref: 61546da45fbc3
caref: 5ef9c5881c158
authentication_method: rsasig
nat_traversal: "on"
auto: start
dhgroup: 2
hash-algorithm: md5,sha1
private-key:
remote-gateway: fw02
dpd_delay: 10
dpd_maxfail: 5
dpd_action: restart
phase2_defaults: # common settings for all phase2 elements in this ikeid
disabled: 0 # ensure all tunnels are enabled as long as they are not explicitly disabled
mode: tunnel
pfsgroup: 2
lifetime: 3600
protocol: esp
localid:
type: lan
encryption-algorithm-options:
- name: aes256
hash-algorithm-options:
- hmac_sha1
phase2:
# key is the uniqid
eea1dcb2e051a:
pinghost: 10.0.0.1
descr: 10.0.0.0/12
disabled: 1 # this way you can disable a p2 entry without deleting it; a disabled p2 entry must be enabled by explicitly setting disabled: 0
remoteid:
type: network
address: 10.0.0.0
netbits: 12
reqid: 1
e471b7299c8c1:
pinghost: 10.128.0.1
descr: 10.128.0.0/12
disabled: 1
remoteid:
type: network
address: 10.128.0.0
netbits: 12
reqid: 2
e98f78c414ece:
pinghost: 10.224.0.1
descr: 10.224.0.0/12
disabled: 1
remoteid:
type: network
address: 10.224.0.0
netbits: 12
reqid: 3

Loading
Loading