Skip to content

Commit ecc8c9d

Browse files
committed
Merge branch 'add-checkmarx-iast-framework' into main
Signed-off-by: Ben Hale <[email protected]>
2 parents 7077891 + 2a0a476 commit ecc8c9d

File tree

6 files changed

+78
-34
lines changed

6 files changed

+78
-34
lines changed

.idea/codeStyles/Project.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The buildpack supports extension through the use of Git repository forking. The
8080
* Standard Frameworks
8181
* [AppDynamics Agent](docs/framework-app_dynamics_agent.md) ([Configuration](docs/framework-app_dynamics_agent.md#configuration))
8282
* [AspectJ Weaver Agent](docs/framework-aspectj_weaver_agent.md) ([Configuration](docs/framework-aspectj_weaver_agent.md#configuration))
83+
* [Checkmarx IAST Agent](docs/framework-checkmarx_iast_agent.md) ([Configuration](docs/framework-checkmarx_iast_agent.md#configuration))
8384
* [Client Certificate Mapper](docs/framework-client_certificate_mapper.md) ([Configuration](docs/framework-client_certificate_mapper.md#configuration))
8485
* [Container Customizer](docs/framework-container_customizer.md) ([Configuration](docs/framework-container_customizer.md#configuration))
8586
* [Container Security Provider](docs/framework-container_security_provider.md) ([Configuration](docs/framework-container_security_provider.md#configuration))
@@ -111,7 +112,6 @@ The buildpack supports extension through the use of Git repository forking. The
111112
* [SkyWalking Agent](docs/framework-sky_walking_agent.md) ([Configuration](docs/framework-sky_walking_agent.md#configuration))
112113
* [Takipi Agent](docs/framework-takipi_agent.md) ([Configuration](docs/framework-takipi_agent.md#configuration))
113114
* [YourKit Profiler](docs/framework-your_kit_profiler.md) ([Configuration](docs/framework-your_kit_profiler.md#configuration))
114-
* [Checkmarx IAST Agent](docs/framework-checkmarx_iast_agent.md) ([Configuration](docs/framework-checkmarx_iast_agent.md#configuration))
115115
* Standard JREs
116116
* [Azul Zulu](docs/jre-zulu_jre.md) ([Configuration](docs/jre-zulu_jre.md#configuration))
117117
* [GraalVM](docs/jre-graal_vm_jre.md) ([Configuration](docs/jre-graal_vm_jre.md#configuration))

config/components.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ frameworks:
4444
- "JavaBuildpack::Framework::AppDynamicsAgent"
4545
- "JavaBuildpack::Framework::AspectjWeaverAgent"
4646
- "JavaBuildpack::Framework::AzureApplicationInsightsAgent"
47+
- "JavaBuildpack::Framework::CheckmarxIastAgent"
4748
- "JavaBuildpack::Framework::ClientCertificateMapper"
4849
- "JavaBuildpack::Framework::ContainerCustomizer"
4950
- "JavaBuildpack::Framework::ContainerSecurityProvider"
@@ -74,5 +75,4 @@ frameworks:
7475
- "JavaBuildpack::Framework::YourKitProfiler"
7576
- "JavaBuildpack::Framework::TakipiAgent"
7677
- "JavaBuildpack::Framework::JavaSecurity"
77-
- "JavaBuildpack::Framework::CheckmarxIastAgent"
7878
- "JavaBuildpack::Framework::JavaOpts"

lib/java_buildpack/framework/checkmarx_iast_agent.rb

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,46 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18+
require 'java_buildpack/component/versioned_dependency_component'
1819
require 'java_buildpack/framework'
1920

2021
module JavaBuildpack
2122
module Framework
2223

2324
# Encapsulates the functionality for running with Checkmarx IAST Agent
24-
class CheckmarxIastAgent < JavaBuildpack::Component::BaseComponent
25+
class CheckmarxIastAgent < JavaBuildpack::Component::VersionedDependencyComponent
2526
include JavaBuildpack::Util
2627

2728
# Creates an instance. In addition to the functionality inherited from +BaseComponent+, +@version+ and +@uri+
2829
# instance variables are exposed.
2930
#
3031
# @param [Hash] context a collection of utilities used by components
3132
def initialize(context)
32-
super(context)
33-
34-
# Save the IAST server URL in server, if found
35-
service = @application.services.find_service(FILTER, 'server')
36-
@server = service['credentials']['server'].chomp '/' if service
37-
end
33+
@application = context[:application]
34+
@component_name = self.class.to_s.space_case
35+
@configuration = context[:configuration]
36+
@droplet = context[:droplet]
37+
38+
if supports?
39+
@version = ''
40+
@uri = @application.services.find_service(FILTER, 'server')['credentials']['server'].chomp +
41+
'/iast/compilation/download/JAVA'
42+
end
3843

39-
# (see JavaBuildpack::Component::BaseComponent#detect)
40-
def detect
41-
@server
44+
@logger = JavaBuildpack::Logging::LoggerFactory.instance.get_logger DynatraceOneAgent
4245
end
4346

4447
# (see JavaBuildpack::Component::BaseComponent#compile)
4548
def compile
46-
# Download and extract the agent from the IAST server
47-
FileUtils.mkdir_p @droplet.sandbox
48-
# curl --insecure: most IAST servers will use self-signed SSL
49-
shell 'curl --fail --insecure --silent --show-error ' \
50-
"#{@server}/iast/compilation/download/JAVA -o #{@droplet.sandbox}/cx-agent.zip"
51-
shell "unzip #{@droplet.sandbox}/cx-agent.zip -d #{@droplet.sandbox}"
49+
JavaBuildpack::Util::Cache::InternetAvailability.instance.available(
50+
true, 'The Checkmarx IAST download location is always accessible'
51+
) do
52+
download_zip(false)
53+
end
5254

5355
# Disable cache (no point, when running in a container)
54-
File.open("#{@droplet.sandbox}/#{OVERRIDE_CONFIG}", 'a') do |file|
55-
file.write("\nenableWeavedClassCache=false\n")
56+
File.open(@droplet.sandbox + 'cx_agent.override.properties', 'a') do |f|
57+
f.write("\nenableWeavedClassCache=false\n")
5658
end
5759
end
5860

@@ -63,25 +65,27 @@ def release
6365
# Default team to CxServer if not set as env var
6466
team = ENV['cxTeam'] || 'CxServer'
6567

66-
javaagent = "-javaagent:#{qualify_path(@droplet.sandbox + JAVA_AGENT_JAR, @droplet.root)}"
6768
@droplet.java_opts
68-
.add_preformatted_options(javaagent)
69-
.add_preformatted_options('-Xverify:none')
70-
.add_system_property('cx.logToConsole', 'true')
71-
.add_system_property('cx.appName', application_name)
72-
.add_system_property('cxAppTag', app_tag)
73-
.add_system_property('cxTeam', team)
69+
.add_javaagent(@droplet.sandbox + 'cx-launcher.jar')
70+
.add_preformatted_options('-Xverify:none')
71+
.add_system_property('cx.logToConsole', 'true')
72+
.add_system_property('cx.appName', application_name)
73+
.add_system_property('cxAppTag', app_tag)
74+
.add_system_property('cxTeam', team)
7475
end
7576

76-
private
77+
protected
7778

78-
JAVA_AGENT_JAR = 'cx-launcher.jar'
79+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
80+
def supports?
81+
@application.services.find_service(FILTER, 'server')
82+
end
7983

80-
OVERRIDE_CONFIG = 'cx_agent.override.properties'
84+
private
8185

8286
FILTER = /^checkmarx-iast$/.freeze
8387

84-
private_constant :JAVA_AGENT_JAR, :FILTER, :OVERRIDE_CONFIG
88+
private_constant :FILTER
8589

8690
def application_name
8791
@application.details['application_name'] || 'ROOT'
905 Bytes
Binary file not shown.

spec/java_buildpack/framework/checkmarx_iast_agent_spec.rb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,39 @@
3030

3131
before do
3232
allow(services).to receive(:one_service?).with(/^checkmarx-iast$/, 'server').and_return(true)
33-
allow(services).to receive(:find_service).and_return('credentials' => { 'server' => 'http://iast-server:8080/' })
33+
allow(services).to receive(:find_service).and_return('credentials' => { 'server' => 'test-server' })
34+
35+
allow(application_cache).to receive(:get)
36+
.with('test-server/iast/compilation/download/JAVA')
37+
.and_yield(Pathname.new('spec/fixtures/stub-checkmarx-agent.zip').open, false)
3438
end
3539

3640
it 'detects with checkmarx-iast service' do
37-
expect(component.detect).to eq('http://iast-server:8080')
41+
expect(component.detect).to eq('checkmarx-iast-agent=')
42+
end
43+
44+
it 'downloads agent',
45+
cache_fixture: 'stub-checkmarx-agent.zip' do
46+
47+
component.compile
48+
49+
expect(sandbox + 'cx-launcher.jar').to exist
50+
end
51+
52+
it 'appends override configuration',
53+
cache_fixture: 'stub-checkmarx-agent.zip' do
54+
55+
component.compile
56+
57+
expect(File.read(sandbox + 'cx_agent.override.properties')).to eq('test-data
58+
59+
enableWeavedClassCache=false
60+
')
3861
end
3962

4063
it 'updates JAVA_OPTS' do
4164
component.release
4265

43-
puts java_opts
4466
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/checkmarx_iast_agent/cx-launcher.jar')
4567
expect(java_opts).to include('-Dcx.logToConsole=true')
4668
expect(java_opts).to include('-Dcx.appName=test-application-name')

0 commit comments

Comments
 (0)