auth

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AuthType_IGNORE         = "IGNORE"
	AuthType_ALTER_SYSTEM   = "ALTER_SYSTEM"
	AuthType_CONNECT        = "CONNECT"
	AuthType_CREATE         = "CREATE"
	AuthType_CREATEDATABASE = "CREATEDATABASE"
	AuthType_DELETE         = "DELETE"
	AuthType_DROPDATABASE   = "DROPDATABASE"
	AuthType_DROPTABLE      = "DROPTABLE"
	AuthType_EXECUTE        = "EXECUTE"
	AuthType_INSERT         = "INSERT"
	AuthType_REFERENCES     = "REFERENCES"
	AuthType_SELECT         = "SELECT"
	AuthType_SET            = "SET"
	AuthType_SUPER          = "SUPER"
	AuthType_TEMPORARY      = "TEMPORARY"
	AuthType_TRIGGER        = "TRIGGER"
	AuthType_TRUNCATE       = "TRUNCATE"
	AuthType_UPDATE         = "UPDATE"
	AuthType_USAGE          = "USAGE"
)

These AuthType_ enums are used as the AuthType in vitess.AuthInformation.

View Source
const (
	AuthTargetType_Ignore                            = "IGNORE"
	AuthTargetType_DatabaseIdentifiers               = "DB_IDENTS"
	AuthTargetType_SchemaIdentifiers                 = "DB_SCH_IDENTS"
	AuthTargetType_TableIdentifiers                  = "DB_SCH_TABLE_IDENTS"
	AuthTargetType_ViewIdentifiers                   = "DB_SCH_VIEW_IDENTS"
	AuthTargetType_FunctionIdentifiers               = "DB_SCH_FUNCTION_IDENTS"
	AuthTargetType_SequenceIdentifiers               = "DB_SCH_SEQUENCE_IDENTS"
	AuthTargetType_AlterDefaultPrivilegesIdentifiers = "DB_SCH_ADP_IDENTS"
	AuthTargetType_TODO                              = "TODO"
)

These AuthTargetType_ enums are used as the TargetType in vitess.AuthInformation.

View Source
const (
	Privilege_SELECT       = "r"
	Privilege_INSERT       = "a"
	Privilege_UPDATE       = "w"
	Privilege_DELETE       = "d"
	Privilege_TRUNCATE     = "D"
	Privilege_REFERENCES   = "x"
	Privilege_TRIGGER      = "t"
	Privilege_CREATE       = "C"
	Privilege_CONNECT      = "c"
	Privilege_TEMPORARY    = "T"
	Privilege_EXECUTE      = "X"
	Privilege_USAGE        = "U"
	Privilege_SET          = "s"
	Privilege_ALTER_SYSTEM = "A"
	Privilege_DROP         = "Y"
)

Variables

This section is empty.

Functions

func AddDatabasePrivilege added in v0.15.0

func AddDatabasePrivilege(key DatabasePrivilegeKey, privilege GrantedPrivilege, withGrantOption bool)

AddDatabasePrivilege adds the given database privilege to the global database.

func AddDefaultPrivilege added in v1.5.0

func AddDefaultPrivilege(key DefaultPrivilegeKey, grantee RoleID, privilege GrantedPrivilege, withGrantOption bool)

AddDefaultPrivilege adds a default privilege entry to the global database.

func AddMemberToGroup added in v0.15.0

func AddMemberToGroup(member RoleID, group RoleID, withAdminOption bool, grantedBy RoleID)

AddMemberToGroup adds the member role to the group role.

func AddRoutinePrivilege added in v0.55.6

func AddRoutinePrivilege(key RoutinePrivilegeKey, privilege GrantedPrivilege, withGrantOption bool)

AddRoutinePrivilege adds the given routine privilege to the global database.

func AddSchemaPrivilege added in v0.15.0

func AddSchemaPrivilege(key SchemaPrivilegeKey, privilege GrantedPrivilege, withGrantOption bool)

AddSchemaPrivilege adds the given schema privilege to the global database.

func AddSequencePrivilege added in v0.55.6

func AddSequencePrivilege(key SequencePrivilegeKey, privilege GrantedPrivilege, withGrantOption bool)

AddSequencePrivilege adds the given sequence privilege to the global database.

func AddTablePrivilege added in v0.14.0

func AddTablePrivilege(key TablePrivilegeKey, privilege GrantedPrivilege, withGrantOption bool)

AddTablePrivilege adds the given table privilege to the global database.

func ApplyDefaultPrivilegesForNewRoutine added in v1.5.0

func ApplyDefaultPrivilegesForNewRoutine(ownerRoleID RoleID, schemaName, routineName string) bool

ApplyDefaultPrivilegesForNewRoutine applies any matching default privileges to a newly created function or procedure. Returns whether any privileges were added. Must be called under LockWrite.

func ApplyDefaultPrivilegesForNewSequence added in v1.5.0

func ApplyDefaultPrivilegesForNewSequence(ownerRoleID RoleID, schemaName, seqName string) bool

ApplyDefaultPrivilegesForNewSequence applies any matching default privileges to a newly created sequence. Returns whether any privileges were added. Must be called under LockWrite.

func ApplyDefaultPrivilegesForNewTable added in v1.5.0

func ApplyDefaultPrivilegesForNewTable(ownerRoleID RoleID, schemaName, tableName string) bool

ApplyDefaultPrivilegesForNewTable applies any matching default privileges to a newly created table. Returns whether any privileges were added. Must be called under LockWrite.

