mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-26 12:19:56 -05:00
### Does this PR have any customer impact? Yes ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Feature ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No ### Are you introducing any new config? If yes, do you have tests with and without them being set? No ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description We've implemented several key improvements to DocumentDB's user management system, with a focus on enhancing the `usersInfo` command to support privilege information display. ### Feature Overview - Added support for the `showPrivileges` flag in `usersInfo` command - When enabled, user information responses now include detailed privilege documents - Privileges are organized by resource and action, similar to MongoDB's privilege format ### Implementation Details 1. **Privilege Data Structures** - Created predefined privilege sets for each role type (readOnly, readWrite, clusterAdmin) - Designed efficient merging of privilege sets with hash-based deduplication 2. **GUC Configuration** - Added `EnableUsersInfoPrivileges` boolean GUC to control feature availability 3. **Command Flow** - Parse `showPrivileges` flag from incoming BSON documents - When flag is true and GUC is enabled, append privilege array to user documents - Privileges include resource targets (cluster/database/collection) and action lists 4. **Memory Optimization** - Implemented hash-based privilege merging to avoid duplicate entries - Proper memory management with PostgreSQL allocation functions This functionality supports the `connectionStatus` command, which requires authenticated user privileges. We will also support `dbowner` and `root` roles, which will come in a follow-up PR. Related work items: #3852887
74 lines
1.4 KiB
C
74 lines
1.4 KiB
C
/*-------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
*
|
|
* include/users.h
|
|
*
|
|
* User CRUD functions.
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifndef EXTENSION_USERS_H
|
|
#define EXTENSION_USERS_H
|
|
|
|
#include "postgres.h"
|
|
#include "utils/string_view.h"
|
|
|
|
enum DocumentDB_BuiltInRoles
|
|
{
|
|
DocumentDB_Role_Read_AnyDatabase = 0x1,
|
|
DocumentDB_Role_ReadWrite_AnyDatabase = 0x2,
|
|
DocumentDB_Role_Cluster_Admin = 0x4,
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
/* "createUser" field */
|
|
const char *createUser;
|
|
|
|
/* "pwd" field */
|
|
const char *pwd;
|
|
|
|
/* "roles" field */
|
|
bson_value_t roles;
|
|
|
|
/* "identityProvider" field*/
|
|
bson_value_t identityProviderData;
|
|
|
|
/* pgRole the passed in role maps to */
|
|
char *pgRole;
|
|
|
|
/* principalType */
|
|
char *principalType;
|
|
|
|
/* has_identity_provider */
|
|
bool has_identity_provider;
|
|
} CreateUserSpec;
|
|
|
|
typedef struct
|
|
{
|
|
/* "updateUser" field */
|
|
const char *updateUser;
|
|
|
|
/* "pwd" field */
|
|
const char *pwd;
|
|
} UpdateUserSpec;
|
|
|
|
typedef struct
|
|
{
|
|
StringView user;
|
|
|
|
bool showPrivileges;
|
|
} GetUserSpec;
|
|
|
|
/* GUC that controls the blocked role prefix list */
|
|
extern char *BlockedRolePrefixList;
|
|
|
|
/* Method to validate and obtain user role */
|
|
char * ValidateAndObtainUserRole(const bson_value_t *rolesDocument);
|
|
|
|
/* Method to verify if username is valid */
|
|
bool IsUserNameInvalid(const char *userName);
|
|
|
|
#endif
|