Skip to content

Commit c3af8d3

Browse files
committed
Add a docker image and security notes
1 parent c3fb191 commit c3af8d3

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ cargo install --git https://github.com/tweag/genealogos.git genealogos-api
5757

5858
The `frontend` feature is enabled by default, so once the api is running open `http://localhost:8000/` for the frontend.
5959

60+
## Running as a Docker image
61+
62+
Genealogos API and frontend can also be packaged into a Docker image.
63+
64+
To get and run the image,
65+
66+
```fish
67+
# Produce the image
68+
nix build github:tweag/genealogos#dockerImage
69+
70+
# Load it into docker
71+
docker load -i=./result
72+
73+
# Run the image
74+
# Note: --rm will wipe the nix store inside the container after it quits
75+
# The service will be available on port 8000
76+
docker run -it --rm -p 8000:8000 localhost/genealogos
77+
```
78+
6079
## Hacking
6180
### Prerequisites
6281
Development of Genealogos requires Cargo, and some other dependencies.
@@ -211,6 +230,20 @@ This means some inputs can be missed, in particular those that are part of strin
211230
Additionally, Nixtract (through Genealogos) restarts nix for every SBOM component.
212231
When evaluation of your derivation takes a long time, this will result in very slow SBOM generation.
213232

233+
### Security notes
234+
235+
By its very nature, Genealogos API evaluates arbitrary Nix code provided by users.
236+
If you are planning to run it as a public service, make sure to properly secure the process and set up appropriate serivce management measures, taking into account:
237+
238+
- Potential for Denial of Service attacks by any user, in particular
239+
* Unlimited memory usage,
240+
* Unlimited storage usage,
241+
* Unlimited CPU time usage
242+
- Reliance on the assumption that Nix Flake evaluation is fully hermetic and pure, and thus safe
243+
- Reliance on the Nix sandbox to be secure and non-leaking
244+
245+
As such, we recommend running any public Genealogos instance in some containerised setting, such as via the provided [Docker Image](#Running_as_a_Docker_image), and properly limiting the resources available to the container.
246+
214247
## License
215248
Distributed under the MIT License. See `LICENSE` for more information.
216249

flake.nix

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,30 @@
2828
crane-outputs = import ./nix/crane.nix {
2929
inherit pkgs crane-lib nixtract-cli cyclonedx;
3030
};
31+
tmp = pkgs.runCommand "tmp" { } ''
32+
mkdir $out
33+
mkdir -m 1777 $out/tmp
34+
'';
35+
dockerImage = pkgs.dockerTools.buildLayeredImageWithNixDb {
36+
name = "genealogos";
37+
tag = "latest";
38+
contents = [ crane-outputs.packages.genealogos-api tmp ];
39+
config = {
40+
EntryPoint = [ "genealogos-api" ];
41+
ExposedPorts."8000" = {};
42+
Env = [
43+
"ROCKET_ADDRESS=0.0.0.0"
44+
"ROCKET_PORT=8000"
45+
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
46+
];
47+
};
48+
};
3149
in
3250
rec {
33-
inherit (crane-outputs) checks packages;
51+
inherit (crane-outputs) checks;
52+
packages = crane-outputs.packages // {
53+
inherit dockerImage;
54+
};
3455
overlays.default = import ./nix/overlays.nix {
3556
inherit crane-lib;
3657
};

0 commit comments

Comments
 (0)