11## Package Management
22
33Every non-trivial Flix project should have a ` flix.toml ` manifest. The manifest
4- contains information about the project and its dependencies.
4+ contains information about the project and its dependencies.
55
66A minimal manifest is of the form:
77
@@ -15,7 +15,7 @@ license = "Apache-2.0"
1515authors = [
" John Doe <[email protected] >" ]
1616```
1717
18- > ** Note:** The ` flix ` field is not yet used, but it will be used in the future.
18+ > ** Note:** The ` flix ` field is not yet used, but it will be used in the future.
1919
2020### Adding Flix Dependencies
2121
@@ -43,9 +43,9 @@ We can also add dependencies on Maven packages to the manifest:
4343Flix dependency resolution works as follows:
4444
45451 . Flix reads ` flix.toml ` and computes the transitive set of Flix package
46- dependencies.
46+ dependencies.
47472 . Flix downloads all of these Flix packages.
48- 3 . Flix inspects each package for its Maven dependencies and downloads these.
48+ 3 . Flix inspects each package for its Maven dependencies and downloads these.
4949
5050We illustrate with an example. Assume we have a Flix package with:
5151
@@ -87,3 +87,55 @@ This happens because `flix/museum` has the following dependency tree:
8787 - ` flix/museum-clerk `
8888 - ` flix/museum-restaurant ` which depends on
8989 - ` org.apache.commons:commons-lang3 `
90+
91+ ### Security & Trust Levels
92+ To reduce the risk of supply-chain attacks, every dependency
93+ has a * trust* level--even if you don't set one explicitly.
94+ Trust levels control which language features a dependency may use.
95+ Higher trust levels enable more features but also increase
96+ the risk of supply-chain attacks.
97+
98+ The trust levels are as follows (from lowest to highest):
99+ - ` paranoid ` : forbids Java interop, the ` IO ` effect, and unchecked casts.
100+ - ` plain ` (default): permits the ` IO ` effect but forbids Java interop
101+ and unchecked casts.
102+ - ` unrestricted ` : allows Java interop, the ` IO ` effect, and unchecked casts.
103+
104+ You can set the trust level of each dependency in the manifest like so:
105+ ``` toml
106+ [dependencies ]
107+ "github:flix/museum" = { "version" = " 1.4.0" , "trust" = " plain" }
108+ "github:magnus-madsen/helloworld" = { "version" = " 1.3.0" , "trust" = " unrestricted" }
109+ ```
110+
111+ Trust levels are transitive: a dependency's trust level also applies
112+ to its transitive dependencies, unless a dependency explicitly declares
113+ a lower trust level.
114+ If multiple dependencies require the same library,
115+ the library inherits the lowest trust level requested.
116+
117+ The recommended approach is to ** not** specify a trust level, thus
118+ defaulting to ` plain ` .
119+ It provides the best balance between flexibility and safety.
120+ You should avoid ` unrestricted ` when possible, as it permits
121+ (transitive) dependencies to do * anything* .
122+ Even building or compiling code that includes ` unrestricted ` dependencies
123+ can by itself expose you to a supply-chain attack.
124+ However, the package manager never downloads a package
125+ that declares Java dependencies in its manifest if it has
126+ trust level ` plain ` or lower.
127+
128+ You should attempt to only depend on core library packages
129+ and use your own handlers (or in some cases default handlers).
130+ This allows you to limit what parts of the system a program
131+ can access, e.g., such as only allowing certain directories
132+ to be accessed or black/white-listing URLs.
133+
134+ If you author a Flix library, e.g., ` webserver ` , that uses Java,
135+ split it into two packages: a core library ` webserver-lib ` that
136+ implements pure logic and custom effects, and a separate handler
137+ package ` webserver-lib-handlers ` that performs Java interop.
138+ Doing so also makes the core library easier to test and review.
139+ Try to keep effects small and focues and document the expected
140+ handler behavior so users can implement their own handlers if
141+ they do no wish to use handler library.
0 commit comments