Skip to content

Commit 0ddda96

Browse files
committed
[server] Add spicedb client
1 parent 12f9f6f commit 0ddda96

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

components/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"/dist"
2828
],
2929
"dependencies": {
30+
"@authzed/authzed-node": "^0.10.0",
3031
"@gitbeaker/node": "^35.7.0",
3132
"@gitpod/content-service": "0.1.5",
3233
"@gitpod/gitpod-db": "0.1.5",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { v1 } from "@authzed/authzed-node";
8+
9+
export const SpiceDBClient = Symbol("SpiceDBClient");
10+
export type SpiceDBClient = v1.ZedPromiseClientInterface;
11+
12+
export function spicedbClientFromEnv(): v1.ZedPromiseClientInterface {
13+
const token = process.env["SPICEDB_PRESHARED_KEY"];
14+
if (!token) {
15+
throw new Error("No spicedb token configured.");
16+
}
17+
18+
const address = process.env["SPICEDB_ADDRESS"];
19+
if (!address) {
20+
throw new Error("No spicedb address configured.");
21+
}
22+
23+
const client = v1.NewClient(token, address, v1.ClientSecurity.INSECURE_PLAINTEXT_CREDENTIALS);
24+
return client.promises;
25+
}

components/server/src/container-module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import { contentServiceBinder } from "./util/content-service-sugar";
112112
import { UbpResetOnCancel } from "@gitpod/gitpod-payment-endpoint/lib/chargebee/ubp-reset-on-cancel";
113113
import { retryMiddleware } from "nice-grpc-client-middleware-retry";
114114
import { IamSessionApp } from "./iam/iam-session-app";
115+
import { spicedbClientFromEnv, SpiceDBClient } from "./authorization/spicedb";
115116

116117
export const productionContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
117118
bind(Config).toConstantValue(ConfigFile.fromFile());
@@ -307,4 +308,9 @@ export const productionContainerModule = new ContainerModule((bind, unbind, isBo
307308

308309
// IAM Support
309310
bind(IamSessionApp).toSelf().inSingletonScope();
311+
312+
// Authorization & Perms
313+
bind(SpiceDBClient)
314+
.toDynamicValue(() => spicedbClientFromEnv())
315+
.inSingletonScope();
310316
});

yarn.lock

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# yarn lockfile v1
33

44

5+
"@authzed/authzed-node@^0.10.0":
6+
version "0.10.0"
7+
resolved "https://registry.yarnpkg.com/@authzed/authzed-node/-/authzed-node-0.10.0.tgz#623e4911fde221bb526e7f2e9ca335d9f3b9072d"
8+
integrity sha512-TnAnatcU5dHvyGqrWoZzPNaO1opPpVU1y7P5LrJsV2j54y0xvx/OFhYtfeguMxHSz2kpbdCuIvIKJuB8WFbRRA==
9+
dependencies:
10+
"@grpc/grpc-js" "^1.2.8"
11+
"@protobuf-ts/runtime" "^2.8.1"
12+
"@protobuf-ts/runtime-rpc" "^2.8.1"
13+
google-protobuf "^3.15.3"
14+
515
616
version "7.10.4"
717
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz"
@@ -1474,6 +1484,14 @@
14741484
stream-events "^1.0.1"
14751485
xdg-basedir "^4.0.0"
14761486

1487+
"@grpc/grpc-js@^1.2.8":
1488+
version "1.8.7"
1489+
resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.8.7.tgz#2154fc0134462ad45f4134e8b54682a25ed05956"
1490+
integrity sha512-dRAWjRFN1Zy9mzPNLkFFIWT8T6C9euwluzCHZUKuhC+Bk3MayNPcpgDRyG+sg+n2sitEUySKxUynirVpu9ItKw==
1491+
dependencies:
1492+
"@grpc/proto-loader" "^0.7.0"
1493+
"@types/node" ">=12.12.47"
1494+
14771495
"@grpc/grpc-js@^1.3.7":
14781496
version "1.4.2"
14791497
resolved "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.4.2.tgz"
@@ -2131,6 +2149,18 @@
21312149
readable-stream "^3.6.0"
21322150
split2 "^4.0.0"
21332151

2152+
"@protobuf-ts/runtime-rpc@^2.8.1":
2153+
version "2.8.2"
2154+
resolved "https://registry.yarnpkg.com/@protobuf-ts/runtime-rpc/-/runtime-rpc-2.8.2.tgz#8af6d5eab44e2fc92cfe9a83a5c351b5f2fcdfbe"
2155+
integrity sha512-vum/Y7AXdUTWGFu7dke/jCSB9dV3Oo3iVPcce3j7KudpzzWarDkEGvXjKv3Y8zJPj5waToyxwBNSb7eo5Vw5WA==
2156+
dependencies:
2157+
"@protobuf-ts/runtime" "^2.8.2"
2158+
2159+
"@protobuf-ts/runtime@^2.8.1", "@protobuf-ts/runtime@^2.8.2":
2160+
version "2.8.2"
2161+
resolved "https://registry.yarnpkg.com/@protobuf-ts/runtime/-/runtime-2.8.2.tgz#5d5424a6ae7fb846c3f4d0f2dd6448db65bb69d6"
2162+
integrity sha512-PVxsH81y9kEbHldxxG/8Y3z2mTXWQytRl8zNS0mTPUjkEC+8GUX6gj6LsA8EFp25fAs9V0ruh+aNWmPccEI9MA==
2163+
21342164
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
21352165
version "1.1.2"
21362166
resolved "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz"
@@ -9091,6 +9121,11 @@ [email protected]:
90919121
resolved "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.15.8.tgz"
90929122
integrity sha512-2jtfdqTaSxk0cuBJBtTTWsot4WtR9RVr2rXg7x7OoqiuOKopPrwXpM1G4dXIkLcUNRh3RKzz76C8IOkksZSeOw==
90939123

9124+
google-protobuf@^3.15.3:
9125+
version "3.21.2"
9126+
resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.21.2.tgz#4580a2bea8bbb291ee579d1fefb14d6fa3070ea4"
9127+
integrity sha512-3MSOYFO5U9mPGikIYCzK0SaThypfGgS6bHqrUGXG3DPHCrb+txNqeEcns1W0lkGfk0rCyNXm7xB9rMxnCiZOoA==
9128+
90949129
google-protobuf@^3.19.1, google-protobuf@^3.6.1:
90959130
version "3.19.1"
90969131
resolved "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.19.1.tgz"

0 commit comments

Comments
 (0)