feat(api): unify policy handling with default action updates
- Updated `evofw-firewall.sh` and related scripts to replace `policy_mode` with `default_action`, enhancing clarity and consistency in policy management. - Adjusted agent routes and evaluation logic to accommodate the new default action structure, ensuring backward compatibility with legacy modes. - Enhanced tests to validate the new default action behavior and its integration within the agent policy framework. - Refactored related components in the web interface to align with the updated policy handling, improving user experience and reducing confusion around policy modes.
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
import { cn } from '@evofw/ui/lib/utils'
|
||||
import {
|
||||
ToggleGroup,
|
||||
ToggleGroupItem,
|
||||
} from '@evofw/ui/components/toggle-group'
|
||||
import {
|
||||
Frame,
|
||||
FrameDescription,
|
||||
FrameHeader,
|
||||
FramePanel,
|
||||
FrameTitle,
|
||||
} from '@/components/reui/frame'
|
||||
|
||||
type PolicyMode = 'blacklist' | 'whitelist'
|
||||
|
||||
type PolicyModeToggleProps = {
|
||||
value: PolicyMode
|
||||
onChange: (mode: PolicyMode) => void
|
||||
disabled?: boolean
|
||||
className?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter mode — settings-3 ToggleGroup pattern.
|
||||
* Preview: https://reui.io/preview/base/settings-3
|
||||
* Docs: https://ui.shadcn.com/docs/components/base/toggle-group
|
||||
*/
|
||||
export function PolicyModeToggle({
|
||||
value,
|
||||
onChange,
|
||||
disabled,
|
||||
className,
|
||||
}: PolicyModeToggleProps) {
|
||||
return (
|
||||
<Frame dense spacing="sm" className={cn(className)}>
|
||||
<FrameHeader>
|
||||
<FrameTitle>Режим фильтра</FrameTitle>
|
||||
<FrameDescription>
|
||||
Чёрный список: блокировать deny. Белый список: пропускать только
|
||||
allow, остальное (forward) — DROP.
|
||||
</FrameDescription>
|
||||
</FrameHeader>
|
||||
<FramePanel>
|
||||
<ToggleGroup
|
||||
multiple={false}
|
||||
value={[value]}
|
||||
onValueChange={(next) => {
|
||||
const mode = next[0]
|
||||
if (mode === 'blacklist' || mode === 'whitelist') {
|
||||
onChange(mode)
|
||||
}
|
||||
}}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={disabled}
|
||||
aria-label="Режим фильтра"
|
||||
className="flex flex-wrap justify-start gap-1"
|
||||
>
|
||||
<ToggleGroupItem value="blacklist" aria-label="Чёрный список">
|
||||
Чёрный список
|
||||
</ToggleGroupItem>
|
||||
<ToggleGroupItem value="whitelist" aria-label="Белый список">
|
||||
Белый список
|
||||
</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</FramePanel>
|
||||
</Frame>
|
||||
)
|
||||
}
|
||||
@@ -58,7 +58,6 @@ function ruleSubtitle(r: PolicyRule): string | null {
|
||||
type PolicyRulesSortableProps = {
|
||||
setId: string
|
||||
rules: PolicyRule[]
|
||||
policyMode: 'blacklist' | 'whitelist'
|
||||
onDelete: (id: string) => void
|
||||
onAdd?: () => void
|
||||
}
|
||||
@@ -66,7 +65,6 @@ type PolicyRulesSortableProps = {
|
||||
export function PolicyRulesSortable({
|
||||
setId,
|
||||
rules: rulesProp,
|
||||
policyMode,
|
||||
onDelete,
|
||||
onAdd,
|
||||
}: PolicyRulesSortableProps) {
|
||||
@@ -105,22 +103,16 @@ export function PolicyRulesSortable({
|
||||
onError: (e: Error) => toast.error(e.message),
|
||||
})
|
||||
|
||||
const isWl = policyMode === 'whitelist'
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Frame dense spacing="sm">
|
||||
<FramePanel className="flex items-center gap-3 py-3">
|
||||
<Badge
|
||||
variant={isWl ? 'destructive-light' : 'success-light'}
|
||||
size="sm"
|
||||
>
|
||||
{isWl ? 'DROP' : 'ACCEPT'}
|
||||
<Badge variant="secondary" size="sm">
|
||||
deny → allow
|
||||
</Badge>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{isWl
|
||||
? 'По умолчанию DROP — ниже только allow-правила пропускают трафик'
|
||||
: 'По умолчанию ACCEPT — ниже deny-правила блокируют адреса'}
|
||||
Правила с action deny блокируют, allow — пропускают; default задаётся
|
||||
на агенте
|
||||
</p>
|
||||
</FramePanel>
|
||||
</Frame>
|
||||
|
||||
@@ -3,7 +3,6 @@ import { cn } from '@evofw/ui/lib/utils'
|
||||
import { Item, ItemMedia } from '@evofw/ui/components/item'
|
||||
|
||||
type PolicySetIconProps = {
|
||||
mode?: 'blacklist' | 'whitelist' | string | null
|
||||
className?: string
|
||||
}
|
||||
|
||||
@@ -11,16 +10,14 @@ type PolicySetIconProps = {
|
||||
* KPI-style tile for policy set rows.
|
||||
* Preview DNA: https://reui.io/preview/base/stats-12
|
||||
*/
|
||||
export function PolicySetIcon({ mode, className }: PolicySetIconProps) {
|
||||
const isWhitelist = mode === 'whitelist'
|
||||
export function PolicySetIcon({ className }: PolicySetIconProps) {
|
||||
return (
|
||||
<Item
|
||||
className={cn(
|
||||
'border-background bg-muted flex size-10.5 shrink-0 items-center justify-center border-2 p-0 shadow-[0_1px_3px_0_rgba(0,0,0,0.14)] dark:border [&_svg]:size-4',
|
||||
isWhitelist ? 'text-warning' : 'text-muted-foreground',
|
||||
'border-background bg-muted text-muted-foreground flex size-10.5 shrink-0 items-center justify-center border-2 p-0 shadow-[0_1px_3px_0_rgba(0,0,0,0.14)] dark:border [&_svg]:size-4',
|
||||
className,
|
||||
)}
|
||||
aria-label={isWhitelist ? 'Whitelist' : 'Blacklist'}
|
||||
aria-label="Набор правил"
|
||||
>
|
||||
<ItemMedia variant="icon" className="size-auto">
|
||||
<Shield aria-hidden />
|
||||
|
||||
Reference in New Issue
Block a user