func ApplySessionAuthorization added in v1.5.0

func ApplySessionAuthorization(ctx *sql.Context, name string, reset, local bool) error

ApplySessionAuthorization checks against the authenticated connection, not the currently selected role. The authentication-time superuser entitlement is intentionally preserved when the session role changes.

func ApplySetRole added in v1.5.0

func ApplySetRole(ctx *sql.Context, name string, none, reset, local bool) error

ApplySetRole is the checked entry point for all supported SET ROLE forms. A selected role never becomes the authority for a subsequent switch.

func CanAdministerRole added in v1.5.0

func CanAdministerRole(actorRole, targetRole RoleID) bool

CanAdministerRole requires an ADMIN grant on the target, reached from the actor through inherited memberships. It is distinct from SET authority. The caller must hold the auth lock.

func CanSetRole added in v1.5.0

func CanSetRole(sessionRole, targetRole RoleID) bool

CanSetRole answers whether a session role may select a target. PostgreSQL 15 permits SET through membership even when the member is NOINHERIT. The caller must hold the auth lock.

func ClearDatabase

func ClearDatabase()

ClearDatabase clears the internal database, leaving only the default users. This is primarily for use by tests.

func DefaultPrivilegeObjTypeChar added in v1.5.0

func DefaultPrivilegeObjTypeChar(objType PrivilegeObject) string

DefaultPrivilegeObjTypeChar returns the PostgreSQL pg_default_acl defaclobjtype character for a PrivilegeObject.

func DropRole

func DropRole(name string)

DropRole removes the given role from the database. If the role does not exist, then this is a no-op.

func GenerateRandomOctetString

func GenerateRandomOctetString(length int) rfc5802.OctetString

GenerateRandomOctetString generates an OctetString filled with random bytes.

func GetRoleName added in v1.5.0

func GetRoleName(id RoleID) string

GetRoleName returns the name of the role with the given ID. Returns an empty string if the role does not exist.

func GetSuperUserAndPassword added in v0.54.4

func GetSuperUserAndPassword() (string, string)

GetSuperUserAndPassword returns the superuser and password for the server to use, as defined in the environment

func HasDatabasePrivilege added in v0.15.0

func HasDatabasePrivilege(key DatabasePrivilegeKey, privilege Privilege) bool

HasDatabasePrivilege checks whether the user has the given privilege on the associated database.

func HasRoleMembership added in v1.5.0

func HasRoleMembership(member, group RoleID) bool

HasRoleMembership checks only stored membership edges. It does not grant virtual membership to superusers or apply INHERIT, SET, or ADMIN rules. The caller must hold the auth lock.

func HasRoutinePrivilege added in v0.55.6

func HasRoutinePrivilege(key RoutinePrivilegeKey, privilege Privilege) bool

HasRoutinePrivilege checks whether the user has the given privilege on the associated routine.

func HasSchemaPrivilege added in v0.15.0

func HasSchemaPrivilege(key SchemaPrivilegeKey, privilege Privilege) bool

HasSchemaPrivilege checks whether the user has the given privilege on the associated schema.

func HasSequencePrivilege added in v0.55.6

func HasSequencePrivilege(key SequencePrivilegeKey, privilege Privilege) bool

HasSequencePrivilege checks whether the user has the given privilege on the associated sequence.

func HasTablePrivilege added in v0.14.0

func HasTablePrivilege(key TablePrivilegeKey, privilege Privilege) bool

HasTablePrivilege checks whether the user has the given privilege on the associated table.

func InheritsPrivileges added in v1.5.0

func InheritsPrivileges(effectiveRole, targetRole RoleID) bool

InheritsPrivileges follows only paths whose member role has INHERIT. Role attributes, including SUPERUSER and BYPASSRLS, are never inherited here. The caller must hold the auth lock.

func Init added in v0.14.0

func Init(dEnv *env.DoltEnv, cfg Config)

Init handles all initialization needs in this package.

func InitializeSessionIdentity added in v1.5.0

func InitializeSessionIdentity(sess sql.Session, name string) error

InitializeSessionIdentity is the explicit connection/bootstrap entry point. It snapshots only the authentication-time superuser entitlement. Call it after authentication and before executing any SQL on the session.

func InstallDoltPrincipalProvider added in v1.5.0

func InstallDoltPrincipalProvider(sess sql.Session)

InstallDoltPrincipalProvider makes Dolt's branch-control user follow the effective SQL role. The connection's Client.User remains the login principal.

func IsSuperUser added in v0.15.0

func IsSuperUser(role RoleID) bool

IsSuperUser returns whether the given role is a SUPERUSER.

func LockRead added in v0.14.0

func LockRead(f func())

LockRead takes an anonymous function and runs it while using a read lock. This ensures that the lock is automatically released once the function finishes.

func LockWrite added in v0.14.0

func LockWrite(f func())

LockWrite takes an anonymous function and runs it while using a write lock. This ensures that the lock is automatically released once the function finishes.

func OverwriteDatabase added in v1.2.0

func OverwriteDatabase(data []byte) error

OverwriteDatabase replaces the entire contents of the auth database, both in memory and on disk, with the deserialized contents of |data|. This is used on cluster standbys to apply the auth state replicated from the primary. The previous state is retained if deserialization fails.

func PersistChanges added in v0.14.0

func PersistChanges(ctx *sql.Context, rsc *doltdb.ReplicationStatusController) error

