cockroach: github.com/cockroachdb/cockroach/pkg/sql/pgwire/hba Index | Files

package hba

import "github.com/cockroachdb/cockroach/pkg/sql/pgwire/hba"

Package hba implements an hba.conf parser.

Index

Package Files

hba.go parser.go scanner.go

type AnyAddr Uses

type AnyAddr struct{}

AnyAddr represents "any address" and is used when parsing "all" for the "Address" field.

func (AnyAddr) String Uses

func (AnyAddr) String() string

String implements the fmt.Formatter interface.

type Conf Uses

type Conf struct {
    Entries []Entry
}

Conf is a parsed configuration.

func Parse Uses

func Parse(input string) (*Conf, error)

Parse parses the provided HBA configuration.

func ParseAndNormalize Uses

func ParseAndNormalize(val string) (*Conf, error)

ParseAndNormalize parses the HBA configuration from the provided string and performs two tasks:

- it unicode-normalizes the usernames. Since usernames are

initialized during pgwire session initialization, this
ensures that string comparisons can be used to match usernames.

- it ensures there is one entry per username. This simplifies

the code in the authentication logic.

func (Conf) String Uses

func (c Conf) String() string

String implements the fmt.Formatter interface.

type ConnType Uses

type ConnType int

ConnType represents the type of connection matched by a rule.

const (
    // ConnLocal matches unix socket connections.
    ConnLocal ConnType = 1 << iota
    // ConnHostNoSSL matches TCP connections without SSL/TLS.
    ConnHostNoSSL
    // ConnHostSSL matches TCP connections with SSL/TLS.
    ConnHostSSL

    // ConnHostAny matches TCP connections with or without SSL/TLS.
    ConnHostAny = ConnHostNoSSL | ConnHostSSL

    // ConnAny matches any connection type. Used when registering auth
    // methods.
    ConnAny = ConnHostAny | ConnLocal
)

func ParseConnType Uses

func ParseConnType(s string) (ConnType, error)

ParseConnType parses the connection type field.

func (ConnType) String Uses

func (t ConnType) String() string

String implements the fmt.Formatter interface.

type Entry Uses

type Entry struct {
    // ConnType is the connection type to match.
    ConnType ConnType
    // Database is the list of databases to match. An empty list means
    // "match any database".
    Database []String
    // User is the list of users to match. An empty list means "match
    // any user".
    User []String
    // Address is either AnyAddr, *net.IPNet or (unsupported) String for a hostname.
    Address interface{}
    Method  String
    // MethodFn is populated during name resolution of Method.
    MethodFn     interface{}
    Options      [][2]string
    OptionQuotes []bool
}

Entry is a single line of a configuration.

func (Entry) AddressMatches Uses

func (h Entry) AddressMatches(addr net.IP) (bool, error)

AddressMatches returns true iff the provided address matches the entry. The function assumes the entry was normalized already. See ParseAndNormalize.

func (Entry) AddressString Uses

func (h Entry) AddressString() string

AddressString returns a string that describes the address field.

func (Entry) ConnMatches Uses

func (h Entry) ConnMatches(clientConn ConnType, ip net.IP) (bool, error)

ConnMatches returns true iff the provided client connection type and address matches the entry spec.

func (Entry) ConnTypeMatches Uses

func (h Entry) ConnTypeMatches(clientConn ConnType) bool

ConnTypeMatches returns true iff the provided actual client connection type matches the connection type specified in the rule.

func (Entry) DatabaseString Uses

func (h Entry) DatabaseString() string

DatabaseString returns a string that describes the database field.

func (Entry) GetOption Uses

func (h Entry) GetOption(name string) string

GetOption returns the value of option name if there is exactly one occurrence of name in the options list, otherwise the empty string.

func (Entry) GetOptions Uses

func (h Entry) GetOptions(name string) []string

GetOptions returns all values of option name.

func (Entry) OptionsString Uses

func (h Entry) OptionsString() string

OptionsString returns a string that describes the option field.

func (Entry) String Uses

func (h Entry) String() string

String implements the fmt.Formatter interface.

func (Entry) UserMatches Uses

func (h Entry) UserMatches(userName string) bool

UserMatches returns true iff the provided username matches the an entry in the User list or if the user list is empty (the entry matches all).

The provided username must be normalized already. The function assumes the entry was normalized to contain only one user and its username normalized. See ParseAndNormalize().

func (Entry) UserString Uses

func (h Entry) UserString() string

UserString returns a string that describes the username field.

type String Uses

type String struct {
    Value  string
    Quoted bool
}

String is a possibly quoted string.

func (String) Empty Uses

func (s String) Empty() bool

Empty returns true iff s is the unquoted empty string.

func (String) IsKeyword Uses

func (s String) IsKeyword(v string) bool

IsKeyword returns whether s is the non-quoted string v.

func (String) String Uses

func (s String) String() string

String implements the fmt.Formatter interface.

Package hba imports 10 packages (graph) and is imported by 2 packages. Updated 2020-02-17. Refresh now. Tools for package owners.