Loading...
Searching...
No Matches
as_admin.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2022 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19/**
20 * @defgroup admin_operations Admin Operations
21 * @ingroup client_operations
22 *
23 * User administration operations.
24 */
25
26#include <aerospike/aerospike.h>
27#include <aerospike/as_config.h>
28#include <aerospike/as_key.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/******************************************************************************
35 * MACROS
36 *****************************************************************************/
37
38/**
39 * Maximum size of role string including null byte.
40 * @ingroup admin_operations
41 */
42#define AS_ROLE_SIZE 64
43
44/******************************************************************************
45 * TYPES
46 *****************************************************************************/
47
48/**
49 * Permission codes define the type of permission granted for a user's role.
50 * @ingroup admin_operations
51 */
52typedef enum as_privilege_code_e {
53 /**
54 * User can edit/remove other users. Global scope only.
55 */
57
58 /**
59 * User can perform systems administration functions on a database that do not involve user
60 * administration. Examples include setting dynamic server configuration.
61 * Global scope only.
62 */
64
65 /**
66 * User can perform UDF and SINDEX administration actions. Global scope only.
67 */
69
70 /**
71 * User can perform user defined function(UDF) administration actions.
72 * Examples include create/drop UDF. Global scope only.
73 * Requires server version 6.0+
74 */
76
77 /**
78 * User can perform secondary index administration actions.
79 * Examples include create/drop index. Global scope only.
80 * Requires server version 6.0+
81 */
83
84 /**
85 * User can read data only.
86 */
88
89 /**
90 * User can read and write data.
91 */
93
94 /**
95 * User can read and write data through user defined functions.
96 */
98
99 /**
100 * User can write data only.
101 */
103
104 /**
105 * User can truncate data only.
106 * Requires server version 6.0+
107 */
110
111/**
112 * User privilege.
113 * @ingroup admin_operations
114 */
115typedef struct as_privilege_s {
116 /**
117 * Namespace scope. Apply permission to this null terminated namespace only.
118 * If string length is zero, the privilege applies to all namespaces.
119 */
121
122 /**
123 * Set name scope. Apply permission to this null terminated set within namespace only.
124 * If string length is zero, the privilege applies to all sets within namespace.
125 */
127
128 /**
129 * Privilege code.
130 */
133
134/**
135 * Role definition.
136 * @ingroup admin_operations
137 */
138typedef struct as_role_s {
139 /**
140 * Role name.
141 */
142 char name[AS_ROLE_SIZE];
143
144 /**
145 * Maximum reads per second limit.
146 */
148
149 /**
150 * Maximum writes per second limit.
151 */
153
154 /**
155 * Array of allowable IP address strings.
156 */
157 char** whitelist;
158
159 /**
160 * Length of whitelist array.
161 */
163
164 /**
165 * Length of privileges array.
166 */
168
169 /**
170 * Array of assigned privileges.
171 */
172 as_privilege privileges[];
173} as_role;
174
175/**
176 * User and assigned roles.
177 * @ingroup admin_operations
178 */
179typedef struct as_user_s {
180 /**
181 * User name.
182 */
183 char name[AS_USER_SIZE];
184
185 /**
186 * Array of read statistics. Array may be null.
187 * Current statistics by offset are:
188 * <ul>
189 * <li>0: read quota in records per second</li>
190 * <li>1: single record read transaction rate (TPS)</li>
191 * <li>2: read scan/query record per second rate (RPS)</li>
192 * <li>3: number of limitless read scans/queries</li>
193 * </ul>
194 * Future server releases may add additional statistics.
195 */
196 uint32_t* read_info;
197
198 /**
199 * Array of write statistics. Array may be null.
200 * Current statistics by offset are:
201 * <ul>
202 * <li>0: write quota in records per second</li>
203 * <li>1: single record write transaction rate (TPS)</li>
204 * <li>2: write scan/query record per second rate (RPS)</li>
205 * <li>3: number of limitless write scans/queries</li>
206 * </ul>
207 * Future server releases may add additional statistics.
208 */
209 uint32_t* write_info;
210
211 /**
212 * Length of read info array.
213 */
215
216 /**
217 * Length of write info array.
218 */
220
221 /**
222 * Number of currently open connections.
223 */
225
226 /**
227 * Length of roles array.
228 */
230
231 /**
232 * Array of assigned role names.
233 */
234 char roles[][AS_ROLE_SIZE];
235} as_user;
236
237struct as_node_s;
238struct as_socket_s;
239
240/******************************************************************************
241 * FUNCTIONS
242 ******************************************************************************/
243
244/**
245 * Create user with password and roles. Clear-text password will be hashed using bcrypt before
246 * sending to server.
247 * @ingroup admin_operations
248 */
251 aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name,
252 const char* password, const char** roles, int roles_size
253 );
254
255/**
256 * Remove user from cluster.
257 * @ingroup admin_operations
258 */
261 aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name
262 );
263
264/**
265 * Set user's password by user administrator. Clear-text password will be hashed using bcrypt
266 * before sending to server.
267 * @ingroup admin_operations
268 */
271 aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name,
272 const char* password
273 );
274
275/**
276 * Change user's password by user. Clear-text password will be hashed using bcrypt before
277 * sending to server.
278 * @ingroup admin_operations
279 */
282 aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name,
283 const char* password
284 );
285
286/**
287 * Add role to user's list of roles.
288 * @ingroup admin_operations
289 */
292 aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name,
293 const char** roles, int roles_size
294 );
295
296/**
297 * Remove role from user's list of roles.
298 * @ingroup admin_operations
299 */
302 aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name,
303 const char** roles, int roles_size
304 );
305
306/**
307 * Create user defined role.
308 * @ingroup admin_operations
309 */
312 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role,
313 as_privilege** privileges, int privileges_size
314 );
315
316/**
317 * Create user defined role with optional privileges and whitelist.
318 * Whitelist IP addresses can contain wildcards (ie. 10.1.2.0/24).
319 * @ingroup admin_operations
320 */
323 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role,
324 as_privilege** privileges, int privileges_size, const char** whitelist, int whitelist_size
325 );
326
327/**
328 * Create user defined role with optional privileges, whitelist and quotas.
329 * Whitelist IP addresses can contain wildcards (ie. 10.1.2.0/24).
330 * Quotas are maximum reads/writes per second limit, pass in zero for no limit.
331 * Quotas require server security configuration "enable-quotas" to be set to true.
332 * @ingroup admin_operations
333 */
336 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role,
337 as_privilege** privileges, int privileges_size, const char** whitelist, int whitelist_size,
338 int read_quota, int write_quota
339 );
340
341/**
342 * Delete user defined role.
343 * @ingroup admin_operations
344 */
346aerospike_drop_role(aerospike* as, as_error* err, const as_policy_admin* policy, const char* role);
347
348/**
349 * Add specified privileges to user.
350 * @ingroup admin_operations
351 */
354 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role,
355 as_privilege** privileges, int privileges_size
356 );
357
358/**
359 * Remove specified privileges from user.
360 * @ingroup admin_operations
361 */
364 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role,
365 as_privilege** privileges, int privileges_size
366 );
367
368/**
369 * Set IP address whitelist for a role.
370 * If whitelist is NULL or empty, remove existing whitelist from role.
371 * IP addresses can contain wildcards (ie. 10.1.2.0/24).
372 * @ingroup admin_operations
373 */
376 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role,
377 const char** whitelist, int whitelist_size
378 );
379
380/**
381 * Set maximum reads/writes per second limits for a role. If a quota is zero, the limit is removed.
382 * @ingroup admin_operations
383 */
386 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role,
387 int read_quota, int write_quota
388 );
389
390/**
391 * Retrieve roles for a given user.
392 * When successful, as_user_destroy() must be called to free resources.
393 * @ingroup admin_operations
394 */
397 aerospike* as, as_error* err, const as_policy_admin* policy, const char* user_name,
398 as_user** user
399 );
400
401/**
402 * Release as_user_roles memory.
403 * @ingroup admin_operations
404 */
405AS_EXTERN void
407
408/**
409 * Retrieve all users and their roles.
410 * When successful, as_users_destroy() must be called to free resources.
411 * @ingroup admin_operations
412 */
415 aerospike* as, as_error* err, const as_policy_admin* policy, as_user*** users, int* users_size
416 );
417
418/**
419 * Release memory for as_user_roles array.
420 * @ingroup admin_operations
421 */
422AS_EXTERN void
423as_users_destroy(as_user** users, int users_size);
424
425/**
426 * Retrieve role definition for a given role name.
427 * When successful, as_role_destroy() must be called to free resources.
428 * @ingroup admin_operations
429 */
432 aerospike* as, as_error* err, const as_policy_admin* policy, const char* role_name,
433 as_role** role
434 );
435
436/**
437 * Release as_role memory.
438 * @ingroup admin_operations
439 */
440AS_EXTERN void
442
443/**
444 * Retrieve all roles and their privileges.
445 * When successful, as_roles_destroy() must be called to free resources.
446 * @ingroup admin_operations
447 */
450 aerospike* as, as_error* err, const as_policy_admin* policy, as_role*** roles, int* roles_size
451 );
452
453/**
454 * Release memory for as_role array.
455 * @ingroup admin_operations
456 */
457AS_EXTERN void
458as_roles_destroy(as_role** roles, int roles_size);
459
460struct as_cluster_s;
461struct as_node_info_s;
462struct as_session_s;
463
464/**
465 * @private
466 * Login to node on node discovery. Do not use this method directly.
467 */
470 struct as_cluster_s* cluster, as_error* err, struct as_socket_s* sock, uint64_t deadline_ms,
471 struct as_node_info_s* node_info
472 );
473
474/**
475 * @private
476 * Authenticate user with a server node. This is done automatically after socket open.
477 * Do not use this method directly.
478 */
481 struct as_cluster_s* cluster, as_error* err, struct as_socket_s* sock, struct as_node_s* node,
482 struct as_session_s* session, uint32_t socket_timeout, uint64_t deadline_ms
483 );
484
485/**
486 * @private
487 * Write authentication command to buffer. Return buffer length.
488 */
489uint32_t
490as_authenticate_set(struct as_cluster_s* cluster, struct as_session_s* session, uint8_t* buffer);
491
492#ifdef __cplusplus
493} // end extern "C"
494#endif
as_status as_cluster_login(struct as_cluster_s *cluster, as_error *err, struct as_socket_s *sock, uint64_t deadline_ms, struct as_node_info_s *node_info)
uint32_t as_authenticate_set(struct as_cluster_s *cluster, struct as_session_s *session, uint8_t *buffer)
as_status as_authenticate(struct as_cluster_s *cluster, as_error *err, struct as_socket_s *sock, struct as_node_s *node, struct as_session_s *session, uint32_t socket_timeout, uint64_t deadline_ms)
char as_namespace[AS_NAMESPACE_MAX_SIZE]
Definition as_key.h:55
char as_set[AS_SET_MAX_SIZE]
Definition as_key.h:60
#define AS_USER_SIZE
Definition as_password.h:29
as_status
Definition as_status.h:30
#define AS_EXTERN
Definition as_std.h:25
AS_EXTERN as_status aerospike_drop_user(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name)
AS_EXTERN as_status aerospike_create_user(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char *password, const char **roles, int roles_size)
AS_EXTERN as_status aerospike_revoke_roles(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char **roles, int roles_size)
AS_EXTERN as_status aerospike_create_role(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size)
AS_EXTERN as_status aerospike_set_whitelist(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, const char **whitelist, int whitelist_size)
AS_EXTERN as_status aerospike_query_users(aerospike *as, as_error *err, const as_policy_admin *policy, as_user ***users, int *users_size)
AS_EXTERN void as_role_destroy(as_role *role)
as_privilege_code
Definition as_admin.h:52
AS_EXTERN as_status aerospike_grant_roles(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char **roles, int roles_size)
AS_EXTERN as_status aerospike_set_password(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char *password)
AS_EXTERN as_status aerospike_set_quotas(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, int read_quota, int write_quota)
AS_EXTERN as_status aerospike_query_user(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, as_user **user)
AS_EXTERN as_status aerospike_query_role(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role_name, as_role **role)
AS_EXTERN as_status aerospike_query_roles(aerospike *as, as_error *err, const as_policy_admin *policy, as_role ***roles, int *roles_size)
AS_EXTERN as_status aerospike_change_password(aerospike *as, as_error *err, const as_policy_admin *policy, const char *user_name, const char *password)
AS_EXTERN void as_roles_destroy(as_role **roles, int roles_size)
#define AS_ROLE_SIZE
Definition as_admin.h:42
AS_EXTERN as_status aerospike_revoke_privileges(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size)
AS_EXTERN void as_users_destroy(as_user **users, int users_size)
AS_EXTERN as_status aerospike_grant_privileges(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size)
AS_EXTERN as_status aerospike_drop_role(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role)
AS_EXTERN as_status aerospike_create_role_whitelist(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size, const char **whitelist, int whitelist_size)
AS_EXTERN void as_user_destroy(as_user *user)
AS_EXTERN as_status aerospike_create_role_quotas(aerospike *as, as_error *err, const as_policy_admin *policy, const char *role, as_privilege **privileges, int privileges_size, const char **whitelist, int whitelist_size, int read_quota, int write_quota)
@ AS_PRIVILEGE_READ
Definition as_admin.h:87
@ AS_PRIVILEGE_SINDEX_ADMIN
Definition as_admin.h:82
@ AS_PRIVILEGE_READ_WRITE_UDF
Definition as_admin.h:97
@ AS_PRIVILEGE_DATA_ADMIN
Definition as_admin.h:68
@ AS_PRIVILEGE_WRITE
Definition as_admin.h:102
@ AS_PRIVILEGE_READ_WRITE
Definition as_admin.h:92
@ AS_PRIVILEGE_USER_ADMIN
Definition as_admin.h:56
@ AS_PRIVILEGE_TRUNCATE
Definition as_admin.h:108
@ AS_PRIVILEGE_SYS_ADMIN
Definition as_admin.h:63
@ AS_PRIVILEGE_UDF_ADMIN
Definition as_admin.h:75
as_privilege_code code
Definition as_admin.h:131
as_namespace ns
Definition as_admin.h:120
as_set set
Definition as_admin.h:126
int read_quota
Definition as_admin.h:147
int write_quota
Definition as_admin.h:152
int privileges_size
Definition as_admin.h:167
int whitelist_size
Definition as_admin.h:162
char ** whitelist
Definition as_admin.h:157
int read_info_size
Definition as_admin.h:214
uint32_t * read_info
Definition as_admin.h:196
int roles_size
Definition as_admin.h:229
int write_info_size
Definition as_admin.h:219
int conns_in_use
Definition as_admin.h:224
uint32_t * write_info
Definition as_admin.h:209