PersistChanges will save the state of the global database to disk (assuming we are not using the pure in-memory implementation). When cluster replication is enabled, the new state is also offered to the standby replicas, and the replication-ack waiters are appended to |rsc|. Callers must hold the write lock, and should pass |rsc| to WaitForReplication once the lock is released.

func ReadSerializedDatabase added in v1.2.0

func ReadSerializedDatabase() ([]byte, error)

ReadSerializedDatabase returns the serialized auth database as persisted to the auth database file, or nil when running with the pure in-memory implementation. The file is written on every auth change, so its contents match the live state. Unlike serializing the live state, reading the file takes no locks, which matters because cluster replication calls this while holding its own locks (see PersistChanges, which is called with the auth write lock held and takes replication locks — the opposite order).

func RemoveDatabasePrivilege added in v0.15.0

func RemoveDatabasePrivilege(key DatabasePrivilegeKey, privilege GrantedPrivilege, grantOptionOnly bool)

RemoveDatabasePrivilege removes the privilege from the global database. If `grantOptionOnly` is true, then only the WITH GRANT OPTION portion is revoked. If `grantOptionOnly` is false, then the full privilege is removed. If the GrantedBy field contains a valid RoleID, then only the privilege associated with that granter is removed. Otherwise, the privilege is completely removed for the grantee.

func RemoveDatabaseRoleSettings added in v1.5.0

func RemoveDatabaseRoleSettings(database string)

RemoveDatabaseRoleSettings removes every setting that targets the given database, which is used when the database is dropped. Database names are case-insensitive, so this matches the name case-insensitively. Callers must hold the write lock.

func RemoveDefaultPrivilege added in v1.5.0

func RemoveDefaultPrivilege(key DefaultPrivilegeKey, grantee RoleID, privilege GrantedPrivilege, grantOptionOnly bool)

RemoveDefaultPrivilege removes a default privilege entry from the global database. If grantOptionOnly is true, only the WITH GRANT OPTION flag is revoked.

func RemoveMemberFromGroup added in v0.15.0

func RemoveMemberFromGroup(member RoleID, group RoleID, adminOptionOnly bool)

RemoveMemberFromGroup removes the member from the group. If `adminOptionOnly` is true, then only the WITH ADMIN OPTION portion is revoked. If `adminOptionOnly` is false, then the member is fully is removed.

func RemoveRoutinePrivilege added in v0.55.6

func RemoveRoutinePrivilege(key RoutinePrivilegeKey, privilege GrantedPrivilege, grantOptionOnly bool)

RemoveRoutinePrivilege removes the privilege from the global database. If `grantOptionOnly` is true, then only the WITH GRANT OPTION portion is revoked. If `grantOptionOnly` is false, then the full privilege is removed.

func RemoveSchemaPrivilege added in v0.15.0

func RemoveSchemaPrivilege(key SchemaPrivilegeKey, privilege GrantedPrivilege, grantOptionOnly bool)

RemoveSchemaPrivilege removes the privilege from the global database. If `grantOptionOnly` is true, then only the WITH GRANT OPTION portion is revoked. If `grantOptionOnly` is false, then the full privilege is removed. If the GrantedBy field contains a valid RoleID, then only the privilege associated with that granter is removed. Otherwise, the privilege is completely removed for the grantee.

func RemoveSequencePrivilege added in v0.55.6

func RemoveSequencePrivilege(key SequencePrivilegeKey, privilege GrantedPrivilege, grantOptionOnly bool)

RemoveSequencePrivilege removes the privilege from the global database. If `grantOptionOnly` is true, then only the WITH GRANT OPTION portion is revoked. If `grantOptionOnly` is false, then the full privilege is removed.

func RemoveTablePrivilege added in v0.14.0

func RemoveTablePrivilege(key TablePrivilegeKey, privilege GrantedPrivilege, grantOptionOnly bool)

RemoveTablePrivilege removes the privilege from the global database. If `grantOptionOnly` is true, then only the WITH GRANT OPTION portion is revoked. If `grantOptionOnly` is false, then the full privilege is removed. If the GrantedBy field contains a valid RoleID, then only the privilege associated with that granter is removed. Otherwise, the privilege is completely removed for the grantee.

func RenameRole added in v0.14.0

func RenameRole(oldName string, newName string)

RenameRole renames the role with the old name to the new name. If the role does not exist, then this is a no-op.

func ResetAllRoleSettings added in v1.5.0

func ResetAllRoleSettings(key RoleSettingKey)

ResetAllRoleSettings removes every parameter from the given key. Callers must hold the write lock.

func ResetRoleSetting added in v1.5.0

func ResetRoleSetting(key RoleSettingKey, name string)

ResetRoleSetting removes the parameter from the given key. This is a no-op if the parameter is not set. Callers must hold the write lock.

func RoleExists

func RoleExists(name string) bool

RoleExists returns whether the given role exists.

func RoleNameForSession added in v1.5.0

func RoleNameForSession(id RoleID) (string, bool)

RoleNameForSession resolves the current name of a stable role ID without taking the auth lock. Dolt's search-path expansion may run inside auth checks, where taking the same lock again would deadlock.

func SelectedRoleSetting added in v1.5.0

func SelectedRoleSetting(ctx *sql.Context) (string, error)

SelectedRoleSetting projects the role GUC from typed identity state. NONE is a real selection state, distinct from selecting the session role.

func SessionAuthorizationSetting added in v1.5.0

func SessionAuthorizationSetting(ctx *sql.Context) (string, error)

