Skip to content

Commit a07b662

Browse files
authored
Merge pull request #13 from shoddyguard/add_tls
Add TLS Support
2 parents 9d3f0c7 + dbd69ff commit a07b662

File tree

9 files changed

+342
-6
lines changed

9 files changed

+342
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ All notable changes to this project will be documented in this file.
1212
- Tidied up documentation and added some more examples
1313
- Expanded acceptance testing slightly
1414
- Adds support for DHCP on IPV4 and IPV6, IPV6 remains untested
15+
- Adds experimental support for TLS/SSL
1516

1617
**Bugfixes**
1718
Partially fixed #10 whereby you could not specify port numbers when using IP addresses (eg `127.0.0.1:5353` would fail).
1819
This is marked as partially fixed as it works for IPV4 addresses but not IPV6 addresses at present.
1920
Will require more familiarity with IPV6 before that can be implemented.
2021

2122
**Known Issues**
22-
IPSET and TLS/SSL still not implemented
23+
IPSET still not implemented
2324

2425
### [v0.1.0](https://github.com/shoddyguard/Puppet-Adguard/tree/v0.1.0) (2020-03-21)
2526

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,4 @@ In these cases this module will disable `DNSStubListener` in `/etc/systemd/resol
163163

164164
## Unsupported features
165165
Currently this module does not support:
166-
- ipset
167-
- TLS/SSL settings
166+
- ipset

REFERENCE.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
* `adguard::params`: Private class for managing some of the more complex default parameters
1616

17+
### Functions
18+
19+
* [`adguard::validate_tls_options`](#adguardvalidate_tls_options): This function ensures that the TLS config is valid before applying it.
20+
1721
### Data types
1822

1923
* [`Adguard::Blocked_service`](#adguardblocked_service): A list of services that AdGuard Home is able to block out of the box.
@@ -24,9 +28,11 @@
2428
* [`Adguard::Dhcp_v6_options`](#adguarddhcp_v6_options): A structured hash for sepcifying DHCP options for IPV6
2529
* [`Adguard::Dns_server`](#adguarddns_server): Valid DNS server types
2630
* [`Adguard::Filter`](#adguardfilter): Used to manage filters in Adguard
31+
* [`Adguard::Http_proxy`](#adguardhttp_proxy): Very basic validation to ensure the proxy type is sensible
2732
* [`Adguard::Ipv4_port`](#adguardipv4_port): Accepts an IPV4 address with a port (eg 192.168.1.1:8080)
2833
* [`Adguard::Log_file`](#adguardlog_file): Supported log file types
2934
* [`Adguard::Rewrite`](#adguardrewrite): Stuctured hash for managing rewrites
35+
* [`Adguard::Tls_options`](#adguardtls_options): Configures TLS options in AdGuard Home
3036
* [`Adguard::User`](#adguarduser): A structed hash for providing users for the adguard web UI.
3137

3238
## Classes
@@ -104,6 +110,8 @@ The following parameters are available in the `adguard` class:
104110
* [`cache_time`](#cache_time)
105111
* [`rewrites`](#rewrites)
106112
* [`blocked_services`](#blocked_services)
113+
* [`enable_tls`](#enable_tls)
114+
* [`tls_options`](#tls_options)
107115
* [`filters`](#filters)
108116
* [`whitelist_filters`](#whitelist_filters)
109117
* [`user_rules`](#user_rules)
@@ -150,7 +158,7 @@ Note: the password needs to be in BCrypt-encrypted format.
150158

151159
##### <a name="http_proxy"></a>`http_proxy`
152160

153-
Data type: `Optional[Stdlib::HTTPUrl]`
161+
Data type: `Optional[Adguard::Http_proxy]`
154162

155163
Define an optional http_proxy.
156164
While adguard supports SOCKS5 alongside HTTP/S, this is **not** supported in the Puppet module at this time.
@@ -566,6 +574,22 @@ An array of any services you wish to block.
566574

567575
Default value: ``undef``
568576

577+
##### <a name="enable_tls"></a>`enable_tls`
578+
579+
Data type: `Boolean`
580+
581+
EXPERIMENTAL: enable TLS. This workflow is largely untested, use with caution.
582+
583+
Default value: ``false``
584+
585+
##### <a name="tls_options"></a>`tls_options`
586+
587+
Data type: `Optional[Adguard::Tls_options]`
588+
589+
The TLS configuration options.
590+
591+
Default value: ``undef``
592+
569593
##### <a name="filters"></a>`filters`
570594

571595
Data type: `Array[Adguard::Filter]`
@@ -740,6 +764,26 @@ The version to install from the GitHub release
740764

741765
Default value: `'latest'`
742766

767+
## Functions
768+
769+
### <a name="adguardvalidate_tls_options"></a>`adguard::validate_tls_options`
770+
771+
Type: Puppet Language
772+
773+
This function ensures that the TLS config is valid before applying it.
774+
775+
#### `adguard::validate_tls_options(Adguard::Tls_options $tls_options)`
776+
777+
The adguard::validate_tls_options function.
778+
779+
Returns: `Boolean` Returns true if the configuration is valid
780+
781+
##### `tls_options`
782+
783+
Data type: `Adguard::Tls_options`
784+
785+
Accepts a hash of tls_options
786+
743787
## Data types
744788

745789
### <a name="adguardblocked_service"></a>`Adguard::Blocked_service`
@@ -858,6 +902,16 @@ Struct[{
858902
}]
859903
```
860904

905+
### <a name="adguardhttp_proxy"></a>`Adguard::Http_proxy`
906+
907+
Very basic validation to ensure the proxy type is sensible
908+
909+
Alias of
910+
911+
```puppet
912+
Pattern[/^(http|https|socks5)\:\/\//]
913+
```
914+
861915
### <a name="adguardipv4_port"></a>`Adguard::Ipv4_port`
862916

