Skip to content

Commit 4262bb8

Browse files
committed
Container Security Provider Manager Flags
Previously, the Container Security Provider could only be enabled and disabled completely for a given application. In certain circumstances it was useful to disable the KeyManager and TrustManager individually. This change takes advantage of a new feature in the Container Security Provider itself and sets the appropriate flags to disable the managers independently. [resolves #552]
1 parent e06790a commit 4262bb8

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

.idea/inspectionProfiles/Project_Default.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/container_security_provider.yml

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
---
1818
version: 1.+
1919
repository_root: "{default.repository.root}/container-security-provider"
20+
key_manager_enabled:
21+
trust_manager_enabled:

docs/framework-container_security_provider.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The framework can be configured by modifying the [`config/container_security_pro
2222
| ---- | -----------
2323
| `repository_root` | The URL of the Container Customizer repository index ([details][repositories]).
2424
| `version` | The version of Container Customizer to use. Candidate versions can be found in [this listing][].
25+
| `key_manager_enabled` | Whether the container `KeyManager` is enabled. Defaults to `true`.
26+
| `trust_manager_enabled` | Whether the container `TrustManager` is enabled. Defaults to `true`.
2527

2628
## Security Provider
2729
The [security provider][] added by this framework contributes two types, a `TrustManagerFactory` and a `KeyManagerFactory`. The `TrustManagerFactory` adds an additional new `TrustManager` after the configured system `TrustManager` which reads the contents of `/etc/ssl/certs/ca-certificates.crt` which is where [BOSH trusted certificates][] are placed. The `KeyManagerFactory` adds an additional `KeyManager` after the configured system `KeyManager` which reads the contents of the files specified by `$CF_INSTANCE_CERT` and `$CF_INSTANCE_KEY` which are set by Diego to give each container a unique cryptographic identity. These `TrustManager`s and `KeyManager`s are used transparently by any networking library that reads standard system SSL configuration and can be used to enable system-wide trust and [mutual TLS authentication][].

lib/java_buildpack/framework/container_security_provider.rb

+17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def release
3838
else
3939
@droplet.extension_directories << @droplet.sandbox
4040
end
41+
42+
unless key_manager_enabled.nil?
43+
@droplet.java_opts.add_system_property 'org.cloudfoundry.security.keymanager.enabled', key_manager_enabled
44+
end
45+
46+
return if trust_manager_enabled.nil?
47+
@droplet.java_opts.add_system_property 'org.cloudfoundry.security.trustmanager.enabled', trust_manager_enabled
4148
end
4249

4350
protected
@@ -47,6 +54,16 @@ def supports?
4754
true
4855
end
4956

57+
private
58+
59+
def key_manager_enabled
60+
@configuration['key_manager_enabled']
61+
end
62+
63+
def trust_manager_enabled
64+
@configuration['trust_manager_enabled']
65+
end
66+
5067
end
5168

5269
end

spec/java_buildpack/framework/container_security_provider_spec.rb

+52-1
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,63 @@
6363
expect(additional_libraries).to include(droplet.sandbox + "container_security_provider-#{version}.jar")
6464
end
6565

66-
it 'adds does not add extension directory in Java 9' do
66+
it 'does not add extension directory in Java 9' do
6767
component.release
6868

6969
expect(extension_directories).not_to include(droplet.sandbox)
7070
end
7171

7272
end
7373

74+
it 'does not manager system properties' do
75+
component.release
76+
77+
expect(java_opts).not_to include('-Dorg.cloudfoundry.security.keymanager.enabled=false')
78+
expect(java_opts).not_to include('-Dorg.cloudfoundry.security.trustmanager.enabled=false')
79+
end
80+
81+
context 'when KeyManager disabled' do
82+
let(:configuration) { { 'key_manager_enabled' => false } }
83+
84+
it 'adds system property' do
85+
component.release
86+
87+
expect(java_opts).to include('-Dorg.cloudfoundry.security.keymanager.enabled=false')
88+
end
89+
90+
end
91+
92+
context 'when TrustManager disabled' do
93+
let(:configuration) { { 'trust_manager_enabled' => false } }
94+
95+
it 'adds system property' do
96+
component.release
97+
98+
expect(java_opts).to include('-Dorg.cloudfoundry.security.trustmanager.enabled=false')
99+
end
100+
101+
end
102+
103+
context 'when KeyManager enabled' do
104+
let(:configuration) { { 'key_manager_enabled' => true } }
105+
106+
it 'adds system property' do
107+
component.release
108+
109+
expect(java_opts).to include('-Dorg.cloudfoundry.security.keymanager.enabled=true')
110+
end
111+
112+
end
113+
114+
context 'when TrustManager enabled' do
115+
let(:configuration) { { 'trust_manager_enabled' => true } }
116+
117+
it 'adds system property' do
118+
component.release
119+
120+
expect(java_opts).to include('-Dorg.cloudfoundry.security.trustmanager.enabled=true')
121+
end
122+
123+
end
124+
74125
end

0 commit comments

Comments
 (0)