SessionAuthorizationSetting returns the current session role name.

func SetClusterReplicator added in v1.2.0

func SetClusterReplicator(replicator cluster.ReplicatingAuthPersister)

SetClusterReplicator routes all subsequent auth database persistence through |replicator|, which persists the serialized state locally and replicates it to cluster standbys. Called during server startup when cluster replication is configured.

func SetRole

func SetRole(role Role)

SetRole sets the role matching the given name. This will add a role that does not yet exist, and overwrite an existing role.

func SetRoleSetting added in v1.5.0

func SetRoleSetting(key RoleSettingKey, name string, value string)

SetRoleSetting sets the parameter for the given key. Parameter names are case-insensitive, and a parameter that is already set keeps its position, which matches the ordering of setconfig in Postgres. Callers must hold the write lock.

func WaitForReplication added in v1.2.0

func WaitForReplication(ctx *sql.Context, rsc doltdb.ReplicationStatusController)

WaitForReplication blocks until the replication acks accumulated in |rsc| complete, subject to the dolt_cluster_ack_writes_timeout_secs system variable. It is a no-op when |rsc| holds no waiters (e.g. when cluster replication is not enabled). Callers must not hold the auth database lock.

func WriteSerializedDatabase added in v1.2.0

func WriteSerializedDatabase(data []byte) error

WriteSerializedDatabase writes an already-serialized auth database payload to the auth database file. It does not touch the in-memory state; use OverwriteDatabase to replace both.

Types

type AuthContext added in v0.14.0

type AuthContext struct {
	// contains filtered or unexported fields
}

AuthContext contains the auth portion of the context when converting from the Postgres AST to the Vitess AST.

func NewAuthContext added in v0.14.0

func NewAuthContext() *AuthContext

NewAuthContext returns a new *AuthContext.

func (*AuthContext) PeekAuthType added in v0.14.0

func (ctx *AuthContext) PeekAuthType() string

PeekAuthType returns the AuthType that is on the top of the stack. This does not remove it from the stack. Returns AuthType_IGNORE if the stack is empty.

func (*AuthContext) PopAuthType added in v0.14.0

func (ctx *AuthContext) PopAuthType() string

PopAuthType returns the AuthType that is on the top of the stack. This also removes it from the stack. Returns AuthType_IGNORE if the stack is empty.

func (*AuthContext) PushAuthType added in v0.14.0

func (ctx *AuthContext) PushAuthType(authType string)

PushAuthType pushes the given AuthType into the context's stack.

type AuthorizationHandler added in v0.14.0

type AuthorizationHandler struct {
	// contains filtered or unexported fields
}

AuthorizationHandler handles vitess.AuthInformation for Doltgres.

func (*AuthorizationHandler) CheckDatabase added in v0.14.0

func (h *AuthorizationHandler) CheckDatabase(ctx *sql.Context, aqs sql.AuthorizationQueryState, dbName string) error

CheckDatabase implements the sql.AuthorizationHandler interface.

func (*AuthorizationHandler) CheckSchema added in v0.14.0

func (h *AuthorizationHandler) CheckSchema(ctx *sql.Context, aqs sql.AuthorizationQueryState, dbName string, schemaName string) error

CheckSchema implements the sql.AuthorizationHandler interface.

func (*AuthorizationHandler) CheckTable added in v0.14.0

func (h *AuthorizationHandler) CheckTable(ctx *sql.Context, aqs sql.AuthorizationQueryState, dbName string, schemaName string, tableName string) error

CheckTable implements the sql.AuthorizationHandler interface.

func (*AuthorizationHandler) HandleAuth added in v0.14.0

HandleAuth implements the sql.AuthorizationHandler interface.

func (*AuthorizationHandler) HandleAuthNode added in v0.14.0

HandleAuthNode implements the sql.AuthorizationHandler interface.

func (*AuthorizationHandler) HandleResolvedTableAuth added in v1.4.0

func (h *AuthorizationHandler) HandleResolvedTableAuth(ctx *sql.Context, aqs sql.AuthorizationQueryState, auth vitess.AuthInformation, node sql.Node) error

HandleResolvedTableAuth implements the sql.ResolvedTableAuthorizationHandler interface.

func (*AuthorizationHandler) NewQueryState added in v0.14.0

NewQueryState implements the sql.AuthorizationHandler interface.

type AuthorizationHandlerFactory added in v0.14.0

type AuthorizationHandlerFactory struct{}

AuthorizationHandlerFactory is the factory for Doltgres.

func (AuthorizationHandlerFactory) CreateHandler added in v0.14.0

CreateHandler implements the sql.AuthorizationHandlerFactory interface.

type AuthorizationQueryState added in v0.14.0

type AuthorizationQueryState struct {
	// contains filtered or unexported fields
}

AuthorizationQueryState contains any cached state for a query.

func (AuthorizationQueryState) AuthorizationQueryStateImpl added in v0.14.0

func (state AuthorizationQueryState) AuthorizationQueryStateImpl()

AuthorizationQueryStateImpl implements the sql.AuthorizationQueryState interface.

func (AuthorizationQueryState) Error added in v0.14.0

func (state AuthorizationQueryState) Error() error

Error implements the sql.AuthorizationQueryState interface.

type Config added in v0.54.6

type Config interface {
	AuthFilePath() string
}

Config is an interface that exists as pulling the actual config package would cause a cyclical dependency.

type Database added in v0.14.0

type Database struct {
	// contains filtered or unexported fields
}

