You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Main` actor authorizes the `Connect` actor by passing a `TCPConnectAuth` token created from the ambient authority token in `env.root`. The ambient authority token is unforgeable since the `AmbientAuth` constructor is private and the only existing instance is provided by the runtime itself.
41
20
42
21
The `Connect` actor uses this derived authority when it creates a TCP connection:
The `TCPConnection` requires an authority as first parameter, and since the compiler checks that the correct type was passed, this guarantees that a `TCPConnection` can only be created by an actor holding the required authorization.
@@ -58,13 +37,7 @@ The first parameter of the `TCPConnection` constructor has the type `TCPConnectA
58
37
Now imagine we don't trust the `Connect` actor, so we don't want to provide it with more authority than needed. For example, there is no point in granting it filesystem access, since it is supposed to do network things (specifically, TCP), not access the filesystem. Instead of passing the entire `AmbientAuth` (the root of all authority), we "downgrade" that to a `TCPConnectAuth` (the most restrictive authority in `net`), pass it to the `Connect` actor, and have that pass it to the `TCPConnection` constructor:
59
38
60
39
```pony
61
-
actor Connect
62
-
new create(out: OutStream, auth: TCPConnectAuth) =>
Now we are sure it cannot access the filesystem or listen on a TCP or UDP port. Pay close mind to the authority that code you are calling is asking for. Never give `AmbientAuth` to __any__ code you do not trust completely both now and in the future. You should always create the most specific authority and give the library that authority. If the library is asking for more authority than it needs, __do not use the library__.
@@ -80,35 +53,13 @@ As the package author, it is then our responsibility to realize that the minimal
80
53
Let's have a look at the authorizations available in the standard library's `net` package.
81
54
82
55
```pony
83
-
primitive NetAuth
84
-
new create(from: AmbientAuth) =>
85
-
None
86
-
87
-
primitive DNSAuth
88
-
new create(from: (AmbientAuth | NetAuth)) =>
89
-
None
90
-
91
-
primitive UDPAuth
92
-
new create(from: (AmbientAuth | NetAuth)) =>
93
-
None
94
-
95
-
primitive TCPAuth
96
-
new create(from: (AmbientAuth | NetAuth)) =>
97
-
None
98
-
99
-
primitive TCPListenAuth
100
-
new create(from: (AmbientAuth | NetAuth | TCPAuth)) =>
101
-
None
102
-
103
-
primitive TCPConnectAuth
104
-
new create(from: (AmbientAuth | NetAuth | TCPAuth)) =>
Where `TCPAuth` grants less authority than `NetAuth`. `NetAuth` can be used to create any of the derived authorities `DNSAuth`, `UDPAuth`, `TCPAuth`, `TCPListenAuth`, `TCPConnectAuth` whereas `TCPAuth` can only be used to derive `TCPListenAuth` and `TCPConnectAuth`.
Copy file name to clipboardExpand all lines: docs/object-capabilities/trust-boundary.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ But we can do better than that.
17
17
In Pony, you can optionally declare a set of _safe_ packages on the `ponyc` command line, like this:
18
18
19
19
```sh
20
-
ponyc --safe=files:net:process my_project
20
+
--8<-- "trust-boundary-safe-packages.sh"
21
21
```
22
22
23
23
Here, we are declaring that only the `files`, `net` and `process` packages are allowed to use C-FFI calls. We've established our trust boundary: any other packages that try to use C-FFI calls will result in a compile-time error.
0 commit comments