Documentation
¶
Overview ¶
Package netrule is the grammar of the net_rules keyword, and what turns its rules into the addresses a filter is made of.
A rule says what a resource may reach, or may not, in the words of the cluster: allow or deny, then a node, a network, the cluster itself. The rules are an ordered list, and the first one matching a packet decides of it. The package parses the rules and resolves them to address sets over a view of the cluster, in their order, so the backend applying the filter is given addresses and nothing to interpret: the steps as they are for a backend judging a packet rule after rule, and flattened to an allowed and a denied list for one that knows no order, see Filter.Flat.
It knows no backend, and nothing of where the view comes from: the driver feeds it the configuration of the node and what the daemon says of the objects, and the daemon what it knows of the cluster, so a rule naming an object follows its addresses.
Index ¶
- Variables
- func Any() []netip.Prefix
- func Datastores(namespace string, lists ...Rules) []naming.Path
- func LookupObjects(objects []naming.Path, namespaces []string) (Objects, Identities, error)
- func Normalize(l []netip.Prefix) []netip.Prefix
- func ParsePrefixes(l []string) ([]netip.Prefix, error)
- func Public(rules Rules, view View, namespace string) (Filter, Foreign)
- func References(namespace string, lists ...Rules) (objects []naming.Path, namespaces []string)
- func RegisterLocalView(fn func() (View, error))
- func RegisterObjects(...)
- func Resolve(rules Rules, view View, namespace string) (Filter, Notes)
- func Strings(l []netip.Prefix) []string
- func Subtract(allow, deny []netip.Prefix) []netip.Prefix
- func Validator(keyword string, backend Backend) func(string) error
- type Action
- type AddrIdentifier
- type Backend
- type Data
- func (t Data) DNS() []netip.Addr
- func (t Data) Holders(addr netip.Addr) []naming.Path
- func (t Data) IsUnsure(holder Holder) bool
- func (t Data) Key(datastore naming.Path, key, namespace string) ([]byte, error)
- func (t Data) NamespaceObjects(namespace string) []naming.Path
- func (t Data) Network(name string) ([]netip.Prefix, bool)
- func (t Data) NetworkNode(name, node string) ([]netip.Prefix, bool)
- func (t Data) Node(name string) ([]netip.Addr, bool)
- func (t Data) Nodes() []string
- func (t Data) Object(path naming.Path) (ObjectAddrs, bool)
- type DataNetwork
- type Filter
- type Foreign
- type Held
- type Holder
- type Identifier
- type Identities
- type Identity
- type Kind
- type Memory
- type Note
- type Notes
- type ObjectAddrs
- type Objects
- type Publisher
- type Record
- type Rule
- func (t Rule) Datastore(namespace string) (naming.Path, error)
- func (t Rule) Foreign(namespace string) bool
- func (t Rule) Hidden(namespace string) bool
- func (t Rule) Names(p naming.Path, namespace string) bool
- func (t Rule) NamespaceName(namespace string) string
- func (t Rule) ObjectPath(namespace string) (naming.Path, error)
- func (t Rule) Reference(namespace string) string
- func (t Rule) Secret() bool
- func (t Rule) Unsupported(backend Backend) error
- type Rules
- type Step
- type Texts
- type View
- type Witness
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoDatastore = errors.New("no such datastore") ErrNoKey = errors.New("no such key") )
ErrNoDatastore and ErrNoKey are the errors of a view asked a key of a datastore the node does not hold, and a key the datastore does not. See ErrNotShared for a datastore of another namespace.
var ErrNoLocalView = errors.New("no view of the cluster networks and nodes here")
ErrNoLocalView is the error of a binary knowing nothing of the node it runs on, as one driving a cluster through its api.
var ErrNoObjects = errors.New("nobody to ask the addresses of the objects here")
ErrNoObjects is the error of a binary with nobody to ask the addresses of the objects.
ErrNotShared is the error of a view asked a key of a datastore of another namespace than the one of the object, which its share keyword does not share its keys with.
Functions ¶
func Datastores ¶
Datastores returns the datastores the rules read their ranges from, for the rules of an object of the namespace given, each once.
func LookupObjects ¶
LookupObjects returns the addresses of the objects named and of the objects of the namespaces named, an object the cluster does not have left out, with which objects they are, and ErrNoObjects where nobody is registered to tell.
func Normalize ¶
Normalize returns the ranges of l as the smallest sorted list covering the same addresses: no range within another, and two halves of a range joined into it. An ipv4 range written as an ipv6 one is the ipv4 one.
func ParsePrefixes ¶
ParsePrefixes reads the ranges a backend reports, an address being the range of itself.
func Public ¶
Public returns the filter the rules make with the ones naming another namespace, and the ones reading a sec, resolving to nothing, and what those add to it: what is shown of the filter to who reads the status of the resource.
func References ¶
References returns the objects and the namespaces the rules name, for the rules of an object of the namespace given, each once.
func RegisterLocalView ¶
RegisterLocalView sets the function returning the view of the node the caller runs on, read from its configuration.
It is registered rather than called because the package reading the networks of a node configuration imports the one validating the object configurations, which warns of the rules naming a network or a node the cluster does not have.
func RegisterObjects ¶
func RegisterObjects(fn func(objects []naming.Path, namespaces []string) (Objects, Identities, error))
RegisterObjects sets the function returning the addresses of the objects named and of the objects of the namespaces named, and which objects they are, as the daemon of the node knows them: asked through its api by a command, and read from its own data by the daemon.
func Resolve ¶
Resolve returns the filter the rules of a resource make over the view, and the rules resolving to nothing. namespace is the one of the object of the resource, which ./ and . stand for in its rules.
The filter is a step per rule, in their order, then the steps of the implicit rules, see Rules.WithImplicit: the first step matching a packet decides of it, and what no rule matches is denied. No rule is no filter.
A rule naming what the view does not have, as a network not created yet or an object not started, resolves to nothing, and is noted: its step matches nothing until what it names exists, so an allow rule lets nothing more through, and a deny rule denies nothing, leaving the packets to the rules after it.
Types ¶
type Action ¶
type Action string
Action is what becomes of a packet a rule is the first to match, allow or deny: the word the rule starts with, its verb, and the action of a step of the filter, as the firewalls name it.
type AddrIdentifier ¶
type AddrIdentifier interface {
// AddrIdentity returns the id of the object publishing the
// address under the path, and the version of its
// configuration, the newest of the instances publishing the
// address, each zero when the configuration of none is known.
AddrIdentity(path naming.Path, addr netip.Addr) (id string, version time.Time)
}
AddrIdentifier is a view telling which object publishes an address of a path: the daemon is one, which hears of the status and of the configuration of each instance.
A path may name two objects for a time: the one deleted, an instance of which a node still tells, and the one created again or restored under it, whose configuration another node tells already. An address is the one of the object whose instance publishes it, and the record of the delete of that object lifts it, whatever newer configuration the path is known by.
type Backend ¶
type Backend string
Backend is what applies a filter to what a resource runs, which says the rules a filter is made of there.
const ( // BackendCgroup is the filter systemd attaches to the cgroup of the // units of a slice, the one of the app, task, oci and lxc container // resources: it knows addresses, and no port. It is the backend of a // record naming none. BackendCgroup Backend = "" // BackendNetdev is the nftables filter of the network interfaces of // a guest, the one of container.kvm, which knows the ports too. BackendNetdev Backend = "netdev" )
type Data ¶
type Data struct {
// Networks are the cluster networks, by name.
Networks map[string]DataNetwork `json:"networks"`
// NodeAddrs are the addresses of the cluster nodes, by name: a
// node with none is still a node of the cluster.
NodeAddrs map[string][]netip.Addr `json:"nodes"`
// Nameservers are the nameservers what is filtered resolves
// through.
Nameservers []netip.Addr `json:"dns"`
// Objects are the addresses of the objects of the cluster, by
// path: an object with none is still an object of the cluster.
Objects Objects `json:"objects,omitempty"`
// Keys are the keys of the datastores the node holds, decoded,
// by path then by key name.
Keys map[string]map[string]string `json:"keys,omitempty"`
// with, beside their own, by path, as their share keyword
// says them: * is every namespace.
Shares map[string][]string `json:"shares,omitempty"`
// Unsure are the paths of the objects with an instance whose
// status nothing tells for now.
Unsure []string `json:"unsure,omitempty"`
}
Data is a view held as data: what the daemon is to hand to a driver asking for it, and what the tests resolve over.
type DataNetwork ¶
type DataNetwork struct {
// Ranges are the address ranges of the network.
Ranges []netip.Prefix `json:"ranges"`
// NodeRanges are the parts of the network the nodes hand out, by
// node name.
NodeRanges map[string][]netip.Prefix `json:"node_ranges,omitempty"`
}
DataNetwork is a cluster network of a Data view.
type Filter ¶
type Filter struct {
Steps []Step `json:"steps"`
}
Filter is what the rules of a resource resolve to, in the form a backend applies: a step per rule, in the order of the rules, the implicit ones included. A packet is judged by the first step it matches, and passes when it matches none.
A filter made of rules ends with the step of the implicit deny any, so nothing of it passes unmatched. One that does not is what a backend knowing no order reports of itself, see Flattened, or what a record written before the rules were ordered holds.
The steps are one per rule, also for a rule resolving to nothing: a backend making a set of each step keeps the same sets as the addresses move, and replaces their elements.
func FlatFilter ¶
FlatFilter returns the filter of an allowed and a denied list, as a backend knowing no order holds them: an allowed range wins, so the allowed step comes first.
func (Filter) Describe ¶
Describe says the filter in a line, in the order a packet is judged: "allow 10.0.1.5/32, deny 10.0.0.0/8, implicit allow 127.0.0.0/8 ::1/128, implicit deny any". A range on ports is said tcp/5432@10.0.0.5/32.
A step naming no address for now matches nothing, and is not said. The steps after one matching every packet are never reached, and are not said either: after an allow any, the implicit rules decide of nothing.
func (Filter) Equal ¶
Equal says the two filters are the same steps, in the same order: they let the same packets through, and a backend making a set of each step holds the same sets for both.
func (Filter) Flat ¶
Flat returns the filter as an allowed and a denied list, for a backend knowing no order, as systemd: one where a packet from or to an allowed range passes, one from or to a denied range and no allowed one is dropped, and any other passes. The two lists let through exactly what the steps do.
The denied list is every range a deny step names. The allowed list is, for each allow step, its ranges less the ones of the deny steps before it: an address a deny step matches first is in no allowed range, so it is dropped, and one an allow step matches first was taken out of none, so it passes, whatever denies it after.
The steps after one matching every packet are never reached, and left out. When that step allows, it is left out too: what reaches it is what no deny step before it names, which a backend passing the unmatched lets through already. So a list ending with allow any, written to deny a few hosts, is these hosts denied, and not every address less them, allowed range by range around each.
The steps on ports are none of such a backend, see HasPorts.
func (Filter) Flattened ¶
Flattened returns the filter as a backend knowing no order holds it: the step of its allowed list, then the one of its denied list, see Flat. It is what such a backend reports of itself, and what it is compared with.
func (*Filter) UnmarshalJSON ¶
UnmarshalJSON reads the steps of a filter, and what an om knowing no order wrote: an allowed and a denied list, with the ranges on ports apart, which it judged in this order: dropped on a denied port, passed from or to an allowed range, passed on an allowed port, dropped from or to a denied range, and passed otherwise. They are read as the steps saying the same.
type Foreign ¶
type Foreign struct {
// Rules is the number of rules naming an object of another
// namespace, or another namespace.
Rules int `json:"rules"`
// Secret is the number of rules reading a key of a sec.
Secret int `json:"secret,omitempty"`
// Addrs is the number of addresses they resolve to, all
// together.
Addrs int `json:"addrs"`
}
Foreign counts what the rules whose addresses are not shown add to the filter of the resource: the rules naming another namespace than the one of the object, whose addresses are the business of the namespace they are in, and the rules reading a key of a sec, told to who may decode it. It is what the status of the resource says of them.
type Held ¶
Held are the addresses a rule naming an object or a namespace resolves to, each with the object publishing it.
It is the memory of a filter kept current: what tells an address a status no longer shows from one no status ever showed, and whose it was.
func (Held) Equal ¶
Equal says the two hold the same addresses of the same objects, known by the same configurations.
func (Held) Keep ¶
Keep returns the addresses of t its rule no longer resolves to, current being what it resolves to now, which the filter keeps all the same, in the step of that rule. denied says the rule is a deny one.
A filter fails closed: what is not known is decided on the side that lets less through.
An allowed address is dropped when the status of its object says it is gone. It is kept while that status is not known, the node of an instance being lost or not heard of yet: a daemon restarting, on this node or another, stops nothing of what the objects run, and cuts nothing of what reaches them.
A denied address is kept as long as nothing says who holds it: an object stopped, or whose status is lost, may still answer there. It is dropped when its object is deleted.
Either is dropped once another object publishes the address: it is that object's then, and the rules naming it, if any, resolve to it.
An address whose holder tells no version, as one an om knowing no holder recorded, or one of an object whose configuration was not heard yet, is given the object the view knows under the path: nothing says it was another, and the newer object is the one a record of a delete lifts less of.
type Holder ¶
type Holder struct {
// Path is the path of the object.
Path string `json:"path"`
// ObjectID is the id of the object, its DEFAULT.id, empty when
// its configuration tells none, or was not known.
ObjectID string `json:"object_id,omitempty"`
// Version is the modification time of the configuration of the
// object, as the node committing it set it, and as every node
// holding that configuration carries it: the newest of the
// instances publishing the address, see AddrIdentifier. Zero
// when no configuration was known.
Version time.Time `json:"version,omitzero"`
}
Holder is the object publishing an address held: its path, and which object of that path it is, as the configuration it was known by when it published the address tells.
A path names the object deleted and the one created again under it alike: the id and the version tell them apart, so the record of a delete takes away the addresses of the object it deleted, and not the ones of the object that took its place, see IsDeletedBy.
func (Holder) IsDeletedBy ¶
IsDeletedBy says the record is the one of the delete of the holder: of its path, of its id when both tell one, and of a configuration not older than the one the holder was known by.
A record of another id, or of an older configuration, is the delete of the object the path named before: the holder was created again, or restored, since. A holder of no known version is not judged, as a record of none: nothing says the record is about it.
The ids are compared first, then the two versions, each the time the node committing the configuration gave it, carried with it: no clock of the node judging is read.
func (*Holder) UnmarshalJSON ¶
UnmarshalJSON reads a holder, and the one an om knowing no holder wrote: the path of the object alone, which tells no id and no version.
type Identifier ¶
type Identifier interface {
// Identity returns the id of the object of the path, and the
// version of its configuration, the newest the instances
// hold, each zero when not known.
Identity(path naming.Path) (id string, version time.Time)
}
Identifier is a view telling which object a path names for now: the daemon is one, which hears of the configuration of every instance.
type Identities ¶
Identities are which objects the paths name, and which publish their addresses, by path, as the daemon tells them with the addresses of the objects: a path it tells nothing of, as every path told by a daemon knowing no identity, is not there.
type Identity ¶
type Identity struct {
ObjectID string
Version time.Time
// Publishers are the objects publishing the addresses of the
// path, by address: a path names two objects while a node still
// tells its instance of the one deleted beside the one created
// again, each publishing its own addresses.
//
// Nil when the daemon tells the object of the path alone, as one
// not upgraded yet: every address is then the one of that
// object. Not nil, an address it does not hold is one no
// configuration of the instances publishing it is known of, and
// no object is told of it, not the one of the path.
Publishers map[netip.Addr]Publisher
}
Identity is which object a path names: its id, and the version of its configuration, each zero when not known. See Holder.
type Memory ¶
Memory are the addresses held of each rule naming an object or a namespace, by the text of the rule, its verb included.
The rules are an ordered list, where the place of a rule decides of what it matches: an address is remembered with the rule that resolved to it, so one kept is kept at the place of that rule, on its ports, and as its verb says, see Held.Keep. A list naming an object in an allow rule and in a deny rule keeps the addresses of each apart.
The text is the key, not the place: a rule moved in the list, or one a rule is written before, keeps its memory, and two rules written the same resolve to the same.
func Holding ¶
Holding returns the addresses each rule naming an object or a namespace resolves to over the view, each with the object publishing it, for the rules of an object of the namespace given. A rule resolving to no address holds nothing, and is not there.
The object is the one whose instances publish the address, see AddrIdentifier: an address a node still publishes of an object deleted is not given the object created again under its path, which the record of the delete would then not lift.
func (Memory) Count ¶
Count returns the number of addresses held of the rules of the verb given, an address held of two of them counted once.
type Note ¶
type Note struct {
Rule Rule
Reason string
// Refused says the rule is one that may not be written, not
// one naming what does not exist yet: it reads a datastore
// of another namespace that does not share its keys with the
// one of the object.
Refused bool
}
Note is a rule resolving to no address, and why.
type Notes ¶
type Notes []Note
Notes are the rules of a keyword resolving to no address.
func Shadowed ¶
Shadowed returns the rules that can never be the first to match a packet, each with the reason: a rule written before it matches all it names, whatever the cluster holds. namespace is the one of the object of the rules, which ./ and . stand for.
The first rule matching decides, so such a rule decides of nothing: it is what a validation warns of, most often a rule added after a last allow any, where an append to the keyword puts it.
Only what the rules say by themselves is judged, a rule against each rule before it: any rule after an allow any or a deny any, a node after the cluster, an object after its namespace or after itself whole, the part a node hands out of a network after that network, an address or a range after a range holding it, a rule written twice. Nothing is resolved: two rules naming the same addresses on this cluster today, as a node and its address, are not found, nor a rule several rules cover together. And the verbs are not compared: a rule after one matching all it names is never reached, whether it would say the same or the opposite.
A rule on ports matches the packets of its ports alone, and so shadows the rules on ports within its own.
func Unknown ¶
Unknown returns the rules naming a network, a node, an object, a resource or a namespace the view does not have, each with the reason it resolves to nothing, which names the object or the namespace as resolved for an object of the namespace given. objects says the view knows the objects of the cluster: where nobody tells them, their rules are not judged.
A rule naming another namespace is not judged either: a validation is run for whoever writes a configuration, who is not to learn from it which objects another namespace holds. The start of the resource says what such a rule resolves to.
It is what a validation warns of, without resolving an address: a configuration may be written before what it names exists, and its filter is the stricter for it until then.
type ObjectAddrs ¶
ObjectAddrs are the addresses the resources of an object publish in their status, by resource id, the instances of all the nodes together: an address is the one of the object wherever it runs, so a failover changes nothing of it.
type Objects ¶
type Objects map[string]ObjectAddrs
Objects are the addresses of objects, by path.
func (Objects) NamespaceObjects ¶
NamespaceObjects returns the objects held of a namespace, sorted.
type Publisher ¶
Publisher is the object publishing an address of a path: its id, and the version of its configuration, the newest of the instances publishing the address.
type Record ¶
type Record struct {
// NetRules are the rules, in their order, as the start read
// them, or the daemon since, in a configuration changed under
// the running resource: a rule per entry, not the text of the
// keyword, whose layout is none of the record, see Texts.
NetRules Texts `json:"rules"`
// Namespace is the namespace of the object of the resource,
// which ./ and . stand for in the rules.
Namespace string `json:"namespace"`
// PG is the id of the process group whose slice takes the
// filter, with the cgroup backend.
PG string `json:"pg"`
// Backend is what applies the filter, the cgroup one when not
// named, and Devs the network interfaces it is applied on,
// with the netdev one.
Backend Backend `json:"backend,omitempty"`
Devs []string `json:"devs,omitempty"`
// DNS are the nameservers what the resource runs resolves
// through, nil for the ones of the resolver of the node.
DNS []netip.Addr `json:"dns"`
// Filter is what the rules resolved to, the last time they
// were resolved.
Filter Filter `json:"filter"`
// Public is the filter without what the rules naming another
// namespace add to it, and Foreign counts what they add: what
// the status of the resource shows.
Public Filter `json:"public"`
Foreign Foreign `json:"foreign"`
// Held are the addresses the rules naming objects and
// namespaces resolved to, by rule, each with the object that
// published it, and Kept the ones they no longer resolve to
// that the filter keeps, in the step of their rule, see
// Memory and Held.Keep.
Held Memory `json:"held"`
Kept Memory `json:"kept"`
}
Record is the filter applied to a resource, with what it was resolved from: written by the start of the resource, for its status to compare the filter in force with, and for the daemon to resolve the rules again when what they name changes.
It holds all the daemon needs to keep the filter current as what the rules name changes, without reading the configuration of the object: the daemon reads it when it changes, and writes the rules it finds changed here, see WithRules.
func LoadRecord ¶
LoadRecord reads the record of a resource from its file.
func (Record) HasRules ¶
HasRules says the rules of the record are the ones of the value of the keyword given, as a configuration has it: the same rules in the same order, however the value lays them out, on one line or several, indented or not. The same rules in another order are other rules: the first one matching decides.
A value the grammar refuses is the rules of no record: it is a change, for who applies it to say it is refused.
func (Record) Refresh ¶
Refresh returns the record of what the rules resolve to over the view now, and the rules resolving to nothing.
Over a view telling what is not known of the objects, the addresses a rule resolved to the last time and no longer does are kept or dropped as Held.Keep says, the ones of an allow rule and the ones of a deny rule each their way, and the ones kept are addresses of the step of their rule: an address denied by a rule written before the one allowing its network is still denied first. Over any other view, as the one of a start, nothing is kept: a start has no memory.
Each object is asked of the view once: the filter and the addresses held are of one state of the cluster.
func (Record) Rules ¶
Rules returns the rules of the record, each entry read as a line of the keyword is, and the error of a rule the grammar refuses or no filter is made of.
The error names the keyword and the entry of its list, counted from 1, as net_rules rule 2: a record tells no line of the configuration the rules were read from, whose own errors name one, see ParseKeyword.
func (Record) Save ¶
Save writes the record to the file of its resource, whole or not at all: the status of the resource and the daemon read it while it is written.
func (*Record) UnmarshalJSON ¶
UnmarshalJSON reads a record, and the one an om knowing two keywords wrote, net_allow and net_deny, whose deny rules won over the allow ones, and which allowed what no rule named when it had deny rules only.
Such a record is read as the list saying the same: its deny rules, then its allow rules, each given its verb, and a last allow any when it has no allow rule. The addresses it held of all its allow rules together, and of all its deny rules, are given to the rules of each verb naming their object, see Memory.adopt.
func (Record) WithRules ¶
WithRules returns the record with the rules of the value of the keyword given in place of its own, as a configuration changed under the running resource has it, to be resolved by Refresh.
The addresses held and kept are the memory of the rules. The ones of a rule still written stay its own, wherever the rule is in the list now. The ones of a rule no longer written go to the rules of its verb still naming their object, by itself or by its namespace, and are kept or dropped there as before the change: a rule written another way, as one narrowed to a resource, is not a reason to let through what was denied. The ones of an object no rule of the verb names any more are forgotten, where Refresh would keep them as addresses their rule lost, a denied one for as long as its object exists.
Rules the grammar refuses, or no filter is made of, are an error naming the line of the value, and the record is returned as it was.
type Rule ¶
type Rule struct {
// Action says the rule lets through, or drops, what it names.
Action Action
// Kind is the noun of the rule.
Kind Kind
// Implicit says no keyword wrote the rule: it is one of the
// rules ending every list, see Rules.WithImplicit.
Implicit bool
// Line is the line of the keyword value the rule is written on,
// from 1, the empty lines not counted. For a rule read from a
// record, it is the entry of the list holding it.
Line int
// Text is the rule as written, its verb included, its words
// separated by a space.
Text string
// Prefix is the range of an address rule naming one.
Prefix netip.Prefix
// From and Key are the datastore and the key an address rule
// reads its ranges from.
From string
Key string
// Network is the cluster network of a network rule.
Network string
// Node is the cluster node of a node rule, and the one a network
// rule narrows the network to.
Node string
// Object is the path of an object rule, as written, and RID the
// resource it narrows the object to.
Object string
RID string
// Namespace is the namespace of a namespace rule, as written.
Namespace string
// HasPort says the rule is qualified by ports, PortMin to PortMax
// of the protocol Proto.
HasPort bool
PortMin uint16
PortMax uint16
Proto string
}
Rule is a line of the net_rules keyword.
func (Rule) Datastore ¶
Datastore returns the datastore an address rule reads its ranges from, for a rule of an object of the namespace given: a path starting with ./ is one of that namespace, as an object rule names an object.
The datastore may be one of another namespace. Whether its keys are read is not said here but by the view asked for them, which knows what the datastore shares, see View.Key: a filter reading the keys of a namespace that did not consent to it would tell them, address by address.
func (Rule) Foreign ¶
Foreign says the rule names an object of another namespace than the one given, or another namespace: what its administrator has no say on, so the rule is root's to write, and its addresses are not shown to who reads the status of the resource.
It is judged on what the rule resolves to, not on how it is written: a path spelling the namespace of the object is the same reference as its ./ form. A path that is none resolves to nothing, and is nobody's.
func (Rule) Hidden ¶
Hidden says the addresses of the rule are not shown to who reads the status of the resource, and counted instead: the ones of the objects of another namespace, and the ones read from a sec.
The ones read from a cfg another namespace shares with the one of the object are shown, as the ones of a cfg of its own: the share keyword of the cfg is its administrator saying the namespace of the object may read its keys, which are no secret there, and a reader of the resource is a reader of that namespace. The addresses of the objects of another namespace are hidden for want of such a consent.
func (Rule) Names ¶
Names says the rule names the object of the path given, by itself or by its namespace, for a rule of an object of the namespace given: the rule resolves to the addresses the object publishes, or to the ones of a resource of it.
func (Rule) NamespaceName ¶
NamespaceName returns the namespace a namespace rule names, for a rule of an object of the namespace given, which a dot stands for.
func (Rule) ObjectPath ¶
ObjectPath returns the object an object rule names, for a rule of an object of the namespace given: a path starting with ./ is one of that namespace, as a datastore is named, and any other is the path as written.
func (Rule) Reference ¶
Reference returns what a rule naming an object or a namespace resolves to, for a rule of an object of the namespace given, in the words of a rule: "object prod/svc/db rid ip#1", "namespace prod". It is empty for any other rule, and for a path that is none.
func (Rule) Secret ¶
Secret says the rule reads its ranges from a key of a sec: what a reader of the resource is not shown, the keys of a sec being told to who may decode them only.
func (Rule) Unsupported ¶
Unsupported returns why a rule the grammar reads is not one the backend given makes a filter of, nil when it is.
The grammar is the same for every resource, so a configuration is refused for what it asks of the resource it is written on, not for how it is written.
type Rules ¶
type Rules []Rule
Rules are the rules of a keyword, in the order written, which is the order they are matched in.
func Parse ¶
Parse returns the rules of the value of the keyword named.
A rule is a verb, allow or deny, a noun, and what qualifies the noun, and a line holds one rule. A value written on one line, as a command sets it, holds several: a verb starts a rule where the rule before it is complete, so "allow network lan allow node n1" is two rules. A word a rule may take is taken by it: "allow network lan node n1" is one rule, the part of the network lan the node n1 hands out. A rule has one verb and one noun: the verb is written again for each.
An error names the keyword, the line, and the words refused.
func ParseKeyword ¶
ParseKeyword returns the rules of the value of the keyword, as a configuration has it, for a resource whose filter the backend given applies, and the error of a rule the grammar refuses or that backend makes no filter of, naming the keyword and the line of its value.
func (Rules) HasAllow ¶
HasAllow says a rule of the list lets something through: a list with none denies everything but what the implicit rules allow, the loopback addresses and the nameservers, which is seldom what its writer means, a list of deny rules being ended by an allow any to deny them alone.
func (Rules) WithImplicit ¶
WithImplicit returns the rules followed by the ones ending every list: allow localhost, allow dns, then deny any.
What no rule matches is denied: a list says what is let through. The loopback addresses and the nameservers are allowed just before, without a rule saying so: a filter written for the peers of an application is not meant to cut it from its own node, nor from the names it resolves. They come last, so a written rule matching them wins: a deny of the cluster nodes takes the nameservers they are away, unless an allow dns is written before it.
No rule is no list: nothing is added to it, and nothing is filtered.
type Step ¶
type Step struct {
// Action says the packets matching are let through, or dropped.
Action Action `json:"action"`
// Ranges are the addresses the rule resolved to, none for a
// rule resolving to nothing for now.
Ranges []netip.Prefix `json:"ranges"`
// Proto is the protocol of a step on ports, tcp or udp, and
// Min and Max the first and the last port. A step on no port
// has no protocol.
Proto string `json:"proto,omitempty"`
Min uint16 `json:"min,omitempty"`
Max uint16 `json:"max,omitempty"`
// Implicit says the step is one of a rule no keyword wrote,
// see Rules.WithImplicit.
Implicit bool `json:"implicit,omitempty"`
}
Step is what a rule resolves to: the ranges a packet is let through from or to, or dropped, when no step before it matched.
A step on ports matches a packet from or to its ranges on these ports of the protocol alone. The port is the one of the address named, not the one of what is filtered: a packet sent to a range matches by its destination port, and one received from it by its source port. So a rule opens, or closes, a service of what it names.
func (*Step) UnmarshalJSON ¶
UnmarshalJSON reads a step, and the one an om naming its action verb wrote.
type Texts ¶
type Texts []string
Texts are the rules of a keyword as a record holds them: a rule per entry, each as its Text says it, its words separated by a space, in their order.
A keyword value is a text, a rule or several per line, laid out as the writer of the configuration liked: that is the format of the configuration file, and no reason for what is made of it to be a text too. The rules are what a record remembers, so the same rules laid out another way are the same record.
func TextsOf ¶
TextsOf returns the rules of the value of a keyword as a record holds them: a rule per entry, however the value lays them out.
A value the grammar refuses has no rules to tell: its lines are returned, their words separated by a space, the empty ones left out. They are no rules of any record, so the value still reads as a change of the rules, and reading them again refuses the same words.
func (Texts) MarshalJSON ¶
MarshalJSON writes the rules as a list, an empty one for no rule.
func (*Texts) UnmarshalJSON ¶
UnmarshalJSON reads the list of the rules, an empty one as no rule.
type View ¶
type View interface {
// Network returns the ranges of a cluster network, and false
// for a network the cluster has none of that name.
Network(name string) ([]netip.Prefix, bool)
// NetworkNode returns the part of a cluster network a node hands
// out, none for a network giving the nodes no part of their own,
// and false for a network or a node the cluster does not have.
NetworkNode(name, node string) ([]netip.Prefix, bool)
// Node returns the addresses of a cluster node, the one its
// listener is on and the ones its name resolves to, and false
// for a node the cluster does not have.
Node(name string) ([]netip.Addr, bool)
// Nodes returns the names of the cluster nodes.
Nodes() []string
// DNS returns the nameservers what is filtered resolves
// through: the ones of the node for a command run on it, the
// ones of its own resolver for a container. Opening more, as
// the nameservers of the cluster for a command that asks the
// stub resolver of its node, would open hosts it never talks
// to, on every port.
DNS() []netip.Addr
// Object returns the addresses the resources of an object
// publish, the instances of all the nodes together, and false
// for an object the cluster does not have.
Object(path naming.Path) (ObjectAddrs, bool)
// NamespaceObjects returns the objects of a namespace the
// cluster has.
NamespaceObjects(namespace string) []naming.Path
// Key returns the value of a key of a datastore, a cfg or a
// sec, as the node resolving holds it, decoded, for a rule
// of an object of the namespace given: an error that is
// ErrNoDatastore for a datastore the node does not have,
// ErrNotShared for one of another namespace whose share
// keyword does not admit the namespace given, and ErrNoKey
// for a key the datastore does not have.
//
// The view is what holds the datastore, so it is the one
// place its sharing is judged, at every read: a share taken
// back is a key no longer read.
Key(datastore naming.Path, key, namespace string) ([]byte, error)
}
View is what the rules are resolved over: the networks and the nodes of the cluster, as the node resolving knows them, and the nameservers of what the rules are resolved for.
The driver starting a resource reads the networks and the nodes from the configuration of its node, and asks the daemon the addresses of the objects its rules name, which only the daemon knows. The daemon resolves over its own data, to keep the filter of a running resource current.
func LocalView ¶
LocalView returns the view of the node the caller runs on, and ErrNoLocalView where none is registered.
func WithAddrIdentities ¶
func WithAddrIdentities(view View, identities Identities) View
WithAddrIdentities returns the view telling which objects publish the addresses of the paths, as the daemon told them with their addresses: the view a driver reads from the configuration of its node knows none, and the addresses a start records are then held by the objects that published them, not by their paths alone, see Holder.
The object is the one of each address, as the daemon resolving the rules tells it, see AddrIdentifier: a start made while a node still tells its instance of an object deleted, beside the object created again under the path, would else record the address of the first as one of the second, which the record of the delete does not lift when that node is lost before the daemon resolves the rules of the start again.
func WithDNS ¶
WithDNS returns the view with the nameservers given in place of its own: the networks and the nodes are the same for every resource of a node, and the nameservers are the ones of the resolver of each, which its driver knows.
func WithObjects ¶
WithObjects returns the view with the objects given in place of its own: the view a driver reads from the configuration of its node knows none, and the daemon tells the ones the rules name.
type Witness ¶
type Witness interface {
View
// IsUnsure says nothing tells the status of an instance of the
// object holding an address for now: its node is not heard of,
// as while its daemon restarts, or did not say yet. What its
// resources hold is then not known, which is not known gone,
// unless a record of the delete of that very object says so.
IsUnsure(holder Holder) bool
// Holders returns the objects publishing the address.
Holders(addr netip.Addr) []naming.Path
}
Witness is a view telling, beyond what the objects publish, what is not known of them: the daemon is one, which hears of the nodes it loses and of every object.