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

Reimplement caching to use a per-year scope fixes #258 #259

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ nb-configuration.xml
**/nbproject/
local.properties
data-source/data/

# IntellIJ run configs
.run
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.github.jeremylong.openvulnerability.client.nvd;

import io.github.jeremylong.openvulnerability.client.HttpAsyncClientSupplier;
import java.util.stream.Collectors;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.slf4j.Logger;
Expand Down Expand Up @@ -224,12 +225,22 @@ public NvdCveClientBuilder withFilter(BooleanFilter filter) {
* @return the builder
*/
public NvdCveClientBuilder withLastModifiedFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ssX");
DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
// ensure we have no filters yet
removeLastModifiedFilter();
jeremylong marked this conversation as resolved.
Show resolved Hide resolved

filters.add(new BasicNameValuePair("lastModStartDate", utcStartDate.format(dtf)));
filters.add(new BasicNameValuePair("lastModEndDate", utcEndDate.format(dtf)));
return this;
}

public NvdCveClientBuilder removeLastModifiedFilter() {
// ensure we have no filters yet
filters.removeIf((item) -> item.getName().equals("lastModStartDate"));
filters.removeIf((item) -> item.getName().equals("lastModEndDate"));
return this;
}

jeremylong marked this conversation as resolved.
Show resolved Hide resolved
/**
* Use an additional identifier as part of the User-Agent when making requests.
*
Expand All @@ -249,12 +260,22 @@ public NvdCveClientBuilder withAdditionalUserAgent(String userAgent) {
* @return the builder
*/
public NvdCveClientBuilder withPublishedDateFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ssX");
DateTimeFormatter dtf = DateTimeFormatter.ISO_OFFSET_DATE_TIME;

// ensure we have no filters yet
removePublishDateFilter();

filters.add(new BasicNameValuePair("pubStartDate", utcStartDate.format(dtf)));
filters.add(new BasicNameValuePair("pubEndDate", utcEndDate.format(dtf)));
return this;
}

public NvdCveClientBuilder removePublishDateFilter() {
filters.removeIf((item) -> item.getName().equals("pubStartDate"));
filters.removeIf((item) -> item.getName().equals("pubEndDate"));
return this;
}

/**
* Filter the results for a specific CVSS V2 Severity.
*
Expand Down
3 changes: 1 addition & 2 deletions vulnz/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ COPY ["/src/docker/supervisor/supervisord.conf", "/etc/supervisord.conf"]
COPY ["/src/docker/scripts/mirror.sh", "/mirror.sh"]
COPY ["/src/docker/scripts/validate.sh", "/validate.sh"]
COPY ["/src/docker/crontab/mirror", "/etc/crontabs/mirror"]
COPY ["/src/docker/crontab/validate", "/etc/crontabs/validate"]
COPY ["/src/docker/apache/mirror.conf", "/usr/local/apache2/conf"]
COPY ["/build/libs/vulnz-$BUILD_VERSION.jar", "/usr/local/bin/vulnz"]

RUN chmod +x /mirror.sh /validate.sh && \
chown root:root /etc/crontabs/mirror /etc/crontabs/validate && \
chown root:root /etc/crontabs/mirror && \
chown mirror:mirror /mirror.sh /validate.sh && \
chown mirror:mirror /usr/local/bin/vulnz

Expand Down
4 changes: 2 additions & 2 deletions vulnz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ docker run --name vulnz -e JAVA_OPT=-Xmx2g jeremylong/open-vulnerability-data-mi

# you can also adjust the delay
docker run --name vulnz -e NVD_API_KEY=myapikey -e DELAY=3000 jeremylong/open-vulnerability-data-mirror:v7.2.1

```

If you like, run this to pre-populate the database right away
Expand All @@ -148,7 +147,8 @@ Assuming the current version is `7.2.1`
```bash
export TARGET_VERSION=7.2.1
./gradlew vulnz:build -Pversion=$TARGET_VERSION
docker build vulnz/ -t ghcr.io/jeremylong/vulnz:$TARGET_VERSION --build-arg BUILD_VERSION=$TARGET_VERSION
docker build vulnz/ -t ghcr.io/jeremylong/vulnz:v$TARGET_VERSION --build-arg BUILD_VERSION=$TARGET_VERSION
docker push
```

### Release
Expand Down
1 change: 1 addition & 0 deletions vulnz/src/docker/crontab/mirror
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0 0 * * * /mirror.sh 2>&1 | tee -a /var/log/docker_out.log | tee -a /var/log/cron_mirror.log
0 4 * * * /validate.sh 2>&1 | tee -a /var/log/docker_out.log | tee -a /var/log/cron_validate.log
1 change: 0 additions & 1 deletion vulnz/src/docker/crontab/validate

This file was deleted.

18 changes: 17 additions & 1 deletion vulnz/src/docker/scripts/mirror.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/bin/sh

set -e

echo "Updating..."

LOCKFILE=/tmp/vulzn.lock

if [ -f $LOCKFILE ]; then
echo "Lockfile found - another mirror-sync process already running"
else
touch $LOCKFILE
fi

DELAY_ARG=""
if [ -z $NVD_API_KEY ]; then
DELAY_ARG="--delay=10000"
Expand Down Expand Up @@ -33,5 +42,12 @@ if [ -n "${DEBUG}" ]; then
DEBUG_ARG="--debug"
fi

exec java $JAVA_OPT -jar /usr/local/bin/vulnz cve $DELAY_ARG $DEBUG_ARG $MAX_RETRY_ARG $MAX_RECORDS_PER_PAGE_ARG --cache --directory /usr/local/apache2/htdocs
function remove_lockfile() {
rm -f $LOCKFILE
exit 0
}
trap remove_lockfile SIGHUP SIGINT SIGQUIT SIGABRT SIGALRM SIGTERM SIGTSTP

java $JAVA_OPT -jar /usr/local/bin/vulnz cve $DELAY_ARG $DEBUG_ARG $MAX_RETRY_ARG $MAX_RECORDS_PER_PAGE_ARG $CONTINUE_ARG --cache --directory /usr/local/apache2/htdocs
Copy link
Owner

Choose a reason for hiding this comment

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

Can we look for an exit code and if it failed for a single year - try kicking it off again automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i like the idea generally, but IMHO we should try this in a separate PR, what do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm fine with a separate PR. We just need to consider outputting the correct exit code that we can look for here.

Copy link
Owner

Choose a reason for hiding this comment

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


rm -f $LOCKFILE
1 change: 1 addition & 0 deletions vulnz/src/docker/supervisor/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
user=mirror
stopsecs=29
Loading
Loading