Deploy Java Agent Using Dockerfile

An example illustrating how to deploy on Kubernetes a sample application with the Java Agent using a Dockerfile.

  1. Create a Dockerfile for the sample Webgoat application:
    Dockerfile
    FROM openjdk:8-alpine
     
    # Install the required basic tools
    RUN apk add unzip curl
     
    # Download the Webgoat application
    RUN curl -L -o /tmp/webgoat.jar https://github.com/WebGoat/WebGoat/releases/download/v8.0.0.M21/webgoat-server-8.0.0.M21.jar
     
    # Copy the container run script
    COPY run.sh /run.sh
     
    EXPOSE 8080
    ENTRYPOINT ["/bin/sh", "run.sh"]
  2. Create a container run.sh script including the Java Agent deployment:
    run.sh
    #!/bin/sh
     
    # Configure basic Java options for your application
    JAVA_OPTS="-Xmx512m"
     
    # Deploy the Seeker Java Agent
    if [ ! -z "${SEEKER_SERVER_URL}" ];
    then
        # Download the Agent package
        curl -k -o /tmp/seeker-agent.zip "${SEEKER_SERVER_URL}/rest/api/latest/installers/agents/binaries/JAVA"
        # Unzip the Agent package
        unzip -d /tmp/seeker /tmp/seeker-agent.zip
        # Append the Seeker options to the JVM options
        JAVA_OPTS="-javaagent:/tmp/seeker/seeker-agent.jar ${JAVA_OPTS}"
    fi
     
    # Run Webgoat
    java ${JAVA_OPTS} -jar /tmp/webgoat.jar
  3. Build the image:
    docker build -t webgoat .
  4. Run the image in your Kubernetes cluster:
    # Publish the image to a Docker registry
    docker push webgoat
     
    # Schedule the service to launch in your Kubernetes cluster
    kubectl create deployment --image webgoat webgoat8-app
  5. To run the application with the Agent, deploy it using the SEEKER_SERVER_URL environment variable.

    Additionally, you can pass configuration parameters, for example, SEEKER_PROJECT_KEY:

    kubectl create deployment --image webgoat webgoat8-app --env=SEEKER_SERVER_URL=https://seeker-server:8443 --env=SEEKER_PROJECT_KEY=webgoat