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

Graphql poc #1226

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
31f6d74
added Hasura admin secret to config
jstucke Jun 10, 2024
21b6c6e
added hasura init script to installation
jstucke Jun 10, 2024
7cb746e
added hasura poc compose yaml
jstucke Jun 10, 2024
d003cbb
added poc route & template
jstucke Jun 10, 2024
19ee400
fix hasura config
jstucke Jun 11, 2024
8d2a4c2
update postgres installation for hasura
jstucke Jun 11, 2024
81aba9f
update graphql db routes
jstucke Jun 11, 2024
118201a
update graphql template and deps
jstucke Jun 11, 2024
7e434b2
hasura: added restart script
jstucke Jun 12, 2024
c0552fd
hasura: remove secret from template, remove unused endpoint
jstucke Jun 12, 2024
d76bd5a
move graphql folder to avoid name conflict with graphql lib
jstucke Jun 13, 2024
c008faa
add graphql database search
jstucke Jun 13, 2024
779207b
graphql template: remove tabs
jstucke Jun 13, 2024
3248adc
graphql template: replaced textarea with codemirror
jstucke Jun 13, 2024
711a5c1
graphql db search: search only with $where filter
jstucke Jun 14, 2024
a506dbb
tests: fixed test config for new graphql cfg entries
jstucke Jun 17, 2024
e162f64
graphql db template: improve help modal
jstucke Jun 17, 2024
1b5ab16
Merge branch 'graphql-poc' of github.com:fkie-cad/FACT_core into grap…
jstucke Jun 18, 2024
8c84366
graphql template: improved template + added docs/examples
jstucke Jun 18, 2024
b52bb78
crypto hints: ruff fixes
jstucke Jun 3, 2024
e5b4a55
hasura scripts: fix import path + rename attributes
jstucke Jun 19, 2024
d8a715a
graphql search: allow queries with unquoted keys
jstucke Jun 19, 2024
b557dec
graphql template: adjusted template for hasura schema changes
jstucke Jun 19, 2024
2d12c94
Merge remote-tracking branch 'origin/master' into graphql-poc
jstucke Jun 19, 2024
b90b4e5
postgres: switch to socket connection in case of local db
jstucke Jun 20, 2024
a2009ae
graphql template: small improvements + refactoring
jstucke Jun 20, 2024
768d0ec
graphql template: copy/help button bug fix
jstucke Jun 20, 2024
d6f6206
added proxy endpoint for graphql
jstucke Jun 20, 2024
73aaab7
remove unused function
jstucke Jun 20, 2024
9a42d1a
graphql template: tabs fix
jstucke Jun 20, 2024
5f26363
graphql/hasura: added read-only user
jstucke Jun 20, 2024
d212432
graphql proxy: also exclude hop-by-hop headers as defined in RFC 2616
jstucke Jun 20, 2024
9253041
move docker depencency from backend to common
jstucke Jun 20, 2024
5d67038
installation: switched installation order of db and frontend
jstucke Jun 21, 2024
cc1fa13
hasura compose: removed commented out parts + added default locality
jstucke Jun 21, 2024
f75d938
hasura: added to init to fix connection error directly after compose up
jstucke Jun 21, 2024
cfd839b
docs: added missing package json5 to mock list
jstucke Jun 21, 2024
f049cee
hasura init: python3.8 path fix
jstucke Jun 21, 2024
b4aaaa9
docs: added missing graphql packages to mock list
jstucke Jun 21, 2024
20fd6bd
graphql: changed interface to class to fix docs build error
jstucke Jun 21, 2024
09c4f63
graphql init: refactoring to make testing possible
jstucke Jun 24, 2024
b1811df
added graphql interface test
jstucke Jun 24, 2024
116cf38
graphql template: add min height to graphiql
jstucke Jun 24, 2024
35ae9ec
graphql template: added validation/check button
jstucke Jun 28, 2024
a916bc8
graphql interface: fixed copy&paste errors
jstucke Jun 28, 2024
fc38c9f
graphql template: renamed relations with more intuitive names
jstucke Jun 28, 2024
8edd602
graphql template: start search on ctrl+enter
jstucke Jun 28, 2024
c873f18
graphql template: remove redundant where and add hints to help
jstucke Jun 28, 2024
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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repos:

- id: pretty-format-json
args: [--autofix]
exclude: ^src/web_interface/static/package-lock.json

- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.5
Expand Down
3 changes: 3 additions & 0 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
'flask_restx',
'flask_security',
'flask_sqlalchemy',
'gql',
'graphql',
'itsdangerous',
'json5',
'lief',
'magic',
'markupsafe',
Expand Down
7 changes: 7 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class Authentication(BaseModel):

radare2_url: str

hasura: Frontend.Hasura

class Hasura(BaseModel):
model_config = ConfigDict(extra='forbid')
admin_secret: str
port: int = 33_333


class Backend(Common):
model_config = ConfigDict(extra='forbid')
Expand Down
4 changes: 4 additions & 0 deletions src/config/fact-core-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ radare2-url = "http://localhost:8000"
enabled = false
user-database = "sqlite:////media/data/fact_auth_data/fact_users.db"
password-salt = "5up3r5tr0n6_p455w0rd_5417"


[frontend.hasura]
admin-secret = "4dM1n_S3cR3T_changemeplz"
2 changes: 2 additions & 0 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def frontend_config(request, common_config) -> config.Frontend:
'user_database': 'sqlite:////media/data/fact_auth_data/fact_users.db',
'password_salt': '5up3r5tr0n6_p455w0rd_5417',
},
# we need the actual secret to set up the test configuration
'hasura': {'admin_secret': config.frontend.hasura.admin_secret},
}

test_config.update(common_config.model_dump())
Expand Down
7 changes: 5 additions & 2 deletions src/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def _setup_argparser():
install_options.add_argument(
'-R', '--no_radare', action='store_true', default=False, help='do not install radare view container'
)
install_options.add_argument(
'-H', '--no-hasura', action='store_true', default=False, help='do not set up hasura for GraphQL'
)
install_options.add_argument(
'-U',
'--statistic_cronjob',
Expand Down Expand Up @@ -192,10 +195,10 @@ def install():
def install_fact_components(args, distribution, none_chosen, skip_docker):
if (args.common or args.frontend or args.backend or none_chosen) and not args.no_common:
common(distribution)
if args.frontend or none_chosen:
frontend(skip_docker, not args.no_radare, args.nginx, distribution)
if args.db or none_chosen:
db()
if args.frontend or none_chosen:
frontend(skip_docker, not args.no_radare, args.nginx, distribution, args.no_hasura)
if args.backend or none_chosen:
backend(skip_docker, distribution)

Expand Down
9 changes: 8 additions & 1 deletion src/install/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ def install_postgres(version: int = 14):
if process.returncode != 0:
raise InstallationError(f'Failed to set up PostgreSQL: {process.stderr}')

# increase the maximum number of concurrent connections (and restart for the change to take effect)

def configure_postgres(version: int = 14):
config_path = f'/etc/postgresql/{version}/main/postgresql.conf'
# increase the maximum number of concurrent connections
run(f'sudo sed -i -E "s/max_connections = [0-9]+/max_connections = 999/g" {config_path}', shell=True, check=True)
hba_config_path = f'/etc/postgresql/{version}/main/pg_hba.conf'
# change UNIX domain socket auth mode from peer to user/pw
run(f'sudo sed -i -E "s/(local +all +all +)peer/\\1scram-sha-256/g" {hba_config_path}', shell=True, check=True)
# restart for the changes to take effect
run('sudo service postgresql restart', shell=True, check=True)


Expand All @@ -53,6 +59,7 @@ def main():
else:
logging.info('Setting up PostgreSQL database')
install_postgres()
configure_postgres()

# initializing DB
logging.info('Initializing PostgreSQL database')
Expand Down
15 changes: 13 additions & 2 deletions src/install/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
read_package_list_from_file,
run_cmd_with_logging,
)
from storage.graphql.util import get_env

DEFAULT_CERT = '.\n.\n.\n.\n.\nexample.com\n.\n\n\n'
INSTALL_DIR = Path(__file__).parent
Expand Down Expand Up @@ -102,7 +103,8 @@ def _configure_nginx():
# copy is better on redhat to respect selinux context
'(cd ../config && sudo install -m 644 $PWD/nginx.conf /etc/nginx/nginx.conf)',
'(sudo mkdir /etc/nginx/error || true)',
'(cd ../web_interface/templates/ && sudo ln -s $PWD/maintenance.html /etc/nginx/error/maintenance.html) || true', # noqa: E501
'(cd ../web_interface/templates/ '
'&& sudo ln -s $PWD/maintenance.html /etc/nginx/error/maintenance.html) || true',
],
error='configuring nginx',
)
Expand Down Expand Up @@ -141,7 +143,13 @@ def _copy_mime_icons():
run_cmd_with_logging(f'cp -rL {ICON_THEME_INSTALL_PATH / source} {MIME_ICON_DIR / target}')


