Skip to content
Draft
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
6721b1d
Check if bug exists before executing tasks. Delete bug and libraries …
pedrogalvao Mar 30, 2022
1a6297e
Fixed small mistakes
pedrogalvao Mar 30, 2022
94597d5
check if hashmap contains key
pedrogalvao Mar 30, 2022
764cef9
Fixed code style
pedrogalvao Apr 5, 2022
04b50a4
Removed files added by accident
pedrogalvao Apr 6, 2022
e6e3346
Removed repeated option variables from Tasks
pedrogalvao Apr 7, 2022
bbd4116
Removed skip condition in ImportVulnerability and changed tests accor…
Apr 8, 2022
c0ea508
Fixed code style
pedrogalvao Apr 8, 2022
3d83e6c
Created Manager and added function to extract tar (still have some er…
pedrogalvao Apr 12, 2022
e0dcbff
fixed some problems. still not working
pedrogalvao Apr 13, 2022
8247b13
Changing architecture (contains errors)
pedrogalvao Apr 15, 2022
8e8c751
Extracting and cloning in parallel, but without locks
pedrogalvao Apr 22, 2022
0e79f95
repositories locks
pedrogalvao Apr 25, 2022
93b0f7a
Parallel processing working for repos with tar (need to test more)
pedrogalvao Apr 29, 2022
4e50e90
started writing a test
pedrogalvao Apr 29, 2022
fbebcd9
Test for ExtractOrClone
pedrogalvao May 3, 2022
af7b43b
Started to write ImporterController
May 6, 2022
d9a4e6f
Removed comments, fixed small problems, added stopWatch to Import
May 11, 2022
d28d6f1
Rest service with Spring Framework
May 12, 2022
599a161
Added status and stop endpoints, removed some unused classes and othe…
May 13, 2022
59b00cf
Changes in shell scripts and Dockerfile
May 13, 2022
cc11bee
Removed export from kaybeeconf.yaml.sample
May 13, 2022
097f464
Added java command in start.sh
May 13, 2022
5ed1c79
Fixed some tests
May 16, 2022
ecfa8c1
Tests running again (with some errors)
May 17, 2022
86f6b25
Added missing resources. All tests succeed again
May 17, 2022
1964773
Properly cleaning directory after test
May 17, 2022
f46b984
More detailed status. Endpoints for single vulnerabilities
May 18, 2022
89ab062
Fixed problems with parameter refetchAllMs
May 18, 2022
16f9e37
Small changes. Removed unused classes
May 19, 2022
4b6d787
Removed some comments
May 19, 2022
38eeda3
Renamed Import to ImportCommand
pedrogalvao May 25, 2022
65346d7
Removed static variable that caused Empty Stack Error
pedrogalvao May 27, 2022
2f8a01f
Changed variable name in properties file
pedrogalvao May 27, 2022
7b12ce6
Removed thread from importSingleVuln
pedrogalvao May 27, 2022
738c8f1
Added licenses. Removed one file
pedrogalvao May 27, 2022
0930dea
Added license to kb-importer/pom.xml
pedrogalvao May 27, 2022
8e3f885
Fixed code style
pedrogalvao May 27, 2022
ee870dd
Fixed name and description in kb-importer pom.xml
pedrogalvao May 27, 2022
c827f28
function to retry failed vulnerabilities
pedrogalvao Jun 1, 2022
e170624
Fixed kaybeeconf, removed an unused dependency
pedrogalvao Jun 1, 2022
9e4e4b5
fixed code style
pedrogalvao Jun 1, 2022
bf286d1
Removed GoalClient again
pedrogalvao Jun 1, 2022
1b56295
Renamed a method and a variable in Manager
pedrogalvao Jun 1, 2022
9e929d5
Removed a Jenkinsfile
pedrogalvao Jun 1, 2022
a949408
catch IOException
pedrogalvao Jun 1, 2022
6bb6895
added curl installation in dockerfile
pedrogalvao Jun 1, 2022
5e41ded
Removed some comments, changed some logs, added GoalClient again
pedrogalvao Jun 2, 2022
dc06822
Added license in some new files
pedrogalvao Jun 2, 2022
9b07d69
Removed .gitignore form kb-importer directory
pedrogalvao Jun 2, 2022
4d2dffd
Moved snakeyaml dependency to kb-importer/pom.xml
pedrogalvao Jun 2, 2022
38b25e6
Fixed a mistake in kb-importer dockerfile
pedrogalvao Jun 2, 2022
d6a04e3
Removed a comment
pedrogalvao Jun 2, 2022
0016296
Documentation
pedrogalvao Jun 2, 2022
5fbf2a7
Removed MainTest.java
pedrogalvao Jun 2, 2022
6748bf0
Removed IOExceptio in commented code
pedrogalvao Jun 2, 2022
caf4d55
Removed printStackTrace from BackendConnectionException
pedrogalvao Jun 2, 2022
d65daaa
mend
pedrogalvao Jun 2, 2022
14a6e22
Fixed mistake in pom files (moved snakeyaml dependency)
pedrogalvao Jun 2, 2022
7999bf7
whitespace
pedrogalvao Jun 2, 2022
d9f9dc3
Removed GoalClient from wrong directory. Removed whitespace
pedrogalvao Jun 2, 2022
e1186cc
Reversed change in BasicHttpRequest
pedrogalvao Jun 2, 2022
ebdc259
Reversed change in kb-importer pom
pedrogalvao Jun 7, 2022
86a433b
Function isBugExisting throws BackendConnectionException
pedrogalvao Jun 7, 2022
62b6b17
Fixed code style
pedrogalvao Jun 7, 2022
a326de9
Substituted string literals by constants in tests
pedrogalvao Jun 7, 2022
e3d3381
feat: upgrade Docker images and fixes digest
Naramsim Jun 9, 2022
7f2829b
Added TestManager. Keeping failures as Exceptions instead of strings
pedrogalvao Jun 15, 2022
51cafa2
Added paths to properties. Other small changes
pedrogalvao Jun 21, 2022
914bdb9
Merge remote-tracking branch 'remote-2/fix_images'
pedrogalvao Jun 21, 2022
d8436f1
Corrected version + relativePath, added flatten-maven-plugin and star…
henrikplate Jul 28, 2022
1260868
Updated description and properties
henrikplate Jul 28, 2022
6c24fa5
Create CycloneDX BOM for REST services; Fix shell script starting the…
henrikplate Jul 28, 2022
59c4fb1
Added documentation with javadocs
pedrogalvao Aug 2, 2022
a4b766c
Start thread in constructor of ImporterController
pedrogalvao Aug 2, 2022
727698e
Changed Docker Compose so that start-steady works in clone and after …
henrikplate Aug 3, 2022
676edd1
Merge branch 'master' of https://github.com/pedrogalvao/steady
henrikplate Aug 3, 2022
2e966d9
Commented lang-python out
henrikplate Aug 3, 2022
29636df
Avoid mv of binaries into data folder
henrikplate Aug 3, 2022
b33c727
Using ProcessWrapper in kb-importer Manager
pedrogalvao Aug 10, 2022
2339bc9
Fixed thread names
pedrogalvao Aug 10, 2022
1aa0265
Added lang-python back in (its removal will be done in a separate PR)
henrikplate Aug 17, 2022
dfcd0a6
Fixed some bugs, added comments and improved log messages
henrikplate Aug 25, 2022
1222d2b
Changed default wait time to 1d
henrikplate Aug 26, 2022
bfc4ac4
Maintain stats for all statuses
henrikplate Sep 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docker/kb-importer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ WORKDIR /kb-importer
RUN wget https://github.com/SAP/project-kb/releases/download/v0.6.18/kaybee-0.6.18_linux-amd64 -O kaybee
RUN chmod +x kaybee

COPY kb-importer-$VULAS_RELEASE-jar-with-dependencies.jar kb-importer.jar
COPY kb-importer-$VULAS_RELEASE.jar kb-importer.jar
RUN chmod +x kb-importer.jar

COPY kb-importer.sh start.sh /kb-importer/
COPY start.sh /kb-importer/

EXPOSE 8080

RUN chmod +x /kb-importer/kb-importer.sh /kb-importer/start.sh
Comment thread
pedrogalvao marked this conversation as resolved.
Outdated

ENTRYPOINT ["sh","/kb-importer/start.sh"]
231 changes: 0 additions & 231 deletions docker/kb-importer/conf/kaybeeconf.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -21,234 +21,3 @@ policies:
# - CVE-2005-3164
# - CVE-2005-4838
# - CVE-2007-0450

export:
Comment thread
pedrogalvao marked this conversation as resolved.
# - target: csv
# filename: vulnerabilities.csv
# pre:
# each: |
# {{ if .Fixes }} {{ .VulnerabilityID}},{{ (index (index .Fixes 0).Commits 0).RepositoryURL }}{{end}}
# post:
- target: steady
filename: steady.sh
pre: |
#!/bin/bash

# ------------------------------------------------
# Import script for Eclipse Steady
# ------------------------------------------------

##-------- E D I T T H I S S E C T I O N --------
##
## COMMENT OUT THE NEXT LINE AND EDIT THE FOLLOWING LINES
#echo "Please configure the necessary variables in the script and try again" && exit 1

# Your user token (required to upload vulnerability data to Steady backend)
USER_TOKEN=$BACKEND_BUGS_TOKEN

# Backend URL of your Steady instance
BACKEND_URL=$BACKEND_SERVICE_URL

# URL of the CIA service of your Steady instance
CIA_URL=$CIA_SERVICE_URL

# This must be the absolute path to the kb-importer jar file
KB_IMPORTER_PATH="/kb-importer/data/kb-importer.jar"

# Skip repos clone and thus vulnerabilities requiring it
SKIP_CLONE=$KB_IMPORTER_SKIP_CLONE
##---------------------- E N D --------------------

ANALYZER_CMD="java -Dvulas.shared.backend.header.X-Vulas-Client-Token=$USER_TOKEN -Dvulas.shared.cia.serviceUrl=$CIA_URL -Dvulas.shared.backend.serviceUrl=$BACKEND_URL -jar $KB_IMPORTER_PATH -u"
LOCAL_CLONES_DIR=$KB_IMPORTER_CLONE_FOLDER

folder_for_repo(){
X=$1

# remove trailing slash
X=${X%/}

# remove everything until '://' is matched
X=${X#*:\/\/}

# replace _ for .
X=${X//./_}

# replace _ for /
X=${X//\//_}
echo ${LOCAL_CLONES_DIR}/$X
}

clone_once(){
DIR=$(folder_for_repo $1)

if [ -d $DIR ];
then
echo "Folder $DIR exists, skipping git clone"
else
echo "Cloning $1 to folder $DIR"
git clone $1 $DIR
fi
}

#make_vuln_metadata(){
# vulnerability_id="$1"
# description="$2"
# links="$3"
#
# [ -d $vulnerability_id ] || mkdir ./$vulnerability_id
# > $vulnerability_id/meta.properties
# echo "vulnerability_id=$vulnerability_id" >> $vulnerability_id/meta.properties
# echo "description=$description" >> $vulnerability_id/meta.properties
# echo "links=$links" >> $vulnerability_id/meta.properties
#}

create_meta_from_tar(){
repo_url=$1
commit_id=$2
branch=$3
vulnerability_id=$4
source_path=$5

if [ -f $vulnerability_id/$commit_id/metadata.json ]
then
return
fi

[ -d $vulnerability_id/$commit_id ] || mkdir -p $vulnerability_id/$commit_id
if [ -f $source_path/changed-source-code.tar.gz ]
then
timestamp=`cat $vulnerability_id/$commit_id/timestamp`
echo "{" > $vulnerability_id/$commit_id/metadata.json
echo " \"repository\" : \"$repo_url\"," >> $vulnerability_id/$commit_id/metadata.json
echo " \"branch\" : \"$branch\"," >> $vulnerability_id/$commit_id/metadata.json
echo " \"timestamp\" : \"$timestamp\"," >> $vulnerability_id/$commit_id/metadata.json
echo " \"commit_id\" : \"$commit_id\"" >> $vulnerability_id/$commit_id/metadata.json
echo "}" >> $vulnerability_id/$commit_id/metadata.json
rm $vulnerability_id/$commit_id/timestamp
fi
return
}

clone_and_create_meta(){
repo_url=$1
commit_id=$2
branch=$3
vulnerability_id=$4
source_path=$5

if [ -f $vulnerability_id/$commit_id/metadata.json ]
then
return
fi

clone_once $repo_url
repo_dir=$(folder_for_repo $repo_url)

timestamp=$(git -C $repo_dir show --no-patch --no-notes --pretty='%at' $commit_id)

echo "{" > $vulnerability_id/$commit_id/metadata.json
echo " \"repository\" : \"$repo_url\"," >> $vulnerability_id/$commit_id/metadata.json
echo " \"branch\" : \"$branch\"," >> $vulnerability_id/$commit_id/metadata.json
echo " \"timestamp\" : \"$timestamp\"," >> $vulnerability_id/$commit_id/metadata.json
echo " \"commit_id\" : \"$commit_id\"" >> $vulnerability_id/$commit_id/metadata.json
echo "}" >> $vulnerability_id/$commit_id/metadata.json

echo "dir=$repo_dir"
echo "pwd=`pwd`"

# cd repository
for F in $(git -C $repo_dir diff --name-only $commit_id^..$commit_id);
do

echo "repo_dir=$repo_dir"
echo "pwd=`pwd`"

echo "Extracting file: $F"
[ -d $vulnerability_id/$commit_id/before/$(dirname $F) ] || mkdir -p $vulnerability_id/$commit_id/before/$(dirname $F)
[ -d $vulnerability_id/$commit_id/after/$(dirname $F) ] || mkdir -p $vulnerability_id/$commit_id/after/$(dirname $F)

if ( git -C $repo_dir cat-file -e $commit_id~1:$F &> /dev/null )
then
git -C $repo_dir show $commit_id~1:$F > $vulnerability_id/$commit_id/before/$F
fi

if ( git -C $repo_dir cat-file -e $commit_id:$F &> /dev/null )
then
git -C $repo_dir show $commit_id:$F > $vulnerability_id/$commit_id/after/$F
fi
done
}

each: |+
# -----------------------------------------------
# Analyzing vulnerability {{ .VulnerabilityID}}
# -----------------------------------------------
{{ if .VulnerabilityID }}
[ -d ./{{ .VulnerabilityID }} ] || mkdir ./{{ .VulnerabilityID }}
{{ $source_path := .Metadata.LocalPath }}
[ -f {{ $source_path }}/changed-source-code.tar.gz ] && tar -xf {{ $source_path }}/changed-source-code.tar.gz -C ./{{ .VulnerabilityID }}

cat << 'EOM' > ./{{ .VulnerabilityID }}/metadata.json
{{ .ToJSON }}
EOM

if [ -f {{ $source_path }}/changed-source-code.tar.gz ] ;
then
# Create the metadata from the tarball cloned previously
{{ if .Fixes}}{{ $description := or ((index .Notes 0).Text) "" }}
{{ $vuln := .VulnerabilityID}}{{ $repo := (index (index .Fixes 0).Commits 0).RepositoryURL }}
{{ range $f := .Fixes }}{{ range .Commits }}create_meta_from_tar {{$repo}} {{.ID}} {{$f.ID}} {{ $vuln }} {{ $source_path }}
{{end}}{{end}}
{{end}}
$ANALYZER_CMD -d ./{{ .VulnerabilityID }}
:
else
if [ ! "${KB_IMPORTER_SKIP_CLONE}" == "True" ];
then
# Create the metadata after cloning the repo of the affected package and checking out every commit
{{ if .Fixes}}{{ $description := or ((index .Notes 0).Text) "" }}
#make_vuln_metadata {{ .VulnerabilityID }} '{{ JoinNotes . }}' {{ LinksAsCSV . }}
{{ $vuln := .VulnerabilityID}}{{ $repo := (index (index .Fixes 0).Commits 0).RepositoryURL }}
{{ range $f := .Fixes }}{{ range .Commits }}clone_and_create_meta {{$repo}} {{.ID}} {{$f.ID}} {{ $vuln }} {{ $source_path }}
{{end}}{{end}}
{{else}}
# This vulnerability has no fix-commits
:
{{end}}
$ANALYZER_CMD -d ./{{ .VulnerabilityID }}
fi
fi
{{end}}

post: |-
# ------------------------------------------------
# This script was generated with KayBee
# ------------------------------------------------
- target: xml
filename: vulnerabilities.xml
pre: |
<xml>
<Vulnerabilities>

each: |
<Vulnerability id="{{ .VulnerabilityID}}">
<fixes>
{{range .Fixes }}
<fix id="{{ .ID }}">
{{range .Commits }}
<commit hash="{{ .ID }}" repository="{{ .RepositoryURL }}" />{{end}}
</fix>
</fixes>{{end}}
<notes>
{{range .Notes }}
<note>
{{range $link := .Links }}<link url="{{ $link }}" />
{{end}}
{{ if .Text }}<text>{{ .Text }}</text>{{ end }}
</note>{{end}}
</notes>
</VulnerabilityID>
post: |
</Vulnerabilities>
</xml>
47 changes: 0 additions & 47 deletions docker/kb-importer/kb-importer.sh

This file was deleted.

29 changes: 8 additions & 21 deletions docker/kb-importer/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,24 @@ sed "s|KB_IMPORTER_STATEMENTS_REPO|$KB_IMPORTER_STATEMENTS_REPO|g" ../conf/kaybe
sed -i "s|KB_IMPORTER_STATEMENTS_BRANCH|$KB_IMPORTER_STATEMENTS_BRANCH|g" ../conf/kaybeeconf.yaml

echo "Statements repo: " $KB_IMPORTER_STATEMENTS_REPO

echo "Statements branch: " $KB_IMPORTER_STATEMENTS_BRANCH
echo "Statements folder: " $KB_IMPORTER_STATEMENTS_FOLDER
echo "Clones folder: " $KB_IMPORTER_CLONE_FOLDER
echo "Skip clones: " $KB_IMPORTER_SKIP_CLONE

./kaybee update --force

#Adding certs
certs=`ls /kb-importer/certs | grep -v readme.txt`
for cert in $certs; do
keytool -import -alias $cert -storepass changeit -keystore /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts -file /kb-importer/certs/$cert -noprompt
done

#Wait for backend to start
java -Dvulas.shared.backend.header.X-Vulas-Client-Token=$BACKEND_BUGS_TOKEN \
-Dvulas.shared.cia.serviceUrl=$CIA_SERVICE_URL \
-Dvulas.shared.backend.serviceUrl=$BACKEND_SERVICE_URL \
-jar /kb-importer/data/kb-importer.jar >> analyzer_logs.txt &
Comment thread
pedrogalvao marked this conversation as resolved.
Outdated

#Wait for kb-importer and backend to start
sleep 40

#Run initial import
./../kb-importer.sh

#create a cron job kaybeeconf.yaml
crontab -l > tmpcron
if ! cat tmpcron | grep "kb-importer.sh"
then
if [ -z "$KB_IMPORTER_CRON_HOUR" ]
then
echo "0 0 * * * PATH=$PATH BACKEND_SERVICE_URL=$BACKEND_SERVICE_URL KB_IMPORTER_STATEMENTS_FOLDER=$KB_IMPORTER_STATEMENTS_FOLDER KB_IMPORTER_STATEMENTS_BRANCH=$KB_IMPORTER_STATEMENTS_BRANCH KB_IMPORTER_STATEMENTS_REPO=$KB_IMPORTER_STATEMENTS_REPO KB_IMPORTER_CLONE_FOLDER=$KB_IMPORTER_CLONE_FOLDER KB_IMPORTER_SKIP_CLONE=$KB_IMPORTER_SKIP_CLONE /kb-importer/kb-importer.sh >> /kb-importer/cron.log 2>&1" >> tmpcron
else
echo "0 " "$KB_IMPORTER_CRON_HOUR" " * * * PATH=$PATH BACKEND_SERVICE_URL=$BACKEND_SERVICE_URL KB_IMPORTER_STATEMENTS_FOLDER=$KB_IMPORTER_STATEMENTS_FOLDER KB_IMPORTER_STATEMENTS_BRANCH=$KB_IMPORTER_STATEMENTS_BRANCH KB_IMPORTER_STATEMENTS_REPO=$KB_IMPORTER_STATEMENTS_REPO KB_IMPORTER_CLONE_FOLDER=$KB_IMPORTER_CLONE_FOLDER KB_IMPORTER_SKIP_CLONE=$KB_IMPORTER_SKIP_CLONE /kb-importer/kb-importer.sh >> /kb-importer/cron.log 2>&1" >> tmpcron
fi
fi
crontab tmpcron
echo "cron job created."
rm tmpcron
cron -f
curl localhost:8080/start -X POST
Loading