Database contains all information pertaining to authorization and privileges. This is a global structure that is shared between all branches.

type DatabasePrivilegeKey added in v0.15.0

type DatabasePrivilegeKey struct {
	Role RoleID
	Name string
}

DatabasePrivilegeKey points to a specific database object.

type DatabasePrivilegeValue added in v0.15.0

type DatabasePrivilegeValue struct {
	Key        DatabasePrivilegeKey
	Privileges map[Privilege]map[GrantedPrivilege]bool
}

DatabasePrivilegeValue is the value associated with the DatabasePrivilegeKey.

type DatabasePrivileges added in v0.15.0

type DatabasePrivileges struct {
	Data map[DatabasePrivilegeKey]DatabasePrivilegeValue
}

DatabasePrivileges contains the privileges given to a role on a database.

func NewDatabasePrivileges added in v0.15.0

func NewDatabasePrivileges() *DatabasePrivileges

NewDatabasePrivileges returns a new *DatabasePrivileges.

type DefaultPrivilegeGranteeValue added in v1.5.0

type DefaultPrivilegeGranteeValue struct {
	Grantee    RoleID
	Privileges map[Privilege]map[GrantedPrivilege]bool
}

DefaultPrivilegeGranteeValue stores the privileges granted to a specific role within a default ACL.

type DefaultPrivilegeKey added in v1.5.0

type DefaultPrivilegeKey struct {
	OwnerRole  RoleID
	Schema     string          // empty = applicable to any schema
	ObjectType PrivilegeObject // TABLE, SEQUENCE, FUNCTION, SCHEMA, TYPE
}

DefaultPrivilegeKey identifies the context for a set of default privileges: the owner role, the optional schema scope, and the object type.

type DefaultPrivilegeValue added in v1.5.0

type DefaultPrivilegeValue struct {
	Key      DefaultPrivilegeKey
	Grantees map[RoleID]DefaultPrivilegeGranteeValue
}

DefaultPrivilegeValue stores the grantee ACL entries for a given DefaultPrivilegeKey.

func GetAllDefaultPrivileges added in v1.5.0

func GetAllDefaultPrivileges() []DefaultPrivilegeValue

GetAllDefaultPrivileges returns all default privilege entries.

type DefaultPrivileges added in v1.5.0

type DefaultPrivileges struct {
	Data map[DefaultPrivilegeKey]DefaultPrivilegeValue
}

DefaultPrivileges stores the default privileges automatically applied when objects are created.

func NewDefaultPrivileges added in v1.5.0

func NewDefaultPrivileges() *DefaultPrivileges

NewDefaultPrivileges returns a new *DefaultPrivileges.

type GrantedPrivilege added in v0.14.0

type GrantedPrivilege struct {
	Privilege
	GrantedBy RoleID
}

GrantedPrivilege specifies details.

type MembershipGrant added in v1.5.0

type MembershipGrant struct {
	Member        RoleID
	GrantedRole   RoleID
	Grantor       RoleID
	AdminOption   bool
	InheritOption *bool
	SetOption     *bool
}

MembershipGrant is the logical view of a membership. Nil option pointers identify a PostgreSQL 15 legacy grant: INHERIT comes from role attributes, and SET is allowed through structural membership. Explicit options need an auth-file format migration before they can be written.

func MembershipGrants added in v1.5.0

func MembershipGrants(member RoleID) []MembershipGrant

MembershipGrants returns the grants for a member without exposing the current pair-keyed storage. The caller must hold the auth lock.

type Privilege added in v0.14.0

type Privilege string

Privilege represents some permission for a database object. https://www.postgresql.org/docs/15/ddl-priv.html

func GetAllPrivileges added in v0.14.0

func GetAllPrivileges() []Privilege

GetAllPrivileges returns every Privilege.

func (Privilege) ACLAbbreviation added in v0.14.0

func (p Privilege) ACLAbbreviation() string

ACLAbbreviation returns the name of the privilege using the Access Control List abbreviation.

func (Privilege) String added in v0.14.0

func (p Privilege) String() string

String returns the name of the privilege (uppercased).

type PrivilegeObject added in v0.14.0

type PrivilegeObject byte

PrivilegeObject is the database object that privileges are applied to. https://www.postgresql.org/docs/15/ddl-priv.html

const (
	PrivilegeObject_DATABASE PrivilegeObject = iota
	PrivilegeObject_DOMAIN
	PrivilegeObject_FUNCTION // Also applies to procedures and routines
	PrivilegeObject_FOREIGN_DATA_WRAPPER
	PrivilegeObject_FOREIGN_SERVER
	PrivilegeObject_LANGUAGE
	PrivilegeObject_LARGE_OBJECT
	PrivilegeObject_PARAMETER
	PrivilegeObject_SCHEMA
	PrivilegeObject_SEQUENCE
	PrivilegeObject_TABLE
	PrivilegeObject_TABLE_COLUMN
	PrivilegeObject_TABLESPACE
	PrivilegeObject_TYPE
)

func GetAllPrivilegeObjects added in v0.14.0

func GetAllPrivilegeObjects() []PrivilegeObject

GetAllPrivilegeObjects returns every PrivilegeObject.

func (PrivilegeObject) AllPrivileges added in v0.14.0

func (po PrivilegeObject) AllPrivileges() []Privilege

AllPrivileges returns all valid privileges that may be applied to this object.

func (PrivilegeObject) DefaultPublicPrivileges added in v0.14.0

