Skip to content

Commit

Permalink
Merge pull request #49 from redBorder/development
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
manegron authored Oct 8, 2024
2 parents cf7ff22 + 34691a9 commit edc700d
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 36 deletions.
89 changes: 89 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,95 @@
cookbook-rb-proxy CHANGELOG
===============

## 1.0.0

- Miguel Negrón
- [64e7db8] Merge pull request #47 from redBorder/bugfix/18716_remove_sync_address_from_hosts_file
- [2a15362] Merge pull request #43 from redBorder/development
- [b271475] Merge pull request #42 from redBorder/development
- [c939764] Merge pull request #36 from redBorder/development
- [a88941c] Merge pull request #33 from redBorder/development
- [91f880b] Improvement/fix lint (#32)
- [6917897] Merge pull request #31 from redBorder/development
- [569bdd3] Merge pull request #30 from redBorder/bugfix/#15141_remove_geoip_from_service_list
- manegron
- [64e7db8] Merge pull request #47 from redBorder/bugfix/18716_remove_sync_address_from_hosts_file
- [08d7c8e] Simplify code
- [2a15362] Merge pull request #43 from redBorder/development
- [b271475] Merge pull request #42 from redBorder/development
- [c939764] Merge pull request #36 from redBorder/development
- [a88941c] Merge pull request #33 from redBorder/development
- [91f880b] Improvement/fix lint (#32)
- [6917897] Merge pull request #31 from redBorder/development
- [208cb02] Bump version
- [569bdd3] Merge pull request #30 from redBorder/bugfix/#15141_remove_geoip_from_service_list
- nilsver
- [cf63684] fix lint
- [20f4348] fix duplication bug
- [7a174c5] fix lint
- [f1d532e] update hosts file
- [b329547] Release 0.4.0
- [c1cdf71] Release 0.4.0
- [1e3bb37] Merge pull request #39 from redBorder/feature/18019_add_chronyd_cookbook
- [cc8b9a6] update format
- [d7bf449] update hosts file
- [e1272bb] add check for monitor configuration pipelines
- [6185bfa] fix logstash not running when pipelines empty
- [08f57da] fix logstash not running when pipelines empty
- [bbb37f7] disable freeradius
- [ec5d379] update configure.rb
- [c35b312] logstash should not be running when there are no pipelines
- JuanSheba
- [630cc1d] Release 0.6.0
- [45c4856] Release 0.3.0
- [b80305e] Release 0.2.5
- Juan Soto
- [2629e25] Merge pull request #46 from redBorder/feature/#18681_split_traffic_with_logstash
- [c521a5f] Update CHANGELOG.md
- [7338e9b] Update CHANGELOG.md
- [48f3636] Update CHANGELOG.md
- [ad927c6] Merge pull request #34 from redBorder/bugfix/17238_logstash_not_running_when_no_pipelines
- [5e2004d] Merge pull request #37 from redBorder/feature/add_clamav
- [9eeef01] Merge pull request #35 from redBorder/bugfix/17578_disable_freeradius
- David Vanhoucke
- [7dadc5e] use descrfptive name
- [964e8d0] remove blank line
- [a686df0] add method to activate the split of the traffic through logstash
- JPeraltaNic
- [1effbed] Merge pull request #45 from redBorder/development
- [546fc0d] Release 0.5.1
- [3df81bb] Merge pull request #44 from redBorder/bugfix/18586_no_sensors_in_proxy
- [20616f2] Merge branch 'master' into bugfix/18586_no_sensors_in_proxy
- [acd32dc] Merge pull request #41 from redBorder/feature/18393_update_hosts_file
- [982e2b0] Merge branch 'master' into feature/18393_update_hosts_file
- [4a64c6d] Update CHANGELOG.md
- Daniel Castro
- [8645664] get rid of unnecesary attributes
- [22fb6a9] fix chef node attribute
- [c3c2fd3] 18586 send node info to redborder-monitor
- [794a4a6] Release 0.5.0
- [b85f706] Release 0.4.1 ammend
- [26855b5] Release 0.4.1
- [2d14d08] Merge pull request #40 from redBorder/feature/#16519_enable_ale_if_sensors
- Miguel Álvarez
- [8a7c051] Update configure.rb
- [4cfaf41] Update default.rb
- [49a3825] Update configure.rb
- [2cd3e11] Update default.rb
- Miguel Alvarez
- [2daff03] Add chronyd cookbook
- [56ef242] Add chronyd cookbook
- [3f38047] Add clamAV
- Luis Blanco
- [cb38a36] disable service ale by default
- [bbaff20] action based on if there is any ale sensor
- [2bda259] Merge pull request #38 from redBorder/development
- [e02fe7a] remove from the service list. Not remove, always add in configuration
- vimesa
- [8f950d5] Release 0.2.4
- Miguel Negron
- [208cb02] Bump version

## 0.6.0

- David Vanhoucke
Expand Down
60 changes: 25 additions & 35 deletions resources/libraries/update_hosts_file.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
module RbProxy
module Helpers
def update_hosts_file
managers = get_managers_all()
manager_ip = []
managers.each do |m|
manager_ip << m['ipaddress_sync']
end

# grouped_virtual_ips returns a hash where:
# - The keys are IP addresses from the data bags, or `nil` if an IP is missing.
# - The values are arrays of services associated with each IP address.
# - If an IP is missing from a data bag, the associated services are grouped under the sync_ip key.
grouped_virtual_ips = Hash.new { |hash, key| hash[key] = [] }
databags = Chef::DataBag.load('rBglobal').keys
databags.each do |bag|
next unless bag.start_with?('ipvirtual-external')
virtual_dg = data_bag_item('rBglobal', bag)
ip = virtual_dg['ip']

if ip && !ip.empty?
grouped_virtual_ips[ip] << bag.gsub('ipvirtual-external-', '')
else
grouped_virtual_ips[manager_ip[0]] << bag.gsub('ipvirtual-external-', '')
end
end

# Read hosts file and store in hash
def read_hosts_file
hosts_hash = Hash.new { |hash, key| hash[key] = [] }
File.readlines('/etc/hosts').each do |line|
next if line.strip.empty? || line.start_with?('#')
Expand All @@ -34,23 +9,39 @@ def update_hosts_file
services = values
hosts_hash[ip].concat(services).uniq!
end
hosts_hash
end

# Update hosts_hash based on grouped_virtual_ips
def update_hosts_file
manager_registration_ip = node['redborder']['manager_registration_ip'] if node['redborder'] && node['redborder']['manager_registration_ip']

return unless manager_registration_ip

running_services = node['redborder']['systemdservices'].values.flatten if node['redborder']['systemdservices']
databags = Chef::DataBag.load('rBglobal').keys.grep(/^ipvirtual-external-/).map { |bag| bag.sub('ipvirtual-external-', '') }
hosts_hash = read_hosts_file

# Hash where services (from databag) are grouped by ip
grouped_virtual_ips = Hash.new { |hash, key| hash[key] = [] }
databags.each { |bag_serv| grouped_virtual_ips[manager_registration_ip] << "#{bag_serv}" }
running_services.each { |serv| grouped_virtual_ips['127.0.0.1'] << serv }

# Group services
grouped_virtual_ips.each do |new_ip, new_services|
new_services.each do |new_service|
# Avoids having duplicate services in the list
service_key = new_service.split('.').first

hosts_hash.each do |_ip, services|
services.delete_if { |service| service.split('.').first == service_key }
end

if new_ip
hosts_hash[new_ip] << "#{new_service}.service"
hosts_hash[new_ip] << "#{new_service}.#{node['redborder']['cdomain']}"
else
hosts_hash[manager_ip[0]] << "#{new_service}.service"
hosts_hash[manager_ip[0]] << "#{new_service}.#{node['redborder']['cdomain']}"
# Add running services to localhost
if new_ip == '127.0.0.1' && running_services.include?(new_service)
hosts_hash['127.0.0.1'] << "#{new_service}.service"
next
end
hosts_hash[manager_registration_ip] << "#{new_service}.service"
hosts_hash[manager_registration_ip] << "#{new_service}.#{node['redborder']['cdomain']}"
end
end

Expand All @@ -60,7 +51,6 @@ def update_hosts_file
format_entry = format('%-18s%s', ip, services.join(' '))
hosts_entries << format_entry unless services.empty?
end

hosts_entries
end
end
Expand Down
2 changes: 1 addition & 1 deletion resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
maintainer_email 'git@redborder.com'
license 'AGPL-3.0'
description 'Installs/Configures redborder proxy'
version '0.6.0'
version '1.0.0'

depends 'rb-common'
depends 'rb-selinux'
Expand Down

0 comments on commit edc700d

Please sign in to comment.