@ggui-ai/registry-server 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +87 -0
- package/dist/authn/bearer.d.ts +28 -0
- package/dist/authn/bearer.d.ts.map +1 -0
- package/dist/authn/bearer.js +102 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +181 -0
- package/dist/filesystem-bundle-storage.d.ts +12 -0
- package/dist/filesystem-bundle-storage.d.ts.map +1 -0
- package/dist/filesystem-bundle-storage.js +152 -0
- package/dist/filesystem-registry-storage.d.ts +7 -0
- package/dist/filesystem-registry-storage.d.ts.map +1 -0
- package/dist/filesystem-registry-storage.js +362 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/server.d.ts +52 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +307 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Loqu, Inc. (Guuey)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @ggui-ai/registry-server
|
|
2
|
+
|
|
3
|
+
OSS-runnable HTTP server for the **ggui marketplace registry**. Wraps [`@ggui-ai/registry-core`](https://github.com/ggui-ai/ggui/tree/main/packages/registry-core) with [hono](https://hono.dev) + filesystem storage + bearer-token auth. Self-hostable via `npx @ggui-ai/registry-server` for local dev, CI, and enterprise on-prem deployments.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Filesystem storage, bearer auth
|
|
9
|
+
npx @ggui-ai/registry-server \
|
|
10
|
+
--storage fs:./registry-data \
|
|
11
|
+
--token $(openssl rand -hex 32) \
|
|
12
|
+
--port 9001 \
|
|
13
|
+
--bundle-host http://localhost:9001 \
|
|
14
|
+
--registry-hostname localhost:9001
|
|
15
|
+
|
|
16
|
+
# In-memory storage (e2e / dev)
|
|
17
|
+
GGUI_REGISTRY_TOKEN=test-token \
|
|
18
|
+
npx @ggui-ai/registry-server --storage memory --port 9001 \
|
|
19
|
+
--bundle-host http://localhost:9001 \
|
|
20
|
+
--registry-hostname localhost:9001
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Once running:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
ggui gadget publish --auth=bearer --token=$GGUI_REGISTRY_TOKEN \
|
|
27
|
+
--registry=http://localhost:9001
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Routes
|
|
31
|
+
|
|
32
|
+
| Method | Path | Auth | Description |
|
|
33
|
+
| ------ | ---------------------------------------------- | ------ | ---------------------------------------------------------- |
|
|
34
|
+
| GET | `/healthz` | none | Liveness probe |
|
|
35
|
+
| GET | `/search` | none | Filtered scan over the public metadata rows |
|
|
36
|
+
| GET | `/pkg/:scope/:name` | none\* | List the version timeline for an artifact |
|
|
37
|
+
| GET | `/pkg/:scope/:name/:version` | none\* | Read a published version (manifest + URLs) |
|
|
38
|
+
| POST | `/publish` | bearer | Publish a new artifact version (gadget or blueprint) |
|
|
39
|
+
| POST | `/author-keys` | bearer | Register a publisher Ed25519 public key |
|
|
40
|
+
| POST | `/conformance/check` | none | Pre-flight conformance gate (the publish flow re-verifies) |
|
|
41
|
+
| GET | `/bundles/:scope/:name/:version/bundle.js` | none | Serve a gadget bundle (immutable cache) |
|
|
42
|
+
| GET | `/bundles/:scope/:name/:version/bundle.js.sig` | none | Serve the signature envelope (immutable cache) |
|
|
43
|
+
| GET | `/bundles/:scope/:name/:version/manifest.json` | none | Serve the manifest verbatim (immutable cache) |
|
|
44
|
+
|
|
45
|
+
\* Reads of `visibility: 'private'` rows require bearer; unauthenticated callers see only public rows.
|
|
46
|
+
|
|
47
|
+
## Storage modes
|
|
48
|
+
|
|
49
|
+
- `--storage=fs:<path>` Filesystem — JSON row files under `<path>/state/`, blobs under `<path>/bundles/`. Persists across restarts.
|
|
50
|
+
- `--storage=memory` In-memory — process-local state. Wiped on restart. Used by the e2e suite + CI.
|
|
51
|
+
|
|
52
|
+
## Auth
|
|
53
|
+
|
|
54
|
+
Pass `--token=<token>` or set `GGUI_REGISTRY_TOKEN`. The server constant-time compares the `Authorization: Bearer <token>` header against the configured token. The verified caller subject is configurable via `--subject=<id>` (default: a hash prefix of the token).
|
|
55
|
+
|
|
56
|
+
## Non-goals
|
|
57
|
+
|
|
58
|
+
This server is **MVP-scoped** for self-hosters who want the marketplace surface without the AWS deployment cost. Out of scope for now:
|
|
59
|
+
|
|
60
|
+
- Rate limiting (use a reverse proxy)
|
|
61
|
+
- TLS termination (use a reverse proxy)
|
|
62
|
+
- Backup automation (the filesystem mode is single-machine)
|
|
63
|
+
- Per-org private artifact scoping (treat `visibility: 'private'` as a label, not enforcement)
|
|
64
|
+
- Sigstore transparency log integration
|
|
65
|
+
|
|
66
|
+
If you need any of the above, build your own transport on top of [`@ggui-ai/registry-core`](https://github.com/ggui-ai/ggui/tree/main/packages/registry-core).
|
|
67
|
+
|
|
68
|
+
## Programmatic embedding
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { createRegistryServer } from "@ggui-ai/registry-server";
|
|
72
|
+
import { inMemoryRegistryStorage, inMemoryBundleStorage } from "@ggui-ai/registry-core";
|
|
73
|
+
import { createBearerAuthn } from "@ggui-ai/registry-server";
|
|
74
|
+
|
|
75
|
+
const handle = createRegistryServer({
|
|
76
|
+
storage: inMemoryRegistryStorage(),
|
|
77
|
+
bundleStorage: inMemoryBundleStorage({ bundleHost: "http://localhost:9001" }),
|
|
78
|
+
authn: createBearerAuthn({ token: "test-token" }),
|
|
79
|
+
port: 9001,
|
|
80
|
+
bundleHost: "http://localhost:9001",
|
|
81
|
+
registryHostname: "localhost:9001",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await handle.start();
|
|
85
|
+
// … use it …
|
|
86
|
+
await handle.stop();
|
|
87
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AuthnContext } from '@ggui-ai/registry-core';
|
|
2
|
+
export interface CreateBearerAuthnOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The configured shared secret. The server constant-time compares the
|
|
5
|
+
* incoming `Authorization: Bearer <token>` against this value.
|
|
6
|
+
*
|
|
7
|
+
* MUST be a non-empty string. Empty / undefined tokens would make
|
|
8
|
+
* every request authenticated — the CLI rejects this at boot.
|
|
9
|
+
*/
|
|
10
|
+
readonly token: string;
|
|
11
|
+
/**
|
|
12
|
+
* The subject ({@link AuthnContext.subject}) issued for successful
|
|
13
|
+
* authentications. Operator-supplied so the AuthorKeys rows match a
|
|
14
|
+
* known identity. Defaults to a short hash prefix of the token —
|
|
15
|
+
* stable across restarts, never logs the secret.
|
|
16
|
+
*/
|
|
17
|
+
readonly subject?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface BearerAuthn {
|
|
20
|
+
/**
|
|
21
|
+
* Verify an `Authorization` header. Returns an {@link AuthnContext}
|
|
22
|
+
* on success; `null` on any failure (missing, malformed, mismatch).
|
|
23
|
+
* Constant-time compare against the configured token.
|
|
24
|
+
*/
|
|
25
|
+
verify(authorizationHeader: string | undefined): AuthnContext | null;
|
|
26
|
+
}
|
|
27
|
+
export declare function createBearerAuthn(options: CreateBearerAuthnOptions): BearerAuthn;
|
|
28
|
+
//# sourceMappingURL=bearer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bearer.d.ts","sourceRoot":"","sources":["../../src/authn/bearer.ts"],"names":[],"mappings":"AA6CA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,WAAW,wBAAwB;IACvC;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,IAAI,CAAC;CACtE;AAID,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW,CA+BhF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bearer-token authentication for the self-hostable registry server.
|
|
3
|
+
*
|
|
4
|
+
* The transport-layer translator between an HTTP `Authorization` header
|
|
5
|
+
* and the registry-core {@link AuthnContext}. Operates only on a
|
|
6
|
+
* constant-time-compared static token configured at server boot —
|
|
7
|
+
* any per-request rotation, multi-tenant key-pinning, or audience
|
|
8
|
+
* checks belong to a reverse proxy in front of this server.
|
|
9
|
+
*
|
|
10
|
+
* Vendor-neutral surface: no string in this module names a specific
|
|
11
|
+
* identity provider (no "OAuth", no "JWT", no cloud-vendor enum). A
|
|
12
|
+
* deployment fronted by a managed identity provider would supply its
|
|
13
|
+
* own `AuthnContext` adapter instead of this one.
|
|
14
|
+
*
|
|
15
|
+
* ## Protocol & Contract Bar
|
|
16
|
+
*
|
|
17
|
+
* **Parties:**
|
|
18
|
+
* - Producer: the HTTP server's `/publish` middleware. Reads the
|
|
19
|
+
* request's `Authorization` header and invokes {@link BearerAuthn.verify}.
|
|
20
|
+
* - Consumer: {@link publishArtifact} (via the route handler that
|
|
21
|
+
* wraps it). Reads the `subject` field and uses it as the partition
|
|
22
|
+
* key for AuthorKey lookups + the `publishedBy` field on rows.
|
|
23
|
+
*
|
|
24
|
+
* **Obligations:**
|
|
25
|
+
* - {@link BearerAuthn.verify} MUST compare the candidate token in
|
|
26
|
+
* constant time relative to the candidate length. A naive `===`
|
|
27
|
+
* string compare leaks the configured token over a timing side
|
|
28
|
+
* channel; the OSS server treats this as a load-bearing invariant.
|
|
29
|
+
* - {@link BearerAuthn.verify} MUST return `null` (not throw) on
|
|
30
|
+
* any failure — missing header, malformed scheme, token mismatch.
|
|
31
|
+
* The route handler decides the HTTP status code (401 in every case
|
|
32
|
+
* today; a future tier may surface 403 for known-but-revoked tokens
|
|
33
|
+
* and the discrimination would happen above this layer).
|
|
34
|
+
*
|
|
35
|
+
* **Failure mode:**
|
|
36
|
+
* - All verification failures collapse to `null`. The route handler
|
|
37
|
+
* emits 401 with `{ error: 'unauthorized', message: ... }`.
|
|
38
|
+
*
|
|
39
|
+
* **Observable violation:**
|
|
40
|
+
* - The integration test in `server.test.ts` exercises three negative
|
|
41
|
+
* paths (no header, wrong scheme, bad token) and asserts identical
|
|
42
|
+
* 401 responses. Any divergence — a different status, a leaked
|
|
43
|
+
* token hint in the body — is a contract violation.
|
|
44
|
+
*/
|
|
45
|
+
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
46
|
+
const BEARER_PREFIX = 'Bearer ';
|
|
47
|
+
export function createBearerAuthn(options) {
|
|
48
|
+
if (typeof options.token !== 'string' || options.token.length === 0) {
|
|
49
|
+
throw new Error('createBearerAuthn: `token` is required and must be a non-empty string');
|
|
50
|
+
}
|
|
51
|
+
const expected = Buffer.from(options.token, 'utf8');
|
|
52
|
+
const subject = options.subject ?? defaultSubject(options.token);
|
|
53
|
+
return {
|
|
54
|
+
verify(authorizationHeader) {
|
|
55
|
+
if (typeof authorizationHeader !== 'string')
|
|
56
|
+
return null;
|
|
57
|
+
if (!authorizationHeader.startsWith(BEARER_PREFIX))
|
|
58
|
+
return null;
|
|
59
|
+
const candidate = authorizationHeader.slice(BEARER_PREFIX.length);
|
|
60
|
+
if (candidate.length === 0)
|
|
61
|
+
return null;
|
|
62
|
+
const candidateBuffer = Buffer.from(candidate, 'utf8');
|
|
63
|
+
// `timingSafeEqual` requires both buffers to be the same length.
|
|
64
|
+
// The length-comparison short-circuit IS observable, but the
|
|
65
|
+
// ggui registry's deployment model assumes the token length is
|
|
66
|
+
// public knowledge (no length-based fingerprinting risk). We
|
|
67
|
+
// still compare lengths first to satisfy the API contract.
|
|
68
|
+
if (candidateBuffer.length !== expected.length)
|
|
69
|
+
return null;
|
|
70
|
+
if (!timingSafeEqual(candidateBuffer, expected))
|
|
71
|
+
return null;
|
|
72
|
+
return { subject };
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Compose a stable, non-secret subject from the token. Hash prefix
|
|
78
|
+
* (first 12 hex chars of SHA-256) so two operators sharing the same
|
|
79
|
+
* token surface as the same `publishedBy` value — desirable because
|
|
80
|
+
* a single configured token IS a single logical publisher.
|
|
81
|
+
*
|
|
82
|
+
* **Deployment posture.** This collapses-to-one-subject behavior is
|
|
83
|
+
* the intended design for single-operator deployments (one team, one
|
|
84
|
+
* shared token, one logical publisher identity). It is **NOT safe
|
|
85
|
+
* for multi-operator deployments** where multiple humans or services
|
|
86
|
+
* share the same bearer token: every `POST /author-keys` registration
|
|
87
|
+
* and every `publishedBy` field on `ArtifactVersionRow` will land
|
|
88
|
+
* under a single `bearer-<hash>` subject, erasing per-operator
|
|
89
|
+
* attribution and partitioning of the `AuthorKeys` table. In that
|
|
90
|
+
* regime, operators MUST run separate server instances each with a
|
|
91
|
+
* distinct token AND an explicit `options.subject` per operator
|
|
92
|
+
* (e.g. `subject: 'alice@team.example'`), or front the registry with
|
|
93
|
+
* a reverse proxy that performs real identity verification and
|
|
94
|
+
* forwards a per-request subject downstream. The OSS bearer surface
|
|
95
|
+
* exists for self-hosted single-publisher convenience — multi-tenant
|
|
96
|
+
* deployments belong behind a real identity provider or a
|
|
97
|
+
* proxy-mediated identity tier.
|
|
98
|
+
*/
|
|
99
|
+
function defaultSubject(token) {
|
|
100
|
+
const digest = createHash('sha256').update(token, 'utf8').digest('hex');
|
|
101
|
+
return `bearer-${digest.slice(0, 12)}`;
|
|
102
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `npx @ggui-ai/registry-server` — CLI entry for the OSS registry.
|
|
4
|
+
*
|
|
5
|
+
* Flag reference:
|
|
6
|
+
*
|
|
7
|
+
* --port=<n> Default 9001. Use 0 to let the OS assign.
|
|
8
|
+
* --host=<h> Default 0.0.0.0.
|
|
9
|
+
* --storage=fs:<path> Filesystem mode; `<path>` is the state root.
|
|
10
|
+
* --storage=memory In-memory mode; wiped on restart.
|
|
11
|
+
* --token=<t> Required if not set via GGUI_REGISTRY_TOKEN env.
|
|
12
|
+
* --subject=<s> Optional. Override the verified subject.
|
|
13
|
+
* --bundle-host=<url> Required. Public URL prefix for bundles.
|
|
14
|
+
* --registry-hostname=<h> Required. Hostname embedded in installCommand.
|
|
15
|
+
*
|
|
16
|
+
* Vendor-neutral help text: "bearer auth" is the only auth scheme this
|
|
17
|
+
* CLI knows about; no specific identity-provider name appears anywhere.
|
|
18
|
+
*/
|
|
19
|
+
import { mkdir } from 'node:fs/promises';
|
|
20
|
+
import { resolve } from 'node:path';
|
|
21
|
+
import { inMemoryBundleStorage, inMemoryRegistryStorage } from '@ggui-ai/registry-core';
|
|
22
|
+
import { createBearerAuthn } from './authn/bearer.js';
|
|
23
|
+
import { createFilesystemBundleStorage } from './filesystem-bundle-storage.js';
|
|
24
|
+
import { createFilesystemRegistryStorage } from './filesystem-registry-storage.js';
|
|
25
|
+
import { createRegistryServer } from './index.js';
|
|
26
|
+
const USAGE = `\
|
|
27
|
+
Usage: registry-server [options]
|
|
28
|
+
|
|
29
|
+
Self-hostable HTTP server for the ggui marketplace registry. Pairs with
|
|
30
|
+
the \`ggui gadget\` and \`ggui blueprint\` CLIs over a bearer token.
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--port=<n> Listening port (default: 9001; 0 for OS-assigned)
|
|
34
|
+
--host=<h> Listening host (default: 0.0.0.0)
|
|
35
|
+
--storage=fs:<path> Filesystem state root (persistent)
|
|
36
|
+
--storage=memory In-memory state (wiped on restart)
|
|
37
|
+
--token=<t> Bearer token. Or set GGUI_REGISTRY_TOKEN
|
|
38
|
+
--subject=<s> Verified-caller subject (default: token-hash prefix)
|
|
39
|
+
--bundle-host=<url> Public URL prefix served bundles fetch from
|
|
40
|
+
(e.g. http://localhost:9001). Required.
|
|
41
|
+
--registry-hostname=<h> Hostname embedded in publish installCommand
|
|
42
|
+
(e.g. localhost:9001). Required.
|
|
43
|
+
--help, -h Show this help
|
|
44
|
+
|
|
45
|
+
Examples:
|
|
46
|
+
# Local dev with in-memory state + a test token
|
|
47
|
+
GGUI_REGISTRY_TOKEN=test-token registry-server \\
|
|
48
|
+
--storage=memory --bundle-host=http://localhost:9001 \\
|
|
49
|
+
--registry-hostname=localhost:9001
|
|
50
|
+
|
|
51
|
+
# Self-hosted with filesystem persistence on port 8080
|
|
52
|
+
registry-server --storage=fs:./registry-data --port=8080 \\
|
|
53
|
+
--token=$(openssl rand -hex 32) \\
|
|
54
|
+
--bundle-host=https://registry.example.com \\
|
|
55
|
+
--registry-hostname=registry.example.com
|
|
56
|
+
`;
|
|
57
|
+
function parseFlags(argv, env) {
|
|
58
|
+
const flags = new Map();
|
|
59
|
+
for (const arg of argv) {
|
|
60
|
+
if (arg === '--help' || arg === '-h') {
|
|
61
|
+
process.stdout.write(USAGE);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
if (!arg.startsWith('--')) {
|
|
65
|
+
throw new Error(`unknown positional argument: ${arg}`);
|
|
66
|
+
}
|
|
67
|
+
const eqIdx = arg.indexOf('=');
|
|
68
|
+
if (eqIdx < 0) {
|
|
69
|
+
throw new Error(`flag ${arg} requires a value (use --${arg.slice(2)}=<value>)`);
|
|
70
|
+
}
|
|
71
|
+
const key = arg.slice(2, eqIdx);
|
|
72
|
+
const value = arg.slice(eqIdx + 1);
|
|
73
|
+
flags.set(key, value);
|
|
74
|
+
}
|
|
75
|
+
// ── port ────────────────────────────────────────────────────────────
|
|
76
|
+
let port = 9001;
|
|
77
|
+
const rawPort = flags.get('port');
|
|
78
|
+
if (rawPort !== undefined) {
|
|
79
|
+
const n = Number.parseInt(rawPort, 10);
|
|
80
|
+
if (!Number.isInteger(n) || n < 0 || n > 65535) {
|
|
81
|
+
throw new Error(`--port must be an integer in [0, 65535] (got ${rawPort})`);
|
|
82
|
+
}
|
|
83
|
+
port = n;
|
|
84
|
+
}
|
|
85
|
+
// ── host ────────────────────────────────────────────────────────────
|
|
86
|
+
const host = flags.get('host') ?? '0.0.0.0';
|
|
87
|
+
// ── storage ─────────────────────────────────────────────────────────
|
|
88
|
+
const rawStorage = flags.get('storage');
|
|
89
|
+
if (rawStorage === undefined) {
|
|
90
|
+
throw new Error('--storage is required. Use --storage=fs:<path> or --storage=memory');
|
|
91
|
+
}
|
|
92
|
+
let storage;
|
|
93
|
+
if (rawStorage === 'memory') {
|
|
94
|
+
storage = { kind: 'memory' };
|
|
95
|
+
}
|
|
96
|
+
else if (rawStorage.startsWith('fs:')) {
|
|
97
|
+
const path = rawStorage.slice(3);
|
|
98
|
+
if (path.length === 0) {
|
|
99
|
+
throw new Error('--storage=fs:<path> requires a non-empty path');
|
|
100
|
+
}
|
|
101
|
+
storage = { kind: 'fs', path: resolve(path) };
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw new Error(`--storage=${rawStorage} is invalid. Use --storage=fs:<path> or --storage=memory`);
|
|
105
|
+
}
|
|
106
|
+
// ── token ───────────────────────────────────────────────────────────
|
|
107
|
+
const token = flags.get('token') ?? env['GGUI_REGISTRY_TOKEN'];
|
|
108
|
+
if (token === undefined || token.length === 0) {
|
|
109
|
+
throw new Error('bearer auth requires --token=<t> or GGUI_REGISTRY_TOKEN environment variable');
|
|
110
|
+
}
|
|
111
|
+
// ── subject ─────────────────────────────────────────────────────────
|
|
112
|
+
const subject = flags.get('subject');
|
|
113
|
+
// ── bundleHost ──────────────────────────────────────────────────────
|
|
114
|
+
const bundleHost = flags.get('bundle-host');
|
|
115
|
+
if (bundleHost === undefined || bundleHost.length === 0) {
|
|
116
|
+
throw new Error('--bundle-host=<url> is required (the public URL prefix served bundles fetch from)');
|
|
117
|
+
}
|
|
118
|
+
// ── registryHostname ────────────────────────────────────────────────
|
|
119
|
+
const registryHostname = flags.get('registry-hostname');
|
|
120
|
+
if (registryHostname === undefined || registryHostname.length === 0) {
|
|
121
|
+
throw new Error('--registry-hostname=<h> is required (the hostname embedded in publish installCommand)');
|
|
122
|
+
}
|
|
123
|
+
return { port, host, storage, token, subject, bundleHost, registryHostname };
|
|
124
|
+
}
|
|
125
|
+
async function main() {
|
|
126
|
+
let flags;
|
|
127
|
+
try {
|
|
128
|
+
flags = parseFlags(process.argv.slice(2), process.env);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
process.stderr.write(`registry-server: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
132
|
+
process.stderr.write('Run with --help for usage.\n');
|
|
133
|
+
process.exit(2);
|
|
134
|
+
}
|
|
135
|
+
const storage = flags.storage.kind === 'memory'
|
|
136
|
+
? inMemoryRegistryStorage()
|
|
137
|
+
: await initFilesystemStorage(flags.storage.path);
|
|
138
|
+
const bundleStorage = flags.storage.kind === 'memory'
|
|
139
|
+
? inMemoryBundleStorage({ bundleHost: flags.bundleHost })
|
|
140
|
+
: createFilesystemBundleStorage({
|
|
141
|
+
root: flags.storage.path,
|
|
142
|
+
bundleHost: flags.bundleHost,
|
|
143
|
+
});
|
|
144
|
+
const authn = createBearerAuthn({
|
|
145
|
+
token: flags.token,
|
|
146
|
+
subject: flags.subject,
|
|
147
|
+
});
|
|
148
|
+
const handle = createRegistryServer({
|
|
149
|
+
storage,
|
|
150
|
+
bundleStorage,
|
|
151
|
+
authn,
|
|
152
|
+
host: flags.host,
|
|
153
|
+
port: flags.port,
|
|
154
|
+
bundleHost: flags.bundleHost,
|
|
155
|
+
registryHostname: flags.registryHostname,
|
|
156
|
+
});
|
|
157
|
+
await handle.start();
|
|
158
|
+
process.stdout.write(`registry-server listening on http://${flags.host}:${handle.actualPort}\n`);
|
|
159
|
+
// ── Graceful shutdown ──────────────────────────────────────────────
|
|
160
|
+
let shuttingDown = false;
|
|
161
|
+
const shutdown = (signal) => {
|
|
162
|
+
if (shuttingDown)
|
|
163
|
+
return;
|
|
164
|
+
shuttingDown = true;
|
|
165
|
+
process.stdout.write(`registry-server: received ${signal}, shutting down\n`);
|
|
166
|
+
handle
|
|
167
|
+
.stop()
|
|
168
|
+
.then(() => process.exit(0))
|
|
169
|
+
.catch((err) => {
|
|
170
|
+
process.stderr.write(`registry-server: shutdown failed: ${err}\n`);
|
|
171
|
+
process.exit(1);
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
process.on('SIGINT', shutdown);
|
|
175
|
+
process.on('SIGTERM', shutdown);
|
|
176
|
+
}
|
|
177
|
+
async function initFilesystemStorage(root) {
|
|
178
|
+
await mkdir(root, { recursive: true });
|
|
179
|
+
return createFilesystemRegistryStorage({ root });
|
|
180
|
+
}
|
|
181
|
+
void main();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BundleStorage } from '@ggui-ai/registry-core';
|
|
2
|
+
export interface FilesystemBundleStorageOptions {
|
|
3
|
+
/** Absolute path to the bundle storage root. */
|
|
4
|
+
readonly root: string;
|
|
5
|
+
/**
|
|
6
|
+
* URL prefix for `bundleUrl` / `signatureUrl` / `manifestUrl`. Must
|
|
7
|
+
* not end with a slash. Example: `http://localhost:9001`.
|
|
8
|
+
*/
|
|
9
|
+
readonly bundleHost: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function createFilesystemBundleStorage(options: FilesystemBundleStorageOptions): BundleStorage;
|
|
12
|
+
//# sourceMappingURL=filesystem-bundle-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem-bundle-storage.d.ts","sourceRoot":"","sources":["../src/filesystem-bundle-storage.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,WAAW,8BAA8B;IAC7C,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,8BAA8B,GACtC,aAAa,CA+Ef"}
|