Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Contrast Security framework support #446

Closed
wants to merge 4 commits into from
Closed

Added Contrast Security framework support #446

wants to merge 4 commits into from

Conversation

prodion23
Copy link
Contributor

This commit adds support for using Contrast Security's Java agent.
A bound service will be used to create a configuration file for the agent, as well as set some Java system properties.

@cfdreddbot
Copy link

Hey donniepropst!

Thanks for submitting this pull request!

All pull request submitters and commit authors must have a Contributor License Agreement (CLA) on-file with us. Please sign the appropriate CLA (individual or corporate).

When sending signed CLA please provide your github username in case of individual CLA or the list of github usernames that can make pull requests on behalf of your organization.

If you are confident that you're covered under a Corporate CLA, please make sure you've publicized your membership in the appropriate Github Org, per these instructions.

Once you've publicized your membership, one of the owners of this repository can close and reopen this pull request, and dreddbot will take another look.

@nebhale nebhale self-requested a review June 12, 2017 16:20
@nebhale nebhale self-assigned this Jun 12, 2017
@nebhale nebhale added this to the v3.18 milestone Jun 12, 2017
@nebhale
Copy link
Member

nebhale commented Jun 12, 2017

@donniepropst I'll start a review on this today, but please get started on the CLA so that we merge as soon as the technical changes are complete.

Copy link
Member

@nebhale nebhale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad given that you've never dealt with the API before. Some technical changes and signing the CLA and we should be able to add this quite quickly.


# Configuration for the ContrastSecurity framework
---
enabled: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no need for an enabled flag on the component. Enable/Disable is achieved by either binding or not binding a service to the application.


<table>
<tr>
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound Contrast Security service. The existence of an Contrast Security service 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 name, label or tag with <code>contrast-security</code> or <code>contrastsecurity</code> as a substring.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you're supporting two forms of the service name/label/tag? Since this the first time we've ever integrated, you should pick a single, canonical, representation that you'd like to search for and that should become the truth. Everywhere else you might see a pair in existing integrations, it's a historical artifact where changes have been made.

Tags are printed to standard output by the buildpack detect script

## User-Provided Service
When binding ContrastSecurity using a user-provided service, it must have name or tag with `contrast-security` or `contrastsecurity` in it. The credential payload can contain the following entries:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a single choice.

| Name | Description
| ---- | -----------
| `teamserver_url` | (Optional) The base URL in which your user has access to and the URL to which the Agent will report. ex: https://app.contrastsecurity.com
| `username` | (Required) The account name to use when downloading the agent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for (Required). The absence of (Optional) is sufficient.

| ---- | -----------
| `teamserver_url` | (Optional) The base URL in which your user has access to and the URL to which the Agent will report. ex: https://app.contrastsecurity.com
| `username` | (Required) The account name to use when downloading the agent
| `org_uuid` | (Required) The org uuid to send app information to, this is the org that your bound application will appear within
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for (Required). The absence of (Optional) is sufficient.

java_opts.add_system_property('contrast.dir', '/tmp')
java_opts.add_system_property('contrast.override.appname', app_name)
path = java_opts.qualify_path(@droplet.sandbox)
java_opts.add_preformatted_options("-javaagent:#{path}/#{boot_class_name}=#{path}/contrast.config")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... We really need to get an add_javaagent_with_props added. Not your responsibility.


# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
def supports?
@application.services.one_service?(CONTRAST_FILTER, [TEAMSERVER_URL, USERNAME, API_KEY, SERVICE_KEY])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit unclear, but putting these keys in an array means "or". If you want "and" (and I I'm pretty sure you do), it should just be comma delimited. @application.services.one_service?(CONTRAST_FILTER, TEAMSERVER_URL, USERNAME, API_KEY, SERVICE_KEY).

private

CONTRAST_FILTER = /contrast[-]?security/
private_constant :CONTRAST_FILTER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these constants should be alphabetized and added to private_constants.


private

CONTRAST_FILTER = /contrast[-]?security/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this the first time we've ever integrated, you should pick a single, canonical, representation that you'd like to search for and that should become the truth.

"contrast-engine-#{version}.jar"
end

def build_contrast_configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this one to you to decide, but making a real live XML document might not be the easiest or clearest way to do this. Another option is to use extended literals and just write clear text that you know to be valid XML. An example. It's up to you though, and if you think this is easier, I'm happy to leave it as-is.

@prodion23
Copy link
Contributor Author

@nebhale thanks for the quick review, I'm hoping to work on the fixes you mentioned later today or early tomorrow, and will touch base with product/legal teams in regard to the CLA.

@prodion23
Copy link
Contributor Author

prodion23 commented Jun 13, 2017

@nebhale I believe I resolved all your comments with the exception of 1.) How I built the xml contrast.config file, I would prefer to keep this the same. and 2.) the renaming of the jar.

