Skip to content

Commit 2520cef

Browse files
committed
Checkmarx IAST Framework
Add support for running apps with the Checkmarx IAST agent, if a checkmarx-iast service is detected
1 parent f888b34 commit 2520cef

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ The buildpack supports extension through the use of Git repository forking. The
111111
* [SkyWalking Agent](docs/framework-sky_walking_agent.md) ([Configuration](docs/framework-sky_walking_agent.md#configuration))
112112
* [Takipi Agent](docs/framework-takipi_agent.md) ([Configuration](docs/framework-takipi_agent.md#configuration))
113113
* [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))
114115
* Standard JREs
115116
* [Azul Zulu](docs/jre-zulu_jre.md) ([Configuration](docs/jre-zulu_jre.md#configuration))
116117
* [GraalVM](docs/jre-graal_vm_jre.md) ([Configuration](docs/jre-graal_vm_jre.md#configuration))

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ frameworks:
7474
- "JavaBuildpack::Framework::YourKitProfiler"
7575
- "JavaBuildpack::Framework::TakipiAgent"
7676
- "JavaBuildpack::Framework::JavaSecurity"
77+
- "JavaBuildpack::Framework::CheckmarxIastAgent"
7778
- "JavaBuildpack::Framework::JavaOpts"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Checkmarx IAST Agent Framework
2+
The Checkmarx IAST Agent Framework causes an application to be automatically configured to work with a bound [Checkmarx IAST Service][].
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td><td>Existence of a bound Checkmarx IAST service. The existence of an Checkmarx IAST service is defined by the <a href="http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES"><code>VCAP_SERVICES</code></a> payload containing a service named <code>checkmarx-iast</code>.
7+
</td>
8+
</tr>
9+
</table>
10+
11+
## User-Provided Service
12+
When binding Checkmarx IAST using a user-provided service, it must have the name `checkmarx-iast` and the credential payload must include the following entry:
13+
14+
| Name | Description
15+
| ---- | -----------
16+
| `server` | The IAST Manager URL
17+
18+
## Configuration
19+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
20+
21+
[Checkmarx IAST Service]: https://www.checkmarx.com/products/interactive-application-security-testing
22+
[Configuration and Extension]: ../README.md#configuration-and-extension
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# frozen_string_literal: true
2+
3+
# Cloud Foundry Java Buildpack
4+
# Copyright 2013-2020 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'java_buildpack/framework'
19+
20+
module JavaBuildpack
21+
module Framework
22+
23+
# Encapsulates the functionality for running with Checkmarx IAST Agent
24+
class CheckmarxIastAgent < JavaBuildpack::Component::BaseComponent
25+
include JavaBuildpack::Util
26+
27+
# Creates an instance. In addition to the functionality inherited from +BaseComponent+, +@version+ and +@uri+
28+
# instance variables are exposed.
29+
#
30+
# @param [Hash] context a collection of utilities used by components
31+
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
38+
39+
# (see JavaBuildpack::Component::BaseComponent#detect)
40+
def detect
41+
@server
42+
end
43+
44+
# (see JavaBuildpack::Component::BaseComponent#compile)
45+
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}"
52+
53+
# 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+
end
57+
end
58+
59+
# (see JavaBuildpack::Component::BaseComponent#release)
60+
def release
61+
# Default cxAppTag to application name if not set as an env var
62+
app_tag = ENV['cxAppTag'] || application_name
63+
# Default team to CxServer if not set as env var
64+
team = ENV['cxTeam'] || 'CxServer'
65+
66+
javaagent = "-javaagent:#{qualify_path(@droplet.sandbox + JAVA_AGENT_JAR, @droplet.root)}"
67+
@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)
74+
end
75+
76+
private
77+
78+
JAVA_AGENT_JAR = 'cx-launcher.jar'
79+
80+
OVERRIDE_CONFIG = 'cx_agent.override.properties'
81+
82+
FILTER = /^checkmarx-iast$/.freeze
83+
84+
private_constant :JAVA_AGENT_JAR, :FILTER, :OVERRIDE_CONFIG
85+
86+
def application_name
87+
@application.details['application_name'] || 'ROOT'
88+
end
89+
90+
end
91+
92+
end
93+
94+
end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
# Cloud Foundry Java Buildpack
4+
# Copyright 2013-2020 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'spec_helper'
19+
require 'component_helper'
20+
require 'java_buildpack/framework/checkmarx_iast_agent'
21+
22+
describe JavaBuildpack::Framework::CheckmarxIastAgent do
23+
include_context 'with component help'
24+
25+
it 'does not detect without checkmarx-iast service' do
26+
expect(component.detect).to be_nil
27+
end
28+
29+
context do
30+
31+
before do
32+
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/' })
34+
end
35+
36+
it 'detects with checkmarx-iast service' do
37+
expect(component.detect).to eq('http://iast-server:8080')
38+
end
39+
40+
it 'updates JAVA_OPTS' do
41+
component.release
42+
43+
puts java_opts
44+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/checkmarx_iast_agent/cx-launcher.jar')
45+
expect(java_opts).to include('-Dcx.logToConsole=true')
46+
expect(java_opts).to include('-Dcx.appName=test-application-name')
47+
expect(java_opts).to include('-DcxAppTag=test-application-name')
48+
expect(java_opts).to include('-DcxTeam=CxServer')
49+
end
50+
51+
end
52+
53+
end

0 commit comments

Comments
 (0)