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

Importing v3 #482

Merged
merged 91 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
0cb4fd7
logging improvement
northdpole Jan 14, 2024
1d9ed6f
add design doc
northdpole Jan 14, 2024
eb3102f
spreadsheet parser refactored
northdpole Jan 21, 2024
db3b273
parallelize main
northdpole Jan 25, 2024
d1ddecb
parallelise importing of standards from a spreadsheet and generation …
northdpole Jan 28, 2024
cc1458c
add progress bars
northdpole Jan 30, 2024
423daa4
return list of imported resources
northdpole Jan 30, 2024
a67c417
initial base parser implementation
northdpole Jan 31, 2024
75d4bda
move parsers to own dir and migrate cwe, dsomm and iso27k to the new …
northdpole Feb 1, 2024
9e9774f
migrate parsers
northdpole Feb 2, 2024
8d3afbb
make main call parser
northdpole Feb 2, 2024
187a013
add embeddings in the document object allow prasers to generate and f…
northdpole Feb 4, 2024
e94bd17
add default value for embeddings object in dataclass
northdpole Feb 4, 2024
ddd4008
sort out imports
northdpole Feb 4, 2024
630c69a
cwe parser test
northdpole Feb 11, 2024
9ad3627
dsomm parser tests
northdpole Feb 11, 2024
0639649
secure headers + tests
northdpole Feb 11, 2024
c1bfc64
cloud native security controls parser +tests
northdpole Feb 11, 2024
1e7e396
ccmv4
northdpole Feb 11, 2024
e1fe452
rename method
northdpole Feb 11, 2024
68ac798
juiceshop + tests
northdpole Feb 11, 2024
d1f5be2
mega lint
northdpole Feb 11, 2024
d38645e
rm commented code
northdpole Feb 11, 2024
0102356
fix docs equality test
northdpole Feb 11, 2024
4f0bf55
change external project parsers to return dict of 'resourcename':<res…
northdpole Feb 11, 2024
e31ea15
fix web main test related to CSV returning inconsistency
northdpole Feb 11, 2024
debbe50
fix nit on gap analysis enqueue job
northdpole Feb 11, 2024
6c6172e
operational changes to make mass importing easier
northdpole Feb 13, 2024
0c29d19
fix spreadsheet importing bugs, add validation to dataclasses
northdpole Feb 17, 2024
4dc85ce
makefile improvements
northdpole Feb 20, 2024
2b731bb
add validation and fix tests
northdpole Feb 20, 2024
d358508
drop support for OSIB
northdpole Feb 20, 2024
5917fdd
fix more tests
northdpole Feb 21, 2024
e0d86ff
pin black to same version as superlinter and lint everything
northdpole Feb 24, 2024
6d92982
change array hash to array key so that its legible, introduce ids for…
northdpole Feb 25, 2024
2b20c6b
add tests for bug where standards would only link to one cre
northdpole Feb 25, 2024
be25860
change neo4j standards for regular postgres standards
northdpole Feb 29, 2024
de8e479
adjust main to not require redis when getting standards
northdpole Feb 29, 2024
03602be
cache key to str
northdpole Feb 29, 2024
82326da
add ability to import only the projects
northdpole Mar 3, 2024
eb5626a
delete all traces of node and gap analysis of node, used when reimpor…
northdpole Mar 3, 2024
3778930
nit: rearrange argument handling on main
northdpole Mar 9, 2024
1fa2544
fix previously introduced cre hierarchy bug
northdpole Mar 12, 2024
bf182b1
move commands for regenerating DB to a new 'import-all' script
northdpole Mar 15, 2024
0ea58bb
fix embedding gen
northdpole Mar 15, 2024
e4943ff
disable iso, set port to 5001
northdpole Mar 20, 2024
b10f6f5
add 'automatically linked to' linktype and use it for low confidence …
northdpole Mar 23, 2024
ceef928
fix scripts, make import-projects use scripts
northdpole Mar 23, 2024
eccd29f
rm cres, too large to keep around
northdpole Mar 23, 2024
b78ba02
add migration
northdpole Mar 24, 2024
90eb188
since we removed cres dir, also remove export functionality
northdpole Mar 25, 2024
f0bcac4
fix importing script
northdpole Mar 25, 2024
1b123b8
add new link status to db
northdpole Mar 28, 2024
e979c79
add import-only for external parsers and remove export and review fun…
northdpole Apr 4, 2024
229a6cf
fix cwe typo
northdpole Apr 4, 2024
5140392
generate embeddings for guaranteed non-none name
northdpole Apr 4, 2024
10f570c
add message on waiting jobs
northdpole Apr 7, 2024
ce1af06
improve gap analysis logging
northdpole Apr 7, 2024
1f0e314
add ability to skip reimporting if something already exists
northdpole Apr 14, 2024
fb74978
logging nit
northdpole Apr 15, 2024
d93df17
make the base parser not load the in-memory graph by default and fix the
northdpole Apr 16, 2024
e279081
make loading the graph in memory optional
northdpole Apr 16, 2024
1317af3
improve logging for gap analysis jobs
northdpole Apr 16, 2024
a6cb654
fix endless loop when importing and gap analysis exists
northdpole Apr 16, 2024
b763af9
add gap analysis relationship 'automaticallyt linked to' and throw ex…
northdpole Apr 16, 2024
5bf0cb5
paginate graph retrieval init (#491)
northdpole Apr 6, 2024
c156a87
Macos support (#496)
northdpole Apr 16, 2024
f478561
backend runs on 5001 (#495)
northdpole Apr 16, 2024
7cac06a
Revert "backend runs on 5001 (#495)" (#498)
northdpole Apr 16, 2024
4d65092
rm version from cwe and make ccm and iso disabled parsers commented o…
northdpole Apr 18, 2024
fce0d2b
add dev environment variables that do only graph importing to be used…
northdpole May 1, 2024
dc388be
import external projects individually
northdpole May 12, 2024
e5c1767
print less when calculating ga
northdpole May 19, 2024
603cfc0
[ticket-508] Ensure autolinks appear on the CRE page (#509)
dlicheva May 21, 2024
1bd363d
fix broken rebase
northdpole May 21, 2024
41b6e84
add ability to run cre as a container and sync local cre with upstream
northdpole Jun 8, 2024
056cd77
cleanup unused spreadsheet parser methods
northdpole Jun 9, 2024
c442f4f
fix e2e tests
northdpole Jun 9, 2024
5f6951d
pin black to same version as superlinter
northdpole Jun 9, 2024
e2ee9b9
pin node version in github e2e
northdpole Jun 9, 2024
85bf4e9
upgrade actions node
northdpole Jun 9, 2024
5b801f0
ga query test
northdpole Jun 16, 2024
ed27b55
add ability to external project parsers to skip gap analysis and embe…
northdpole Jun 18, 2024
9388f84
nit: logging
northdpole Jun 26, 2024
404ac9b
fix gap analysis bug where we wouldn't remove calculated ga from wait…
northdpole Jun 26, 2024
702b336
move ga preloading into script
northdpole Jun 26, 2024
85c2fd0
fix error where standards would get preloaded twice
northdpole Jun 27, 2024
864fedd
add explorer to header in staging
northdpole Jun 27, 2024
addc315
Merge branch 'main' into importing-v3
northdpole Jul 6, 2024
d6394fb
in pyyaml, try to fix incompatibility with cython
northdpole Jul 6, 2024
3ab53c0
init fix e2e tests
northdpole Jul 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: staging
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Deploy backend to heroku
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,24 @@ jobs:
timeout-minutes: 10
steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11.4'
cache: 'pip'
- uses: actions/setup-node@v3
with:
cache: 'yarn'
- name: Install python dependencies
node-version: 'v20.12.1'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3-setuptools python3-pip python3-virtualenv chromium-browser libgbm1
make install
- name: DB setup
run: |
cp cres/db.sqlite standards_cache.sqlite
make migrate-upgrade
python cre.py --upstream_sync
- name: Run app and e2e tests
run: |
yarn build
[ -d "./venv" ] && . ./venv/bin/activate
export FLASK_APP=./cre.py
export FLASK_CONFIG=development
export INSECURE_REQUESTS=1
FLASK_CONFIG=development flask run &
sleep 20s
yarn test:e2e
make e2e
4 changes: 1 addition & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Lint Code Base
uses: github/super-linter@v5
env:

VALIDATE_PYTHON_BLACK: true
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish
on:
push:
tags:
- "v*.*.*"

permissions:
# Grant the ability to checkout the repository
contents: write
# Grant the ability to push packages
packages: write

jobs:
publish-docker-images:
name: Push Docker images
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Docker images
run: |
CRE_VERSION_SEMVER=$(sed 's/v//' <<< ${{ github.ref_name }});
make docker-prod
docker tag opencre:$(git rev-parse HEAD) ghcr.io/owasp/OpenCRE/opencre:${CRE_VERSION_SEMVER}
docker tag opencre:$(git rev-parse HEAD) ghcr.io/owasp/OpenCRE/opencre:latest
docker push ghcr.io/owasp/OpenCRE/opencre:${CRE_VERSION_SEMVER}
docker push ghcr.io/owasp/OpenCRE/opencre:latest
26 changes: 15 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- uses: actions/setup-python@v4
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11.4'
cache: 'pip'
- uses: actions/setup-node@v3
with:
cache: 'yarn'
python-version: '3.12.3'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
python3-setuptools \
python3-virtualenv \
python3-pip \
libxml2-dev \
libxslt-dev
- name: Install python dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3-setuptools python3-virtualenv python3-pip
pip install --upgrade pip
make install-python
pip install --upgrade pip
pip install --upgrade setuptools
make install-python
- name: Test
run: make test
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ neo4j/
.neo4j/

.mypy_cache
tmp/
tmp/

### CREs dir
cres/*
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ WORKDIR /code
COPY . /code
RUN yarn install && yarn build

FROM python:3.11.0 as run
FROM python:3.11 as run

COPY --from=build /code /code
WORKDIR /code
COPY ./scripts/prod-docker-entrypoint.sh /code
RUN pip install -r requirements.txt gunicorn

ENTRYPOINT gunicorn
CMD ["--timeout","800","--workers","8","cre:app"]
ENV INSECURE_REQUESTS=1
ENV FLASK_CONFIG="production"
RUN chmod +x /code/prod-docker-entrypoint.sh
ENTRYPOINT ["/code/prod-docker-entrypoint.sh"]
52 changes: 24 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@

.ONESHELL:

.PHONY: run test covers install-deps dev docker lint frontend clean all

prod-run:
cp cres/db.sqlite standards_cache.sqlite; gunicorn cre:app --log-file=-

docker-neo4j-rm:
docker stop cre-neo4j
docker rm -f cre-neo4j
docker volume rm cre_neo4j_data
docker volume rm cre_neo4j_logs
# rm -rf .neo4j

docker-neo4j:
docker start cre-neo4j 2>/dev/null || docker run -d --name cre-neo4j --env NEO4J_PLUGINS='["apoc"]' --env NEO4J_AUTH=neo4j/password --volume=`pwd`/.neo4j/data:/data --volume=`pwd`/.neo4j/logs:/logs --workdir=/var/lib/neo4j -p 7474:7474 -p 7687:7687 neo4j

docker-redis-rm:
docker stop cre-redis-stack
docker rm -f cre-redis-stack

docker-redis:
docker start redis-stack 2>/dev/null || docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
docker start cre-redis-stack 2>/dev/null ||\
docker run -d --name cre-redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

start-containers: docker-neo4j docker-redis

Expand Down Expand Up @@ -49,7 +63,7 @@ install-deps-typescript:
install-deps: install-deps-python install-deps-typescript

install-python:
virtualenv -p python3.11 venv
virtualenv -p python3 --system-site-packages venv
. ./venv/bin/activate &&\
make install-deps-python &&\
playwright install
Expand Down Expand Up @@ -101,35 +115,17 @@ migrate-downgrade:
export FLASK_APP=$(CURDIR)/cre.py
flask db downgrade

import-projects:
$(shell CRE_SKIP_IMPORT_CORE=1 bash ./scripts/import-all.sh)

import-all:
[ -d "./venv" ] && . ./venv/bin/activate &&\
rm -rf standards_cache.sqlite &&\
make migrate-upgrade && export FLASK_APP=$(CURDIR)/cre.py &&\
python cre.py --add --from_spreadsheet https://docs.google.com/spreadsheets/d/1eZOEYgts7d_-Dr-1oAbogPfzBLh6511b58pX3b59kvg &&\
python cre.py --generate_embeddings && \
python cre.py --zap_in --cheatsheets_in --github_tools_in --capec_in --owasp_secure_headers_in --pci_dss_4_in --juiceshop_in --dsomm_in --dsomm_in --cloud_native_security_controls_in &&\
python cre.py --generate_embeddings
$(shell bash ./scripts/import-all.sh)

import-neo4j:
[ -d "./venv" ] && . ./venv/bin/activate &&\
export FLASK_APP=$(CURDIR)/cre.py && python cre.py --populate_neo4j_db

preload-map-analysis:
make docker-redis&\
make start-worker&\
make start-worker&\
make start-worker&\
make start-worker&\
make start-worker&\
make start-worker&\
make start-worker&\
make start-worker&\
make start-worker&\
make start-worker&\
make dev-flask&
sleep 5
[ -d "./venv" ] && . ./venv/bin/activate &&\
export FLASK_APP=$(CURDIR)/cre.py
python cre.py --preload_map_analysis_target_url 'http://127.0.0.1:5000'
killall python flask
preload-map-analysis:
$(shell RUN_COUNT=5 bash ./scripts/preload_gap_analysis.sh)

all: clean lint test dev dev-run
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: gunicorn cre:app --log-file=-g
worker: FLASK_APP=`pwd`/cre.py python cre.py --start_worker
web: gunicorn cre:app
worker: FLASK_APP=`pwd`/cre.py python cre.py --start_worker
Loading
Loading