Skip to content

Commit dcd0a03

Browse files
authored
Merge pull request #3 from magdasmat/sync-ega-main
2 parents 850ed64 + 3534c22 commit dcd0a03

128 files changed

Lines changed: 15872 additions & 5637 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Code comment coverage
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- develop
8+
9+
jobs:
10+
comment-coverage:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
TARGET_DIR: beacon
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Check comment coverage
24+
run: python scripts/check_comment_coverage.py "$TARGET_DIR"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Language for comments needs to be English
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- develop
8+
9+
jobs:
10+
check-comments-language:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
TARGET_DIR: beacon
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Install dependencies
24+
run: |
25+
pip install pyspellchecker
26+
27+
- name: Check comment language
28+
run: python scripts/check_comment_language.py "$TARGET_DIR"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Dead code checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- develop
8+
9+
jobs:
10+
dead-code-detection:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
TARGET_DIR: beacon
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Install dependencies
24+
run: |
25+
pip install vulture
26+
27+
- name: Check dead code
28+
run: python scripts/check_dead_code.py "$TARGET_DIR"

.github/workflows/push_docker_image.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ jobs:
3434
with:
3535
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3636
tags: |
37+
# Accept the Git tag
38+
type=ref,event=tag
39+
# Extras that are optional
3740
type=ref,event=branch
3841
type=ref,event=pr
42+
# Only applies if the tag is valid semver
3943
type=semver,pattern={{version}}
4044
type=semver,pattern={{major}}.{{minor}}
41-
# set latest tag for master branch
42-
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
43-
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
45+
# latest only on main branch
46+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
4447
- name: Set up Docker Buildx
4548
uses: docker/setup-buildx-action@v3
4649
- name: Build and push Docker image

.github/workflows/update_api_version.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

README.md

Lines changed: 171 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,119 @@ Welcome to Beacon v2 Production Implementation (B2PI). This is an application th
44

55
## Documentation
66

