Skip to content

Commit bc4a07e

Browse files
Add support for DNSSEC (hestiacp#2938)
* Solve issues with DNSKEY in v-add-dns-record Bug in v-add-dns-record Fix A new NS DNSKEY Mix up Don't add " Fix error Fix few typos * Add support for DS record * Apply changes to user account Bind need write access to the folder where .db file is stored * Add support for DS type and allow . in common name * Add support for DNSSEC * Remove hardcoded domain * Fix permission issues * Make sure DS record is last and fix small issues * Add option to enable existing DNS domain and clean up everything * Get public key Need to improved to support json * Don't add DS records * Rebuild on changes * Update rebuild.sh * Add rebuild.sh * Remove non needed lines * Fix error * Add support for zonetransfer but Hestia create the slave record * Fix error * Fix error * Add new options to v-insert-dns-domain * Solve issue with remote creation * Update error * Adjust spacing * Remove double space * Add inline signing * Update some other scripts that might use v-insert-domain * Check if DNS-CLUSTER is set to yes and not if exists * Fix issues with IDN domains * Fix error * Execute pipe before continue * Fix issue in sync-dns-cluster breaking everything * DNS_CLUSTER_SYSTEM caused issues with DNS_CLUSTER * Fixed an issue with rebuild and key is 4 digits long instead of 5 * Update v-list-dns-domain to include DNSSEC * Add more information * Add UI interface * Fix bug in v-delete-dns-domain When deleting DNS domain it doesn't delete the keys * Backup DNSSEC keys * Fix restore * Include DS record also * Update from element * Add missing <div class="form-check"> Co-authored-by: Raphael <rs@scit.ch>
1 parent 8fc3d5b commit bc4a07e

38 files changed

+725
-175
lines changed

bin/v-add-dns-domain

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ns6=$9
2727
ns7=${10}
2828
ns8=${11}
2929
restart=${12}
30+
dnssec=${13}
3031

3132
# Includes
3233
# shellcheck source=/etc/hestiacp/hestia.conf
@@ -35,6 +36,8 @@ source /etc/hestiacp/hestia.conf
3536
source $HESTIA/func/main.sh
3637
# shellcheck source=/usr/local/hestia/func/domain.sh
3738
source $HESTIA/func/domain.sh
39+
# shellcheck source=/usr/local/hestia/func/rebuild.sh
40+
source $HESTIA/func/rebuild.sh
3841
# load config file
3942
source_conf "$HESTIA/conf/hestia.conf"
4043

@@ -70,6 +73,10 @@ if [ -n "$restart" ]; then
7073
is_format_valid 'restart'
7174
fi
7275

76+
if [ -n "$dnssec" ]; then
77+
is_boolean_format_valid "$dnssec" 'dnssec'
78+
fi
79+
7380
is_package_full 'DNS_DOMAINS'
7481
template=$(get_user_value '$DNS_TEMPLATE')
7582
is_dns_template_valid "$template"
@@ -152,6 +159,9 @@ fi
152159
if [ -z "$ns8" ]; then
153160
template_data=$(echo "$template_data" |grep -v %ns8%)
154161
fi
162+
if [ -z "$dnssec" ]; then
163+
dnssec="no"
164+
fi
155165

156166
# Generating timestamp
157167
time_n_date=$(date +'%T %F')
@@ -180,36 +190,15 @@ records="$(wc -l $USER_DATA/dns/$domain.conf |cut -f 1 -d ' ')"
180190
# Adding dns.conf record
181191
dns_rec="DOMAIN='$domain' IP='$ip' TPL='$template' TTL='$ttl' EXP='$exp'"
182192
dns_rec="$dns_rec SOA='$soa' SERIAL='$serial' SRC='' RECORDS='$records'"
183-
dns_rec="$dns_rec SUSPENDED='no' TIME='$time' DATE='$date'"
193+
dns_rec="$dns_rec DNSSEC='$dnssec' KEY='' SLAVE='no' MASTER='' SUSPENDED='no' TIME='$time' DATE='$date'"
184194

185195
echo "$dns_rec" >> $USER_DATA/dns.conf
186196
chmod 660 $USER_DATA/dns.conf
187197

188-
# Creating system configs
189-
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
190-
if [ -e '/etc/named.conf' ]; then
191-
dns_conf='/etc/named.conf'
192-
dns_group='named'
193-
else
194-
dns_conf='/etc/bind/named.conf'
195-
dns_group='bind'
196-
fi
197-
198-
# Adding zone in named.conf
199-
named="zone \"$domain_idn\" {type master; file"
200-
named="$named \"$HOMEDIR/$user/conf/dns/$domain.db\";};"
201-
echo "$named" >> $dns_conf
202-
203-
# Updating domain dns zone
204-
update_domain_zone
205-
206-
# Changing permissions
207-
chmod 640 $HOMEDIR/$user/conf/dns/$domain.db
208-
chown root:$dns_group $HOMEDIR/$user/conf/dns/$domain.db
209-
fi
198+
rebuild_dns_domain_conf
210199

211200
# Updating dns-cluster queue
212-
if [ -n "$DNS_CLUSTER" ]; then
201+
if [ "$DNS_CLUSTER" = "yes" ]; then
213202
cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
214203
echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
215204
fi

bin/v-add-dns-record

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ source /etc/hestiacp/hestia.conf
3838
source $HESTIA/func/main.sh
3939
# shellcheck source=/usr/local/hestia/func/domain.sh
4040
source $HESTIA/func/domain.sh
41+
# shellcheck source=/usr/local/hestia/func/rebuild.sh
42+
source $HESTIA/func/rebuild.sh
4143
# load config file
4244
source_conf "$HESTIA/conf/hestia.conf"
4345

@@ -47,29 +49,32 @@ if [ "$rtype" != 'MX' ] && [ "$rtype" != 'SRV' ]; then
4749
fi
4850

4951
# Add trailing dot at the end of NS/CNAME/MX/PTR/SRV record
50-
if [[ $rtype =~ NS|CNAME|MX|PTR|SRV ]]; then
52+
if [[ $rtype =~ ^NS|CNAME|MX|PTR|SRV ]]; then
5153
trailing_dot=$(echo $dvalue | grep "\.$")
5254
if [ -z "$trailing_dot" ]; then
5355
dvalue="$dvalue."
5456
fi
5557
fi
5658

57-
if [[ $rtype =~ NS|CNAME|MX|PTR|SRV ]]; then
59+
if [[ $rtype =~ ^NS|CNAME|MX|PTR|SRV ]]; then
5860
dvalue=$(idn2 --quiet "$dvalue" )
5961
record=$(idn2 --quiet "$record" )
6062
fi
6163

6264
# Cleanup quotes on dvalue
6365
# - [CAA] records will be left unchanged
64-
# - [SRV] will be stripped of double quotes even when containg spaces
66+
# - [SRV] will be stripped of double quotes even when containing spaces
67+
# - [DNSKEY] will be stripped of double quotes even when containing spaces
6568
# - Rest of record types will be striped of quotes and the final string
66-
# will be enclosed in double quotes if containg spaces or semicolons
69+
# will be enclosed in double quotes if containing spaces or semicolons
6770

6871
if [ "$rtype" != "CAA" ]; then
6972
dvalue=${dvalue//\"/}
70-
71-
if [ "$rtype" != 'SRV' ] && [[ "$dvalue" =~ [\;[:space:]] ]]; then
72-
dvalue='"'"$dvalue"'"'
73+
# Add support for DS key
74+
if [ "$rtype" != "DNSKEY" ] && [ "$rtype" != "DS" ] ; then
75+
if [ "$rtype" != 'SRV' ] && [[ "$dvalue" =~ [\;[:space:]] ]]; then
76+
dvalue='"'"$dvalue"'"'
77+
fi
7378
fi
7479
fi
7580

@@ -129,12 +134,12 @@ sort_dns_records
129134

130135
# Updating zone
131136
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
132-
update_domain_serial
133-
update_domain_zone
137+
# Do full rebuild due DNS SEC
138+
rebuild_dns_domain_conf
134139
fi
135140

136141
# Updating dns-cluster queue
137-
if [ -n "$DNS_CLUSTER" ]; then
142+
if [ "$DNS_CLUSTER" = "yes" ]; then
138143
# Check for first sync
139144
dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
140145
if [ -z "$dlock" ]; then

bin/v-add-remote-dns-domain

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,37 @@ for cluster in $(grep "SUSPENDED='no'" $HESTIA/conf/dns-cluster.conf); do
6969
# Parsing domain parameters
7070
parse_object_kv_list "$str"
7171

72-
# Syncing domain data
73-
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
74-
check_result $? "$HOST connection failed" "$E_CONNECT"
75-
76-
# Syncing domain records
77-
tmp_file="/tmp/vst-sync.$DOMAIN"
78-
cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file
79-
check_result $? "$HOST connection failed" "$E_CONNECT"
80-
81-
# Inserting synced records
82-
cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
83-
check_result $? "$HOST connection failed" "$E_CONNECT"
84-
85-
# Rebuilding dns zone
86-
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
87-
check_result $? "$HOST connection failed" "$E_CONNECT"
72+
if [ "$DNS_CLUSTER_SYSTEM" = "zone" ]; then
73+
str=$(echo "$str" | sed "s/SLAVE='no'/SLAVE='yes'/g");
74+
ip=$($BIN/v-list-sys-ips plain | cut -f1);
75+
str=$(echo "$str" | sed "s/MASTER='*'/MASTER='$ip'/g");
76+
77+
# Syncing domain data
78+
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
79+
check_result $? "$HOST connection failed" "$E_CONNECT"
80+
81+
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
82+
check_result $? "$HOST connection failed" "$E_CONNECT"
83+
84+
rndc notify $domain > /dev/null 2>&1
85+
else
86+
# Syncing domain data
87+
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
88+
check_result $? "$HOST connection failed" "$E_CONNECT"
89+
90+
# Syncing domain records
91+
tmp_file="/tmp/vst-sync.$DOMAIN"
92+
cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file
93+
check_result $? "$HOST connection failed" "$E_CONNECT"
94+
95+
# Inserting synced records
96+
cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
97+
check_result $? "$HOST connection failed" "$E_CONNECT"
98+
99+
# Rebuilding dns zone
100+
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
101+
check_result $? "$HOST connection failed" "$E_CONNECT"
102+
fi
88103
done
89104

90105
#----------------------------------------------------------#

bin/v-add-remote-dns-host

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ echo "$str" >> $HESTIA/conf/dns-cluster.conf
9292
chmod 660 $HESTIA/conf/dns-cluster.conf
9393

9494
# Enabling DNS_CLUSTER
95-
if [ -z "$(grep DNS_CLUSTER $HESTIA/conf/hestia.conf)" ]; then
95+
if [ -z "$(grep DNS_CLUSTER= $HESTIA/conf/hestia.conf)" ]; then
9696
sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $HESTIA/conf/hestia.conf
9797
else
9898
sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $HESTIA/conf/hestia.conf

bin/v-add-remote-dns-record

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ for cluster in $(grep "SUSPENDED='no'" $HESTIA/conf/dns-cluster.conf); do
6363

6464
# Parsing remote host parameters
6565
parse_object_kv_list "$cluster"
66-
66+
6767
# Syncing serial
6868
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
69+
# Parsing domain parameters
70+
parse_object_kv_list "$str"
71+
72+
if [ "$DNS_CLUSTER_SYSTEM" != "zone" ]; then
6973
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
7074
check_result $? "$HOST connection failed (soa sync)" "$E_CONNECT"
7175

@@ -77,9 +81,12 @@ for cluster in $(grep "SUSPENDED='no'" $HESTIA/conf/dns-cluster.conf); do
7781
# Rebuilding dns zone
7882
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
7983
check_result $? "$HOST connection failed (rebuild)" "$E_CONNECT"
80-
84+
fi
8185
done
8286

87+
if [ "$DNS_CLUSTER_SYSTEM" != "zone" ]; then
88+
rndc notify $domain > /dev/null 2>&1
89+
fi
8390
#----------------------------------------------------------#
8491
# Hestia #
8592
#----------------------------------------------------------#

bin/v-add-user

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,14 @@ if [ -n "$MAIL_SYSTEM" ]; then
117117
fi
118118

119119
if [ -n "$DNS_SYSTEM" ]; then
120+
if [ "$DNS_SYSTEM" = 'named' ]; then
121+
dns_group='named'
122+
else
123+
dns_group='bind'
124+
fi
120125
mkdir $HOMEDIR/$user/conf/dns
121-
chmod 751 $HOMEDIR/$user/conf/dns
126+
chmod 771 $HOMEDIR/$user/conf/dns
127+
chown root:$dns_group $HOMEDIR/$user/conf/dns
122128
fi
123129

124130
# Create default writeable folders

bin/v-backup-user

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ if [ -n "$DNS_SYSTEM" ] && [ "$DNS" != '*' ]; then
419419

420420
# Building directory tree
421421
mkdir -p $tmpdir/dns/$domain/conf
422+
mkdir -p $tmpdir/dns/$domain/conf/keys
422423
mkdir -p $tmpdir/dns/$domain/hestia
423424

424425
# Backup dns.conf
@@ -431,6 +432,12 @@ if [ -n "$DNS_SYSTEM" ] && [ "$DNS" != '*' ]; then
431432
if [ "$DNS_SYSTEM" != 'remote' ]; then
432433
cp $HOMEDIR/$user/conf/dns/$domain.db conf/$domain.db
433434
fi
435+
# Backup DNSSEC public and private key if enabled
436+
dnssec=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf |grep "DNSSEC='yes'")
437+
if [ -n "$dnssec" ]; then
438+
format_domain_idn
439+
cp $USER_DATA/keys/K$domain_idn*.* $tmpdir/dns/$domain/conf/keys
440+
fi
434441
done
435442

436443
# Print total

bin/v-change-dns-domain-dnssec

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
# info: change dns domain dnssec status
3+
# options: USER DOMAIN STATUS
4+
#
5+
# example: v-change-dns-domain-status admin domain.pp.ua yes
6+
7+
#----------------------------------------------------------#
8+
# Variables & Functions #
9+
#----------------------------------------------------------#
10+
11+
# Argument definition
12+
user=$1
13+
domain=$2
14+
domain_idn=$2
15+
status=$3
16+
17+
# Includes
18+
# shellcheck source=/etc/hestiacp/hestia.conf
19+
source /etc/hestiacp/hestia.conf
20+
# shellcheck source=/usr/local/hestia/func/main.sh
21+
source $HESTIA/func/main.sh
22+
# shellcheck source=/usr/local/hestia/func/rebuild.sh
23+
source $HESTIA/func/rebuild.sh
24+
# shellcheck source=/usr/local/hestia/func/domain.sh
25+
source $HESTIA/func/domain.sh
26+
# load config file
27+
source_conf "$HESTIA/conf/hestia.conf"
28+
29+
# Additional argument formatting
30+
format_domain
31+
format_domain_idn
32+
33+
#----------------------------------------------------------#
34+
# Verifications #
35+
#----------------------------------------------------------#
36+
37+
check_args '3' "$#" 'USER DOMAIN STATUS'
38+
is_format_valid 'user' 'domain' ''
39+
is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
40+
is_object_valid 'user' 'USER' "$user"
41+
is_object_unsuspended 'user' 'USER' "$user"
42+
is_object_valid 'dns' 'DOMAIN' "$domain"
43+
is_object_unsuspended 'dns' 'DOMAIN' "$domain"
44+
45+
if [ -n "$status" ]; then
46+
is_boolean_format_valid "$status" 'status'
47+
fi
48+
49+
# Perform verification if read-only mode is enabled
50+
check_hestia_demo_mode
51+
52+
#----------------------------------------------------------#
53+
# Action #
54+
#----------------------------------------------------------#
55+
56+
if [ -f "$HESTIA/data/queue/dns-cluster.pipe" ]; then
57+
bash $HESTIA/data/queue/dns-cluster.pipe
58+
fi
59+
60+
# Changing exp
61+
update_object_value 'dns' 'DOMAIN' "$domain" '$DNSSEC' "$status"
62+
63+
# Rebuild DNS config
64+
65+
rebuild_dns_domain_conf
66+
67+
if [ $status = "no" ]; then
68+
update_object_value 'dns' 'DOMAIN' "$domain" '$KEY' ""
69+
# Delete existing keys
70+
rm -fr $HOMEDIR/$user/conf/dns/$domain.db.*
71+
rm -fr /var/cache/bind/K$domain_idn.*
72+
rm -fr $USER_DATA/keys/K$domain_idn.*
73+
fi
74+
75+
# Updating dns-cluster queue
76+
if [ "$DNS_CLUSTER" = "yes" ]; then
77+
# Check for first sync
78+
dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
79+
if [ -z "$dlock" ]; then
80+
cmd="$BIN/v-add-remote-dns-domain $user $domain yes"
81+
echo "$cmd" >> $HESTIA/data/queue/dns-cluster.pipe
82+
fi
83+
fi
84+
85+
#----------------------------------------------------------#
86+
# Hestia #
87+
#----------------------------------------------------------#
88+
89+
# Logging
90+
$BIN/v-log-action "$user" "Info" "DNS" "Updated DNS SOA expiration date (Domain: $domain, Value: $exp)."
91+
log_event "$OK" "$ARGUMENTS"
92+
93+
exit

bin/v-change-dns-domain-exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ check_hestia_demo_mode
5353
update_object_value 'dns' 'DOMAIN' "$domain" '$EXP' "$exp"
5454

5555
# Updating dns-cluster queue
56-
if [ -n "$DNS_CLUSTER" ]; then
56+
if [ "$DNS_CLUSTER" = "yes" ]; then
5757
# Check for first sync
5858
dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
5959
if [ -z "$dlock" ]; then

bin/v-change-dns-domain-ip

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ source /etc/hestiacp/hestia.conf
2424
source $HESTIA/func/main.sh
2525
# shellcheck source=/usr/local/hestia/func/domain.sh
2626
source $HESTIA/func/domain.sh
27+
# shellcheck source=/usr/local/hestia/func/rebuild.sh
28+
source $HESTIA/func/rebuild.sh
2729
# load config file
2830
source_conf "$HESTIA/conf/hestia.conf"
2931

@@ -63,12 +65,11 @@ sed -i "s/$old/$ip/g" $USER_DATA/dns/$domain.conf
6365

6466
# Updating zone
6567
if [[ "$DNS_SYSTEM" =~ named|bind ]]; then
66-
update_domain_serial
67-
update_domain_zone
68+
rebuild_dns_domain_conf
6869
fi
6970

7071
# Updating dns-cluster queue
71-
if [ -n "$DNS_CLUSTER" ]; then
72+
if [ "$DNS_CLUSTER" = "yes" ]; then
7273
# Check for first sync
7374
dlock=$(grep "domain $user $domain" $HESTIA/data/queue/dns-cluster.pipe)
7475
if [ -z "$dlock" ]; then

0 commit comments

Comments
 (0)