Compare commits

...
1 Commits
Author SHA1 Message Date
Denozordec f9b742b730 fix(ix): учесть включённые правила блокировки открытых туннелей
Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 11m35s
Docker images / backend-image (push) Successful in 4m31s
Docker images / frontend-image (push) Successful in 4m57s
Docker images / updater-image (push) Successful in 2m9s
Docker images / netflow-agent-image (push) Successful in 37s
Docker images / notify-webhook (push) Successful in 2s
Docker images / publish-release (push) Successful in 10s
2026-12-04 22:53:04 +07:00
2 changed files with 34 additions and 4 deletions

No files matched your search

@@ -138,6 +138,25 @@ test("another Linux VPS can be planned while a managed GRE/IPsec peer has no SA"
assert.throws(() => planIxNative(id, desired, previous, device(rows)), /изменён вне операции/)
})
test("an omitted enabled-by-default flag on a GRE plaintext drop does not block IX", () => {
const path = "/ip/firewall/filter"
const object = (chain: string, policy: string) => ({ serverId: 17, path, fields: {
comment: name + ":gre-" + chain + "-il-vps", chain, action: "drop", protocol: "gre", "ipsec-policy": policy, disabled: "false",
} })
const inbound = object("input", "in,none"), outbound = object("output", "out,none")
const rows = [inbound, outbound].map(({ fields }, index) => {
const { disabled: _disabled, ...observed } = fields
return { ...observed, ".id": "*" + (index + 1), invalid: "false" }
})
assert.deepEqual(planIxNative(id, [inbound], [inbound], device({ [path]: [rows[0]] })), [])
assert.deepEqual(planIxNative(id, [inbound, outbound], [inbound], device({ [path]: rows }), true), [])
const disabled = { ...rows[0], disabled: "true" }
assert.throws(() => planIxNative(id, [inbound], [inbound], device({ [path]: [disabled] }), true), /изменён вне операции.*gre-input-il-vps.*disabled/)
const otherRule = { ...inbound, fields: { ...inbound.fields, protocol: "tcp" } }
const observedOtherRule = { ...rows[0], protocol: "tcp" }
assert.throws(() => planIxNative(id, [otherRule], [otherRule], device({ [path]: [observedOtherRule] })), /изменён вне операции.*disabled/)
})
test("RouterOS REST encodes an enabled blackhole route as a present empty flag", () => {
const fields = { comment: name + ":default-discard-4", "routing-table": name, "dst-address": "0.0.0.0/0", blackhole: "yes" }
const discard = { ...route, fields }
@@ -78,8 +78,17 @@ function normalize(field: string, value: string | undefined) {
return value
}
function fieldMatches(row: NativeRow, fields: Record<string, string>, field: string) {
// RouterOS can omit disabled=no on GRE plaintext drops created without an explicit flag.
if (field === "disabled" && row.disabled === undefined && fields.disabled === "false" &&
fields.action === "drop" && fields.protocol === "gre" &&
((fields.chain === "input" && fields["ipsec-policy"] === "in,none") ||
(fields.chain === "output" && fields["ipsec-policy"] === "out,none"))) return true
return normalize(field, row[field]) === normalize(field, fields[field])
}
function matches(row: NativeRow, fields: Record<string, string>) {
return Object.entries(fields).every(([field, value]) => normalize(field, row[field]) === normalize(field, value))
return Object.keys(fields).every(field => fieldMatches(row, fields, field))
}
function rowsFor(device: NativeDevice, path: string) { return device.rows[path] ?? [] }
@@ -138,11 +147,13 @@ export function planIxNative(id: string, desired: IxRouterObject[], previous: Ix
}
if (row) {
const before = previousByKey.get(deviceMarker(object))!
if (!matches(row, before.fields)) throw new IxConflict("Объект IX изменён вне операции")
const differences = Object.keys(before.fields).filter(field => !fieldMatches(row, before.fields, field))
if (differences.length) throw new IxConflict("Объект IX изменён вне операции · узел " + object.serverId + " · " + path +
" · " + (object.fields.comment ?? object.fields.name) + " · " + differences.join(", "))
if (Object.keys(before.fields).some(field => !(field in object.fields))) {
throw new IxConflict("Поле RouterOS нельзя неявно сбросить. Замените объект с новым идентификатором")
}
const fields = Object.fromEntries(Object.entries(object.fields).filter(([field, value]) => normalize(field, row[field]) !== normalize(field, value)))
const fields = Object.fromEntries(Object.entries(object.fields).filter(([field]) => !fieldMatches(row, object.fields, field)))
if (Object.keys(fields).length) result.push({ serverId: object.serverId, path, rosId: verifyNativeId(row), fields, before: row })
continue
}
@@ -1007,7 +1018,7 @@ async function applyNativeTasks(native: IxNativeChange, authorize: () => Promise
if (!returnedId || !routerId.test(returnedId)) throw new IxConflict("RouterOS не подтвердил ID объекта IX")
const row = (await readRows(client, task.path, [".id", ...Object.keys(task.fields)])).find(entry => entry[".id"] === returnedId)
if (!row || !matches(row, task.fields)) {
const fields = row ? Object.keys(task.fields).filter(field => normalize(field, row[field]) !== normalize(field, task.fields![field])) : []
const fields = row ? Object.keys(task.fields).filter(field => !fieldMatches(row, task.fields!, field)) : []
throw new IxConflict("Перечитанный объект IX не совпал с планом · " + task.path + (fields.length ? " · " + fields.join(", ") : ""))
}
const vrfName = task.path === "/ip/vrf" ? task.fields.name : undefined