{"modulePath":"github.com/cockroachdb/cockroachdb-parser","version":"v0.25.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package privilege\n\nPackage privilege outlines the basic privilege system for cockroach.\n\n## Variables\n\n```go\nvar (\n\t// AllPrivileges is populated during init.\n\tAllPrivileges         List\n\tReadData              = List{SELECT}\n\tReadWriteData         = List{SELECT, INSERT, DELETE, UPDATE}\n\tReadWriteSequenceData = List{SELECT, UPDATE, USAGE}\n\tDBPrivileges          = List{ALL, BACKUP, CONNECT, CREATE, DROP, RESTORE, ZONECONFIG}\n\tTablePrivileges       = List{ALL, BACKUP, CHANGEFEED, CREATE, DROP, SELECT, INSERT, DELETE, UPDATE, ZONECONFIG, TRIGGER, REPLICATIONDEST, REPLICATIONSOURCE}\n\tSchemaPrivileges      = List{ALL, CREATE, USAGE}\n\tTypePrivileges        = List{ALL, USAGE}\n\tRoutinePrivileges     = List{ALL, EXECUTE}\n\t// SequencePrivileges is appended with TablePrivileges as well. This is because\n\t// before v22.2 we treated Sequences the same as Tables. This is to avoid making\n\t// certain privileges unavailable after upgrade migration.\n\t// Note that \"CREATE, CHANGEFEED, INSERT, DELETE, ZONECONFIG\" are no-op privileges on sequences.\n\tSequencePrivileges = List{ALL, USAGE, SELECT, UPDATE, CREATE, CHANGEFEED, DROP, INSERT, DELETE, ZONECONFIG}\n\tGlobalPrivileges   = List{\n\t\tALL, BACKUP, RESTORE, MODIFYCLUSTERSETTING, EXTERNALCONNECTION, VIEWACTIVITY, VIEWACTIVITYREDACTED,\n\t\tVIEWCLUSTERSETTING, CANCELQUERY, NOSQLLOGIN, VIEWCLUSTERMETADATA, VIEWDEBUG, EXTERNALIOIMPLICITACCESS, VIEWJOB,\n\t\tMODIFYSQLCLUSTERSETTING, REPLICATION, MANAGEVIRTUALCLUSTER, VIEWSYSTEMTABLE, CREATEROLE, CREATELOGIN, CREATEDB, CONTROLJOB,\n\t\tREPAIRCLUSTER, BYPASSRLS, REPLICATIONDEST, REPLICATIONSOURCE,\n\t}\n\tVirtualTablePrivileges       = List{ALL, SELECT}\n\tExternalConnectionPrivileges = List{ALL, USAGE, DROP}\n)\n```\nPredefined sets of privileges.\n\n```go\nvar ByDisplayName map[KindDisplayName]Kind\n```\nByDisplayName is a map of display name -\u003e kind value. It is populated by init. All names use upper case.\n\nNote that all internal keys are also added into this map to allow for backward-compatibility.\n\n```go\nvar ByInternalKey map[KindInternalKey]Kind\n```\nByInternalKey is a map of internal key -\u003e kind value. It is populated by init. All keys use upper case.\n\n## Functions\n\n```go\nfunc KeyToName(key string) (string, error)\n```\nKeyToName converts a privilege key to its name.\n\n```go\nfunc ValidatePrivileges(privileges List, objectType ObjectType) error\n```\nValidatePrivileges returns an error if any privilege in privileges cannot be granted on the given objectType.\n\n## Types\n\n```go\ntype Kind uint32\n```\nKind defines a privilege. This is output by the parser, and used to generate the privilege bitfields in the PrivilegeDescriptor.\n\n```go\nconst (\n\tALL    Kind = 1\n\tCREATE Kind = 2\n\tDROP   Kind = 3\n\n\tSELECT                   Kind = 5\n\tINSERT                   Kind = 6\n\tDELETE                   Kind = 7\n\tUPDATE                   Kind = 8\n\tUSAGE                    Kind = 9\n\tZONECONFIG               Kind = 10\n\tCONNECT                  Kind = 11\n\tRULE                     Kind = 12\n\tMODIFYCLUSTERSETTING     Kind = 13\n\tEXTERNALCONNECTION       Kind = 14\n\tVIEWACTIVITY             Kind = 15\n\tVIEWACTIVITYREDACTED     Kind = 16\n\tVIEWCLUSTERSETTING       Kind = 17\n\tCANCELQUERY              Kind = 18\n\tNOSQLLOGIN               Kind = 19\n\tEXECUTE                  Kind = 20\n\tVIEWCLUSTERMETADATA      Kind = 21\n\tVIEWDEBUG                Kind = 22\n\tBACKUP                   Kind = 23\n\tRESTORE                  Kind = 24\n\tEXTERNALIOIMPLICITACCESS Kind = 25\n\tCHANGEFEED               Kind = 26\n\tVIEWJOB                  Kind = 27\n\tMODIFYSQLCLUSTERSETTING  Kind = 28\n\tREPLICATION              Kind = 29\n\tMANAGEVIRTUALCLUSTER     Kind = 30\n\tVIEWSYSTEMTABLE          Kind = 31\n\tCREATEROLE               Kind = 32\n\tCREATELOGIN              Kind = 33\n\tCREATEDB                 Kind = 34\n\tCONTROLJOB               Kind = 35\n\tREPAIRCLUSTER            Kind = 36\n\tTRIGGER                  Kind = 37\n\tBYPASSRLS                Kind = 38\n\tREPLICATIONDEST          Kind = 39\n\tREPLICATIONSOURCE        Kind = 40\n)\n```\nList of privileges. ALL is specifically encoded so that it will automatically pick up new privileges. Do not change values of privileges. These correspond to the position of the privilege in a bit field and are expected to stay constant.\n\n```go\nfunc (k Kind) DisplayName() KindDisplayName\n```\nDisplayName reports the display name for a privilege.\n\n```go\nfunc (k Kind) InternalKey() KindInternalKey\n```\nInternalKey returns the KindInternalKey for a Kind (see docs on KindInternalKey). The InternalKey must not change between releases.\n\n```go\nfunc (k Kind) IsSetIn(bits uint64) bool\n```\nIsSetIn returns true if this privilege kind is set in the supplied bitfield.\n\n```go\nfunc (k Kind) Mask() uint64\n```\nMask returns the bitmask for a given privilege.\n\n```go\nfunc (k Kind) SafeFormat(p redact.SafePrinter, _ rune)\n```\nSafeFormat implements the redact.SafeFormatter interface.\n\n```go\ntype KindDisplayName string\n```\nKindDisplayName is the string representation of privileges displayed to end users and recognized by the parser. The name can be different from the key (e.g. when we choose a better name).\n\n```go\nfunc (KindDisplayName) SafeValue()\n```\nSafeValue implements the redact.SafeValuer interface.\n\n```go\ntype KindInternalKey string\n```\nKindInternalKey is the value stored in system tables, etc, that represent the privilege internally. It is not visible to end-users.\n\n```go\nfunc (KindInternalKey) SafeValue()\n```\nSafeValue implements the redact.SafeValuer interface.\n\n```go\ntype List []Kind\n```\nList is a list of privileges.\n\n```go\nfunc GetValidPrivilegesForObject(objectType ObjectType) (List, error)\n```\nGetValidPrivilegesForObject returns the list of valid privileges for the specified object type.\n\n```go\nfunc ListFromBitField(m uint64, objectType ObjectType) (List, error)\n```\nListFromBitField takes a bitfield of privileges and a ObjectType returns a List. It is ordered in increasing value of privilege.Kind.\n\n```go\nfunc ListFromStrings(strs []string, origin Origin) (List, error)\n```\nListFromStrings takes a list of internal storage keys and attempts to build a list of Kind. Each string is converted to uppercase and is searched for either in ByInternalKey or in ByDisplayName maps, depending on the origin. If an entry is not found, it is either ignored or an error is raised (also depending on the origin).\n\n```go\nfunc (pl List) Contains(k Kind) bool\n```\nContains returns true iff the list contains the given privilege kind.\n\n```go\nfunc (pl List) FormatNames(buf *bytes.Buffer)\n```\nFormatNames prints out the list of display names in a buffer. This keeps the existing order and uses \", \" as separator.\n\n```go\nfunc (pl List) Len() int\n```\nLen, Swap, and Less implement the Sort interface.\n\n```go\nfunc (pl List) Less(i, j int) bool\n```\n\n```go\nfunc (pl List) ListToACL(grantOptions List, objectType ObjectType) (string, error)\n```\nListToACL converts a list of privileges to a list of Postgres ACL items. See: [https://www.postgresql.org/docs/13/ddl-priv.html#PRIVILEGE-ABBREVS-TABLE](https://www.postgresql.org/docs/13/ddl-priv.html#PRIVILEGE-ABBREVS-TABLE)\n\n\tfor privileges and their ACL abbreviations.\n\n```go\nfunc (pl List) SafeFormat(s interfaces.SafePrinter, _ rune)\n```\nSafeFormat implements the redact.SafeFormatter interface.\n\n```go\nfunc (pl List) SortedDisplayNames() []string\n```\nSortedDisplayNames returns a list of privilege display names in sorted order.\n\n```go\nfunc (pl List) SortedKeys() []string\n```\nSortedKeys returns a list of privilege internal keys in sorted order.\n\n```go\nfunc (pl List) Swap(i, j int)\n```\n\n```go\nfunc (pl List) ToBitField() uint64\n```\nToBitField returns the bitfield representation of a list of privileges.\n\n```go\ntype Object interface {\n\t// GetObjectType returns the privilege.ObjectType of the Object.\n\tGetObjectType() ObjectType\n\t// GetObjectTypeString returns a human-readable representation of the\n\t// privilege.ObjectType.\n\t// NOTE: It may not match the privilege.ObjectType directly because it may\n\t// be more specific for some object types. For example, for functions and\n\t// procedures it will return \"function\" and \"procedure\", respectively,\n\t// instead of the more generic term \"routine\".\n\tGetObjectTypeString() string\n\t// GetName returns the name of the object. For example, the name of a\n\t// table, schema or database.\n\tGetName() string\n}\n```\nObject represents an object that can have privileges. The privileges can either live on the descriptor or in the system.privileges table.\n\n```go\ntype ObjectType string\n```\nObjectType represents objects that can have privileges.\n\n```go\nconst (\n\t// Any represents any object type.\n\tAny ObjectType = \"any\"\n\t// Database represents a database object.\n\tDatabase ObjectType = \"database\"\n\t// Schema represents a schema object.\n\tSchema ObjectType = \"schema\"\n\t// Table represents a table object.\n\tTable ObjectType = \"table\"\n\t// Type represents a type object.\n\tType ObjectType = \"type\"\n\t// Sequence represents a sequence object.\n\tSequence ObjectType = \"sequence\"\n\t// Routine represents a function or procedure object.\n\tRoutine ObjectType = \"routine\"\n\t// Global represents global privileges.\n\tGlobal ObjectType = \"global\"\n\t// VirtualTable represents a virtual table object.\n\tVirtualTable ObjectType = \"virtual_table\"\n\t// ExternalConnection represents an external connection object.\n\tExternalConnection ObjectType = \"external_connection\"\n)\n```\n\n```go\nfunc (o ObjectType) IsDescriptorBacked() bool\n```\nIsDescriptorBacked returns whether o is a descriptor backed object. If o is not a descriptor backed object, then privileges are stored to system.privileges.\n\n```go\nfunc (k ObjectType) SafeValue()\n```\nSafeValue makes ObjectType a redact.SafeValue.\n\n```go\ntype Origin bool\n```\nOrigin indicates the origin of the privileges being parsed in ListFromStrings.\n\n```go\nconst (\n\t// OriginFromUserInput indicates that the privilege name came from user\n\t// input and should be validated to make sure it refers to a real privilege.\n\tOriginFromUserInput Origin = false\n\n\t// OriginFromSystemTable indicates that the privilege name came from a\n\t// system table and should be ignored if it does not refer to a real\n\t// privilege.\n\tOriginFromSystemTable Origin = true\n)\n```\n\n```go\ntype Privilege struct {\n\tKind Kind\n\t// Each privilege Kind has an optional \"grant option\" flag associated with\n\t// it. A role can only grant a privilege on an object to others if it is the\n\t// owner of the object or if it itself holds that privilege WITH GRANT OPTION\n\t// on the object. This replaced the CockroachDB-specific GRANT privilege.\n\tGrantOption bool\n}\n```\nPrivilege represents a privilege parsed from an Access Privilege Inquiry Function's privilege string argument.\n\n```go\nfunc PrivilegesFromBitFields(\n\tkindBits, grantOptionBits uint64, objectType ObjectType,\n) ([]Privilege, error)\n```\nPrivilegesFromBitFields takes a bitfield of privilege kinds, a bitfield of grant options, and an ObjectType returns a List. It is ordered in increasing value of privilege.Kind.\n\n```go\nfunc (k Privilege) SafeFormat(s redact.SafePrinter, _ rune)\n```\nSafeFormat implements the redact.SafeFormatter interface.\n\n```go\ntype TargetObjectType uint32\n```\nTargetObjectType represents the type of object that is having its default privileges altered.\n\n```go\nconst (\n\tTables    TargetObjectType = 1\n\tSequences TargetObjectType = 2\n\tTypes     TargetObjectType = 3\n\tSchemas   TargetObjectType = 4\n\tRoutines  TargetObjectType = 5\n)\n```\nThe numbers are explicitly assigned since the DefaultPrivilegesPerObject map defined in the DefaultPrivilegesPerRole proto requires the key value for the object type to remain unchanged.\n\n```go\nfunc GetTargetObjectTypes() []TargetObjectType\n```\nGetTargetObjectTypes returns a slice of all the AlterDefaultPrivilegesTargetObjects.\n\n```go\nfunc (t TargetObjectType) String() string\n```\nString makes TargetObjectType a fmt.Stringer.\n\n```go\nfunc (t TargetObjectType) ToObjectType() ObjectType\n```\nToObjectType returns the privilege.ObjectType corresponding to the TargetObjectType.\n\n","path":"github.com/cockroachdb/cockroachdb-parser/pkg/sql/privilege","name":"privilege","synopsis":"Package privilege outlines the basic privilege system for cockroach.","isRedistributable":true}