7-
Please, go to [B2RI/B2PI docs website](https://b2ri-documentation-demo.ega-archive.org/) to know how to use Beacon v2 Production Implementation.
8-
9-
## New release beacon v2.0-d4012a4 features added
10-
11-
* Models plug in. Beacon PI now accepts different beacon flavours, based on different model specifications. Kicking off with two models: ga4gh beacon v2 default model and EUCAIM.
12-
* Conf now is not affected by further releases. Use your conf and keep it forever.
13-
* Cross queries between collections and non collections now are ready to be performed at full power.
14-
* Schema request now working: feel free to request any schema you'd like for beacon to return.
15-
* Validation on the fly per framework and model(s).
16-
* Configuration of the entities of each entry type now done by .yml files.
17-
* Restart of the app when conf files or generic conf is modified (no need to rebuild).
18-
* OR Filters (in test approach, as it is still not approved officially by GA4GH).
19-
* Other bug fixes.
20-
* Unit tests expanded, with a total of 313 now.
21-
22-
## Main changes from B2RI
23-
24-
* Handlers of the endpoints are classes, not functions
25-
* Unit testing has been developed for the application, starting with 108 unit tests that cover 4000 lines of code approximately (100%)
26-
* Concurrency testing has been applied for this new beacon instance, showing results of responses for more than 3 million genomic variants splitted in different datasets in less than 100 millisecs, for a total of 1000 requests made by 10 users per second at the same time.
27-
* Linking ids to a dataset in a yaml file is not needed anymore
28-
* A couple more indexes for mongoDB have been applied, that, in addition to the restructuration of the code, have improved the quickness of the responses
29-
* Authentication/Authorization is now applied as a decorator, not as a different container
30-
* LOGS now show more relevant information about the different processes (from request to response) including transaction id, the time of execution of each function and the initial call and the return call
31-
* Exceptions now are raised from the lower layer to the top layer, with information and status for the origin of the exception
32-
* Architecture of the code is not dependent on a particular database, meaning that different types of databases (and more than one) can be potentially applied to this instance (although now only MongoDB is the one developed)
33-
* Parameters are sanitized
34-
* Users can manage what entry types want their beacon to show by editing a manage conf file inside source
35-
* Admin-ui to manage all the configuration settings from a UI is in development.
7+
Please, go to [CRG Beacon docs website](https://b2ri-documentation-demo.ega-archive.org/) to know how to use Beacon v2 Production Implementation.
8+
9+
## Upgrading mongoDB (New release v2.2)
10+
11+
As mongoDB version 5 is [end of life](https://github.com/EGA-archive/beacon2-pi-api/issues/161), two new images for versions 6 and 7 of mongoDB are now available. Just comment and uncomment the image you prefer. **The mongoDB image that is recommended for production is the one at version 7 (default one).**
12+
13+
### Upgrading MongoDB to version 6 from a container with an existing data for version 5
14+
15+
This version is compatible with previous version 5. Just build the container with the version 6 uncommented and you will be ready to use it without further actions on your side.
16+
17+
### Upgrading MongoDB to version 7 from a container with an existing data for version 5
18+
19+
If your container you want to upgrade is version 5 and you want version 7, first you will have to rebuild the container with the version 6. After that you will need to go to the mongoshell of the container:
20+
21+
```bash
22+
docker exec -it mongoprod mongosh
23+
```
24+
25+
And go to admin database:
26+
27+
```bash
28+
use admin
29+
```
30+
31+
Once authenticated, you will need to make your mongodb instance upgrades compatible with version 6 by executing the following command:
32+
33+
```bash
34+
db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })
35+
```
36+
37+
After that, stop the container, comment version 6 and uncomment image for version 7 and rebuild the container and your mongoDB will be upgraded to version 7.
38+
39+
### Upgrading MongoDB to version 8 from a container with an existing data for version 7
40+
41+
If your container you want to upgrade is version 7 and you want version 8, the procedure is a bit more complex than for other mongo version updates.
42+
43+
First of all, you will need to dump your database executing the following command:
44+
45+
```bash
46+
docker exec mongoprod mongodump \
47+
-u root \
48+
-p example \
49+
--authenticationDatabase admin \
50+
--out /data/db/dump
51+
```
52+
53+
After that, you will need to copy out the dumped files from the volume to your root local filesystem:
54+
```bash
55+
cp -r ./beacon/connections/mongo/data/db/dump ./dump
56+
```
57+
58+
After that, delete completely the mongo instance with version 7:
59+
```bash
60+
docker stop mongoprod
61+
docker rm mongoprod
62+
```
63+
64+
And the persistent data remaining:
65+
```bash
66+
rm -r beacon/connections/mongo/data/db
67+
```
68+
69+
If all steps before have completed successfully, comment version 7 and uncomment version 8 for db service (mongo) at `docker-compose.yml` file. Then, build the mongo instance with version 8:
70+
```bash
71+
docker compose up -d --build db
72+
```
73+
74+
Copy the dumped files to the persistent folder in your new mongo version 8 instance:
75+
```bash
76+
cp -r ./dump ./beacon/connections/mongo/data/db
77+
```
78+
79+
And restore the dumped files to be compatible with version 8 of mongo instance:
80+
```bash
81+
docker exec mongoprod mongorestore \
82+
-u root \
83+
-p example \
84+
--authenticationDatabase admin \
85+
--drop \
86+
/data/db/dump
87+
```
88+
89+
Then remove the dumped files that have already been inserted to your new mongo instance with version 8:
90+
```bash
91+
rm -r dump
92+
```
93+
94+
And reindex the data:
95+
```bash
96+
docker exec beaconprod python -m beacon.connections.mongo.reindex
97+
```
98+
99+
### Downgrading MongoDB to version 5 from an exising mongodb container with a greater version
100+
101+
First, you will have to build the mongodb container using version 6. When up and running, execute the next commands:
102+
103+
```bash
104+
docker exec -it mongoprod mongosh
105+
```
106+
107+
And go to admin database:
108+
109+
```bash
110+
use admin
111+
```
112+
113+
Once authenticated, you will need to make your mongodb instance upgrades compatible with version 6 by executing the following command:
114+
115+
```bash
116+
db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })
117+
```
118+
119+
After that, stop the container, comment version 6 and uncomment image for version 5 and rebuild the container and your mongoDB will be downgraded to version 5.
36120

37121
### TLS configuration
38122

@@ -67,6 +151,14 @@ docker compose up -d --build
67151
Note: If you have an Apple Silicon Mac and use [Colima](https://github.com/abiosoft/colima) as your container runtime, you may have to change the default Colima settings for the Mongo docker container to start correctly.
68152
See [Fredrik Mørstad](https://stackoverflow.com/users/11494958/fredrik-m%c3%b8rstad)'s answer to [this stackoverflow post](https://stackoverflow.com/questions/67498836/docker-chown-changing-ownership-of-data-db-operation-not-permitted) for guidance on how to resolve this issue.
69153

154+
Alternatively. if you are updating the BeaconPI instance from a previous version, it is recommended to use the next commands:
155+
156+
```bash
157+
docker stop beaconprod db
158+
docker compose build --no-cache beaconprod db
159+
docker compose up -d --force-recreate beaconprod db
160+
```
161+
70162
#### Up the containers (with services in independent servers)
71163

72164
If you wish to have each service (or some of them) in different servers, you will need to use the remote version of the docker compose file, and deploy the remote services you need by selecting them individually in the build. Example:
@@ -324,7 +416,7 @@ AV_Dataset:
324416

325417
### Generic configuration
326418

327-
The beacon needs some configuration in order to show the correct mappings or information. In order to do that, the next variables inside [conf.py](https://github.com/EGA-archive/beacon-production-prototype/tree/main/beacon/conf/conf.py) can be modified for that purpose, being **uri** a critical one for showing the correct domain in the mappings of your beacon. The **uri_subpath** will be added behind this **uri** variable, in case there is an extension of the domain for your beacon.
419+
The beacon needs some configuration in order to show the correct mappings or information. In order to do that, the next variables inside [conf.py](https://github.com/EGA-archive/beacon-production-prototype/tree/main/beacon/conf/conf.py) can be modified for that purpose, being **uri** a critical one for showing the correct domain in the mappings of your beacon. The **uri_subpath** will be added behind this **uri** variable, in case there is an extension of the domain for your beacon. See next paragraph: Tips for configuring a nginx proxy compatible with Beacon PI.
328420

329421
```bash
330422
beacon_id = 'org.ega-archive.beacon-ri-demo' # ID of the Beacon
@@ -361,6 +453,28 @@ org_logo_url = 'https://legacy.ega-archive.org/images/logo.png'
361453
org_info = ''
362454
```
363455

456+
#### Tips for configuring a nginx proxy compatible with BeaconPI conf.py uri and uri_subpath vars
457+
458+
If you are building a nginx proxy on top of beacon PI instance, the configuration of your nginx proxy can be a bit tricky if you don't have in mind what do uri and uri_subpath do. First of all, uri sets the root url of your beacon, and uri_subpath adds an extension to each of the endpoints' routes.
459+
This means, that if you want to add a nginx proxy with an extension between the root url and the /api (uri_subpath), you will need to set the extension to the root url of the localhost, like this:
460+
```nginx
461+
location /extension/api/ {
462+
proxy_pass http://localhost:5050;
463+
464+
proxy_set_header Host $host;
465+
proxy_set_header X-Real-IP $remote_addr;
466+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
467+
proxy_set_header X-Forwarded-Proto $scheme;
468+
}
469+
```
470+
471+
And your conf.py variables will need to look like:
472+
```bash
473+
uri = 'https://<yourdomain>'
474+
uri_subpath = '/extension/api'
475+
complete_url = uri + uri_subpath
476+
```
477+
364478
### Models configuration
365479

366480
#### Enable/Disable model
@@ -636,6 +750,33 @@ After editing any comfiguration variable, save the file and restart the API to a
636750
docker compose restart beaconprod
637751
```
638752

753+
### State checks
754+
755+
Now state checks are available through `/health` endpoint. The implemented checks and their flow are the ones that are shown in the diagram below:
756+
757+
![MongoDB vulnerabilities](https://github.com/EGA-archive/beacon-production-prototype/blob/main/ri-tools/files/Machine_State_v3.jpg)
758+
759+
## Fix for MongoDB exploit (CVE-2025-14847)
760+
761+
Beacon PI repository has been updated so the exploit for MongoDB (CVE-2025-14847) is not an issue anymore. In order to do that, the following points have been implemented:
762+
* Removed exposing ports in docker-compose.yml file
763+
* Built done from a mongod.conf file
764+
* Mongo image for major version 5 adjusted to 5.0.32, not allowing prior versions with the vulnerability to be built.
765+
766+
**Please, make sure you update your mongoDB instance and rebuild the mongoDB container after this update.**
767+
768+
The steps to reproduce this exploit and check that your instance is not vulnerable anymore is to download this [repo](https://github.com/Security-Phoenix-demo/mongobleed-exploit-CVE-2025-14847) and insert it in beacon folder.
769+
770+
Then build the beaconprod conainer and execute the next command:
771+
```bash
772+
docker exec -it beaconprod python beacon/mongobleed-exploit-CVE-2025-14847-main/exploit/mongobleed.py --host mongoprod
773+
```
774+
If the message is something like:
775+
![MongoDB no vulnerabilities](https://github.com/EGA-archive/beacon-production-prototype/blob/main/ri-tools/files/mongobleed_ok.png)
776+
Then it means the instance is safe.
777+
Otherwise, you would get a message like:
778+
![MongoDB vulnerabilities](https://github.com/EGA-archive/beacon-production-prototype/blob/main/ri-tools/files/mongobleed_vuln.png)
779+
639780
## Tests report
640781

641782
![Beacon prod concurrency test](https://github.com/EGA-archive/beacon-production-prototype/blob/main/ri-tools/files/concurrencytest.png)

0 commit comments

Comments
 (0)