Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fc7716a0a2 | |||
| d71e221049 | |||
| 0de3ac2a0b | |||
| 0702676da6 | |||
| 88fcb97ad1 |
@@ -6,3 +6,4 @@ profiles::consul::token::node_editor::secret_id: ENC[PKCS7,MIIBmQYJKoZIhvcNAQcDo
|
||||
profiles::consul::server::acl_tokens_initial_management: ENC[PKCS7,MIIBmQYJKoZIhvcNAQcDoIIBijCCAYYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAi1UH7AZirJ1PdxWy+KEgS5ufm0wbn2xy9rkg14hKYpcVjBa4pOZpSLMGMiiUpBIqBytDMZM4ezYa/luktpkBImJbM/TE16beGtsacQGA+9eZk2Tihs9GR2qbAQiu5lLITiDlwNnf0GeWdqHM8CTeD68DczQF320d9U14/k6pG/7z+w/MGLcjsQoSuOFTm42JVn1BI46t1CYSCHMXQc/9Tfs+FzI+vumohI8DxAYBIuyzU5HBX/MntAsvD/yixMJS1pZL9WwgqZJC/wK34rVRB39DpxWf/WROrI+WLuSJwr7WBjaeF9Ju+89WKCgsI53EWhFTj8GgDZm/jqPoE478NjBcBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBAoACRzJdQKNYXZv6cghFIIgDAzB81DMcuY815nb8POtZpiA06jT/068AoZmSctHoFK/zW9tY229N5r1Tb+WHElqLk=]
|
||||
profiles::consul::server::acl_tokens_default: ENC[PKCS7,MIIBmQYJKoZIhvcNAQcDoIIBijCCAYYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAh4Ag95xgkIZHL0gP9OLnZauih0dB1/2l9Jzw8mP3OiIv7fw23otHYONlS3Emtj7oxW8MKcZGKDCzwCT6T2p+V5wx1n15wr2J+FmL24VbclJwrMPQ4AdgP359B9h21uoyo7Zdy7RuuvLfkU1fWXbs3SeWbi2HJs1Ed1/oI1jzr3OgwMbVtbyzd1VuAXeZ9bHQG3IA8z+w/k5m61th0HTyHjw7eldQulbohDuwv545z9axHEoHKCRT2a3ZwBufV2ST6Dm3g9GERzXE9Adp9DQC5adqM74wfsujOMLK2QFJSSIOj2uCs1CpEnrNrQ8zjP3fudM2z3l7KdSHZazEamCSxTBcBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBBY/Tn9tzEKYc5dxnzP2rP7gDBWKgVP3lf2T4Q0WPQt3ns0E6RUSO6OtBegb/5qDyohY2nsDeJTnMKOYzYt/J1PhnY=]
|
||||
profiles::consul::server::acl_tokens_replication: ENC[PKCS7,MIIBmQYJKoZIhvcNAQcDoIIBijCCAYYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAEzTIxbaAR/TZYnC671aBhiahsfwf3ieyeSHpD5hQm40sMEF/fXlEDijq9i2ykPikm94074j1Uo4HNzv/V9GTf0NSC/64t61jJ/Ya3QKa5f/36+DcRj3lcETsSIyhWwmU+E+zkY8I2r68MtXAuvSoMSMZdpgWSkPx/3FFgZlrsg//bzDu69jS9cx4UK582N3A6QN4Uy/qwYtJcm+2iTQlqqgGRWGqnSgTirxhegxPbJGWTDoAEpAL4/DyF5/hqcUn6mgoSfAsHF3loPHOqN30lG+9o0THWJ9B8Gf4W/1X2UWA/avmUnqBnumGoz0p7AYdNgpW+qLl2rk4lyGYa4kvQjBcBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBD9KSLH3Pn/1EIzgVJM+8VOgDDpKWzHfSVsfUMyTD0XIRPGclTdmxqCnsdhKNqmUfSjkYIf2nI9rQtSK6n42TYuO4k=]
|
||||
profiles::dns::updater::key_secret: ENC[PKCS7,MIIBmQYJKoZIhvcNAQcDoIIBijCCAYYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAJ4GrN3W4zGfVygfji1MeGyAlmlFN45TVP5st6b66jSKeDYNg9BwdnXahUzkmKvFIYdPWyvXqJdvuyUNz7lWr1dw/pTNHrvqUKSvI0C5TOwmtrTwXtTvucDGs7c7FZDfgUxvLs/Vrp0ZdW3C81QXWNBI8vBfVZyiegPNq+5mX7mtcrFE7jZj1g1qwpg/30lrlCguPyXqnmdtBa7VAyU2Al1UZwkrKIYSAOb9GTnvM6bk5L26pW/NXGj+ffacwf58b4AiKCak5lhoCIInVnlogPuThxULN4RF+MYAVIlgwk159CR1abjWjioxvmP7XgjQUwUuTlgoLh9fDZa0amDeFZTBcBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBBEb1BTjhuTN9wGrxc2rdQVgDCctNdt72UR/Hj4wteK7XIX6fF43+7FYKBZnPtyWIWalwDniH//H3gfsJ+ULqSb82w=]
|
||||
|
||||
@@ -146,6 +146,8 @@ lookup_options:
|
||||
strategy: deep
|
||||
profiles::etcd::node::initial_cluster_token:
|
||||
convert_to: Sensitive
|
||||
profiles::dns::updater::key_secret:
|
||||
convert_to: Sensitive
|
||||
sysctl::base::values:
|
||||
merge:
|
||||
strategy: deep
|
||||
@@ -208,6 +210,20 @@ vault::disable_mlock: false
|
||||
profiles::dns::base::nameservers:
|
||||
- 198.18.19.16
|
||||
profiles::dns::master::basedir: '/var/named/sources'
|
||||
|
||||
# dns record publishing. During the k8s cutover both methods run; set
|
||||
# manage_export false once k8s is authoritative.
|
||||
# - export: legacy exported-resources -> puppet DNS master
|
||||
# - nsupdate: RFC2136 to the k8s bind-authoritative write endpoint (.9),
|
||||
# inert until the TSIG key is set in eyaml:
|
||||
# profiles::dns::updater::key_secret: ENC[...]
|
||||
# (must match the key the bind-authoritative zones allow-update
|
||||
# with; algorithm hmac-sha256)
|
||||
profiles::dns::updater::manage_export: true
|
||||
profiles::dns::updater::manage_nsupdate: true
|
||||
profiles::dns::updater::server: '198.18.200.9'
|
||||
profiles::dns::updater::key_name: 'client-update'
|
||||
profiles::dns::updater::key_algorithm: 'hmac-sha256'
|
||||
#profiles::dns::base::ns_role: 'roles::infra::dns::resolver'
|
||||
#profiles::dns::base::use_ns: 'region'
|
||||
profiles::consul::server::members_role: roles::infra::storage::consul
|
||||
|
||||
@@ -29,3 +29,5 @@ profiles::nginx::simpleproxy::proxy_path: '/'
|
||||
profiles::packages::include:
|
||||
openbao-plugins: {}
|
||||
openbao-plugin-secrets-litellm: {}
|
||||
openbao-plugin-secrets-gpg: {}
|
||||
openbao-plugin-secrets-rancher: {}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# lib/facter/dns_records.rb
|
||||
#
|
||||
# Reports this host's expected DNS records (assembled by profiles::dns::updater
|
||||
# into its records file) versus what is currently deployed on the authoritative
|
||||
# server, so puppet can detect drift and re-apply.
|
||||
#
|
||||
# Structured value:
|
||||
# { server, count, expected => [{zone,fqdn,type,ttl,value}], in_sync,
|
||||
# drift => [{...,deployed => [...]}] }
|
||||
|
||||
# Helpers for the dns_records fact.
|
||||
module DnsRecordsFact
|
||||
RECORDS_FILE = '/var/lib/dns-updater/records'
|
||||
SERVER_FILE = '/var/lib/dns-updater/server'
|
||||
|
||||
module_function
|
||||
|
||||
# normalise a value for comparison: strip, drop trailing dot, downcase
|
||||
def norm(value)
|
||||
value.to_s.strip.chomp('.').downcase
|
||||
end
|
||||
|
||||
def server
|
||||
File.exist?(SERVER_FILE) ? File.read(SERVER_FILE).strip : nil
|
||||
end
|
||||
|
||||
# a name relative to a zone (or @) as a fully-qualified name
|
||||
def to_fqdn(name, zone)
|
||||
return "#{zone}." if name.to_s.empty? || name == '@'
|
||||
|
||||
"#{name}.#{zone}."
|
||||
end
|
||||
|
||||
# parse one "zone|name|type|ttl|value" line into a record hash (nil to skip)
|
||||
def parse_line(line)
|
||||
line = line.strip
|
||||
return nil if line.empty? || line.start_with?('#')
|
||||
|
||||
zone, name, type, ttl, value = line.split('|', 5)
|
||||
return nil unless zone && type && value
|
||||
|
||||
{ 'zone' => zone, 'fqdn' => to_fqdn(name, zone), 'type' => type, 'ttl' => ttl, 'value' => value }
|
||||
end
|
||||
|
||||
# parse the records file into record hashes
|
||||
def expected
|
||||
return [] unless File.exist?(RECORDS_FILE)
|
||||
|
||||
File.readlines(RECORDS_FILE).filter_map { |line| parse_line(line) }
|
||||
end
|
||||
|
||||
# the values currently deployed for a record, per the authoritative server
|
||||
def deployed(record, srv)
|
||||
cmd = ['dig', '+short', '+time=2', '+tries=1']
|
||||
cmd << "@#{srv}" if srv && !srv.empty?
|
||||
cmd += [record['fqdn'], record['type']]
|
||||
out = Facter::Core::Execution.execute(cmd.join(' '), on_fail: '')
|
||||
out.to_s.split("\n").map { |line| norm(line) }.reject(&:empty?)
|
||||
end
|
||||
|
||||
def report
|
||||
srv = server
|
||||
exp = expected
|
||||
drift = exp.filter_map do |record|
|
||||
dep = deployed(record, srv)
|
||||
record.merge('deployed' => dep) unless dep.include?(norm(record['value']))
|
||||
end
|
||||
{ 'server' => srv, 'count' => exp.length, 'expected' => exp, 'in_sync' => drift.empty?, 'drift' => drift }
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add(:dns_records) do
|
||||
confine kernel: 'Linux'
|
||||
setcode do
|
||||
File.exist?(DnsRecordsFact::RECORDS_FILE) ? DnsRecordsFact.report : nil
|
||||
end
|
||||
end
|
||||
|
||||
# Convenience boolean for `if $facts['dns_records_insync']` guards.
|
||||
Facter.add(:dns_records_insync) do
|
||||
confine kernel: 'Linux'
|
||||
setcode do
|
||||
v = Facter.value(:dns_records)
|
||||
v.nil? ? nil : v['in_sync']
|
||||
end
|
||||
end
|
||||
@@ -11,9 +11,12 @@ class profiles::dns::base (
|
||||
Optional[String] $ns_role = undef,
|
||||
){
|
||||
|
||||
# install bind_utils
|
||||
# install bind_utils (provides nsupdate)
|
||||
include bind::updater
|
||||
|
||||
# assemble the host's DNS records and nsupdate them to the authoritative server
|
||||
include profiles::dns::updater
|
||||
|
||||
# if ns_role is set, find all hosts matching that enc_role
|
||||
$nameserver_array = $ns_role ? {
|
||||
undef => $nameservers,
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
# defines the base record that will be exported
|
||||
# profiles::dns::record
|
||||
#
|
||||
# Declares a DNS record for this host. Publishes it via either or both methods,
|
||||
# controlled by profiles::dns::updater's toggles (both on during cutover):
|
||||
# - nsupdate: a local concat fragment consumed by profiles::dns::updater,
|
||||
# which nsupdates it to the authoritative server.
|
||||
# - export: the legacy @@concat::fragment exported to the puppet DNS master.
|
||||
define profiles::dns::record (
|
||||
String $record,
|
||||
Enum[
|
||||
@@ -13,11 +19,26 @@ define profiles::dns::record (
|
||||
String $value,
|
||||
String $zone,
|
||||
Integer $order,
|
||||
Stdlib::AbsolutePath $basedir = lookup('profiles::dns::master::basedir'),
|
||||
Integer $ttl = 300,
|
||||
) {
|
||||
@@concat::fragment { "${zone}_${name}":
|
||||
target => "${basedir}/${zone}.conf",
|
||||
content => "${record} IN ${type} ${value}\n",
|
||||
order => $order,
|
||||
include profiles::dns::updater
|
||||
|
||||
# new: local records file consumed by the nsupdate service
|
||||
if $profiles::dns::updater::manage_nsupdate {
|
||||
# zone|name|type|ttl|value (parsed by the dns-update script)
|
||||
concat::fragment { "dns-record-${name}":
|
||||
target => $profiles::dns::updater::records_file,
|
||||
content => "${zone}|${record}|${type}|${ttl}|${value}\n",
|
||||
order => sprintf('%03d', $order),
|
||||
}
|
||||
}
|
||||
|
||||
# legacy: export the fragment to the puppet DNS master
|
||||
if $profiles::dns::updater::manage_export {
|
||||
@@concat::fragment { "${zone}_${name}":
|
||||
target => "${profiles::dns::updater::master_basedir}/${zone}.conf",
|
||||
content => "${record} IN ${type} ${value}\n",
|
||||
order => $order,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
# profiles::dns::updater
|
||||
#
|
||||
# Publishes this host's DNS records. Two methods, independently toggled so both
|
||||
# can run during the k8s cutover (profiles::dns::record honours the same flags):
|
||||
#
|
||||
# - nsupdate ($manage_nsupdate): assemble the records into a local file and
|
||||
# nsupdate them to the k8s authoritative write endpoint via a systemd .path
|
||||
# unit that watches the file. Inert until $key_secret (TSIG) is set.
|
||||
# - export ($manage_export): the legacy exported-resources flow to the puppet
|
||||
# DNS master. Kept during cutover; disable once k8s is authoritative.
|
||||
#
|
||||
# nsupdate comes from bind-utils (installed via bind::updater in
|
||||
# profiles::dns::base).
|
||||
class profiles::dns::updater (
|
||||
Boolean $manage_nsupdate = true,
|
||||
Boolean $manage_export = true,
|
||||
String $server = '198.18.200.9',
|
||||
String $key_name = 'client-update',
|
||||
String $key_algorithm = 'hmac-sha256',
|
||||
Optional[Sensitive[String]] $key_secret = undef,
|
||||
Integer $default_ttl = 300,
|
||||
Stdlib::AbsolutePath $records_file = '/var/lib/dns-updater/records',
|
||||
Stdlib::AbsolutePath $state_dir = '/var/lib/dns-updater',
|
||||
Stdlib::AbsolutePath $config_dir = '/etc/dns-updater',
|
||||
Stdlib::AbsolutePath $master_basedir = lookup('profiles::dns::master::basedir'),
|
||||
# dns-updater daemon (replaces the dns-update shell script).
|
||||
String $package_ensure = 'installed',
|
||||
Stdlib::AbsolutePath $api_socket = '/run/dns-updater/api.sock',
|
||||
String $resync = '10m',
|
||||
Enum['debug', 'info', 'warn', 'error'] $log_level = 'info',
|
||||
Boolean $watch_interfaces = true,
|
||||
) {
|
||||
|
||||
$state_file = "${state_dir}/applied"
|
||||
$server_file = "${state_dir}/server"
|
||||
$key_file = "${config_dir}/key"
|
||||
|
||||
if $manage_nsupdate {
|
||||
|
||||
file { $state_dir:
|
||||
ensure => directory,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
}
|
||||
|
||||
# Server address, read by the dns_records fact for drift detection.
|
||||
file { $server_file:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => "${server}\n",
|
||||
require => File[$state_dir],
|
||||
}
|
||||
|
||||
# Records file, assembled from profiles::dns::record fragments.
|
||||
concat { $records_file:
|
||||
ensure => present,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
ensure_newline => true,
|
||||
warn => false,
|
||||
require => File[$state_dir],
|
||||
}
|
||||
|
||||
concat::fragment { 'dns-update-header':
|
||||
target => $records_file,
|
||||
content => "# Managed by puppet (profiles::dns::record): zone|name|type|ttl|value\n",
|
||||
order => '00',
|
||||
}
|
||||
|
||||
if $key_secret =~ Undef {
|
||||
notify { 'dns-updater-inert':
|
||||
message => 'profiles::dns::updater: key_secret unset; records assembled but not applied.',
|
||||
loglevel => 'info',
|
||||
}
|
||||
} else {
|
||||
file { $config_dir:
|
||||
ensure => directory,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0700',
|
||||
}
|
||||
|
||||
file { $key_file:
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0600',
|
||||
show_diff => false,
|
||||
content => Sensitive(epp('profiles/dns/tsig-key.epp', {
|
||||
'name' => $key_name,
|
||||
'algorithm' => $key_algorithm,
|
||||
'secret' => $key_secret.unwrap,
|
||||
})),
|
||||
}
|
||||
|
||||
# dns-updater daemon: watches the records file (inotify) and network
|
||||
# interfaces, pushes TSIG-signed RFC2136 updates to $server natively.
|
||||
package { 'dns-updater':
|
||||
ensure => $package_ensure,
|
||||
}
|
||||
|
||||
$env_content = @("ENV")
|
||||
# Managed by puppet (profiles::dns::updater).
|
||||
DNS_UPDATER_SERVER=${server}
|
||||
DNS_UPDATER_KEY_FILE=${key_file}
|
||||
DNS_UPDATER_RECORDS_FILE=${records_file}
|
||||
DNS_UPDATER_STATE_FILE=${state_file}
|
||||
DNS_UPDATER_API=${api_socket}
|
||||
DNS_UPDATER_RESYNC=${resync}
|
||||
DNS_UPDATER_WATCH_INTERFACES=${watch_interfaces}
|
||||
DNS_UPDATER_LOG_LEVEL=${log_level}
|
||||
| ENV
|
||||
|
||||
file { "${config_dir}/env":
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
content => $env_content,
|
||||
require => [File[$config_dir], Package['dns-updater']],
|
||||
}
|
||||
|
||||
# Restart only on config/key change; records-file changes are picked up by
|
||||
# the daemon's own inotify watch, so no service churn on record edits.
|
||||
service { 'dns-updater':
|
||||
ensure => running,
|
||||
enable => true,
|
||||
subscribe => [File["${config_dir}/env"], File[$key_file]],
|
||||
require => [Package['dns-updater'], Concat[$records_file], File[$key_file]],
|
||||
}
|
||||
|
||||
# Retire the previous shell-based mechanism.
|
||||
file { '/usr/local/bin/dns-update':
|
||||
ensure => absent,
|
||||
}
|
||||
|
||||
systemd::unit_file { 'dns-update.service':
|
||||
ensure => absent,
|
||||
active => false,
|
||||
enable => false,
|
||||
}
|
||||
|
||||
systemd::unit_file { 'dns-update.path':
|
||||
ensure => absent,
|
||||
active => false,
|
||||
enable => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<%- | String $name, String $algorithm, String $secret | -%>
|
||||
key "<%= $name %>" {
|
||||
algorithm <%= $algorithm %>;
|
||||
secret "<%= $secret %>";
|
||||
};
|
||||
Reference in New Issue
Block a user