Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 106 additions & 95 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,105 +380,112 @@ jobs:
fail("prepared tarball digest is invalid");
}

const configDirectory = mkdtempSync(
join(process.env.RUNNER_TEMP || tmpdir(), "rate-limit-npm-config-"),
);
const publishDirectory = mkdtempSync(
join(process.env.RUNNER_TEMP || tmpdir(), "rate-limit-npm-cwd-"),
);
const userConfig = join(configDirectory, "user.npmrc");
const globalConfig = join(configDirectory, "global.npmrc");
writeFileSync(userConfig, "", { mode: 0o600 });
writeFileSync(globalConfig, "", { mode: 0o600 });
chmodSync(userConfig, 0o600);
chmodSync(globalConfig, 0o600);

const keep = new Set([
"CI",
"COMSPEC",
"HOME",
"HOMEDRIVE",
"HOMEPATH",
"PATH",
"PATHEXT",
"RUNNER_TEMP",
"SYSTEMDRIVE",
"SYSTEMROOT",
"TEMP",
"TMP",
"TMPDIR",
"USERPROFILE",
"WINDIR",
]);
const npmEnvironment = {};
for (const [key, value] of Object.entries(process.env)) {
const upper = key.toUpperCase();
if (
value !== undefined &&
(keep.has(upper) ||
upper.startsWith("GITHUB_") ||
upper.startsWith("ACTIONS_ID_TOKEN_"))
) {
npmEnvironment[key] = value;
let configDirectory;
let publishDirectory;
try {
configDirectory = mkdtempSync(
join(process.env.RUNNER_TEMP || tmpdir(), "rate-limit-npm-config-"),
);
publishDirectory = mkdtempSync(
join(process.env.RUNNER_TEMP || tmpdir(), "rate-limit-npm-cwd-"),
);
const userConfig = join(configDirectory, "user.npmrc");
const globalConfig = join(configDirectory, "global.npmrc");
writeFileSync(userConfig, "", { mode: 0o600 });
writeFileSync(globalConfig, "", { mode: 0o600 });
chmodSync(userConfig, 0o600);
chmodSync(globalConfig, 0o600);

const keep = new Set([
"CI",
"COMSPEC",
"HOME",
"HOMEDRIVE",
"HOMEPATH",
"PATH",
"PATHEXT",
"RUNNER_ENVIRONMENT",
"RUNNER_TEMP",
"SYSTEMDRIVE",
"SYSTEMROOT",
"TEMP",
"TMP",
"TMPDIR",
"USERPROFILE",
"WINDIR",
]);
const npmEnvironment = {};
for (const [key, value] of Object.entries(process.env)) {
const upper = key.toUpperCase();
if (
value !== undefined &&
(keep.has(upper) ||
upper.startsWith("GITHUB_") ||
upper.startsWith("ACTIONS_ID_TOKEN_"))
) {
npmEnvironment[key] = value;
}
}
}
npmEnvironment.NPM_CONFIG_USERCONFIG = userConfig;
npmEnvironment.NPM_CONFIG_GLOBALCONFIG = globalConfig;
npmEnvironment.NPM_CONFIG_CACHE = join(configDirectory, "cache");
npmEnvironment.NPM_CONFIG_REGISTRY = REGISTRY;

const runNpm = (arguments_, allowFailure = false) => {
const result = spawnSync("npm", arguments_, {
cwd: publishDirectory,
encoding: "utf8",
env: npmEnvironment,
stdio: allowFailure ? "pipe" : "inherit",
});
if (result.error) throw result.error;
if (!allowFailure && result.status !== 0) {
fail(`npm ${arguments_.join(" ")} failed`);
npmEnvironment.NPM_CONFIG_USERCONFIG = userConfig;
npmEnvironment.NPM_CONFIG_GLOBALCONFIG = globalConfig;
npmEnvironment.NPM_CONFIG_CACHE = join(configDirectory, "cache");
npmEnvironment.NPM_CONFIG_REGISTRY = REGISTRY;

if (npmEnvironment.RUNNER_ENVIRONMENT !== "github-hosted") {
fail("GitHub-hosted runner metadata is required for provenance");
}
return result;
};
const npmVersion = runNpm(["--version"], true).stdout.trim();
const versionMatch = /^(\d+)\.(\d+)\.(\d+)/u.exec(npmVersion);
if (
versionMatch === null ||
Number(versionMatch[1]) < 11 ||
(Number(versionMatch[1]) === 11 &&
(Number(versionMatch[2]) < 5 ||
(Number(versionMatch[2]) === 5 &&
Number(versionMatch[3]) < 1)))
) {
fail("npm 11.5.1 or newer is required for trusted publishing");
}

const registryIntegrity = () => {
const result = runNpm(
[
"view",
`${PACKAGE_NAME}@${manifest.package.version}`,
"dist.integrity",
"--json",
"--registry",
REGISTRY,
],
true,
);
if (result.status === 0) {
const value = JSON.parse(result.stdout);
if (typeof value !== "string") {
fail("registry returned invalid integrity metadata");
const runNpm = (arguments_, allowFailure = false) => {
const result = spawnSync("npm", arguments_, {
cwd: publishDirectory,
encoding: "utf8",
env: npmEnvironment,
stdio: allowFailure ? "pipe" : "inherit",
});
if (result.error) throw result.error;
if (!allowFailure && result.status !== 0) {
fail(`npm ${arguments_.join(" ")} failed`);
}
return value;
}
if (/\bE404\b/u.test(`${result.stdout}\n${result.stderr}`)) {
return null;
return result;
};
const npmVersion = runNpm(["--version"], true).stdout.trim();
const versionMatch = /^(\d+)\.(\d+)\.(\d+)/u.exec(npmVersion);
if (
versionMatch === null ||
Number(versionMatch[1]) < 11 ||
(Number(versionMatch[1]) === 11 &&
(Number(versionMatch[2]) < 5 ||
(Number(versionMatch[2]) === 5 &&
Number(versionMatch[3]) < 1)))
) {
fail("npm 11.5.1 or newer is required for trusted publishing");
}
fail("registry lookup failed");
};

try {
const registryIntegrity = () => {
const result = runNpm(
[
"view",
`${PACKAGE_NAME}@${manifest.package.version}`,
"dist.integrity",
"--json",
"--registry",
REGISTRY,
],
true,
);
if (result.status === 0) {
const value = JSON.parse(result.stdout);
if (typeof value !== "string") {
fail("registry returned invalid integrity metadata");
}
return value;
}
if (/\bE404\b/u.test(`${result.stdout}\n${result.stderr}`)) {
return null;
}
fail("registry lookup failed");
};

const existing = registryIntegrity();
if (existing !== null) {
if (!same(existing, integrity)) {
Expand Down Expand Up @@ -518,7 +525,11 @@ jobs:
}
}
} finally {
rmSync(configDirectory, { force: true, recursive: true });
rmSync(publishDirectory, { force: true, recursive: true });
if (configDirectory !== undefined) {
rmSync(configDirectory, { force: true, recursive: true });
}
if (publishDirectory !== undefined) {
rmSync(publishDirectory, { force: true, recursive: true });
}
}
NODE
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ in-memory tier and a durable storage-backed tier for expensive operations.

> [!IMPORTANT]
> Rate Limit is in early `0.x` development. Its public API is not stable.
> Current source is the **`0.3.2` candidate, not published**. Registry `latest`
> remains `0.2.0`, which
> predates the merged [PR #8 hardening](https://github.com/pegma-dev/rate-limit/pull/8)
> and the new bounded maintenance helper. The first advertised `0.1.0`
> Current source is the **unpublished `0.3.3` candidate**. Registry `latest`
> is `0.3.2`: original bytes match and npm cryptographic checks passed, but strict
> postflight failed its authenticated builder-identity policy. It is not
> qualified for the planned helper adoption. The first advertised `0.1.0`
> release was published from protected signed `v0.1.0` through
> trusted-publisher OIDC with provenance; the historical `0.0.0` name bootstrap
> remains separate under `bootstrap`. pegma.dev composes the durable tier in
> its production Identity worker; this candidate is not a new host deployment.

The source behavior below describes the `0.3.2` candidate. Adoption waits for
its reviewed publication and the host's explicit configuration/storage transition.
The source behavior below describes `0.3.3`, with the limiter/helper API
unchanged from `0.3.2`. Adoption waits for the new candidate's verified release
and the host's explicit configuration/storage transition. The
[public postflight procedure](docs/RELEASING.md#public-postflight-procedure)
defines the required byte, cryptographic, provenance-policy and consumer checks.

The signed `v0.3.0` tag and GitHub release are retained history: their
preparation failed before packing, produced no release artifact, and did not
publish npm bytes. `0.3.1` fixed that trust configuration and passed packing,
but upload discovered no files beneath hidden `.release/`; no artifact was
retained and smoke/publication were skipped. Neither version is on npm.
The `0.3.2` candidate uses one nonhidden preparation/digest/upload directory,
with the limiter/helper API unchanged. See the
[failed upload and new candidate record](docs/RELEASING.md#failed-031-upload-and-032-candidate).
Hosts must wait for actual verified `0.3.2` publication before pinning the new
`0.3.2` corrected artifact discovery and published the original prepared bytes;
an idempotent publisher retry reused that artifact. Its authenticated provenance
contains `https://github.com/actions/runner/undefined`, so successful workflow
completion did not satisfy strict postflight. The `0.3.3` candidate preserves
the nonsecret runner metadata and requires `github-hosted` before isolated npm
calls. See the [release record](docs/RELEASING.md#published-032-with-failed-strict-postflight).
Hosts must wait for actual verified `0.3.3` publication before pinning the new
helper, including through an alias. Existing Identity/Support `0.2.0` imports
remain unchanged; no legacy data transition is automatic.

Expand Down
31 changes: 19 additions & 12 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
## Status

**Stage:** Phases 1, 2, and 4 are complete; Phase 3 has its first production
consumer. Registry `@pegma/rate-limit@0.2.0` is published, and pegma.dev composes
the durable tier for its Identity surface. Registry `latest` remains `0.2.0`.
Current source is the **`0.3.2`
candidate, not published**, retaining exact Storage Core `0.4.0`. Published
consumer. pegma.dev composes the durable tier for its Identity surface.
Registry `latest` is published `0.3.2`; exact-byte and npm cryptographic checks
passed, but strict postflight rejected its authenticated builder identity.
It is not qualified for the planned helper adoption. Current source is the
**unpublished `0.3.3` candidate**, retaining exact Storage Core `0.4.0`. Published
`0.2.0` predates the already-merged [PR #8 hardening](https://github.com/pegma-dev/rate-limit/pull/8)
for immutable policy descriptors, counter kind/configuration bindings, and
clock-skew grace. The candidate includes that hardening plus bounded global
Expand All @@ -19,11 +20,14 @@ temporary verification repository, not the packing checkout. No release
artifact or npm `0.3.0` bytes were published. Signed `v0.3.1` corrected that
trust configuration and passed its gates/pack, then upload excluded hidden
`.release/`: zero artifacts were retained, smoke/publication were skipped, and
no npm `0.3.1` release exists. The `0.3.2` candidate uses one nonhidden
preparation/digest/upload directory, with the helper API unchanged. Its own
review, gates, publication and registry verification remain required. See the
[failed-upload receipt](RELEASING.md#failed-031-upload-and-032-candidate).
Hosts must await verified `0.3.2` publication before adopting the new helper,
no npm `0.3.1` release exists. `0.3.2` corrected artifact discovery and published
the original prepared bytes. Its publisher retry reused the original artifact,
but authenticated provenance names `https://github.com/actions/runner/undefined`.
The `0.3.3` candidate preserves nonsecret runner metadata and requires
`github-hosted` before isolated npm calls, with the helper API unchanged. Its
own review, gates, signed identity, publication and strict registry verification
remain pending. See the [release record](RELEASING.md#published-032-with-failed-strict-postflight).
Hosts must await verified `0.3.3` publication before adopting the new helper,
including an alias; existing Identity/Support `0.2.0` imports stay unchanged.

The exact reviewed `0.0.0` package-name bootstrap remains published under
Expand Down Expand Up @@ -201,7 +205,7 @@ collection over an injected Store). The memory tier must remain importable
without a Store — a host wanting only abuse-dampening should not construct
storage. TypeScript, vitest, the ecosystem's standard layout.

## `0.3.2` bounded-maintenance source candidate
## `0.3.3` bounded-maintenance source candidate

`sweepDurableWindowsPage` is a root/durable export over the existing
`rate-limit-windows` collection. One call makes one physical global scan page,
Expand Down Expand Up @@ -232,8 +236,11 @@ retrying from the previous cursor can repeat work. The
define the interface; current-head gates, review, exact publication, and host
adoption remain release work.

Host aliases for this helper must pin `0.3.2` only after its actual verified
registry publication. A signed tag or GitHub release alone is not publication.
Host aliases for this helper must await actual verified `0.3.3` registry
publication. Published `0.3.2` did not pass strict postflight; a signed tag,
GitHub release or successful publisher job alone is not adoption qualification.
The [public postflight procedure](RELEASING.md#public-postflight-procedure)
records the required independent checks and acceptance criteria.

Upgrading existing durable data is deliberate: use versioned policy names or
an isolated Store namespace, or coordinate a policy-store reset. Immutable
Expand Down
Loading
Loading