Skip to content

Commit fd5a63d

Browse files
tcdowneyelenasharma
authored andcommitted
Consume credhub.port link and internal CredHub Consul route
- added two new spec properties: credhub_api.ca_cert and credhub_api.hostname - properties will only be used if the credhub link is provided - Credhub::Client will now use the credhub_api.ca_cert_path to include the CredHub CA cert as a trusted cert [#150753759] Signed-off-by: Elena Sharma <[email protected]>
1 parent 57c38dd commit fd5a63d

File tree

8 files changed

+58
-8
lines changed

8 files changed

+58
-8
lines changed

bosh/jobs/cloud_controller_ng/spec

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ templates:
4343
stacks.yml.erb: config/stacks.yml
4444
uaa_ca.crt.erb: config/certs/uaa_ca.crt
4545
db_ca.crt.erb: config/certs/db_ca.crt
46+
credhub_ca.crt.erb: config/certs/credhub_ca.crt
4647

4748

4849
packages:
@@ -75,6 +76,9 @@ consumes:
7576
- name: perm
7677
type: perm
7778
optional: true
79+
- name: credhub
80+
type: credhub
81+
optional: true
7882

7983
properties:
8084
bpm.enabled:
@@ -837,6 +841,8 @@ properties:
837841
description: "Enable CF Permissions external service. Requires perm link to take effect"
838842
default: false
839843

840-
credhub_api.port:
841-
description: "Temporary property until credhub-release exposes port as a link"
842-
default: 8844
844+
credhub_api.hostname:
845+
description: "Hostname used to resolve the address of CredHub"
846+
default: "credhub.service.cf.internal"
847+
credhub_api.ca_cert:
848+
description: "The certificate authority being used by CredHub"

bosh/jobs/cloud_controller_ng/templates/cloud_controller_ng.yml.erb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ routing_api:
159159
routing_client_secret: <%= p("uaa.clients.cc_routing.secret") %>
160160
<% end %>
161161

162+
<% if_link("credhub") do |credhub| %>
162163
credhub_api:
163-
# TODO: This should come from credhub internal consul route
164-
# TODO: This should come from the credhub-release link
165-
url: <%= "https://credhub.#{system_domain}:#{p("credhub_api.port")}" %>
164+
url: <%= "https://#{p("credhub_api.hostname")}:#{credhub.p("credhub.port")}" %>
165+
ca_cert_path: "/var/vcap/jobs/cloud_controller_ng/config/certs/credhub_ca.crt"
166+
<% end %>
166167

167168
# App staging parameters
168169
staging:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= p("credhub_api.ca_cert", "") %>

config/cloud_controller.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,4 @@ perm:
346346

347347
credhub_api:
348348
url: https://credhub.vcap.me:8844
349+
ca_cert_path: "spec/fixtures/certs/credhub_ca.crt"

lib/cloud_controller/config_schemas/api_schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ class ApiSchema < VCAP::Config
171171
cc_service_key_client_name: String,
172172
cc_service_key_client_secret: String,
173173

174-
credhub_api: {
174+
optional(:credhub_api) => {
175175
url: String,
176+
ca_cert_path: String,
176177
},
177178

178179
renderer: {

lib/credhub/client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def client
3939
end
4040

4141
def build_client
42-
HTTPClient.new(base_url: credhub_url)
42+
client = HTTPClient.new(base_url: credhub_url)
43+
client.ssl_config.set_trust_ca(VCAP::CloudController::Config.config.get(:credhub_api, :ca_cert_path))
44+
client
4345
end
4446

4547
def auth_header

spec/fixtures/certs/credhub_ca.crt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIE8jCCAtqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAZMRcwFQYDVQQDEw5jZXJ0
3+
LWF1dGhvcml0eTAeFw0xNzAxMDQyMTUwNDRaFw0yNzAxMDQyMTUwNDhaMBkxFzAV
4+
BgNVBAMTDmNlcnQtYXV0aG9yaXR5MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
5+
CgKCAgEAwVQAchJX6iaR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cWxWYsdjnFUgq6HoIfALaYlJu8OIZgy218rxCy2lVi+nIncYAJXdJr9
22+
Aw68ofG/ajHw3faWNr3NcWjE+EY20o7kKlzLX/t8z3Hj8I4Enjf+hNbbw5bD00mH
23+
1L8xFQtl53rfBRd9mE8aSSJHTgpSHpp8jp8j6exHeuxKV8b73lPODcJZnklQIxt4
24+
ro2YCnxeBZDebs2Fn7XZswNvEPpYD0jRhgu5Ovsf4/05SHECs/oA+oXOzdgUW/dj
25+
lp+oD1xRE278eq23kgudUUhtwb/RYEv75yh5d4m4Z2qOj7NP16fiUYU2Tx4F09Rr
26+
Afy8ZXJ5EQmKyZivOexiJ1J/eq3UPgKfiyMV7hG4C3Swo3szskKKwr/vl1SG8rQ9
27+
Ws5eJEyXf1QaMxWEW/8sTCwQjushyE7Wm8DdETmYetcrlBfvQmBptYeJsx3sbx5N
28+
ROk0R8CrGWFqNdCnVgQne4VbnKr42A==
29+
-----END CERTIFICATE-----

spec/unit/lib/credhub/client_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ module Credhub
1111

1212
subject { Credhub::Client.new(credhub_url, uaa_client) }
1313

14+
describe '#client' do
15+
describe 'ssl_config' do
16+
it 'uses the configured credhub_ca.crt' do
17+
expect(subject.send(:client).ssl_config.cert_store_items).
18+
to include(TestConfig.config_instance.get(:credhub_api, :ca_cert_path))
19+
end
20+
end
21+
end
22+
1423
describe '#get_credential_by_name' do
1524
before do
1625
stub_request(:get, "#{credhub_url}/api/v1/data?name=#{credhub_reference}&current=true").

0 commit comments

Comments
 (0)