Skip to content

Commit

Permalink
Improve prepare application and PDS solution
Browse files Browse the repository at this point in the history
- Added storage variables as non-spring parameter
- Added additional tags to skopeo wrapper
- Make git-clone into repository name
  • Loading branch information
lorriborri committed Jul 3, 2024
1 parent f604e8b commit e0bb007
Show file tree
Hide file tree
Showing 61 changed files with 286 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ src-gen/
.idea/
*.ipr
*.iws
out/

# vscode parts
.vscode/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.commons.archive;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.commons.archive;

import static org.junit.jupiter.api.Assertions.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.commons.core.environment;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.commons.pds;

import static org.junit.jupiter.api.Assertions.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

#
# Usage: inside a junit test we call this to verify the process adapter implementation works
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.pds.commons.core;

import java.util.regex.Pattern;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.pds.commons.core.config;

public class PDSStorageConstants {
Expand Down
15 changes: 12 additions & 3 deletions sechub-pds-solutions/pds-base/docker/copy/README.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// SPDX-License-Identifier: MIT
. Place a single PDS Jar into this folder.
. Name it `sechub-pds-0.0.0.jar`
. Run `10-create-image.sh` to build the image
. Build PDS jar local with gradle command
. Copy the pds jar into the copy folder sechub-pds-0.0.0.jar
+
----
cp sechub-pds/build/libs/sechub-pds-0.0.0.jar .
----
. Run `10-create-image.sh` with the copy parameter to build the image
+
----
./10-create-image.sh pds-base-pds latest 0.0.0 debian:12-slim copy
----
4 changes: 2 additions & 2 deletions sechub-pds-solutions/pds-base/docker/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/bin/sh
# SPDX-License-Identifier: MIT

DEFAULT_PDS_MAX_FILE_UPLOAD_BYTES=52428800 # 50 MB
Expand Down Expand Up @@ -89,7 +89,7 @@ start_server() {
-Dfile.encoding=UTF-8 \
-Dserver.port=8444 \
-Dserver.address=0.0.0.0 \
-jar "$PDS_FOLDER/sechub-pds-*.jar" &
-jar "$PDS_FOLDER/"sechub-pds-*.jar &

# Get process pid and wait until it ends
# The pid will be needed by function trigger_shutdown() in case we receive a termination signal.
Expand Down
2 changes: 1 addition & 1 deletion sechub-pds-solutions/prepare/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The folder contains a start script which does the manual steps for you:

The container will be started and attached to the `sechub` network.

WARNING: Make sure the SecHub container is running and executor for Prepare is set up.
WARNING: Make sure the SecHub container is running with compose prepare and executor for Prepare is set up. (./sechub-solution/01-start-single-docker-compose-prepare.sh)

. Start container in local sechub network:
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- "sechub"
volumes:
- ./docker/scripts:/pds/scripts
- /tmp/sechub-shared-volume:/shared_volumes/uploads

networks:
sechub:
Expand Down
2 changes: 1 addition & 1 deletion sechub-pds-solutions/prepare/docker/pds-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"id": "PDS_PREPARE",
"path": "/pds/scripts/prepare.sh",
"envWhitelist" : [ "TOOL_FOLDER" ],
"envWhitelist" : [ "TOOL_FOLDER","PDS_STORAGE_*","HTTPS_PROXY","NO_PROXY"],
"scanType": "prepare",
"description": "Runs the prepare wrapper application to prepare remote data for SecHub scans.",

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.pds;

import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.pds;

import static org.mockito.Mockito.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.pds;

import static org.junit.jupiter.api.Assertions.*;
Expand Down
34 changes: 34 additions & 0 deletions sechub-solution/01-start-single-docker-compose-prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT

ENVIRONMENT_FILE=".env-single"

resource_limits_enabled="$1"
compose_file="docker-compose_sechub-debian-prepare"

mkdir /tmp/sechub-shared-volume
chmod -R 777 /tmp/sechub-shared-volume

cd $(dirname "$0")
source ../sechub-solutions-shared/scripts/9999-env-file-helper.sh

# Only variables from .env can be used in the Docker-Compose file
# all other variables are only available in the container
setup_environment_file ".env" "env"
setup_environment_file "$ENVIRONMENT_FILE" "env-sechub"

echo "Copying install-java scripts into the docker directory"
cp --recursive --force ../sechub-solutions-shared/install-java/ docker/

# Use Docker BuildKit
export BUILDKIT_PROGRESS=plain
export DOCKER_BUILDKIT=1

if [[ "$resource_limits_enabled" == "yes" ]]
then
compose_file="docker-compose_sechub_resource_limits-debian"
fi

echo "Compose file: $compose_file"

docker compose --file "$compose_file.yaml" up --build --remove-orphans
8 changes: 8 additions & 0 deletions sechub-solution/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ To start a single container run the script:
./01-start-single-docker-compose.sh
----

=== Single Container with Prepare (remote Data)

. Start the container with the script:

----
./01-start-single-docker-compose-prepare.sh
----

=== SecHub with PDS Solution

. First start a SecHub container.
Expand Down
32 changes: 32 additions & 0 deletions sechub-solution/docker-compose_sechub-debian-prepare.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: MIT

version: "3"
services:
sechub:
build:
args:
- BASE_IMAGE=debian:12-slim
- BUILD_TYPE=${BUILD_TYPE}
- JAVA_DISTRIBUTION=${JAVA_DISTRIBUTION}
- JAVA_VERSION=${JAVA_VERSION}
- SECHUB_VERSION=${SECHUB_VERSION}
- GO=${GO}
- TAG=${TAG}
- BRANCH=${BRANCH}
context: docker/
dockerfile: SecHub-Debian.dockerfile
container_name: sechub
hostname: sechub
env_file:
- .env
- .env-single
ports:
- "127.0.0.1:${PORT}:8443"
- "127.0.0.1:${JAVA_DEBUG_PORT}:15023"
networks:
- sechub
volumes:
- /tmp/sechub-shared-volume:/shared_volumes/uploads
networks:
sechub:
name: sechub
9 changes: 9 additions & 0 deletions sechub-solution/setup-pds/8900-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ function setup_project_user_executor_profile() {
./8801-create-executor-and-profile.sh "$executor_file_name" "$profile"
./8802-assign-profile-to-project.sh "$project" "$profile"
}

function setup_second_executor_profile_to_existing_project() {
local project="$1"
local executor_file_name="$2"
local profile="$3"

./8801-create-executor-and-profile.sh "$executor_file_name" "$profile"
./8802-assign-profile-to-project.sh "$project" "$profile"
}
17 changes: 17 additions & 0 deletions sechub-solution/setup-pds/setup-prepare.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT

# Print helpFunction in case parameters are empty
if [ -z "$1" ]
then
echo "Error: no second executor was provided! Please provide the seconds executor name as a parameter, e.g. gosec, xray or other.";
echo "Example usage: ./setup-prepare.sh gosec";
exit 1
fi


declare -r SCRIPT_PARAMETERS="<project-id> <user>"

cd $(dirname "$0")
Expand All @@ -17,9 +26,17 @@ user="prepare-user"
project="test-prepare"
executor_file_name="prepare"
profile="pds-prepare"
echo ""
# defining a second profile with the tool to scan
second_profile="pds-$1"
second_executor_filename="$1"
echo "Second profile: $second_profile with executor $second_executor_filename"
echo""

# main setup execution
setup_project_user_executor_profile "$project" "$user" "$executor_file_name" "$profile"

setup_second_executor_profile_to_existing_project "$project" "$second_executor_filename" "$second_profile"

# print sechub scan usage message
setup_complete_message_for_tool "Prepare" "$user" "$project"
1 change: 1 addition & 0 deletions sechub-wrapper-prepare/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {

implementation spring_boot_dependency.logback_classic

implementation library.logstashLogbackEncoder
implementation library.jgit_core
implementation library.apache_commons_io

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare;

import com.mercedesbenz.sechub.pds.commons.core.PDSLogSanitizer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare;

public interface PrepareAcceptFilter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare;

import static com.mercedesbenz.sechub.wrapper.prepare.InputValidatorExitcode.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare;

import com.mercedesbenz.sechub.wrapper.prepare.modules.UsageExceptionExitCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void run(String... args) {
}

storeResultOrFail(result);

LOG.info("Prepare wrapper has finished successfully.");
}

private static AdapterExecutionResult getAdapterExecutionResultFailed(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare.modules;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare.modules;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare.modules;

public enum UsageExceptionExitCode {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare.modules.git;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.wrapper.prepare.modules.git;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
public class GitContext extends AbstractPrepareToolContext {

static final String DOWNLOAD_DIRECTORY_NAME = "git-download";
static final String DEFAULT_REPOSITORY_NAME = "git-repository";
private boolean cloneWithoutHistory;
private String repositoryName = "git-repository";
private String repositoryName = DEFAULT_REPOSITORY_NAME;
private Path toolDownloadDirectory;

public void setCloneWithoutHistory(boolean cloneWithoutHistory) {
Expand All @@ -27,7 +28,9 @@ public String getRepositoryName() {
}

public void setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
if (!(repositoryName == null || repositoryName.isBlank())) {
this.repositoryName = repositoryName;
}
}

public boolean isCloneWithoutHistory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public class GitLocationConverter {
@Autowired
PDSLogSanitizer pdsLogSanitizer;

public String convertLocationToRepositoryName(String location) {
String[] parts = location.split("/");
String repository = parts[parts.length - 1];
repository = repository.replace(".git", "");
return repository;
}

public URL convertLocationToHttpsBasedURL(String originLocation) {
if (originLocation == null) {
throw new IllegalArgumentException("Location may not be null!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class GitPrepareWrapperModule extends AbstractPrepareWrapperModule {
@Autowired
PDSLogSanitizer pdsLogSanitizer;

@Autowired
GitLocationConverter gitLocationConverter;

@Override
public boolean isEnabled() {
return enabled;
Expand Down Expand Up @@ -118,10 +121,12 @@ private void beforeUpload(GitContext gitContext) throws IOException {

private GitContext initializeGitContext(PrepareWrapperContext context, SecHubRemoteDataConfiguration secHubRemoteDataConfiguration) {
Path workingDirectory = Paths.get(context.getEnvironment().getPdsJobWorkspaceLocation());
String location = secHubRemoteDataConfiguration.getLocation();

GitContext gitContext = new GitContext();
gitContext.setCloneWithoutHistory(cloneWithoutGitHistory);
gitContext.setLocation(secHubRemoteDataConfiguration.getLocation());
gitContext.setLocation(location);
gitContext.setRepositoryName(gitLocationConverter.convertLocationToRepositoryName(location));
gitContext.init(workingDirectory);

return gitContext;
Expand Down
Loading

0 comments on commit e0bb007

Please sign in to comment.