secgroup

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package secgroup implements security groups (§8.3): AWS-style allow rules between containers, attached to services. It validates rules, compiles every group into the sets and rules agents enforce with nftables, and answers reachability questions with the same semantics.

Index

Constants

View Source
const (
	KindAny         = "any"         // anywhere
	KindCluster     = "cluster"     // the cluster nodes' mesh addresses
	KindCIDR        = "cidr"        // an IPv4 address or CIDR
	KindGroup       = "group"       // members of a security group
	KindService     = "service"     // tasks of a service
	KindEnvironment = "environment" // every task in an environment
	KindProject     = "project"     // every task in a project
	KindSelfEnv     = "self-env"    // the member's own environment
	KindSelfProject = "self-project"
	KindSelf        = "self" // members of the rule's own group
)

Peer kinds.

View Source
const EtcdServiceID = "etcd"

EtcdServiceID matches the platform etcd's containers (label syncloud.service_id).

Variables

This section is empty.

Functions

func Compile

func Compile(m *Model) *agentv1.SecurityPolicy

Compile turns every group into the policy agents enforce.

func Describe

func Describe(r Rule, dir string) string

Describe is a rule as one line, e.g. "tcp 5432 from service shop/production/web".

Types

type Endpoint

type Endpoint struct {
	ServiceID    string
	Project, Env string // a standalone job run
	IP           string
	Platform     bool
}

Endpoint is one side of a connection: a service's task, a job run without a service, an address, or the platform (Traefik and the controller).

type Group

type Group struct {
	ID, Project, Name string
	Default           bool
	Inbound, Outbound []Rule
	Services          []string // attached service IDs
}

Group is a security group with parsed rules.

func DatabaseGroup

func DatabaseGroup(d store.Database) Group

DatabaseGroup is the security group a database uses: its own members on any port, and its access list over TCP. Outbound is open (replication, Sentinel and DNS).

func EtcdGroup

func EtcdGroup(pgIPs []string) Group

EtcdGroup is the platform etcd's group: its members on any port, and the PostgreSQL members on the client port.

func FromStore

func FromStore(g store.SecurityGroup) Group

FromStore parses a stored group's rules.

type Match

type Match struct {
	GroupID   string `json:"groupId"`
	Group     string `json:"group"` // project/name
	Direction string `json:"direction"`
	Index     int    `json:"index"`
	Rule      Rule   `json:"rule"`
}

Match names the rule that allowed a connection.

type Model

type Model struct {
	Envs        map[string][]string // project -> environment names
	Services    []Service
	Standalone  []Standalone
	Groups      []Group
	ClusterIPs  []string
	PlatformIPs []string
	// contains filtered or unexported fields
}

Model is everything compilation and evaluation need.

func Load

func Load(ctx context.Context, st *store.Store) (*Model, error)

Load builds the model from the database: every group, service, task and job run address, and the cluster's node addresses.

func (*Model) EffectiveLines

func (m *Model) EffectiveLines(serviceID string) []string

EffectiveLines lists what applies to a service, one line per rule; the preview diffs these.

func (*Model) Evaluate

func (m *Model) Evaluate(src, dst Endpoint, proto string, port int) Verdict

Evaluate answers whether src can open a connection to dst (a service's tasks) on proto/port, and which rules decide it.

func (*Model) GroupsOf

func (m *Model) GroupsOf(serviceID string) []*Group

GroupsOf returns the groups a service uses: those attached to it, or its project's default group.

func (*Model) Members

func (m *Model) Members(g *Group) []*Service

Members returns the services using g.

func (*Model) ResetIndex

func (m *Model) ResetIndex()

ResetIndex must be called after changing a model's groups or services.

type Peer

type Peer struct {
	Kind               string
	Project, Env, Name string
	CIDR               netip.Prefix
}

Peer is a parsed rule peer.

func ParsePeer

func ParsePeer(s, project string) (Peer, string, error)

ParsePeer parses a peer written relative to project (the group's project) and returns it with its canonical spelling:

any, cluster, 10.0.0.0/8, group:[project/]name, service:[project/]env/name,
environment:self|[project/]env, project:self|name

type Rule

type Rule struct {
	Protocol    string   `json:"protocol"` // tcp | udp | icmp | any
	Ports       string   `json:"ports"`    // "", "5432", "8000-8100"
	Peers       []string `json:"peers"`    // sources (inbound) or destinations (outbound)
	Description string   `json:"description"`
}

Rule allows traffic to (inbound) or from (outbound) a group's members.

func Validate

func Validate(project string, rules []Rule, exists func(p Peer) bool) ([]Rule, error)

Validate checks a group's rules and canonicalizes their peers. exists reports whether a referenced project, environment, service or group exists (kind, project, env, name).

type Service

type Service struct {
	ID, Project, Env, Name string
	IPs                    []string
}

Service is a service with the addresses of its tasks and job runs.

type Standalone

type Standalone struct {
	Project, Env, IP string
}

Standalone is a job run that belongs to no service.

type Verdict

type Verdict struct {
	Allowed bool   `json:"allowed"`
	Egress  *Match `json:"egress,omitempty"`
	Ingress *Match `json:"ingress,omitempty"`
	Reason  string `json:"reason"`
}

Verdict is the answer to "can A reach B on proto/port?".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL