|
|
@@ -488,6 +488,7 @@ function PolicyTab({
|
|
|
const [rules, setRules] = useState<KeyScopeRule[]>(fn.policy.rules)
|
|
|
const [origins, setOrigins] = useState(fn.policy.origins.join(', '))
|
|
|
const [rateLimit, setRateLimit] = useState(fn.policy.rate_limit_per_min)
|
|
|
+ const [callerRateLimit, setCallerRateLimit] = useState(fn.policy.rate_limit_per_caller_per_min ?? 0)
|
|
|
const [expiresAt, setExpiresAt] = useState(fn.policy.expires_at)
|
|
|
const [saving, setSaving] = useState(false)
|
|
|
const [err, setErr] = useState<ApiError | null>(null)
|
|
|
@@ -496,6 +497,7 @@ function PolicyTab({
|
|
|
setRules(fn.policy.rules)
|
|
|
setOrigins(fn.policy.origins.join(', '))
|
|
|
setRateLimit(fn.policy.rate_limit_per_min)
|
|
|
+ setCallerRateLimit(fn.policy.rate_limit_per_caller_per_min ?? 0)
|
|
|
setExpiresAt(fn.policy.expires_at)
|
|
|
setErr(null)
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
@@ -526,11 +528,19 @@ function PolicyTab({
|
|
|
setErr(null)
|
|
|
try {
|
|
|
const policy: KeyScope = {
|
|
|
+ // SPREAD FIRST, so a field this editor does not model survives the
|
|
|
+ // save. This route REPLACES the whole policy, and this object used to
|
|
|
+ // be a literal of four fields - so saving a rate limit silently wiped
|
|
|
+ // `ip_allow`, removing an address allow-list with a success toast and
|
|
|
+ // nothing to tell the operator. Anything added to the policy later is
|
|
|
+ // now preserved by default rather than by somebody remembering.
|
|
|
+ ...fn.policy,
|
|
|
// require_human_token is dropped: it is an HTTP-header check and a
|
|
|
// function never presents one, so storing it would be decoration.
|
|
|
rules: usableRules(rules, false),
|
|
|
origins: origins.split(',').map((o) => o.trim()).filter((o) => o.length > 0),
|
|
|
rate_limit_per_min: rateLimit,
|
|
|
+ rate_limit_per_caller_per_min: callerRateLimit,
|
|
|
expires_at: expiresAt,
|
|
|
}
|
|
|
await api.setFunctionPolicy(project, fn.function_id, policy)
|
|
|
@@ -595,6 +605,31 @@ function PolicyTab({
|
|
|
className={inputCls}
|
|
|
/>
|
|
|
</div>
|
|
|
+ {/* The per-CALLER ceiling, beside the per-function one because the
|
|
|
+ pair only means anything read together: the first bounds the total
|
|
|
+ damage and says nothing about who caused it, the second stops one
|
|
|
+ caller consuming the whole allowance. A control nobody can see is a
|
|
|
+ control nobody knows exists, so it ships with the field. */}
|
|
|
+ <div className="flex-1 min-w-40">
|
|
|
+ <label className="block text-xs font-medium text-slate-400 mb-1">
|
|
|
+ Rate limit / min per caller{' '}
|
|
|
+ <span className="text-slate-500">(0 = unlimited)</span>
|
|
|
+ </label>
|
|
|
+ <input
|
|
|
+ type="number"
|
|
|
+ min={0}
|
|
|
+ step={1}
|
|
|
+ value={callerRateLimit}
|
|
|
+ onChange={(e) =>
|
|
|
+ setCallerRateLimit(Math.max(0, Math.floor(Number(e.target.value) || 0)))
|
|
|
+ }
|
|
|
+ className={inputCls}
|
|
|
+ />
|
|
|
+ <p className="mt-1 text-xs text-slate-500">
|
|
|
+ Keyed on the caller's resolved address. HTTP calls only; a cron or job run
|
|
|
+ has no caller.
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
<div className="flex-1 min-w-40">
|
|
|
<label className="block text-xs font-medium text-slate-400 mb-1">
|
|
|
Expires at <span className="text-slate-500">(epoch seconds; 0 = never)</span>
|
|
|
@@ -634,6 +669,14 @@ function PolicyLimitsView({ policy }: { policy: KeyScope }) {
|
|
|
<dt className="text-slate-500">Rate limit</dt>
|
|
|
<dd className="text-slate-300 font-mono">
|
|
|
{policy.rate_limit_per_min > 0 ? `${policy.rate_limit_per_min}/min` : 'unlimited'}
|
|
|
+ {(policy.rate_limit_per_caller_per_min ?? 0) > 0
|
|
|
+ ? ` · ${policy.rate_limit_per_caller_per_min}/min per caller`
|
|
|
+ : ''}
|
|
|
+ {/* Surfaced because this is the field a policy save used to wipe: an
|
|
|
+ operator who cannot see an allow-list cannot notice it vanishing. */}
|
|
|
+ {policy.ip_allow && policy.ip_allow.length > 0
|
|
|
+ ? ` · ${policy.ip_allow.length} address range${policy.ip_allow.length === 1 ? '' : 's'}`
|
|
|
+ : ''}
|
|
|
</dd>
|
|
|
<dt className="text-slate-500">Expires</dt>
|
|
|
<dd className="text-slate-300 font-mono">
|