def main(skip_docker, radare, nginx, distribution):
def _init_hasura():
with OperateInDirectory(INSTALL_DIR.parent / 'storage' / 'graphql' / 'hasura'):
run_cmd_with_logging('docker compose up -d', env=get_env())
run_cmd_with_logging('python3 init_hasura.py')


def main(skip_docker, radare, nginx, distribution, skip_hasura):
if distribution != 'fedora':
pkgs = read_package_list_from_file(INSTALL_DIR / 'apt-pkgs-frontend.txt')
apt_install_packages(*pkgs)
Expand Down Expand Up @@ -170,6 +178,9 @@ def main(skip_docker, radare, nginx, distribution):
if not skip_docker:
_install_docker_images(radare)

if not skip_hasura:
_init_hasura()

if not MIME_ICON_DIR.is_dir():
MIME_ICON_DIR.mkdir()
_copy_mime_icons()
Expand Down
1 change: 0 additions & 1 deletion src/install/requirements_backend.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cryptography==42.0.4
docker~=7.1.0
MarkupSafe==2.1.1
networkx==2.6.3
Pillow==10.3.0
Expand Down
1 change: 1 addition & 0 deletions src/install/requirements_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ testresources==2.0.1

# General python dependencies
appdirs==1.4.4
docker~=7.1.0
flaky==3.7.0
lief==0.12.3
psutil==5.9.4
Expand Down
1 change: 1 addition & 0 deletions src/install/requirements_frontend.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ flask-wtf~=1.2.1
flask~=3.0.3
flask-restx~=1.3.0
flask-sqlalchemy~=3.1.1
gql~=3.5.0
itsdangerous~=2.2.0
matplotlib~=3.7.5
more-itertools~=10.2.0
Expand Down
3 changes: 3 additions & 0 deletions src/storage/db_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(
self.base = Base

address = config.common.postgres.server
if address in ('localhost', '127.0.0.1', '::1'):
# local postgres => connect through UNIX domain socket (faster than TCP)
address = '/var/run/postgresql'
port = config.common.postgres.port
user = getattr(config.common.postgres, user)
password = getattr(config.common.postgres, password)
Expand Down
Empty file added src/storage/graphql/__init__.py
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions src/storage/graphql/hasura/docker-compose.base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
postgres-local:
volumes:
- /var/run/postgresql:/var/run/postgresql
postgres-remote:
50 changes: 50 additions & 0 deletions src/storage/graphql/hasura/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
services:
# the postgres instance is only for Hasura to store its metadata and should not be available from outside
postgres:
image: postgres:15
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgrespassword
graphql-engine:
image: hasura/graphql-engine:v2.38.0
ports:
- "${HASURA_PORT}:8080"
restart: always
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
PG_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets
HASURA_GRAPHQL_METADATA_DEFAULTS: '{"backend_configs":{"dataconnector":{"athena":{"uri":"http://data-connector-agent:8081/api/v1/athena"},"mariadb":{"uri":"http://data-connector-agent:8081/api/v1/mariadb"},"mysql8":{"uri":"http://data-connector-agent:8081/api/v1/mysql"},"oracle":{"uri":"http://data-connector-agent:8081/api/v1/oracle"},"snowflake":{"uri":"http://data-connector-agent:8081/api/v1/snowflake"}}}}'
# should be set during init
FACT_DB_URL: "${FACT_DB_URL}"
HASURA_GRAPHQL_ADMIN_SECRET: "${HASURA_ADMIN_SECRET}"
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: "ro_user"
depends_on:
data-connector-agent:
condition: service_healthy
extends:
# this is kind of a hack to make mounting a volume optional, see https://github.com/docker/compose/issues/3979
file: docker-compose.base.yml
service: "postgres-${DB_LOCALITY:-local}"
data-connector-agent:
image: hasura/graphql-data-connector:v2.38.0
restart: always
ports:
- "8081:8081"
environment:
QUARKUS_LOG_LEVEL: ERROR
QUARKUS_OPENTELEMETRY_ENABLED: "false"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8081/api/v1/athena/health"]
interval: 5s
timeout: 10s
retries: 5
start_period: 5s
volumes:
db_data:
Loading
Loading