diff --git a/client/src/components/AddDecisionModal.tsx b/client/src/components/AddDecisionModal.tsx index 3edd0258..ff96b6fe 100644 --- a/client/src/components/AddDecisionModal.tsx +++ b/client/src/components/AddDecisionModal.tsx @@ -1,6 +1,7 @@ import { useEffect, useState, type FormEvent } from 'react'; import { AlertCircle, ShieldCheck } from 'lucide-react'; import { DEFAULT_MANUAL_DECISION_SCENARIO } from '../../../shared/contracts'; +import { MANAGED_BAN_DURATION, MANAGED_BAN_REASON } from '../lib/permanentBans'; import { addDecision, addDecisions, checkAllowlist } from '../lib/api'; import { useI18n } from '../lib/i18n'; import type { @@ -29,6 +30,8 @@ type SkippedBatch = BulkTarget & { entries: BulkAddDecisionResponse['allowlisted interface AddDecisionModalProps { /** In bulk mode (`values` set), `ip` is ignored. */ initialDecision: AddDecisionRequest; + /** Restrict this form to long-lived removable IP bans, not temporary decisions. */ + managedBan?: boolean; /** Adds the same decision for each of these values instead of the single `ip`. */ values?: string[]; instances: InstanceSummary[]; @@ -75,6 +78,7 @@ interface ErrorInfo { export function AddDecisionModal({ initialDecision, + managedBan = false, values, instances, multipleInstances, @@ -239,6 +243,7 @@ export function AddDecisionModal({ const payload: AddDecisionRequest = { ...decision, scenario: selectedScenario, + ...(managedBan ? { type: 'ban' as const, duration: MANAGED_BAN_DURATION, reason: MANAGED_BAN_REASON } : {}), ...(bypassAllowlist ? { bypass_allowlist: true } : {}), }; if (bulk) { @@ -302,8 +307,9 @@ export function AddDecisionModal({ }; return ( - +
+ {managedBan &&

This adds a long-term ban to the Banned IPs list. It can be removed using Unban. CrowdSec requires an expiration, so the ban is set for 10 years.

} {bulk ? (

{t('pages.decisions.bulkValues', { count: bulkValues.length })}

@@ -329,7 +335,7 @@ export function AddDecisionModal({ />
)} -
+ {!managedBan &&
-
-
+
} + {!managedBan &&
updateDecision({ duration: event.target.value })} />

{t('pages.decisions.durationHint')}

-
- {scenarioOptions.length > 1 && ( +
} + {!managedBan && scenarioOptions.length > 1 && (
updateDecision({ reason: event.target.value })} /> -
+ } {multipleInstances && (
diff --git a/client/src/lib/permanentBans.ts b/client/src/lib/permanentBans.ts new file mode 100644 index 00000000..5aac9428 --- /dev/null +++ b/client/src/lib/permanentBans.ts @@ -0,0 +1,7 @@ +/** A removable, long-lived CrowdSec ban distinct from automated temporary decisions. + * CrowdSec requires an expiry; ten years is deliberately long, not infinite. + * The reason marker is used by the Banned IPs page and its dashboard count. + */ +export const MANAGED_BAN_REASON = 'permanent-ban'; +export const MANAGED_BAN_DURATION = '87600h'; // ~10 years +export const MANAGED_BAN_QUERY = 'type:ban AND status:active AND origin:cscli AND scenario:permanent-ban'; diff --git a/client/src/pages/Alerts.tsx b/client/src/pages/Alerts.tsx index 21632b84..ec33d3bd 100644 --- a/client/src/pages/Alerts.tsx +++ b/client/src/pages/Alerts.tsx @@ -2890,6 +2890,7 @@ export function Alerts() { {showToolbarBanIp && ( ([]); @@ -76,7 +77,7 @@ export function BannedIPs() {
{showAdd && 1} currentInstanceId={scope!=='all'?scope:undefined} diff --git a/client/src/pages/Dashboard.tsx b/client/src/pages/Dashboard.tsx index aaad70bd..242bf1f8 100644 --- a/client/src/pages/Dashboard.tsx +++ b/client/src/pages/Dashboard.tsx @@ -23,6 +23,7 @@ import { ShieldBan } from "lucide-react"; import { DASHBOARD_COLORS } from "../lib/dashboardColors"; +import { MANAGED_BAN_QUERY } from "../lib/permanentBans"; import { getCountryCodesMatchingName, getCountryName } from "../lib/utils"; import type { ConfigResponse, @@ -679,7 +680,7 @@ export function Dashboard() { useEffect(() => { let cancelled=false; // Count manually imposed bans shown in Banned IPs; automated decisions remain on Decisions. - void fetchDecisionsPaginated(1,1,{q:'type:ban AND status:active AND origin:cscli'}) + void fetchDecisionsPaginated(1,1,{q:MANAGED_BAN_QUERY}) .then(result=>{if(!cancelled)setActiveBanDecisions(result.pagination.total);}) .catch(()=>{if(!cancelled)setActiveBanDecisions(null);}); return ()=>{cancelled=true;}; @@ -1624,7 +1625,7 @@ export function Dashboard() {

Total banned IPs

{activeBanDecisions===null?'—':activeBanDecisions.toLocaleString()}

-

Manually imposed IP bans

+

Long-term managed IP bans