func (po PrivilegeObject) DefaultPublicPrivileges() []Privilege

DefaultPublicPrivileges return the default PUBLIC privileges for this object.

func (PrivilegeObject) IsValid added in v0.14.0

func (po PrivilegeObject) IsValid(privilege Privilege) bool

IsValid returns whether the given Privilege is valid for the PrivilegeObject, as not all privileges are valid for all objects.

func (PrivilegeObject) String added in v0.14.0

func (po PrivilegeObject) String() string

String returns the name of the privilege (uppercased).

type PrivilegeSetLayer added in v0.55.6

type PrivilegeSetLayer struct {
	// contains filtered or unexported fields
}

PrivilegeSetLayer is used to allow some functions that inspect the GMS privilege set (such as branch control) to interface with Doltgres' auth system.

func NewPrivilegeSetLayer added in v0.55.6

func NewPrivilegeSetLayer(ctx *sql.Context) (*PrivilegeSetLayer, error)

NewPrivilegeSetLayer creates a query privilege set from the effective role.

func (*PrivilegeSetLayer) Count added in v0.55.6

func (privSet *PrivilegeSetLayer) Count() int

Count implements the interface sql.PrivilegeSet.

func (*PrivilegeSetLayer) Database added in v0.55.6

func (privSet *PrivilegeSetLayer) Database(dbName string) sql.PrivilegeSetDatabase

Database implements the interface sql.PrivilegeSet.

func (*PrivilegeSetLayer) Equals added in v0.55.6

func (privSet *PrivilegeSetLayer) Equals(otherPs sql.PrivilegeSet) bool

Equals implements the interface sql.PrivilegeSet.

func (*PrivilegeSetLayer) GetDatabases added in v0.55.6

func (privSet *PrivilegeSetLayer) GetDatabases() []sql.PrivilegeSetDatabase

GetDatabases implements the interface sql.PrivilegeSet.

func (*PrivilegeSetLayer) Has added in v0.55.6

func (privSet *PrivilegeSetLayer) Has(privileges ...sql.PrivilegeType) bool

Has implements the interface sql.PrivilegeSet.

func (*PrivilegeSetLayer) HasPrivileges added in v0.55.6

func (privSet *PrivilegeSetLayer) HasPrivileges() bool

HasPrivileges implements the interface sql.PrivilegeSet.

func (*PrivilegeSetLayer) ToSlice added in v0.55.6

func (privSet *PrivilegeSetLayer) ToSlice() []sql.PrivilegeType

ToSlice implements the interface sql.PrivilegeSet.

type PrivilegeSetLayerDatabase added in v0.55.6

type PrivilegeSetLayerDatabase struct {
	Db string
	// contains filtered or unexported fields
}

PrivilegeSetLayerDatabase is the database portion of PrivilegeSetLayer.

func (*PrivilegeSetLayerDatabase) Count added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) Count() int

Count implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) Equals added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) Equals(otherPs sql.PrivilegeSetDatabase) bool

Equals implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) GetRoutines added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) GetRoutines() []sql.PrivilegeSetRoutine

GetRoutines implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) GetTables added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) GetTables() []sql.PrivilegeSetTable

GetTables implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) Has added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) Has(privileges ...sql.PrivilegeType) bool

Has implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) HasPrivileges added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) HasPrivileges() bool

HasPrivileges implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) Name added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) Name() string

Name implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) Routine added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) Routine(routineName string, isProcedure bool) sql.PrivilegeSetRoutine

Routine implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) Table added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) Table(tblName string) sql.PrivilegeSetTable

Table implements the interface sql.PrivilegeSetDatabase.

func (*PrivilegeSetLayerDatabase) ToSlice added in v0.55.6

func (privSet *PrivilegeSetLayerDatabase) ToSlice() []sql.PrivilegeType

ToSlice implements the interface sql.PrivilegeSetDatabase.

type Role

type Role struct {
	Name                      string               // rolname
	IsSuperUser               bool                 // rolsuper
	InheritPrivileges         bool                 // rolinherit
	CanCreateRoles            bool                 // rolcreaterole
	CanCreateDB               bool                 // rolcreatedb
	CanLogin                  bool                 // rolcanlogin
	IsReplicationRole         bool                 // rolreplication
	CanBypassRowLevelSecurity bool                 // rolbypassrls
	ConnectionLimit           int32                // rolconnlimit
	Password                  *ScramSha256Password // rolpassword
	ValidUntil                *time.Time           // rolvaliduntil
	// contains filtered or unexported fields
}

Role represents a role/user.

func AllRoles added in v0.57.2

func AllRoles() []Role

AllRoles returns every role in the database, sorted by the role's name. This does not handle locking, so callers should protect the call with LockRead.

func CreateDefaultRole

func CreateDefaultRole(name string) Role

CreateDefaultRole creates the given role object with all default values set.

func CurrentRole added in v1.5.0

func CurrentRole(ctx *sql.Context) (Role, error)

CurrentRole resolves the acting role for an ordinary SQL authorization decision. Call CurrentRoleLocked instead when already holding the auth lock.

func CurrentRoleLocked added in v1.5.0

func CurrentRoleLocked(ctx *sql.Context) (Role, error)

CurrentRoleLocked resolves the acting role by stable ID. The caller must already hold the auth read or write lock.

func GetRole

func GetRole(name string) Role

GetRole returns the role with the given name. Use RoleExists to determine if the role exists, as this will return a role with the default values set if it does not exist.