863917
Accepts an IPV4 address with a port (eg 192.168.1.1:8080)
@@ -891,6 +945,33 @@ Struct[{
891945
}]
892946
```
893947

948+
### <a name="adguardtls_options"></a>`Adguard::Tls_options`
949+
950+
Configures TLS options in AdGuard Home
951+
952+
* **See also**
953+
* https://github.com/AdguardTeam/AdGuardHome/wiki/Encryption
954+
955+
Alias of
956+
957+
```puppet
958+
Struct[{
959+
server_name => Stdlib::Host,
960+
force_https => Boolean,
961+
port_https => Stdlib::Port,
962+
port_dns_over_tls => Stdlib::Port,
963+
port_dns_over_quic => Stdlib::Port,
964+
port_dnscrypt => Stdlib::Port,
965+
dnscrypt_config_file => Optional[Stdlib::Unixpath],
966+
allow_unencrypted_doh => Boolean,
967+
strict_sni_check => Boolean,
968+
certificate_chain => Optional[String],
969+
private_key => Optional[String],
970+
certificate_path => Optional[Stdlib::Unixpath],
971+
private_key_path => Optional[Stdlib::Unixpath]
972+
}]
973+
```
974+
894975
### <a name="adguarduser"></a>`Adguard::User`
895976

896977
A structed hash for providing users for the adguard web UI.

functions/validate_tls_options.pp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# @summary
2+
# This function ensures that the TLS config is valid before applying it.
3+
#
4+
# @param tls_options
5+
# Accepts a hash of tls_options
6+
#
7+
# @return [Boolean] Returns true if the configuration is valid
8+
function adguard::validate_tls_options(Adguard::Tls_options $tls_options) >> Boolean {
9+
# If dnscrypt is enabled (any port other than 0) there must be a path to a config file
10+
if ($tls_options['port_dnscrypt'] != 0 and !$tls_options['dnscrypt_config_file'])
11+
{
12+
fail('dnscrypt_config_file must be set when port_dnscrypt is set to a non zero value')
13+
}
14+
# Perform sanity checks on the certificate values as there are a few combinationss that won't work.
15+
if ($tls_options['certificate_chain'] or $tls_options['private_key'])
16+
{
17+
# AdGuard Home only supports using either hardcoded certs or a path on disk, not both at the same time.
18+
if ($tls_options['certificate_path'] or $tls_options['private_key_path'])
19+
{
20+
fail('cannot use certificate_chain/private_key with certificate_path/private_key_path')
21+
}
22+
# Seeing as we've confirmed certificate_chain and/or private_key are in use we need to ensure both values are present
23+
if (!$tls_options['certificate_chain'] or !$tls_options['private_key'])
24+
{
25+
fail('both certificate_chain and private_key must be set together')
26+
}
27+
}
28+
else
29+
{
30+
# We've confirmed that neither certificate_chain or private_key is set so validate we have paths to the certs
31+
if (!$tls_options['certificate_path'] or !$tls_options['private_key_path'])
32+
{
33+
fail('certificate_path and private_key_path required when not providing certificate_chain/private_key')
34+
}
35+
}
36+
# And if we've gotten here then return true
37+
Boolean('true')
38+
}

manifests/init.pp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@
130130
# - answer: the ip address to point to
131131
# @param blocked_services
132132
# An array of any services you wish to block.
133+
# @param enable_tls
134+
# EXPERIMENTAL: enable TLS. This workflow is largely untested, use with caution.
135+
# @param tls_options
136+
# The TLS configuration options.
133137
# @param filters
134138
# An array of block filters to add. Will default to the standard list provided by AdGuard
135139
# Format:
@@ -189,7 +193,7 @@
189193
Array[Adguard::User] $users,
190194
Stdlib::IP::Address::V4::Nosubnet $webui_interface = '0.0.0.0',
191195
Stdlib::Port $webui_port = 80,
192-
Optional[Stdlib::HTTPUrl] $http_proxy = undef,
196+
Optional[Adguard::Http_proxy] $http_proxy = undef,
193197
Integer $rlimit_nofile = 0,
194198
Boolean $debug_pprof = false,
195199
Integer $web_session_ttl = 8,
@@ -247,6 +251,8 @@
247251
Integer $cache_time = 30,
248252
Optional[Array[Adguard::Rewrite]] $rewrites = undef,
249253
Optional[Array[Adguard::Blocked_service]] $blocked_services = undef,
254+
Boolean $enable_tls = false,
255+
Optional[Adguard::Tls_options] $tls_options = undef,
250256
Array[Adguard::Filter] $filters = $adguard::params::filters,
251257
Optional[Array[Adguard::Filter]] $whitelist_filters = undef,
252258
Optional[Array] $user_rules = undef,
@@ -270,6 +276,7 @@
270276
)
271277
inherits adguard::params
272278
{
279+
# Validate various options that may have been provided
273280
if ($blocking_mode == 'custom_ip')
274281
{
275282
if (!$blocking_ipv4 or !$blocking_ipv6)
@@ -313,6 +320,17 @@
313320
warning('dhcp_interface and/or dhcp_vX_options set when enable_dhcp is false. DHCP options will have no effect')
314321
}
315322
}
323+
if ($enable_tls)
324+
{
325+
if (!$tls_options)
326+
{
327+
fail('tls_options required when enable_tls is true')
328+
}
329+
if (adguard::validate_tls_options($tls_options) != true)
330+
{
331+
fail('failed to validate tls_options')
332+
}
333+
}
316334
# Puppet has excellent facts, make use of them
317335
case $::architecture
318336
{

0 commit comments

Comments
 (0)