Documentation ¶
Index ¶
- Variables
- func Register(name string, options ...Option) error
- func RegisterFactory(name string, factory func() ([]Option, error)) error
- func Reset()
- func Setup() error
- type AccessCheckFunc
- type AuthPlugin
- type AuthenticateRequest
- type BootstrapContext
- type ConnEventInfo
- type ConnEventTp
- type Extensions
- func (es *Extensions) Bootstrap(ctx BootstrapContext) error
- func (es *Extensions) GetAccessCheckFuncs() (funcs []AccessCheckFunc)
- func (es *Extensions) GetAuthPlugins() map[string]*AuthPlugin
- func (es *Extensions) Manifests() []*Manifest
- func (es *Extensions) NewSessionExtensions() *SessionExtensions
- type FunctionContext
- type FunctionDef
- type Manifest
- type Option
- func WithBootstrap(fn func(BootstrapContext) error) Option
- func WithBootstrapSQL(sqlList ...string) Option
- func WithClose(fn func()) Option
- func WithCustomAccessCheck(fn AccessCheckFunc) Option
- func WithCustomAuthPlugins(authPlugins []*AuthPlugin) Option
- func WithCustomDynPrivs(privs []string) Option
- func WithCustomFunctions(funcs []*FunctionDef) Option
- func WithCustomSysVariables(vars []*variable.SysVar) Option
- func WithSessionHandlerFactory(factory func() *SessionHandler) Option
- type SessionExtensions
- type SessionHandler
- type SessionPool
- type StmtEventInfo
- type StmtEventTp
- type VerifyDynamicPrivRequest
- type VerifyStaticPrivRequest
Constants ¶
This section is empty.
Variables ¶
var RegisterDynamicPrivilege func(string) error
RegisterDynamicPrivilege is used to resolve dependency cycle
var RegisterExtensionFunc func(*FunctionDef) error
RegisterExtensionFunc is to avoid dependency cycle
var RemoveDynamicPrivilege func(string) bool
RemoveDynamicPrivilege is used to resolve dependency cycle
var RemoveExtensionFunc func(string)
RemoveExtensionFunc is to avoid dependency cycle
Functions ¶
func RegisterFactory ¶
RegisterFactory registers a new extension with a factory
Types ¶
type AccessCheckFunc ¶
type AccessCheckFunc func(db, tbl, column string, priv mysql.PrivilegeType, sem bool) []string
AccessCheckFunc is a function that returns a dynamic privilege list for db/tbl/column access
type AuthPlugin ¶
type AuthPlugin struct { // Name is the name of the auth plugin. It will be registered as a system variable in TiDB which can be used inside the `CREATE USER ... IDENTIFIED WITH 'plugin_name'` statement. Name string // RequiredClientSidePlugin is the name of the client-side plugin required by the server-side plugin. It will be used to check if the client has the required plugin installed and require the client to use it if installed. // The user can require default MySQL plugins such as 'caching_sha2_password' or 'mysql_native_password'. // If this is empty then `AuthPlugin.Name` is used as the required client-side plugin. RequiredClientSidePlugin string // AuthenticateUser is called when a client connects to the server as a user and the server authenticates the user. // If an error is returned, the login attempt fails, otherwise it succeeds. // request: The request context for the authentication plugin to authenticate a user AuthenticateUser func(request AuthenticateRequest) error // GenerateAuthString is a function for user to implement customized ways to encode the password (e.g. hash/salt/clear-text). The returned string will be stored as the encoded password in the mysql.user table. // If the input password is considered as invalid, this should return an error. // pwd: User's input password in CREATE/ALTER USER statements in clear-text GenerateAuthString func(pwd string) (string, bool) // ValidateAuthString checks if the password hash stored in the mysql.user table or passed in from `IDENTIFIED AS` is valid. // This is called when retrieving an existing user to make sure the password stored is valid and not modified and make sure user is passing a valid password hash in `IDENTIFIED AS`. // pwdHash: hash of the password stored in the internal user table ValidateAuthString func(pwdHash string) bool // VerifyPrivilege is called for each user queries, and serves as an extra check for privileges for the user. // It will only be executed if the user has already been granted the privilege in SQL layer. // Returns true if user has the requested privilege. // request: The request context for the authorization plugin to authorize a user's static privilege VerifyPrivilege func(request VerifyStaticPrivRequest) bool // VerifyDynamicPrivilege is called for each user queries, and serves as an extra check for dynamic privileges for the user. // It will only be executed if the user has already been granted the dynamic privilege in SQL layer. // Returns true if user has the requested privilege. // request: The request context for the authorization plugin to authorize a user's dynamic privilege VerifyDynamicPrivilege func(request VerifyDynamicPrivRequest) bool }
AuthPlugin contains attributes needed for an authentication plugin.
type AuthenticateRequest ¶
type AuthenticateRequest struct { // User The username in the connect attempt User string // StoredAuthString The user's auth string stored in mysql.user table StoredAuthString string // InputAuthString The user's auth string passed in from the connection attempt in bytes InputAuthString []byte // Salt Randomly generated salt for the current connection Salt []byte // ConnState The TLS connection state (contains the TLS certificate) if client is using TLS. It will be nil if the client is not using TLS ConnState *tls.ConnectionState // AuthConn Interface for the plugin to communicate with the client AuthConn conn.AuthConn }
AuthenticateRequest contains the context for the authentication plugin to authenticate a user.
type BootstrapContext ¶
type BootstrapContext interface { context.Context // ExecuteSQL is used to execute a sql ExecuteSQL(ctx context.Context, sql string) ([]chunk.Row, error) // EtcdClient returns the etcd client EtcdClient() *clientv3.Client // SessionPool returns the session pool of domain SessionPool() SessionPool }
BootstrapContext is the context used by extension in bootstrap
type ConnEventInfo ¶
type ConnEventInfo struct { *variable.ConnectionInfo SessionAlias string ActiveRoles []*auth.RoleIdentity Error error }
ConnEventInfo is the connection info for the event
type ConnEventTp ¶
type ConnEventTp uint8
ConnEventTp is the type of the connection event
const ( // ConnConnected means connection connected, but not handshake yet ConnConnected ConnEventTp = iota // ConnHandshakeAccepted means connection is accepted after handshake ConnHandshakeAccepted // ConnHandshakeRejected means connections is rejected after handshake ConnHandshakeRejected // ConnReset means the connection is reset ConnReset // ConnDisconnected means the connection is disconnected ConnDisconnected )
type Extensions ¶
type Extensions struct {
// contains filtered or unexported fields
}
Extensions contains all extensions that have already setup
func GetExtensions ¶
func GetExtensions() (*Extensions, error)
GetExtensions returns all extensions after setup
func (*Extensions) Bootstrap ¶
func (es *Extensions) Bootstrap(ctx BootstrapContext) error
Bootstrap bootstraps all extensions
func (*Extensions) GetAccessCheckFuncs ¶
func (es *Extensions) GetAccessCheckFuncs() (funcs []AccessCheckFunc)
GetAccessCheckFuncs returns spec functions of the custom access check
func (*Extensions) GetAuthPlugins ¶
func (es *Extensions) GetAuthPlugins() map[string]*AuthPlugin
GetAuthPlugins returns the registered authentication plugins.
func (*Extensions) Manifests ¶
func (es *Extensions) Manifests() []*Manifest
Manifests returns a extension manifests
func (*Extensions) NewSessionExtensions ¶
func (es *Extensions) NewSessionExtensions() *SessionExtensions
NewSessionExtensions creates a new ConnExtensions object
type FunctionContext ¶
type FunctionContext interface { context.Context User() *auth.UserIdentity ActiveRoles() []*auth.RoleIdentity CurrentDB() string ConnectionInfo() *variable.ConnectionInfo EvalArgs(row chunk.Row) ([]types.Datum, error) }
FunctionContext is an interface to provide context to the custom function
type FunctionDef ¶
type FunctionDef struct { // Name is the function's name Name string // EvalTp is the type of the return value EvalTp types.EvalType // ArgTps is the argument types ArgTps []types.EvalType // OptionalArgsLen is the length of the optional args OptionalArgsLen int // EvalStringFunc is the eval function when `EvalTp` is `types.ETString` EvalStringFunc func(ctx FunctionContext, row chunk.Row) (string, bool, error) // EvalIntFunc is the eval function when `EvalTp` is `types.ETInt` EvalIntFunc func(ctx FunctionContext, row chunk.Row) (int64, bool, error) // RequireDynamicPrivileges is a function to return a list of dynamic privileges to check. RequireDynamicPrivileges func(sem bool) []string }
FunctionDef is the definition for the custom function
func (*FunctionDef) Validate ¶
func (def *FunctionDef) Validate() error
Validate validates the function definition
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
Manifest is an extension's manifest
type Option ¶
type Option func(m *Manifest)
Option represents an option to initialize an extension
func WithBootstrap ¶
func WithBootstrap(fn func(BootstrapContext) error) Option
WithBootstrap specifies the bootstrap func of an extension
func WithBootstrapSQL ¶
WithBootstrapSQL the bootstrap SQL list
func WithClose ¶
func WithClose(fn func()) Option
WithClose specifies the close function of an extension. It will be invoked when `extension.Reset` is called
func WithCustomAccessCheck ¶
func WithCustomAccessCheck(fn AccessCheckFunc) Option
WithCustomAccessCheck specifies the custom db/tbl/column dynamic privilege check
func WithCustomAuthPlugins ¶
func WithCustomAuthPlugins(authPlugins []*AuthPlugin) Option
WithCustomAuthPlugins specifies the custom authentication plugins available for the system.
func WithCustomDynPrivs ¶
WithCustomDynPrivs specifies dynamic privileges of an extension
func WithCustomFunctions ¶
func WithCustomFunctions(funcs []*FunctionDef) Option
WithCustomFunctions specifies custom functions
func WithCustomSysVariables ¶
WithCustomSysVariables specifies custom variables of an extension
func WithSessionHandlerFactory ¶
func WithSessionHandlerFactory(factory func() *SessionHandler) Option
WithSessionHandlerFactory specifies a factory function to handle session
type SessionExtensions ¶
type SessionExtensions struct {
// contains filtered or unexported fields
}
SessionExtensions is the extensions
func (*SessionExtensions) GetAuthPlugin ¶
func (es *SessionExtensions) GetAuthPlugin(name string) (*AuthPlugin, bool)
GetAuthPlugin returns the required registered extension auth plugin and whether it exists.
func (*SessionExtensions) HasStmtEventListeners ¶
func (es *SessionExtensions) HasStmtEventListeners() bool
HasStmtEventListeners returns a bool that indicates if any stmt event listener exists
func (*SessionExtensions) OnConnectionEvent ¶
func (es *SessionExtensions) OnConnectionEvent(tp ConnEventTp, event *ConnEventInfo)
OnConnectionEvent will be called when a connection event happens
func (*SessionExtensions) OnStmtEvent ¶
func (es *SessionExtensions) OnStmtEvent(tp StmtEventTp, event StmtEventInfo)
OnStmtEvent will be called when a stmt event happens
type SessionHandler ¶
type SessionHandler struct { OnConnectionEvent func(ConnEventTp, *ConnEventInfo) OnStmtEvent func(StmtEventTp, StmtEventInfo) }
SessionHandler is used to listen session events
type SessionPool ¶
SessionPool is the pool for session
type StmtEventInfo ¶
type StmtEventInfo interface { // User returns the user of the session User() *auth.UserIdentity // ActiveRoles returns the active roles of the user ActiveRoles() []*auth.RoleIdentity // CurrentDB returns the current database CurrentDB() string // ConnectionInfo returns the connection info of the current session ConnectionInfo() *variable.ConnectionInfo // SessionAlias returns the session alias value set by user SessionAlias() string // StmtNode returns the parsed ast of the statement // When parse error, this method will return a nil value StmtNode() ast.StmtNode // ExecuteStmtNode will return the `ast.ExecuteStmt` node when the current statement is EXECUTE, // otherwise a nil value will be returned ExecuteStmtNode() *ast.ExecuteStmt // ExecutePreparedStmt will return the prepared stmt node for the EXECUTE statement. // If the current statement is not EXECUTE or prepared statement is not found, a nil value will be returned ExecutePreparedStmt() ast.StmtNode // PreparedParams will return the params for the EXECUTE statement PreparedParams() []types.Datum // OriginalText will return the text of the statement. // Notice that for the EXECUTE statement, the prepared statement text will be used as the return value OriginalText() string // SQLDigest will return the normalized and redact text of the `OriginalText()` SQLDigest() (normalized string, digest *parser.Digest) // AffectedRows will return the affected rows of the current statement AffectedRows() uint64 // RelatedTables will return the related tables of the current statement // For statements succeeding to build logical plan, it uses the `visitinfo` to get the related tables // For statements failing to build logical plan, it traverses the ast node to get the related tables RelatedTables() []stmtctx.TableEntry // GetError will return the error when the current statement is failed GetError() error }
StmtEventInfo is the information of stmt event
type StmtEventTp ¶
type StmtEventTp uint8
StmtEventTp is the type of the statement event
const ( // StmtError means the stmt is failed StmtError StmtEventTp = iota // StmtSuccess means the stmt is successfully executed StmtSuccess )
type VerifyDynamicPrivRequest ¶
type VerifyDynamicPrivRequest struct { // User The username in the connect attempt User string // Host The host that the user is connecting from Host string // DynamicPriv the dynamic privilege required by the user's SQL statement DynamicPriv string // ConnState The TLS connection state (contains the TLS certificate) if client is using TLS. It will be nil if the client is not using TLS ConnState *tls.ConnectionState // ActiveRoles List of active MySQL roles for the current user ActiveRoles []*auth.RoleIdentity // WithGrant Whether the statement to be executed is granting the user privilege for executing GRANT statements WithGrant bool }
VerifyDynamicPrivRequest contains the context for the plugin to authorize a user's dynamic privilege.
type VerifyStaticPrivRequest ¶
type VerifyStaticPrivRequest struct { // User The username in the connect attempt User string // Host The host that the user is connecting from Host string // DB The database to check for privilege DB string // Table The table to check for privilege Table string // Column The column to check for privilege (currently just a placeholder in TiDB as column-level privilege is not supported by TiDB yet) Column string // StaticPriv The privilege type of the SQL statement that will be executed StaticPriv mysql.PrivilegeType // ConnState The TLS connection state (contains the TLS certificate) if client is using TLS. It will be nil if the client is not using TLS ConnState *tls.ConnectionState // ActiveRoles List of active MySQL roles for the current user ActiveRoles []*auth.RoleIdentity }
VerifyStaticPrivRequest contains the context for the plugin to authorize a user's static privilege.