Documentation
¶
Overview ¶
Package driver describes the kinds of non-SSH resources komando can talk to (databases, caches, queues, object storage) and the risk levels its safety checks work with.
Index ¶
- Constants
- Variables
- func ClickHouseVerified(raw string) string
- func IsCopyStdin(code string) bool
- func JSONValue(v any) any
- func OracleBlock(sql string) bool
- func OracleDone(sql string) bool
- func ParseDelimiter(trimmed string) (delim string, ok bool)
- func Placeholders(kind, sql string) (n int, ok bool)
- func RuleReason(id string) string
- func WithoutCA(raw string) string
- type BigQueryConn
- type Kind
- type Lexer
- type OracleOptions
- type Risk
- type Rule
- type SQLPlan
- type SQLServerOptions
- type SnowflakeConn
- type Statement
- type Target
- type Verdict
Constants ¶
const BigQueryEndpoint = "https://bigquery.googleapis.com"
BigQueryEndpoint is Google's address for the BigQuery API.
Variables ¶
var ErrSecretNotFound = errors.New("secret not found")
ErrSecretNotFound is what ResolveSecret wraps for a missing secret.
var ResolveSecret func(ref string) (string, error)
ResolveSecret reads a secret reference; the cli sets it to the vault's.
Functions ¶
func ClickHouseVerified ¶ added in v0.9.0
ClickHouseVerified is raw with tls=true, and port 8443 in place of 8123 (ClickHouse's plain HTTP port), for a new conn that crosses the network. "" when raw does not parse.
func IsCopyStdin ¶ added in v0.3.0
IsCopyStdin reports whether code (a statement as Lexer.Last returns it) is COPY ... FROM stdin, whose data lines follow it.
func JSONValue ¶
JSONValue converts a value from a database, cache or bucket into something JSON keeps exactly: text stays text, binary becomes {"base64": ...}, times become RFC 3339, and integers too large for a JSON number become strings.
func OracleBlock ¶ added in v0.9.0
OracleBlock reports whether sql starts a PL/SQL block or stored unit, which a line with only / ends (db shell).
func OracleDone ¶ added in v0.9.0
OracleDone reports whether sql ends with ; outside quotes and comments, read as Oracle reads it: \ is itself, q'[...]' may hold ', and # and $ are part of names (db shell). SQL that komando refuses as written counts as done, so running it shows why.
func ParseDelimiter ¶ added in v0.3.0
ParseDelimiter reads a mysql client DELIMITER line (trimmed, at the start of a statement). ok is false when the line is not a DELIMITER command; delim is "" when it is one komando does not follow: no delimiter, more than one word, or a quote or backslash in it.
func Placeholders ¶
Placeholders counts the parameters in sql ($1.. in postgres, ? in mysql and sqlite, @p1.. in sqlserver), outside strings and comments. ok is false when the count is not known (sqlite named parameters, or SQL that does not parse).
func RuleReason ¶
RuleReason is the human explanation of a rule ID.
Types ¶
type BigQueryConn ¶ added in v0.9.0
type BigQueryConn struct {
Project string
Dataset string // the default dataset for names without one; may be ""
Location string // where jobs run: EU, US, europe-west1, ...; "" lets BigQuery pick
Endpoint string // https://bigquery.googleapis.com, or ?endpoint=
}
BigQueryConn is what a bigquery:// URL says, beyond the Target.
func ParseBigQueryURL ¶ added in v0.9.0
func ParseBigQueryURL(raw string) (BigQueryConn, error)
ParseBigQueryURL reads a bigquery:// conn URL.
type Kind ¶
type Kind struct {
Name string `json:"name"`
Family string `json:"family"` // the command that works with it: db | cache | queue | storage | cluster | registry
Schemes []string `json:"schemes"`
DefaultPort int `json:"default_port,omitempty"`
File bool `json:"file,omitempty"` // a local file, not a network service
Example string `json:"example"`
}
Kind is a resource type komando knows.
type Lexer ¶ added in v0.3.0
type Lexer struct {
Delim string // mysql: the current DELIMITER
// contains filtered or unexported fields
}
Lexer follows a SQL file the way psql (kind "postgres") or the mysql client (kind "mysql") reads it: quotes, E-strings, dollar quotes, comments (nested in PostgreSQL), and where a statement ends (outside parentheses and, in PostgreSQL, outside BEGIN ATOMIC ... END bodies). CheckRestore and komando's own restore use the same Lexer, so the file that was checked is the file that is run.
func (*Lexer) Empty ¶ added in v0.3.0
Empty reports whether the current statement has no code yet (only white space and comments).
func (*Lexer) EndLine ¶ added in v0.3.0
func (l *Lexer) EndLine()
EndLine tells the lexer a line ended (inside a statement, a line break separates words).
func (*Lexer) Idle ¶ added in v0.3.0
Idle reports whether the lexer is outside quotes, dollar quotes and comments.
func (*Lexer) Last ¶ added in v0.3.0
Last is the code of the statement that ended last: upper-cased words and punctuation, comments removed, quoted text shown as a pair of its quote marks.
func (*Lexer) Next ¶ added in v0.3.0
Next reads line from byte i. It returns the position just after the delimiter that ends the current statement (then Last is that statement), or -1 when the line ends first; and the position of a client command (a backslash outside quotes and comments), or -1. It stops at whichever comes first. Call EndLine after the last Next of a line.
type OracleOptions ¶ added in v0.9.0
type OracleOptions struct {
TLS string // true (TCPS, certificate checked) | skip-verify | false; "" when the URL has none
SID string // sid=NAME: an old database reached by its SID instead of a service name
}
OracleOptions are the URL options an oracle:// conn takes.
func ParseOracleOptions ¶ added in v0.9.0
func ParseOracleOptions(q url.Values) (OracleOptions, error)
ParseOracleOptions reads the options of an oracle:// URL.
type Risk ¶
type Risk int
Risk says how much an operation can change. The safety check (guard) decides from it whether --yes or --allow-dangerous is needed.
func (Risk) MarshalText ¶
type Rule ¶
Rule is a named SQL check, listed by `komando policy`.
type SQLPlan ¶
type SQLPlan struct {
Statements []Statement `json:"statements"`
Verdict
// contains filtered or unexported fields
}
SQLPlan is the result of ClassifySQL: the statements and the overall verdict (the highest risk of any statement).
func ClassifySQL ¶
ClassifySQL splits sql into statements and classifies each one. kind is a conn kind (postgres, mysql, sqlite). Transaction control (BEGIN, COMMIT, ...) is refused: komando owns the transaction, and a COMMIT inside a dry run would make it real.
func PlanOnly ¶ added in v0.9.0
PlanOnly is plan for SQL that SQL Server or Oracle only plans (SET SHOWPLAN_TEXT ON, EXPLAIN PLAN; db explain) or BigQuery dry-runs: a statement that the rollback would undo reads, and so does Oracle DDL that EXPLAIN PLAN takes and any BigQuery statement a dry run takes. Statements that may act outside the transaction keep their rating.
func (SQLPlan) NeedsWrite ¶
NeedsWrite reports whether a statement must not run without --write. Unknown statements (often typos) that are not otherwise flagged may run in PostgreSQL and SQLite, whose read-only mode refuses them if they do write, and whose error for a typo is clearer than komando's. MySQL's read-only transaction does not cover admin statements, so there an unknown statement needs --write.
type SQLServerOptions ¶ added in v0.9.0
type SQLServerOptions struct {
Encrypt string // true | strict | false | disable; "" when the URL has none
SkipVerify bool // tls=skip-verify: encrypt without checking the certificate
ReadOnly bool // applicationintent=readonly: ask an availability group for a readable replica
Database string // database=NAME, for URLs written the way go-mssqldb takes them
}
SQLServerOptions are the URL options a sqlserver:// conn takes. Their names are read without regard to case (Encrypt=true works too), as SQL Server's own drivers do.
func ParseSQLServerOptions ¶ added in v0.9.0
func ParseSQLServerOptions(q url.Values) (SQLServerOptions, error)
ParseSQLServerOptions reads the options of a sqlserver:// URL.
type SnowflakeConn ¶ added in v0.9.0
type SnowflakeConn struct {
Account string // as written, without the domain
JWTAccount string // the account part of a key-pair token: upper case, no region
Host string // ACCOUNT.snowflakecomputing.com, with - for _
User string
Database string
Schema string
Warehouse string
Role string
}
SnowflakeConn is what a snowflake:// URL says, beyond the Target.
func ParseSnowflakeURL ¶ added in v0.9.0
func ParseSnowflakeURL(raw string) (SnowflakeConn, error)
ParseSnowflakeURL reads a snowflake:// conn URL.
type Statement ¶
type Statement struct {
SQL string `json:"sql"`
Keyword string `json:"keyword"`
Risk Risk `json:"risk"`
Rows bool `json:"-"` // returns a result set (SELECT, RETURNING, SHOW, ...)
NoTx bool `json:"no_tx,omitempty"` // cannot run inside a transaction, so cannot be rolled back
NoRollback bool `json:"no_rollback,omitempty"` // runs in the transaction, but a rollback may not undo it (setval, DO, COPY ... PROGRAM)
Unknown bool `json:"unknown,omitempty"` // keyword not recognised; rated write to be safe
}
Statement is one classified SQL statement.
type Target ¶
type Target struct {
Kind Kind `json:"kind"`
Address string `json:"address,omitempty"` // host:port for network kinds (s3, sqs, pubsub: the endpoint)
Path string `json:"path,omitempty"` // file path for file kinds; gcs, azblob: the endpoint's path (an emulator)
User string `json:"user,omitempty"` // s3, sqs: the access key ID (not secret)
Database string `json:"database,omitempty"` // SQL database name, redis DB number, or rabbitmq vhost
Bucket string `json:"bucket,omitempty"` // s3
Prefix string `json:"prefix,omitempty"` // storage: keys are relative to this folder
Region string `json:"region,omitempty"` // s3, sqs
Secure bool `json:"secure,omitempty"` // TLS (rediss, https endpoint)
TLS string `json:"tls,omitempty"` // mysql, oracle, clickhouse: the tls= setting (true, skip-verify, preferred, false); ftps, registry, sqlserver: skip-verify (registry also false)
CA string `json:"ca,omitempty"` // registry, postgres, mysql, redis, memcached, mongodb, kafka, rabbitmq, nats, sqlserver, oracle, clickhouse, snowflake, bigquery: secret:NAME holding the PEM CA certificate to trust
Resolve string `json:"resolve,omitempty"` // registry, s3: IP:port to connect to in place of Address (?resolve=)
Cluster bool `json:"cluster,omitempty"` // redis: a Redis Cluster; Address is one node (?cluster=1)
Sentinel string `json:"sentinel,omitempty"` // redis: the master's name at the Sentinels (?sentinel=NAME)
Sentinels []string `json:"sentinels,omitempty"` // redis: more Sentinels besides Address (?sentinels=h2:26379,h3:26379)
SentinelAuth bool `json:"sentinel_auth,omitempty"` // redis: the Sentinels want the conn's login too (?sentinel_auth=same)
Brokers []string `json:"brokers,omitempty"` // kafka, nats: every server the URL lists; Address is the first
SASL string `json:"sasl,omitempty"` // kafka: plain, scram-sha-256 or scram-sha-512 (?sasl=)
Management string `json:"management,omitempty"` // rabbitmq: host:port of the management HTTP API (?management=PORT)
Creds string `json:"creds,omitempty"` // nats: secret:NAME holding the .creds file (user JWT and NKey seed) to log in with
Domain string `json:"domain,omitempty"` // nats: the JetStream domain; smb: the Windows domain of the user (both ?domain=; smb also DOMAIN;user)
Account string `json:"account,omitempty"` // sqs: the AWS account that owns the queues, when not the login's own (?account=)
Project string `json:"project,omitempty"` // pubsub: the Google Cloud project
}
Target is a parsed conn URL.
func Parse ¶
Parse reads a conn URL such as postgres://app@db.internal:5432/app or sqlite:///var/lib/app.db. The kind comes from the scheme. URLs that carry a password are refused: passwords belong in the vault.
func (Target) CAPEM ¶ added in v0.8.0
CAPEM is the conn's ?ca= certificates as clean PEM: only the CERTIFICATE blocks a pool takes, with no headers, comments or blank lines, for a client that reads them from a file (pg_dump, mysqldump). "" without a ca=.
func (Target) DialAddress ¶ added in v0.5.0
DialAddress is where a connection goes: the ?resolve= address when the URL has one, otherwise Address. TLS and HTTP keep using Address's name.
func (Target) Need ¶
Need checks that t belongs to family (a command name: db, cache, storage), with a hint naming the right command.
type Verdict ¶
type Verdict struct {
Risk Risk `json:"risk"`
RuleIDs []string `json:"rules,omitempty"` // matched rules, for error messages
Reasons []string `json:"reasons,omitempty"`
}
Verdict is the result of classifying one operation.
func CheckRestore ¶
CheckRestore reads a whole plain SQL backup. It returns an error naming the first line with a client command that could run code or read files where the restore runs, or the first place where komando cannot be sure how psql or mysql would read the file. Otherwise the verdict names what the SQL does beyond writing data (sql-program, sql-server-file, ...), with the line where each first appears; it is empty for an ordinary dump.
func DataDelete ¶
func DataDelete() Verdict
DataDelete is the verdict for deleting cache keys or stored objects.
Source Files
¶
- amqp_url.go
- bigquery_url.go
- ca.go
- clickhouse_url.go
- driver.go
- kafka_url.go
- mongo_url.go
- nats_url.go
- oracle_url.go
- pubsub_url.go
- redis_topology.go
- restore.go
- snowflake_url.go
- sql.go
- sql_bigquery.go
- sql_clickhouse.go
- sql_oracle.go
- sql_oracle_calls.go
- sql_snowflake.go
- sql_tsql.go
- sqlserver_url.go
- sqs_url.go
- storage_urls.go
- value.go