mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-20 07:00:58 +08:00
Storage, flag and request path of the approval gate for asset targets. The
gate itself is not wired into the tool hook yet (steps 1.5 to 1.7): with this
change nothing is extracted, resolved or blocked, whatever the flag says.
Schema and store (1.2)
- tasks.target_gate, conversations.target_gate (default false).
- intercept_pending.target_key and a partial unique index: one open request
per scope (task or conversation) and host:port.
- target_pins (no foreign keys: a pin outlives its task, its conversation and
its request row) and target_gate_exemption_log. All DDL is idempotent; no
CHECK constraints; the cascade on intercept_pending.conversation_id stays.
- db/target_pins.go: pin lookup with port precedence, list, revoke,
find-or-create of a request, and ResolveTargetRequest, which settles the
row, supersedes the old pin and writes the new version in one transaction.
- Deleting a task or an archive stub revokes its pins and settles its open
target requests in the delete transaction. DeleteConversation and
DeleteConversations revoke the pins of the removed conversations in the
same transaction as the delete.
Opt-in flag (1.3)
- Per task through the create and metadata-patch paths, per conversation
through create and patch; exposed in the task DTO. A retest conversation
takes the flag of the finding's task, never its pins. A spawned task starts
with the gate off.
- The task flag is atomic and read on every call through TargetScope.Enabled.
TargetScope now carries the Interceptor that owns the gate.
Request, wait, decide (1.4)
- pendingManager keeps a list of waiters per request; resolve wakes all.
- RequestTargets: find-or-create per target, one card per request, wait on
channel, poll, context and wait bound. A plain request is never settled by
a call that leaves. A request merged with an ask is bound to its creating
call and a timeout never allows it.
- Decide records the approver (subject of the session token) and the remote
address for every human decision, classic asks included. On a target
request "allowed" pins the displayed addresses; that is the only writer of
pins.
- A request raised while the global egress proxy is set says the approval is
name-only and its pin is stored with name_only_effective.
- Routes: GET/POST .../target-pins and .../target-pins/{pid}/revoke under
/api/tasks/{id} and /api/conversations/{id}; decision_source=target filter.
- ValidateExemptionHost: an exemption written as an IP literal may be private
unicast, never loopback, link-local or metadata, unspecified or multicast.
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package intercept
|
|
|
|
import (
|
|
"fmt"
|
|
"net/netip"
|
|
)
|
|
|
|
// metadataAddrs are instance-metadata addresses that lie outside the link-local
|
|
// ranges and would otherwise pass as private or public unicast.
|
|
var metadataAddrs = []netip.Addr{
|
|
netip.MustParseAddr("fd00:ec2::254"), // AWS IMDS over IPv6
|
|
netip.MustParseAddr("100.100.100.200"), // Alibaba Cloud
|
|
}
|
|
|
|
// ValidateExemptionHost checks the host of an entry an operator adds to the
|
|
// target-gate exemption list. host is expected in normalised form.
|
|
//
|
|
// An exemption on a name is resolved at check time and is void when the name
|
|
// resolves to a private, loopback, link-local or unspecified address. An IP
|
|
// literal is never resolved, so that rule cannot protect it and the literal is
|
|
// checked here instead. A private unicast address is allowed: an internal
|
|
// service the operator names on purpose (10.0.0.5:8080). Loopback, link-local
|
|
// (169.254.0.0/16 holds the cloud metadata address 169.254.169.254; fe80::/10),
|
|
// unspecified and multicast addresses are never accepted, nor are the metadata
|
|
// addresses outside the link-local ranges. A host that is not an IP literal
|
|
// passes: names are the void rule's business.
|
|
func ValidateExemptionHost(host string) error {
|
|
addr, err := netip.ParseAddr(host)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
addr = addr.Unmap().WithZone("")
|
|
kind := ""
|
|
switch {
|
|
case addr.IsLoopback():
|
|
kind = "a loopback"
|
|
case addr.IsUnspecified():
|
|
kind = "the unspecified"
|
|
case addr.IsLinkLocalUnicast():
|
|
kind = "a link-local (metadata range)"
|
|
case addr.IsMulticast():
|
|
kind = "a multicast"
|
|
}
|
|
for _, m := range metadataAddrs {
|
|
if addr == m {
|
|
kind = "an instance-metadata"
|
|
}
|
|
}
|
|
if kind != "" {
|
|
return fmt.Errorf("%s is %s address and can never be exempt from target approval", host, kind)
|
|
}
|
|
return nil
|
|
}
|