@verentis/cli 0.2.21 → 0.2.22

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/README.md CHANGED
@@ -36,7 +36,7 @@ extra configuration. With no credential flags this starts a **device sign-in**:
36
36
  browser (works over SSH), confirm the code, done. Non-interactive alternatives:
37
37
 
38
38
  ```bash
39
- verentis login --api-key vrt_xxx # CI / scripts (create one with `verentis apikey create`)
39
+ verentis login --api-key vrt_xxx # scoped API scripts (not publisher CI publishing)
40
40
  verentis login --token <identity token>
41
41
  # VERENTIS_API_KEY / VERENTIS_TOKEN env vars also work
42
42
  ```
@@ -252,6 +252,27 @@ verentis yank my-app 1.0.3
252
252
 
253
253
  Published versions are `Submitted` for moderation; once approved the marketplace countersigns them and they become installable.
254
254
 
255
+ ### Publisher publishing from GitHub Actions
256
+
257
+ Register a GitHub federated credential on your publisher in each target Verentis
258
+ environment. Bind it to the repository, protected GitHub environment, permitted
259
+ ref and audience. Configure the job with `permissions: { contents: read, id-token: write }`,
260
+ the matching protected environment, and these environment variables:
261
+
262
+ ```text
263
+ VERENTIS_API_URL=https://<target-api>
264
+ VERENTIS_GITHUB_OIDC_AUDIENCE=https://<target-api>
265
+ ```
266
+
267
+ The audience must equal the exact target API HTTPS origin (no trailing slash).
268
+ When `VERENTIS_GITHUB_OIDC_AUDIENCE` is set, `verentis publish` requests a
269
+ short-lived GitHub Actions OIDC assertion, exchanges it for a publisher-scoped
270
+ Verentis token, and resolves the publisher from that token. It never stores the
271
+ assertion or uses a configured human API key as a fallback. The job must also
272
+ provide a **separate** Ed25519 package-signing key to `verentis pack --key <name>`;
273
+ verify that the `.vpkg` is signed before publishing. Hosted-service client
274
+ credentials authenticate hosted app backends and cannot publish packages.
275
+
255
276
  ### Marketplace presentation
256
277
 
257
278
  Applications, execution engines and bundles can add an optional top-level `marketplace` block:
package/dist/index.js CHANGED
@@ -141,6 +141,61 @@ async function refreshIdentityToken(apiUrl, refreshToken, insecure) {
141
141
  }
142
142
  var sleep = (ms) => new Promise((resolve12) => setTimeout(resolve12, ms));
143
143
 
144
+ // src/auth/githubActions.ts
145
+ var PUBLISHING_SCOPES = /* @__PURE__ */ new Set([
146
+ "marketplace.publisher.read",
147
+ "marketplace.package.read",
148
+ "marketplace.package.create",
149
+ "marketplace.package.publish"
150
+ ]);
151
+ function assertPublisherScopes(scopes, options) {
152
+ if (scopes.some((scope) => !PUBLISHING_SCOPES.has(scope)) || options.workspaceId || options.accountId || options.resourceId) {
153
+ throw new Error("GitHub publisher federation only permits publisher and package publishing operations.");
154
+ }
155
+ }
156
+ async function exchangeGitHubPublisherToken(apiUrl, audience) {
157
+ const requestUrl = process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
158
+ const requestToken = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
159
+ if (!requestUrl || !requestToken || !audience) {
160
+ throw new Error("GitHub OIDC publishing requires Actions id-token: write and VERENTIS_GITHUB_OIDC_AUDIENCE.");
161
+ }
162
+ if (!process.env.VERENTIS_API_URL || !apiUrl.startsWith("https://")) {
163
+ throw new Error("GitHub OIDC publishing requires an explicit HTTPS VERENTIS_API_URL.");
164
+ }
165
+ if (audience !== new URL(apiUrl).origin || apiUrl !== audience) {
166
+ throw new Error("GitHub OIDC audience must equal the exact Sprint API URL origin.");
167
+ }
168
+ const url = new URL(requestUrl);
169
+ if (url.protocol !== "https:") {
170
+ throw new Error("The GitHub Actions OIDC endpoint must use HTTPS.");
171
+ }
172
+ url.searchParams.set("audience", audience);
173
+ const assertionResponse = await fetch(url, {
174
+ headers: { Authorization: `Bearer ${requestToken}` }
175
+ });
176
+ if (!assertionResponse.ok) {
177
+ throw new Error(`GitHub Actions OIDC token request failed (${assertionResponse.status}).`);
178
+ }
179
+ const assertion = await assertionResponse.json();
180
+ if (!assertion.value) {
181
+ throw new Error("GitHub Actions did not provide an OIDC assertion.");
182
+ }
183
+ const exchangeResponse = await fetch(`${apiUrl}/v1/publisher-federation/exchange`, {
184
+ method: "POST",
185
+ headers: { "Content-Type": "application/json" },
186
+ body: JSON.stringify({ assertion: assertion.value })
187
+ });
188
+ if (!exchangeResponse.ok) {
189
+ throw new Error(`Verentis publisher federation rejected the GitHub assertion (${exchangeResponse.status}).`);
190
+ }
191
+ const result = await exchangeResponse.json();
192
+ const payload = result.accessToken ? decodeJwtPayload(result.accessToken) : null;
193
+ if (!result.accessToken || typeof payload?.exp !== "number" || !Number.isFinite(payload.exp) || payload.exp * 1e3 <= Date.now()) {
194
+ throw new Error("Publisher federation did not return a valid, unexpired access token.");
195
+ }
196
+ return result.accessToken;
197
+ }
198
+
144
199
  // src/http.ts
145
200
  var ApiError = class extends Error {
146
201
  constructor(status, message, body) {
@@ -157,6 +212,9 @@ async function createApiClient(overrides) {
157
212
  const apiUrl = requireApiUrl(config);
158
213
  const insecure = config.insecure;
159
214
  const tokenCache = /* @__PURE__ */ new Map();
215
+ const githubAudience = process.env.VERENTIS_GITHUB_OIDC_AUDIENCE;
216
+ let publisherToken;
217
+ let publisherExchange;
160
218
  const envIdentity = process.env.VERENTIS_TOKEN;
161
219
  let currentIdentity = envIdentity ?? config.identityToken;
162
220
  let currentRefresh = config.refreshToken;
@@ -210,6 +268,20 @@ async function createApiClient(overrides) {
210
268
  return token;
211
269
  }
212
270
  async function mintAccessToken(options) {
271
+ if (githubAudience !== void 0) {
272
+ assertPublisherScopes(options.scopes, options);
273
+ if (insecure) {
274
+ throw new Error("GitHub publisher federation does not permit insecure TLS.");
275
+ }
276
+ if (publisherToken && !isExpired(publisherToken, 90)) return publisherToken;
277
+ publisherExchange ??= exchangeGitHubPublisherToken(apiUrl, githubAudience).then((token) => {
278
+ publisherToken = token;
279
+ return token;
280
+ }).finally(() => {
281
+ publisherExchange = void 0;
282
+ });
283
+ return publisherExchange;
284
+ }
213
285
  const apiKey = process.env.VERENTIS_API_KEY ?? config.apiKey;
214
286
  if (!apiKey && !currentIdentity) {
215
287
  throw new Error("Not logged in. Run `verentis login` (or pass --api-key / --token).");