Skip to content

Commit

Permalink
Removes nats user and password from hm / director
Browse files Browse the repository at this point in the history
- they were not being used now that we have mutual TLS
- the CPI will actually send the mbus URL for non-mutual TLS
if the CPI has been configured with nats username and password
- the tests have been modified to fix legacy agent support

[#151420600](https://www.pivotaltracker.com/story/show/151420600)

Signed-off-by: Jamil Shamy <[email protected]>
  • Loading branch information
Zachary Gershman authored and pivotal-jamil-shamy committed Oct 19, 2017
1 parent 67591f0 commit b0da4b0
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 105 deletions.
5 changes: 0 additions & 5 deletions jobs/director/spec
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ properties:
default: vcap

# NATs
nats.user:
description: Username to connect to nats with
default: nats
nats.password:
description: Password to connect to nats with
nats.address:
description: Address of the nats server
nats.port:
Expand Down
9 changes: 5 additions & 4 deletions jobs/director/templates/director.yml.erb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ params = {
'level' => 'DEBUG',
'file' => "/var/vcap/sys/log/director/<" + "%= ENV['COMPONENT'] %" + ">.debug.log"
},
'mbus' => "nats://#{p('nats.user')}:#{p('nats.password')}@#{p('nats.address')}:#{p('nats.port')}",
'mbus' => "nats://#{p('nats.address')}:#{p('nats.port')}",
'nats' => {
'server_ca_path' => '/var/vcap/jobs/director/config/nats_server_ca.pem',
'client_ca_certificate_path' => '/var/vcap/jobs/director/config/nats_client_ca_certificate.pem',
Expand Down Expand Up @@ -386,6 +386,7 @@ if_p('director.default_ssh_options.gateway_host',
end

cpi_job_name = p('director.cpi_job')

params['cloud'] = {
'provider' => {
'name' => cpi_job_name,
Expand All @@ -395,12 +396,12 @@ params['cloud'] = {
}

params['cloud']['properties']['agent'] = {
'ntp' => p('ntp'),
'blobstore' => {'provider' => p('blobstore.provider'), 'options' => {} },
'mbus' => "nats://#{p('nats.user')}:#{p('nats.password')}@#{p(['agent.nats.address', 'nats.address'])}:#{p('nats.port')}"
'ntp' => p('ntp'),
'blobstore' => {'provider' => p('blobstore.provider'), 'options' => {} },
}

agent_blobstore_options = params['cloud']['properties']['agent']['blobstore']['options']

if p('blobstore.provider') == "s3"
agent_blobstore_options['bucket_name'] = p('blobstore.bucket_name')
agent_blobstore_options['credentials_source'] = p(['agent.blobstore.credentials_source', 'blobstore.credentials_source'], 'static')
Expand Down
4 changes: 0 additions & 4 deletions jobs/health_monitor/spec
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ properties:
nats.port:
description: Port of the NATS message bus port to connect to
default: 4222
nats.user:
description: User for the NATS message bus connection
nats.password:
description: Password for NATS message bus connection
nats.tls.ca:
description: 'CA cert to trust when communicating with NATS server'
nats.tls.health_monitor.certificate:
Expand Down
2 changes: 0 additions & 2 deletions jobs/health_monitor/templates/health_monitor.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ params = {
},
'mbus' => {
'endpoint' => "nats://#{p('nats.address')}:#{p('nats.port')}",
'user' => p('nats.user'),
'password' => p('nats.password'),
'server_ca_path' => '/var/vcap/jobs/health_monitor/config/nats_server_ca.pem',
'client_certificate_path' => '/var/vcap/jobs/health_monitor/config/nats_client_certificate.pem',
'client_private_key_path' => '/var/vcap/jobs/health_monitor/config/nats_client_private_key'
Expand Down
2 changes: 0 additions & 2 deletions spec/director.yml.erb.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
'provider' => 'dav',
},
'nats' => {
'user' => 'nats',
'password' => '1a0312a24c0a0',
'address' => '10.10.0.7',
'port' => 4222
},
Expand Down
4 changes: 2 additions & 2 deletions spec/director_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'bosh/template/evaluation_context'
require_relative './template_example_group'

describe 'director tempaltes' do
describe 'director templates' do
describe 'director' do
describe 'nats_client_certificate.pem.erb' do
it_should_behave_like 'a rendered file' do
Expand Down Expand Up @@ -83,4 +83,4 @@
end
end

end
end
4 changes: 0 additions & 4 deletions spec/health_monitor_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
'nats' => {
'address' => '0.0.0.0',
'port' => 4222,
'user' => 'my-user',
'password' => 'my-password',
},
'director' => {
'address' => '0.0.0.0',
Expand All @@ -67,8 +65,6 @@
it 'renders' do
expect(parsed_yaml['http']['port']).to eq(8081)
expect(parsed_yaml['mbus']['endpoint']).to eq('nats://0.0.0.0:4222')
expect(parsed_yaml['mbus']['user']).to eq('my-user')
expect(parsed_yaml['mbus']['password']).to eq('my-password')
expect(parsed_yaml['mbus']['server_ca_path']).to eq('/var/vcap/jobs/health_monitor/config/nats_server_ca.pem')
expect(parsed_yaml['mbus']['client_certificate_path']).to eq('/var/vcap/jobs/health_monitor/config/nats_client_certificate.pem')
expect(parsed_yaml['mbus']['client_private_key_path']).to eq('/var/vcap/jobs/health_monitor/config/nats_client_private_key')
Expand Down
12 changes: 12 additions & 0 deletions src/bosh-dev/assets/sandbox/cpi_config.json.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dir": "<%= cloud_storage_dir %>",
"nats": "<%= nats_url %>",
"agent": {
"blobstore": {
"provider": "local",
"options": {
"blobstore_path": "<%= blobstore_storage_dir %>"
}
}
}
}
13 changes: 0 additions & 13 deletions src/bosh-dev/assets/sandbox/director_test.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ runtime:

port: <%= director_ruby_port %>

<% if nats_allow_legacy_clients %>
mbus: nats://<%= nats_user %>:<%= nats_password %>@127.0.0.1:<%= nats_port %>
<% else %>
mbus: nats://127.0.0.1:<%= nats_port %>
<% end %>

logging:
level: DEBUG
Expand Down Expand Up @@ -85,19 +81,10 @@ cloud:
name: <%= external_cpi_config[:name] %>
path: <%= external_cpi_config[:job_path] %>
properties:
<% if nats_allow_legacy_clients %>
nats: nats://<%= nats_user %>:<%= nats_password %>@localhost:<%= nats_port %>
<% else %>
nats: nats://localhost:<%= nats_port %>
<% end %>
dir: <%= cloud_storage_dir %>
agent:
blobstore:
<<: *director_blobstore
server:
host: 127.0.0.1
host: 127.0.0.1
password:

user_management:
provider: <%= user_authentication %>
Expand Down
7 changes: 0 additions & 7 deletions src/bosh-dev/assets/sandbox/health_monitor.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ http:

mbus:
endpoint: nats://localhost:<%= nats_port %>
<% if nats_allow_legacy_clients %>
user: <%= nats_user %>
password: <%= nats_password %>
<% else %>
user:
password:
<% end %>
server_ca_path: <%= nats_certificate_paths['ca_path'] %>
client_private_key_path: <%= nats_certificate_paths['clients']['health_monitor']['private_key_path'] %>
client_certificate_path: <%= nats_certificate_paths['clients']['health_monitor']['certificate_path'] %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ http:

mbus:
endpoint: nats://localhost:<%= nats_port %>
user:
password:
server_ca_path: <%= nats_certificate_paths['ca_path'] %>
client_private_key_path: <%= nats_certificate_paths['clients']['health_monitor']['private_key_path'] %>
client_certificate_path: <%= nats_certificate_paths['clients']['health_monitor']['certificate_path'] %>
Expand Down Expand Up @@ -34,4 +32,4 @@ plugins:
- alert
- heartbeat
options:
format: json
format: json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ http:

mbus:
endpoint: nats://localhost:<%= nats_port %>
user:
password:
server_ca_path: <%= nats_certificate_paths['ca_path'] %>
client_private_key_path: <%= nats_certificate_paths['clients']['health_monitor']['private_key_path'] %>
client_certificate_path: <%= nats_certificate_paths['clients']['health_monitor']['certificate_path'] %>
Expand Down
8 changes: 1 addition & 7 deletions src/bosh-dev/lib/bosh/dev/sandbox/director_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class DirectorConfig
:nats_server_ca_path,
:nats_client_ca_private_key_path,
:nats_client_ca_certificate_path,
:nats_director_tls,
:nats_allow_legacy_clients,
:nats_user,
:nats_password
:nats_director_tls

def initialize(attrs, port_provider)
@director_name = 'TestDirector'
Expand Down Expand Up @@ -82,9 +79,6 @@ def initialize(attrs, port_provider)
@nats_client_ca_private_key_path = attrs.fetch(:nats_client_ca_private_key_path)
@nats_client_ca_certificate_path = attrs.fetch(:nats_client_ca_certificate_path)
@nats_director_tls = attrs.fetch(:nats_director_tls)
@nats_allow_legacy_clients = attrs.fetch(:nats_allow_legacy_clients)
@nats_user = attrs.fetch(:nats_user)
@nats_password = attrs.fetch(:nats_password)
end

def render(template_path)
Expand Down
46 changes: 34 additions & 12 deletions src/bosh-dev/lib/bosh/dev/sandbox/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Main
EXTERNAL_CPI = 'cpi'
EXTERNAL_CPI_TEMPLATE = File.join(SANDBOX_ASSETS_DIR, 'cpi.erb')

EXTERNAL_CPI_CONFIG = 'cpi.json'
EXTERNAL_CPI_CONFIG_TEMPLATE = File.join(SANDBOX_ASSETS_DIR, 'cpi_config.json.erb')

UPGRADE_SPEC_ASSETS_DIR = File.expand_path('spec/assets/upgrade', REPO_ROOT)

attr_reader :name
Expand All @@ -56,7 +59,7 @@ class Main
attr_reader :nats_log_path
attr_reader :nats_host

attr_reader :nats_user, :nats_password, :nats_allow_legacy_clients
attr_reader :nats_url, :nats_user, :nats_password, :nats_allow_legacy_clients
attr_reader :nats_needs_restart

attr_accessor :trusted_certs
Expand Down Expand Up @@ -129,11 +132,23 @@ def initialize(db_opts, debug, test_env_number, logger)

# Note that this is not the same object
# as dummy cpi used inside bosh-director process
@cpi = Bosh::Clouds::Dummy.new({
'dir' => cloud_storage_dir,
'agent' => {'blobstore' => {}},
'nats' => "nats://localhost:#{nats_port}"}, {})
reconfigure({})
@cpi = Bosh::Clouds::Dummy.new(
{
'dir' => cloud_storage_dir,
'agent' => {
'blobstore' => {
'provider' => 'local',
'options' => {
'blobstore_path' => @blobstore_storage_dir,
},
}
},
'nats' => @nats_url,
},
{}
)

reconfigure
end

def agent_tmp_path
Expand Down Expand Up @@ -203,9 +218,6 @@ def director_config
nats_client_ca_private_key_path: get_nats_client_ca_private_key_path,
nats_client_ca_certificate_path: get_nats_client_ca_certificate_path,
nats_director_tls: nats_certificate_paths['clients']['director'],
nats_allow_legacy_clients: @nats_allow_legacy_clients,
nats_user: @nats_user,
nats_password: @nats_password,
}
DirectorConfig.new(attributes, @port_provider)
end
Expand Down Expand Up @@ -299,7 +311,7 @@ def sandbox_root
File.join(Workspace.dir, 'sandbox')
end

def reconfigure(options)
def reconfigure(options={})
@user_authentication = options.fetch(:user_authentication, 'local')
@config_server_enabled = options.fetch(:config_server_enabled, false)
@drop_database = options.fetch(:drop_database, false)
Expand All @@ -324,6 +336,14 @@ def reconfigure(options)
def check_if_nats_need_reset(allow_legacy_clients)
@nats_needs_restart = @nats_allow_legacy_clients != allow_legacy_clients
@nats_allow_legacy_clients = allow_legacy_clients

if @nats_allow_legacy_clients
@nats_url = "nats://#{@nats_user}:#{@nats_password}@127.0.0.1:#{nats_port}"
else
@nats_url = "nats://127.0.0.1:#{nats_port}"
end

@cpi.options['nats'] = @nats_url
end

def certificate_path
Expand Down Expand Up @@ -357,7 +377,7 @@ def nats_certificate_paths

def director_nats_config
{
uri: "nats://localhost:#{nats_port}",
uri: "nats://127.0.0.1:#{nats_port}",
ssl: true,
tls: {
:private_key_file => nats_certificate_paths['clients']['test_client']['private_key_path'],
Expand Down Expand Up @@ -394,7 +414,7 @@ def external_cpi_config
name: 'test-cpi',
exec_path: File.join(REPO_ROOT, 'bosh-director', 'bin', 'dummy_cpi'),
job_path: sandbox_path(EXTERNAL_CPI),
config_path: sandbox_path(DirectorService::DEFAULT_DIRECTOR_CONFIG),
config_path: sandbox_path(EXTERNAL_CPI_CONFIG),
env_path: ENV['PATH'],
gem_home: ENV['GEM_HOME'],
gem_path: ENV['GEM_PATH']
Expand Down Expand Up @@ -425,6 +445,7 @@ def do_reset
@nats_process.stop
nats_template_path = File.join(SANDBOX_ASSETS_DIR, DEFAULT_NATS_CONF_TEMPLATE_NAME)
write_in_sandbox(NATS_CONFIG, load_config_template(nats_template_path))
write_in_sandbox(EXTERNAL_CPI_CONFIG, load_config_template(EXTERNAL_CPI_CONFIG_TEMPLATE))
setup_nats
@nats_process.start
@nats_socket_connector.try_to_connect
Expand All @@ -444,6 +465,7 @@ def setup_sandbox_root
hm_template_path = File.join(SANDBOX_ASSETS_DIR, DEFAULT_HM_CONF_TEMPLATE_NAME)
write_in_sandbox(HM_CONFIG, load_config_template(hm_template_path))
write_in_sandbox(EXTERNAL_CPI, load_config_template(EXTERNAL_CPI_TEMPLATE))
write_in_sandbox(EXTERNAL_CPI_CONFIG, load_config_template(EXTERNAL_CPI_CONFIG_TEMPLATE))
nats_template_path = File.join(SANDBOX_ASSETS_DIR, DEFAULT_NATS_CONF_TEMPLATE_NAME)
write_in_sandbox(NATS_CONFIG, load_config_template(nats_template_path))
FileUtils.chmod(0755, sandbox_path(EXTERNAL_CPI))
Expand Down
7 changes: 3 additions & 4 deletions src/bosh-director/bin/dummy_cpi
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,17 @@ result = nil
error = nil

begin
director_config = YAML.load_file(ARGV.shift)
cloud_properties = director_config['cloud']['properties']
cpi_config = JSON.parse(File.read(ARGV.shift))
log_buffer = StringIO.new
cloud_properties['log_buffer'] = log_buffer
cpi_config['log_buffer'] = log_buffer

request = JSON.parse($stdin.readline)

command = request['method']
arguments = request['arguments']
context = request['context']

dummy = Bosh::Clouds::Dummy.new(cloud_properties, context)
dummy = Bosh::Clouds::Dummy.new(cpi_config, context)

result = dummy.send(command, *arguments)
rescue => e
Expand Down
2 changes: 1 addition & 1 deletion src/bosh-director/lib/bosh/director/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def configure(config)
@nats_client_ca_certificate_path = config['nats']['client_ca_certificate_path']
@nats_client_ca_private_key_path = config['nats']['client_ca_private_key_path']
@nats_server_ca = File.read(@nats_server_ca_path)

@default_ssh_options = config['default_ssh_options']

@cloud_options = config['cloud']
Expand Down
2 changes: 2 additions & 0 deletions src/bosh-director/lib/cloud/dummy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class Dummy
class NotImplemented < StandardError; end

attr_reader :commands
attr_accessor :options

def initialize(options, context)
@options = options


@base_dir = options['dir']
if @base_dir.nil?
raise ArgumentError, 'Must specify dir'
Expand Down
2 changes: 0 additions & 2 deletions src/bosh-monitor/lib/bosh/monitor/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ def connect_to_mbus

nats_client_options = {
:uri => @mbus.endpoint,
:user => @mbus.user,
:pass => @mbus.password,
:autostart => false,
:tls => {
:ca_file => @mbus.server_ca_path,
Expand Down
Loading

0 comments on commit b0da4b0

Please sign in to comment.