Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
75db25a
Recoverable keys feature for the dashboard
harshsbhat Sep 17, 2024
365117e
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 17, 2024
ab6ad58
Checking for the Store_encrypted_keys from teh dashboard too
harshsbhat Sep 18, 2024
197fe6e
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 18, 2024
b795941
Show keyId after creating a new key
harshsbhat Sep 17, 2024
e1a92c2
lint
harshsbhat Sep 17, 2024
3379c0e
Requested changes
harshsbhat Sep 18, 2024
7cd8dc6
Removed unused component
harshsbhat Sep 18, 2024
6f903de
Add the actual link in the description
harshsbhat Sep 18, 2024
43aa747
Remove wrong rebase
harshsbhat Sep 18, 2024
e89dfa3
merge conflicts
harshsbhat Sep 18, 2024
c8d08d0
Fixing pnpm lock file
harshsbhat Sep 18, 2024
babbde4
Merge remote-tracking branch 'origin/main' into harshbhat/recoverable…
harshsbhat Sep 18, 2024
4b74619
Error handling for encrypt fail as well as disabled store encrypt keys
harshsbhat Sep 19, 2024
596b315
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 19, 2024
7ffdbc4
fix: cf cache ratelimits (#2112)
chronark Sep 19, 2024
7028fc4
Merge remote-tracking branch 'origin/main' into harshbhat/recoverable…
harshsbhat Sep 19, 2024
2d6d304
Disabling the card if store encrypted is disabled
harshsbhat Sep 19, 2024
68c6599
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 19, 2024
ee40896
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 20, 2024
ca22641
Added transaction
harshsbhat Sep 20, 2024
2bcfb89
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 21, 2024
9302c62
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 21, 2024
9699b48
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 24, 2024
c46e0a0
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 24, 2024
77b5e03
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 24, 2024
ee5e94a
Change the display after creating the new key with recoverable
harshsbhat Sep 24, 2024
fce16ae
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Sep 25, 2024
f9877c7
Update apps/dashboard/lib/trpc/routers/key/create.ts
harshsbhat Sep 27, 2024
314ac7a
Merge remote-tracking branch 'origin/main' into harshbhat/recoverable…
harshsbhat Sep 28, 2024
bf876bc
Fix link and remove licence from vault
harshsbhat Sep 28, 2024
441a038
Merge branch 'main' into harshbhat/recoverable-keys
harshsbhat Oct 1, 2024
8125c72
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 1, 2024
050145c
feat: Added support to sidebar (#2119)
harshsbhat Oct 2, 2024
0535b2b
chore(email): update styling, copy, urls (#2141)
mcstepp Oct 2, 2024
4944c5f
chore: Delay email and upgrade Resend (#2152)
perkinsjr Oct 2, 2024
3a5bf01
fix: make keys UI responsive to mobile devices (#2145)
geraldmaboshe Oct 2, 2024
1545e7b
chore: Update to dot com (#2155)
perkinsjr Oct 2, 2024
b15c192
Update email to be "James from Unkey <james@updates.unkey.com>"
perkinsjr Oct 2, 2024
bf1dcf7
chore: update legacy_keys_verifyKey.ts (#2158)
eltociear Oct 3, 2024
e7f6bf1
feat: added README.md in /packages/api (#2153)
Abhi-Bohora Oct 3, 2024
a78085a
chore: create changeset
chronark Oct 3, 2024
e8f0f5d
chore(release): version packages (#2160)
github-actions[bot] Oct 3, 2024
7da6d0d
Recoverable keys feature for the dashboard
harshsbhat Sep 17, 2024
72f9983
Checking for the Store_encrypted_keys from teh dashboard too
harshsbhat Sep 18, 2024
69942ca
Show keyId after creating a new key
harshsbhat Sep 17, 2024
ebea66b
Requested changes
harshsbhat Sep 18, 2024
6a35257
merge conflicts
harshsbhat Sep 18, 2024
c739b68
Fixing pnpm lock file
harshsbhat Sep 18, 2024
c25761f
Error handling for encrypt fail as well as disabled store encrypt keys
harshsbhat Sep 19, 2024
5db2d9a
fix: cf cache ratelimits (#2112)
chronark Sep 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func TestIdentitiesRatelimitAccuracy(t *testing.T) {
unkey.WithSecurity(rootKey),
)

<<<<<<< HEAD
for _, nKeys := range []int{1, 3, 10, 1000} {
=======
for _, nKeys := range []int{1} { //, 3, 10, 1000} {
>>>>>>> 7ffdbc4f (fix: cf cache ratelimits (#2112))
t.Run(fmt.Sprintf("with %d keys", nKeys), func(t *testing.T) {

for _, tc := range []struct {
Expand Down Expand Up @@ -133,7 +137,11 @@ func TestIdentitiesRatelimitAccuracy(t *testing.T) {
// ---------------------------------------------------------------------------

exactLimit := int(inferenceLimit.Limit) * int(tc.testDuration/(time.Duration(inferenceLimit.Duration)*time.Millisecond))
<<<<<<< HEAD
upperLimit := int(2.5 * float64(exactLimit))
=======
upperLimit := int(1.2 * float64(exactLimit))
>>>>>>> 7ffdbc4f (fix: cf cache ratelimits (#2112))
lowerLimit := exactLimit
if total < lowerLimit {
lowerLimit = total
Expand Down
4 changes: 4 additions & 0 deletions apps/agent/integration/keys/ratelimits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ func TestDefaultRatelimitAccuracy(t *testing.T) {
// ---------------------------------------------------------------------------

exactLimit := int(ratelimit.Limit) * int(tc.testDuration/(time.Duration(*ratelimit.Duration)*time.Millisecond))
<<<<<<< HEAD
upperLimit := int(2.5 * float64(exactLimit))
=======
upperLimit := int(1.2 * float64(exactLimit))
>>>>>>> 7ffdbc4f (fix: cf cache ratelimits (#2112))
lowerLimit := exactLimit
if total < lowerLimit {
lowerLimit = total
Expand Down
3 changes: 3 additions & 0 deletions apps/api/src/pkg/middleware/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ export function metrics(): MiddlewareHandler<HonoEnv> {
return async (c, next) => {
const { metrics, analytics, logger } = c.get("services");

<<<<<<< HEAD
let requestBody = await c.req.raw.clone().text();
requestBody = requestBody.replaceAll(/"key":\s*"[a-zA-Z0-9_]+"/g, '"key": "<REDACTED>"');
=======
>>>>>>> 7ffdbc4f (fix: cf cache ratelimits (#2112))
const start = performance.now();
const m = {
isolateId: c.get("isolateId"),
Expand Down
22 changes: 15 additions & 7 deletions apps/api/src/pkg/ratelimit/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {
export class AgentRatelimiter implements RateLimiter {
private readonly logger: Logger;
private readonly metrics: Metrics;
private readonly cache: Map<string, { reset: number; current: number }>;
private readonly cache: Map<string, { reset: number; current: number; blocked: boolean }>;
private readonly agent: Agent;
constructor(opts: {
agent: { url: string; token: string };
logger: Logger;
metrics: Metrics;
cache: Map<string, { reset: number; current: number }>;
cache: Map<string, { reset: number; current: number; blocked: boolean }>;
}) {
this.logger = opts.logger;
this.metrics = opts.metrics;
Expand All @@ -36,7 +36,11 @@ export class AgentRatelimiter implements RateLimiter {
return [req.identifier, window, req.shard].join("::");
}

<<<<<<< HEAD
private setCacheMax(id: string, current: number, reset: number) {
=======
private setCache(id: string, current: number, reset: number, blocked: boolean) {
>>>>>>> 7ffdbc4f (fix: cf cache ratelimits (#2112))
const maxEntries = 10_000;
this.metrics.emit({
metric: "metric.cache.size",
Expand All @@ -55,11 +59,15 @@ export class AgentRatelimiter implements RateLimiter {
}
}
}
<<<<<<< HEAD
const cached = this.cache.get(id) ?? { reset: 0, current: 0 };
if (current > cached.current) {
this.cache.set(id, { reset, current });
return current;
}
=======
this.cache.set(id, { reset, current, blocked });
>>>>>>> 7ffdbc4f (fix: cf cache ratelimits (#2112))
}

public async limit(
Expand Down Expand Up @@ -127,8 +135,8 @@ export class AgentRatelimiter implements RateLimiter {
* This might not happen too often, but in extreme cases the cache should hit and we can skip
* the request to the durable object entirely, which speeds everything up and is cheaper for us
*/
const cached = this.cache.get(id) ?? { current: 0, reset: 0 };
if (cached.current >= req.limit) {
const cached = this.cache.get(id) ?? { current: 0, reset: 0, blocked: false };
if (cached.blocked) {
return Ok({
pass: false,
current: cached.current,
Expand Down Expand Up @@ -165,7 +173,7 @@ export class AgentRatelimiter implements RateLimiter {
if (sync) {
const res = await p;
if (res.val) {
this.setCacheMax(id, res.val.current, res.val.reset);
this.setCache(id, res.val.current, res.val.reset, !res.val.pass);
}
return res;
}
Expand All @@ -176,7 +184,7 @@ export class AgentRatelimiter implements RateLimiter {
this.logger.error(res.err.message);
return;
}
this.setCacheMax(id, res.val.current, res.val.reset);
this.setCache(id, res.val.current, res.val.reset, !res.val.pass);

this.metrics.emit({
workspaceId: req.workspaceId,
Expand All @@ -199,7 +207,7 @@ export class AgentRatelimiter implements RateLimiter {
});
}
cached.current += cost;
this.setCacheMax(id, cached.current, reset);
this.setCache(id, cached.current, reset, false);

return Ok({
pass: true,
Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/routes/legacy_keys_verifyKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ A key could be invalid for a number of reasons, for example if it has expired, h
example: true,
}),
name: z.string().optional().openapi({
description:
"The name of the key, give keys a name to easily identifiy their purpose",
description: "The name of the key, give keys a name to easily identify their purpose",
example: "Customer X",
}),
ownerId: z.string().optional().openapi({
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/routes/v1_ratelimit_limit.accuracy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ for (const { limit, duration, rps, seconds } of testCases) {
}, 0);

const exactLimit = Math.min(results.length, (limit / (duration / 1000)) * seconds);
<<<<<<< HEAD
const upperLimit = Math.round(exactLimit * 2.5);
=======
const upperLimit = Math.round(exactLimit * 1.5);
>>>>>>> 7ffdbc4f (fix: cf cache ratelimits (#2112))
const lowerLimit = Math.round(exactLimit * 0.95);
console.info({ name, passed, exactLimit, upperLimit, lowerLimit });
t.expect(passed).toBeGreaterThanOrEqual(lowerLimit);
Expand Down
6 changes: 6 additions & 0 deletions apps/dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @unkey/web

## 0.1.36

### Patch Changes

- @unkey/ratelimit@0.4.5

## 0.1.35

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const Keys: React.FC<Props> = async ({ keyAuthId, apiId }) => {
<Link
href={`/apis/${apiId}/keys/${k.keyAuthId}/${k.id}`}
key={k.id}
className="grid items-center grid-cols-12 px-4 py-2 duration-250 hover:bg-background-subtle "
className="grid items-center sm:grid-cols-12 px-4 py-2 duration-250 hover:bg-background-subtle gap-2"
>
<div className="flex flex-col items-start col-span-6 ">
<span className="text-sm text-content">{k.name}</span>
Expand Down
Loading