func LookupRole added in v1.5.0

func LookupRole(name string) (Role, bool)

LookupRole returns an existing role by name. The caller must hold LockRead or LockWrite; this accessor never takes the auth lock itself.

func LookupRoleByID added in v1.5.0

func LookupRoleByID(id RoleID) (Role, bool)

LookupRoleByID resolves an identity without reusing a later role of the same name. The caller must hold LockRead or LockWrite.

func ResolveRoleID added in v1.5.0

func ResolveRoleID(id sessionstate.RoleID) (Role, error)

ResolveRoleID reads the current role record. It acquires the auth read lock; callers already inside LockRead/LockWrite must use LookupRoleByID directly.

func (*Role) ID added in v0.14.0

func (r *Role) ID() RoleID

ID returns this Role's ID value.

func (*Role) IsValid added in v0.14.0

func (r *Role) IsValid() bool

IsValid returns true when the role has a valid ID.

type RoleID added in v0.14.0

type RoleID uint64

RoleID represents a Role's ID. IDs are assigned during load and will be stable throughout the server's current process. IDs are useful for referencing a specific role without using their name, since names can change. This is basically a special OID specific to roles. Eventually, we'll have a proper OID system, but this is a placeholder for now. TODO: need to replace with id.InternalUser

func GetAllGroupsWithMember added in v0.15.0

func GetAllGroupsWithMember(member RoleID, inheritsPrivilegesOnly bool) []RoleID

GetAllGroupsWithMember returns every group that the role is a direct member of. This can also filter by groups that the member has privilege access on.

func HasDatabasePrivilegeGrantOption added in v0.15.0

func HasDatabasePrivilegeGrantOption(key DatabasePrivilegeKey, privilege Privilege) RoleID

HasDatabasePrivilegeGrantOption checks whether the user has WITH GRANT OPTION for the given privilege on the associated database. Returns the role that has WITH GRANT OPTION, or an invalid role if WITH GRANT OPTION is not available.

func HasRoutinePrivilegeGrantOption added in v0.55.6

func HasRoutinePrivilegeGrantOption(key RoutinePrivilegeKey, privilege Privilege) RoleID

HasRoutinePrivilegeGrantOption checks whether the user has WITH GRANT OPTION for the given privilege on the associated routine. Returns the role that has WITH GRANT OPTION, or an invalid role if not available.

func HasSchemaPrivilegeGrantOption added in v0.15.0

func HasSchemaPrivilegeGrantOption(key SchemaPrivilegeKey, privilege Privilege) RoleID

HasSchemaPrivilegeGrantOption checks whether the user has WITH GRANT OPTION for the given privilege on the associated schema. Returns the role that has WITH GRANT OPTION, or an invalid role if WITH GRANT OPTION is not available.

func HasSequencePrivilegeGrantOption added in v0.55.6

func HasSequencePrivilegeGrantOption(key SequencePrivilegeKey, privilege Privilege) RoleID

HasSequencePrivilegeGrantOption checks whether the user has WITH GRANT OPTION for the given privilege on the associated sequence. Returns the role that has WITH GRANT OPTION, or an invalid role if not available.

func HasTablePrivilegeGrantOption added in v0.14.0

func HasTablePrivilegeGrantOption(key TablePrivilegeKey, privilege Privilege) RoleID

HasTablePrivilegeGrantOption checks whether the user has WITH GRANT OPTION for the given privilege on the associated table. Returns the role that has WITH GRANT OPTION, or an invalid role if WITH GRANT OPTION is not available.

func (RoleID) IsValid added in v0.14.0

func (id RoleID) IsValid() bool

IsValid returns true when the RoleID has a valid value. It does not indicate that the RoleID is attached to a role that actually exists.

type RoleMembership added in v0.15.0

type RoleMembership struct {
	Data map[RoleID]map[RoleID]RoleMembershipValue
}

RoleMembership contains all roles that have been granted to other roles.

func NewRoleMembership added in v0.15.0

func NewRoleMembership() *RoleMembership

NewRoleMembership returns a new *RoleMembership.

type RoleMembershipValue added in v0.15.0

type RoleMembershipValue struct {
	Member          RoleID
	Group           RoleID
	WithAdminOption bool
	GrantedBy       RoleID
}

RoleMembershipValue contains specific membership information between two roles.

func AllRoleMemberships added in v0.57.2

func AllRoleMemberships() []RoleMembershipValue

AllRoleMemberships returns every role membership in the database, sorted by the group's ID and then the member's ID. This does not handle locking, so callers should protect the call with LockRead.

type RoleSetting added in v1.5.0

type RoleSetting struct {
	Name  string
	Value string
}

RoleSetting is a single configuration parameter and its value, stored as the text that will be applied when a session starts.

func RoleSettingsForKey added in v1.5.0

func RoleSettingsForKey(key RoleSettingKey) []RoleSetting

RoleSettingsForKey returns a copy of the settings for the given key. Callers must hold the read or write lock.

func SessionRoleSettings added in v1.5.0

func SessionRoleSettings(roleName string, database string) []RoleSetting

SessionRoleSettings returns the settings that apply to a session for the given role connected to the given database. Settings are returned from least to most specific, so applying them in order gives precedence to the more specific ones: every role and database, the database, the role, and finally the role within the database. This handles locking internally.

type RoleSettingKey added in v1.5.0

type RoleSettingKey struct {
	Role     RoleID
	Database string
}