In our repo the jar is packaged with a META-INF/MANIFEST.MF that specifies the jar name as: contrast-engine-#.#.#.jar. In SaaS (or for customers hosting our platform internally) our server will rename the jar and rewrite the manifest file to specify the name as just contrast.jar. Although we may be able to make a change to our process to match the name and version convention that you specified I don't believe that is something we will be able to do on the short term.

I believe the CLA should be submitted today if it wasn't yesterday.

@nebhale
Copy link
Member

nebhale commented Jun 13, 2017

@donniepropst Just trying to get a better understanding of the JAR naming requirement. Why does the agent care what the name of the JAR is? Is it used for more than just an opaque file path passed to javaagent?

@prodion23
Copy link
Contributor Author

prodion23 commented Jun 13, 2017

@nebhale After talking with one of our Java agent engineers they said the name has to match because the JVM inspects the manifest file and the Boot-Class-Path value gets added to the classpath at boot, so if the jar name doesn't match the information specified in the manifest we see NoClassDefFoundExceptions.

This was a requirement I didn't realize when I was working on the buildpack and calling download_jar without any parameters. The jar would get downloaded, but would have a bunch of class not found exceptions from our agent upon startup because the name of the file as stored in our repo is Java-Agent-#.#.#.#.jar.

The unzipped MANIFEST.MF file:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: jenkins
Build-Jdk: 1.7.0_80
Main-Class: com.contrastsecurity.agent.ContrastEngine
Agent-Class: com.contrastsecurity.agent.ContrastAgent
Boot-Class-Path: contrast-engine-3.4.0.jar
Build-Time: 20170525.2358
Can-Redefine-Classes: true
Can-Retransform-Classes: true
Can-Set-Native-Method-Prefix: true
Implementation-Build: 3.4.0.639
Premain-Class: com.contrastsecurity.agent.ContrastAgent

@nebhale
Copy link
Member

nebhale commented Jun 15, 2017

OK, understood. We'll just wait on the CLA and then everything should be good to go.

@prodion23
Copy link
Contributor Author

Checked in with our product team and it looks like the CLA was accepted last Wednesday so we should be good

@nebhale nebhale closed this Jun 19, 2017
@nebhale nebhale reopened this Jun 19, 2017
@cfdreddbot
Copy link

Hey donniepropst!

Thanks for submitting this pull request!

All pull request submitters and commit authors must have a Contributor License Agreement (CLA) on-file with us. Please sign the appropriate CLA (individual or corporate).

When sending signed CLA please provide your github username in case of individual CLA or the list of github usernames that can make pull requests on behalf of your organization.

If you are confident that you're covered under a Corporate CLA, please make sure you've publicized your membership in the appropriate Github Org, per these instructions.

Once you've publicized your membership, one of the owners of this repository can close and reopen this pull request, and dreddbot will take another look.

nebhale pushed a commit that referenced this pull request Jun 19, 2017
This change adds the Contrast Security Framework which detects a service with
name/label/tag of contrast-security.

[#446]
@nebhale nebhale closed this in 01ebbb5 Jun 19, 2017
@nebhale nebhale reopened this Jun 19, 2017
@cfdreddbot
Copy link

Hey donniepropst!

Thanks for submitting this pull request!

All pull request submitters and commit authors must have a Contributor License Agreement (CLA) on-file with us. Please sign the appropriate CLA (individual or corporate).

When sending signed CLA please provide your github username in case of individual CLA or the list of github usernames that can make pull requests on behalf of your organization.

If you are confident that you're covered under a Corporate CLA, please make sure you've publicized your membership in the appropriate Github Org, per these instructions.

Once you've publicized your membership, one of the owners of this repository can close and reopen this pull request, and dreddbot will take another look.

@nebhale
Copy link
Member

nebhale commented Jun 19, 2017

@donniepropst When you get a moment can you please ensure that you've got the proper GitHub organization publicized?

@prodion23
Copy link
Contributor Author

@nebhale that was probably the issue. It is public now.

@nebhale nebhale closed this Jun 19, 2017
@nebhale nebhale reopened this Jun 19, 2017
@cfdreddbot
Copy link

Hey donniepropst!

Thanks for submitting this pull request! I'm here to inform the recipients of the pull request that you and the commit authors have already signed the CLA.

@nebhale
Copy link
Member

nebhale commented Jun 19, 2017

Looks good. Closing as merged now.

@nebhale nebhale closed this Jun 19, 2017
@prodion23 prodion23 deleted the contrast-framework branch August 16, 2017 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants