Skip to content

Commit 86494a8

Browse files
author
Konstantin Semenov
committed
Added security provider to the list
1 parent e3bf117 commit 86494a8

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2020 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the CloudSql Security Provider framework
17+
---
18+
enabled: true

config/components.yml

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ frameworks:
4949
- "JavaBuildpack::Framework::ClientCertificateMapper"
5050
- "JavaBuildpack::Framework::ContainerCustomizer"
5151
- "JavaBuildpack::Framework::ContainerSecurityProvider"
52+
- "JavaBuildpack::Framework::CloudSqlSecurityProvider"
5253
- "JavaBuildpack::Framework::ContrastSecurityAgent"
5354
- "JavaBuildpack::Framework::DatadogJavaagent"
5455
- "JavaBuildpack::Framework::Debug"

lib/java_buildpack/framework/cloud_sql_security_provider.rb

+17-15
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@
1818
require 'fileutils'
1919
require 'shellwords'
2020
require 'tempfile'
21-
require 'java_buildpack/component/versioned_dependency_component'
21+
require 'java_buildpack/component/base_component'
2222
require 'java_buildpack/framework'
2323
require 'java_buildpack/util/qualify_path'
2424

2525
module JavaBuildpack
2626
module Framework
2727

28-
# Encapsulates the functionality for enabling zero-touch Safenet ProtectApp Java Security Provider support.
29-
class CloudSqlSecurityProvider < JavaBuildpack::Component::VersionedDependencyComponent
28+
# Encapsulates the functionality for enabling secure communication with GCP CloudSQL instances.
29+
class CloudSqlSecurityProvider < JavaBuildpack::Component::BaseComponent
3030
include JavaBuildpack::Util
3131

3232
# (see JavaBuildpack::Component::BaseComponent#compile)
3333
def compile
34-
log '#release'.yellow
35-
download_zip false
34+
return unless supports?
3635

3736
@droplet.copy_resources
3837

@@ -41,22 +40,26 @@ def compile
4140
pkcs12 = merge_client_credentials credentials
4241
add_client_credentials pkcs12
4342

44-
add_trusted_certificates credentials['sslrootcert']
43+
add_trusted_certificate credentials['sslrootcert']
4544
end
4645

4746
# (see JavaBuildpack::Component::BaseComponent#release)
4847
def release
49-
log '#release'.yellow
48+
return unless supports?
49+
5050
java_opts = @droplet.java_opts
5151

5252
add_additional_properties(java_opts)
5353
end
5454

55+
def detect
56+
CloudSqlSecurityProvider.to_s.dash_case
57+
end
58+
5559
protected
5660

5761
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
5862
def supports?
59-
log '#supports?'.yellow
6063
@application.services.one_service? FILTER, 'sslrootcert', 'sslcert', 'sslkey'
6164
end
6265

@@ -67,9 +70,6 @@ def supports?
6770
private_constant :FILTER
6871

6972

70-
def log(message)
71-
puts "#{'===========>'.blue} #{'CloudSqlSecurityProvider'.red.bold} #{message}"
72-
end
7373
def add_additional_properties(java_opts)
7474
java_opts
7575
.add_system_property('javax.net.ssl.keyStore', keystore)
@@ -82,10 +82,12 @@ def add_client_credentials(pkcs12)
8282
" -alias #{File.basename(pkcs12)}"
8383
end
8484

85-
def add_trusted_certificates(trusted_certificate)
86-
File.open("#{@droplet.root}/etc/ssl/certs/ca-certificates.crt", 'a') do |f|
87-
f.write("#{trusted_certificate}\n")
88-
end
85+
def add_trusted_certificate(trusted_certificate)
86+
cert = Tempfile.new('ca-cert-')
87+
cert.write(trusted_certificate)
88+
cert.close
89+
90+
shell "#{keytool} -import -trustcacerts -cacerts -storepass changeit -noprompt -alias CloudSQLCA -file #{cert.path}"
8991
end
9092

9193
def ext_dir

resources/cloud_sql_security_provider/index.yml

Whitespace-only changes.

0 commit comments

Comments
 (0)