RoleSettingKey identifies the target of a group of settings. An invalid Role applies the settings to every role, and an empty Database applies the settings to every database. ALTER DATABASE d SET is therefore stored identically to ALTER ROLE ALL IN DATABASE d SET, as is done in Postgres.

type RoleSettings added in v1.5.0

type RoleSettings struct {
	Data map[RoleSettingKey][]RoleSetting
}

RoleSettings contains the configuration parameter defaults set through ALTER ROLE ... SET and ALTER DATABASE ... SET. This mirrors Postgres' pg_db_role_setting catalog.

func NewRoleSettings added in v1.5.0

func NewRoleSettings() *RoleSettings

NewRoleSettings returns a new *RoleSettings.

type RoleSettingsEntry added in v1.5.0

type RoleSettingsEntry struct {
	Key      RoleSettingKey
	RoleName string
	Settings []RoleSetting
}

RoleSettingsEntry is a single row of pg_db_role_setting.

func AllRoleSettings added in v1.5.0

func AllRoleSettings() []RoleSettingsEntry

AllRoleSettings returns every group of settings, sorted by database and then role name. Callers must hold the read or write lock.

type RoutinePrivilegeKey added in v0.55.6

type RoutinePrivilegeKey struct {
	Role     RoleID
	Schema   string
	Name     string
	ArgTypes string
}

RoutinePrivilegeKey points to a specific routine object. An empty Name represents all routines in the schema. ArgTypes is a comma-separated list of argument type SQL strings, e.g. "integer,text".

type RoutinePrivilegeValue added in v0.55.6

type RoutinePrivilegeValue struct {
	Key        RoutinePrivilegeKey
	Privileges map[Privilege]map[GrantedPrivilege]bool
}

RoutinePrivilegeValue is the value associated with the RoutinePrivilegeKey.

type RoutinePrivileges added in v0.55.6

type RoutinePrivileges struct {
	Data map[RoutinePrivilegeKey]RoutinePrivilegeValue
}

RoutinePrivileges contains the privileges given to a role on a routine (function or procedure).

func NewRoutinePrivileges added in v0.55.6

func NewRoutinePrivileges() *RoutinePrivileges

NewRoutinePrivileges returns a new *RoutinePrivileges.

type SchemaPrivilegeKey added in v0.15.0

type SchemaPrivilegeKey struct {
	Role   RoleID
	Schema string
}

SchemaPrivilegeKey points to a specific schema object.

type SchemaPrivilegeValue added in v0.15.0

type SchemaPrivilegeValue struct {
	Key        SchemaPrivilegeKey
	Privileges map[Privilege]map[GrantedPrivilege]bool
}

SchemaPrivilegeValue is the value associated with the SchemaPrivilegeKey.

type SchemaPrivileges added in v0.15.0

type SchemaPrivileges struct {
	Data map[SchemaPrivilegeKey]SchemaPrivilegeValue
}

SchemaPrivileges contains the privileges given to a role on a schema.

func NewSchemaPrivileges added in v0.15.0

func NewSchemaPrivileges() *SchemaPrivileges

NewSchemaPrivileges returns a new *SchemaPrivileges.

type ScramSha256Password

type ScramSha256Password struct {
	Iterations uint32
	Salt       rfc5802.OctetString
	StoredKey  rfc5802.OctetString
	ServerKey  rfc5802.OctetString
}

ScramSha256Password is the struct form of an encrypted password.

func NewScramSha256Password

func NewScramSha256Password(rawPassword string) (*ScramSha256Password, error)

NewScramSha256Password creates a ScramSha256Password with a randomly-generated salt.

func (ScramSha256Password) AsPasswordString

func (password ScramSha256Password) AsPasswordString() string

AsPasswordString returns the password as defined in https://www.postgresql.org/docs/15/catalog-pg-authid.html

type SequencePrivilegeKey added in v0.55.6

type SequencePrivilegeKey struct {
	Role   RoleID
	Schema string
	Name   string
}

SequencePrivilegeKey points to a specific sequence object. An empty Name represents all sequences in the schema.

type SequencePrivilegeValue added in v0.55.6

type SequencePrivilegeValue struct {
	Key        SequencePrivilegeKey
	Privileges map[Privilege]map[GrantedPrivilege]bool
}

SequencePrivilegeValue is the value associated with the SequencePrivilegeKey.

type SequencePrivileges added in v0.55.6

type SequencePrivileges struct {
	Data map[SequencePrivilegeKey]SequencePrivilegeValue
}

SequencePrivileges contains the privileges given to a role on a sequence.

func NewSequencePrivileges added in v0.55.6

func NewSequencePrivileges() *SequencePrivileges

NewSequencePrivileges returns a new *SequencePrivileges.

type TablePrivilegeKey added in v0.14.0

type TablePrivilegeKey struct {
	Role  RoleID
	Table doltdb.TableName
}

TablePrivilegeKey points to a specific table object.

type TablePrivilegeValue added in v0.14.0

type TablePrivilegeValue struct {
	Key        TablePrivilegeKey
	Privileges map[Privilege]map[GrantedPrivilege]bool
}

TablePrivilegeValue is the value associated with the TablePrivilegeKey.

type TablePrivileges added in v0.14.0

type TablePrivileges struct {
	Data map[TablePrivilegeKey]TablePrivilegeValue
}

TablePrivileges contains the privileges given to a role on a table.

func NewTablePrivileges added in v0.14.0

func NewTablePrivileges() *TablePrivileges

NewTablePrivileges returns a new *TablePrivileges.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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