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

Precompute map analysis #432

Closed
wants to merge 76 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
cc87efe
trigger first staging build
northdpole Sep 6, 2023
322e5dd
Inital Hack of NEO4j DB creation
john681611 Aug 2, 2023
9a7b213
Added: Neo4j docker run
john681611 Aug 10, 2023
d67922d
Added NEO_DB Class
john681611 Aug 10, 2023
914152d
Create Inital Path API response
john681611 Aug 10, 2023
89383ce
Build basic UI for testing
john681611 Aug 11, 2023
c24f45f
Mock score and WIP UI
john681611 Aug 21, 2023
bb22a2e
implement scoring and basic tests
john681611 Aug 24, 2023
4e81dd8
scoring passing tests
john681611 Aug 24, 2023
3245263
Update the UI
john681611 Aug 24, 2023
814996a
Updated: Dropdowns are now dynamic
john681611 Sep 4, 2023
6af9f69
Localise neo4j
john681611 Sep 4, 2023
f4b4e9a
Added Navigation method
john681611 Sep 4, 2023
4b8a86b
Add share and nav links
john681611 Sep 4, 2023
8185d6c
readme improvement
john681611 Sep 4, 2023
6a6ceba
Hide table on new search
john681611 Sep 4, 2023
31b8b75
Optermise query to remove relates to
john681611 Sep 4, 2023
af4fd6e
Get duel running method working and show empty values
john681611 Sep 4, 2023
865bef0
Refactor grouping & scoring code locations
john681611 Sep 4, 2023
0f5cbb5
Add colour to strength raiting
john681611 Sep 4, 2023
65eb937
Add gap analysis tests
john681611 Sep 7, 2023
c684227
Short drop down list
john681611 Sep 7, 2023
a8a849b
Styling improvements and legends
john681611 Sep 7, 2023
22eda1e
rm scikit version pin
northdpole Sep 10, 2023
bcdee15
loosen requirement in sqlalchemy
northdpole Sep 10, 2023
6eb182a
more deps changes
northdpole Sep 10, 2023
49d17c0
fix deps
northdpole Sep 13, 2023
c241914
Disable auto db pop (#372)
john681611 Sep 14, 2023
dca3961
fix pillow
northdpole Sep 14, 2023
6bd5c22
Use python 3.11.4 for CI
john681611 Sep 18, 2023
953c770
Parse cre_dep object from neo4j Node
john681611 Sep 14, 2023
ee42b4b
Standardise Gap Analysis API Object
john681611 Sep 14, 2023
b4b9309
Fix bad parse field
john681611 Sep 14, 2023
88252d6
Use Standard display format and create GA type
john681611 Sep 14, 2023
b1d96f3
GA: Show all strong links by default (or min of 3)
john681611 Sep 14, 2023
8812441
Better route display
john681611 Sep 14, 2023
1ad292a
GA add support for tools
john681611 Sep 14, 2023
b2c9ed1
Fix existing tests
john681611 Sep 15, 2023
fcfbbb4
Add parsing tests
john681611 Sep 15, 2023
dea87ed
make parse_node static
john681611 Sep 15, 2023
32ae469
Use Enum types
john681611 Sep 15, 2023
e224c9f
Merge pull request #377 from OWASP/neo4j-standard-object
john681611 Sep 19, 2023
873fa0b
Better route display
john681611 Sep 14, 2023
bd85837
linting
john681611 Sep 14, 2023
58633ae
Minimal GA styling
john681611 Sep 15, 2023
1071323
Merge pull request #378 from OWASP/minimal_ga_style
john681611 Sep 19, 2023
aed54ed
Fix: GA share link spaces
john681611 Sep 19, 2023
f29508f
linting
john681611 Sep 19, 2023
56adc6a
Added: Direct link grade and removed external link icon
john681611 Sep 19, 2023
2d54921
Fix: linked via standard was possible
john681611 Sep 19, 2023
fabe286
Added: Per link score penalty
john681611 Sep 19, 2023
eb13d0c
Merge pull request #397 from OWASP/387-share-spaces
john681611 Sep 19, 2023
fba3d4e
Merge pull request #398 from OWASP/direct-and-link-correction
john681611 Sep 19, 2023
61bdf52
Merge pull request #399 from OWASP/link_improvements
john681611 Sep 19, 2023
7c0952e
Fix: GA caching not taking queries (#412)
john681611 Oct 4, 2023
c1f0e1c
Make Direct Dark Green (#411)
john681611 Oct 4, 2023
922c9c5
GA Reduce related punishment (#416)
john681611 Oct 5, 2023
981b0de
Rename gap to map (#419)
john681611 Oct 6, 2023
c463efa
GA fix bad links (#417)
john681611 Oct 9, 2023
6807b40
Speed up CICD (#418)
john681611 Oct 9, 2023
1487021
Rename share link (#415)
john681611 Oct 10, 2023
e533bf6
Neo4j ORM (#408)
john681611 Oct 11, 2023
7bd9bca
Remove BOLT from neo4j Setup requirement (#428)
john681611 Oct 11, 2023
3790c16
pin neomodel to a decent version
northdpole Oct 11, 2023
2980408
relax six requirements
northdpole Oct 11, 2023
df857aa
Sort Base standard alphabetically (#427)
john681611 Oct 14, 2023
e33d13d
Use allShortestPaths over shortestPath (#431)
john681611 Oct 17, 2023
2030d13
Added Cross-cutting concerns to GA blacklist (#430)
john681611 Oct 18, 2023
167828c
Revert "Use allShortestPaths over shortestPath (#431)"
northdpole Oct 19, 2023
80c22e4
add time metrics
northdpole Oct 21, 2023
06e884b
progress
northdpole Oct 21, 2023
2da0bc2
Revert "Revert "Use allShortestPaths over shortestPath (#431)""
northdpole Oct 21, 2023
7bc5ee6
map analysis through redis
northdpole Oct 22, 2023
b1a31ee
new reqs
northdpole Oct 22, 2023
f6832ba
add worker actually
northdpole Oct 22, 2023
77f65da
abort if background job fails
northdpole Oct 22, 2023
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: 7 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v2
- 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
run: sudo apt-get update && sudo apt-get install -y python3-setuptools python3-pip chromium-browser libgbm1 && make install-deps
- name: Test-e2e
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v2
- 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
run: sudo apt-get update && sudo apt-get install -y python3-setuptools python3-pip && make install-deps
- name: Test
run: make test
- name: Test-e2e
run: make e2e
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Vagrantfile

## act secrets
.secrets/
.env

### conventions ###
venv/
Expand All @@ -30,4 +31,7 @@ yarn-error.log
coverage/

### Dev db
standards_cache.sqlite
standards_cache.sqlite

### Neo4j
neo4j/
29 changes: 24 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@

.ONESHELL:

.PHONY: dev-run run test covers install-deps dev docker lint frontend clean all
.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=-

dev-run:
. ./venv/bin/activate && FLASK_APP=cre.py FLASK_CONFIG=development flask run
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:
docker start redis-stack 2>/dev/null || docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

start-containers: docker-neo4j docker-redis

start-worker:
. ./venv/bin/activate
FLASK_APP=`pwd`/cre.py python cre.py --start_worker

dev-flask:
. ./venv/bin/activate
FLASK_APP=`pwd`/cre.py FLASK_CONFIG=development flask run

e2e:
yarn build
[ -d "./venv" ] && . ./venv/bin/activate
export FLASK_APP=$(CURDIR)/cre.py
export FLASK_CONFIG=development
fFLASK_CONFIG=development flask run&
flask run&

yarn test:e2e
killall yarn
killall flask

test:
[ -d "./venv" ] && . ./venv/bin/activate
export FLASK_APP=$(CURDIR)/cre.py
Expand Down Expand Up @@ -79,4 +94,8 @@ 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 && python cre.py --generate_embeddings

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

all: clean lint test dev dev-run
3 changes: 2 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: gunicorn cre:app --log-file=-
web: gunicorn cre:app --log-file=-g
worker: FLASK_APP=`pwd`/cre.py python cre.py --start_worker
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,22 @@ To add a remote spreadsheet to your local database you can run
<pre>python cre.py --add --from_spreadsheet < google sheets url></pre>

To run the web application for development you can run
<pre>make dev-run</pre>
<pre>
$ make start-containers
$ make start-worker

# in a seperate shell
$ make dev-flask
</pre>

Alternatively, you can use the dockerfile with
<pre>make docker && make docker-run</pre>

Some features like Gap Analysis require a neo4j DB running, you can start this with
<pre>make docker-neo4j</pre>
enviroment varaibles for app to connect to neo4jDB (default):
- NEO4J_URL (neo4j//neo4j:password@localhost:7687)

To run the web application for production you need gunicorn and you can run from within the cre_sync dir
<pre>make prod-run</pre>

Expand All @@ -84,4 +95,4 @@ Please see [Contributing](CONTRIBUTING.md) for contributing instructions

Roadmap
---
For a roadmap of what we would like to be done please see the [issues](https://github.com/OWASP/common-requirement-enumeration/issues).
For a roadmap of what we would like to be done please see the [issues](https://github.com/OWASP/common-requirement-enumeration/issues).
23 changes: 14 additions & 9 deletions application/cmd/cre_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from application.utils.external_project_parsers import (
capec_parser,
cwe,
ccmv3,
ccmv4,
cheatsheets_parser,
misc_tools_parser,
Expand Down Expand Up @@ -375,14 +374,6 @@ def run(args: argparse.Namespace) -> None: # pragma: no cover
if args.export:
cache = db_connect(args.cache_file)
cache.export(args.export)
if args.csa_ccm_v3_in:
ccmv3.parse_ccm(
ccmFile=sheet_utils.readSpreadsheet(
alias="",
url="https://docs.google.com/spreadsheets/d/1b5i8OV919aiqW2KcYWOQvkLorL1bRPqjthJxLH0QpD8",
),
cache=db_connect(args.cache_file),
)
if args.csa_ccm_v4_in:
ccmv4.parse_ccm(
ccmFile=sheet_utils.readSpreadsheet(
Expand Down Expand Up @@ -426,6 +417,12 @@ def run(args: argparse.Namespace) -> None: # pragma: no cover
generate_embeddings(args.cache_file)
if args.owasp_proj_meta:
owasp_metadata_to_cre(args.owasp_proj_meta)
if args.populate_neo4j_db:
populate_neo4j_db(args.cache_file)
if args.start_worker:
from application.worker import start_worker

start_worker(args.cache_file)


def db_connect(path: str):
Expand Down Expand Up @@ -530,3 +527,11 @@ def owasp_metadata_to_cre(meta_file: str):
},
"""
raise NotImplementedError("someone needs to work on this")


def populate_neo4j_db(cache: str):
logger.info(f"Populating neo4j DB: Connecting to SQL DB")
database = db_connect(path=cache)
logger.info(f"Populating neo4j DB: Populating")
database.neo_db.populate_DB(database.session)
logger.info(f"Populating neo4j DB: Complete")
Loading
Loading