Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0cd99ea7
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0cd99ea7
编写于
5月 29, 2020
作者:
T
Tao Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-424] add audit user
上级
44e4b59e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
56 addition
and
4 deletion
+56
-4
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+2
-0
src/inc/taoserror.h
src/inc/taoserror.h
+2
-1
src/modules/monitor/src/monitorSystem.c
src/modules/monitor/src/monitorSystem.c
+13
-1
src/rpc/src/tstring.c
src/rpc/src/tstring.c
+1
-0
src/system/detail/inc/mgmt.h
src/system/detail/inc/mgmt.h
+3
-1
src/system/detail/src/mgmtShell.c
src/system/detail/src/mgmtShell.c
+31
-1
src/system/detail/src/mgmtUser.c
src/system/detail/src/mgmtUser.c
+4
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
0cd99ea7
...
@@ -442,6 +442,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
...
@@ -442,6 +442,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pCmd
->
count
=
2
;
pCmd
->
count
=
2
;
}
else
if
(
strncasecmp
(
pPrivilege
->
z
,
"write"
,
5
)
==
0
&&
pPrivilege
->
n
==
5
)
{
}
else
if
(
strncasecmp
(
pPrivilege
->
z
,
"write"
,
5
)
==
0
&&
pPrivilege
->
n
==
5
)
{
pCmd
->
count
=
3
;
pCmd
->
count
=
3
;
}
else
if
(
strncasecmp
(
pPrivilege
->
z
,
"audit"
,
5
)
==
0
&&
pPrivilege
->
n
==
5
)
{
pCmd
->
count
=
4
;
}
else
{
}
else
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
}
...
...
src/inc/taoserror.h
浏览文件 @
0cd99ea7
...
@@ -140,8 +140,9 @@ extern "C" {
...
@@ -140,8 +140,9 @@ extern "C" {
#define TSDB_CODE_QUERY_CACHE_ERASED 119
#define TSDB_CODE_QUERY_CACHE_ERASED 119
#define TSDB_CODE_AUTH_BANNED_PERIOD 120
#define TSDB_CODE_AUTH_BANNED_PERIOD 120
#define TSDB_CODE_IP_WHITELIST_FILTERED 121
#define TSDB_CODE_IP_WHITELIST_FILTERED 121
#define TSDB_CODE_NOT_AUDIT_USER 122
#define TSDB_CODE_MAX_ERROR_CODE 12
2
#define TSDB_CODE_MAX_ERROR_CODE 12
3
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/modules/monitor/src/monitorSystem.c
浏览文件 @
0cd99ea7
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#define SQL_LENGTH 1024
#define SQL_LENGTH 1024
#define LOG_LEN_STR 80
#define LOG_LEN_STR 80
#define LOG_RESULT_LEN 10
#define IP_LEN_STR 15
#define IP_LEN_STR 15
#define CHECK_INTERVAL 1000
#define CHECK_INTERVAL 1000
...
@@ -39,6 +40,8 @@ typedef enum {
...
@@ -39,6 +40,8 @@ typedef enum {
MONITOR_CMD_CREATE_TB_DN
,
MONITOR_CMD_CREATE_TB_DN
,
MONITOR_CMD_CREATE_TB_ACCT_ROOT
,
MONITOR_CMD_CREATE_TB_ACCT_ROOT
,
MONITOR_CMD_CREATE_TB_SLOWQUERY
,
MONITOR_CMD_CREATE_TB_SLOWQUERY
,
MONITOR_CMD_CREATE_DB_AUDIT
,
MONITOR_CMD_CREATE_TB_AUDIT
,
MONITOR_CMD_MAX
MONITOR_CMD_MAX
}
MonitorCommand
;
}
MonitorCommand
;
...
@@ -194,9 +197,18 @@ void dnodeBuildMonitorSql(char *sql, int cmd) {
...
@@ -194,9 +197,18 @@ void dnodeBuildMonitorSql(char *sql, int cmd) {
"create table if not exists %s.log(ts timestamp, level tinyint, "
"create table if not exists %s.log(ts timestamp, level tinyint, "
"content binary(%d), ipaddr binary(%d))"
,
"content binary(%d), ipaddr binary(%d))"
,
tsMonitorDbName
,
LOG_LEN_STR
,
IP_LEN_STR
);
tsMonitorDbName
,
LOG_LEN_STR
,
IP_LEN_STR
);
}
else
if
(
cmd
==
MONITOR_CMD_CREATE_DB_AUDIT
)
{
char
*
auditDBname
=
"audit"
;
snprintf
(
sql
,
SQL_LENGTH
,
"create database if not exists %s replica 1 days 10 keep 3650 rows 1024 cache 2048"
,
auditDBname
);
}
else
if
(
cmd
==
MONITOR_CMD_CREATE_TB_AUDIT
)
{
snprintf
(
sql
,
SQL_LENGTH
,
"create table if not exists audit.audit(ts timestamp, level tinyint, "
"dbuser binary(%d), result binary(%d), ipaddr binary(%d), content binary(%d))"
,
TSDB_USER_LEN
,
LOG_RESULT_LEN
,
IP_LEN_STR
,
LOG_LEN_STR
);
}
}
sql
[
SQL_LENGTH
]
=
0
;
}
}
void
monitorInitDatabase
()
{
void
monitorInitDatabase
()
{
...
...
src/rpc/src/tstring.c
浏览文件 @
0cd99ea7
...
@@ -246,4 +246,5 @@ char *tsError[] = {"success",
...
@@ -246,4 +246,5 @@ char *tsError[] = {"success",
"client query cache erased"
,
// 119
"client query cache erased"
,
// 119
"too many authentication failed, try 10 minutes later"
,
//120
"too many authentication failed, try 10 minutes later"
,
//120
"ip not in white list , connection denied"
,
//121
"ip not in white list , connection denied"
,
//121
"not audit user, can not access audit database"
//122
};
};
src/system/detail/inc/mgmt.h
浏览文件 @
0cd99ea7
...
@@ -174,6 +174,7 @@ typedef struct _user_obj {
...
@@ -174,6 +174,7 @@ typedef struct _user_obj {
int64_t
createdTime
;
int64_t
createdTime
;
char
superAuth
:
1
;
char
superAuth
:
1
;
char
writeAuth
:
1
;
char
writeAuth
:
1
;
char
auditAuth
:
1
;
char
reserved
[
16
];
char
reserved
[
16
];
char
updateEnd
[
1
];
char
updateEnd
[
1
];
struct
_user_obj
*
prev
,
*
next
;
struct
_user_obj
*
prev
,
*
next
;
...
@@ -223,9 +224,10 @@ typedef struct _connObj {
...
@@ -223,9 +224,10 @@ typedef struct _connObj {
uint64_t
stime
;
// login time
uint64_t
stime
;
// login time
char
superAuth
:
1
;
// super user flag
char
superAuth
:
1
;
// super user flag
char
writeAuth
:
1
;
// write flag
char
writeAuth
:
1
;
// write flag
char
auditAuth
:
1
;
char
killConnection
:
1
;
// kill the connection flag
char
killConnection
:
1
;
// kill the connection flag
uint8_t
usePublicIp
:
1
;
// if the connection request is publicIp
uint8_t
usePublicIp
:
1
;
// if the connection request is publicIp
uint8_t
reserved
:
4
;
uint8_t
reserved
:
3
;
uint32_t
queryId
;
// query ID to be killed
uint32_t
queryId
;
// query ID to be killed
uint32_t
streamId
;
// stream ID to be killed
uint32_t
streamId
;
// stream ID to be killed
uint32_t
ip
;
// shell IP
uint32_t
ip
;
// shell IP
...
...
src/system/detail/src/mgmtShell.c
浏览文件 @
0cd99ea7
...
@@ -199,6 +199,26 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
...
@@ -199,6 +199,26 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
goto
_exit_code
;
goto
_exit_code
;
}
}
char
db
[
TSDB_DB_NAME_LEN
+
1
]
=
{
0
};
extractDBName
(
pInfo
->
meterId
,
db
);
if
(
strncasecmp
(
db
,
"audit"
,
5
)
==
0
&&
pConn
->
pUser
->
auditAuth
==
0
&&
pConn
->
pUser
->
superAuth
==
0
)
{
if
((
pStart
=
mgmtAllocMsg
(
pConn
,
size
,
&
pMsg
,
&
pRsp
))
==
NULL
)
{
taosSendSimpleRsp
(
pConn
->
thandle
,
TSDB_MSG_TYPE_METERINFO_RSP
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
0
;
}
pRsp
->
code
=
TSDB_CODE_NOT_AUDIT_USER
;
pMsg
++
;
goto
_exit_code
;
}
if
(
strncasecmp
(
db
,
"audit"
,
5
)
!=
0
&&
pConn
->
pUser
->
auditAuth
!=
0
&&
pConn
->
pUser
->
writeAuth
==
0
){
if
((
pStart
=
mgmtAllocMsg
(
pConn
,
size
,
&
pMsg
,
&
pRsp
))
==
NULL
)
{
taosSendSimpleRsp
(
pConn
->
thandle
,
TSDB_MSG_TYPE_METERINFO_RSP
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
0
;
}
pRsp
->
code
=
TSDB_CODE_NO_READ_ACCESS
;
pMsg
++
;
goto
_exit_code
;
}
pMeterObj
=
mgmtGetMeter
(
pInfo
->
meterId
);
pMeterObj
=
mgmtGetMeter
(
pInfo
->
meterId
);
// on demand create table from super table if meter does not exists
// on demand create table from super table if meter does not exists
...
@@ -766,12 +786,19 @@ int mgmtProcessAlterUserMsg(char *pMsg, int msgLen, SConnObj *pConn) {
...
@@ -766,12 +786,19 @@ int mgmtProcessAlterUserMsg(char *pMsg, int msgLen, SConnObj *pConn) {
if
(
pAlter
->
privilege
==
2
)
{
// read
if
(
pAlter
->
privilege
==
2
)
{
// read
pUser
->
superAuth
=
0
;
pUser
->
superAuth
=
0
;
pUser
->
writeAuth
=
0
;
pUser
->
writeAuth
=
0
;
pUser
->
auditAuth
=
0
;
}
}
if
(
pAlter
->
privilege
==
3
)
{
// write
if
(
pAlter
->
privilege
==
3
)
{
// write
pUser
->
superAuth
=
0
;
pUser
->
superAuth
=
0
;
pUser
->
writeAuth
=
1
;
pUser
->
writeAuth
=
1
;
pUser
->
auditAuth
=
0
;
}
}
if
(
pAlter
->
privilege
==
4
)
{
// audit
pUser
->
superAuth
=
0
;
pUser
->
writeAuth
=
0
;
pUser
->
auditAuth
=
1
;
}
printf
(
"user right: s %d, w %d, a %d
\r\n
"
,
pUser
->
superAuth
,
pUser
->
writeAuth
,
pUser
->
auditAuth
);
code
=
mgmtUpdateUser
(
pUser
);
code
=
mgmtUpdateUser
(
pUser
);
mLPrint
(
"user:%s privilege is altered by %s, code:%d"
,
pAlter
->
user
,
pConn
->
pUser
->
user
,
code
);
mLPrint
(
"user:%s privilege is altered by %s, code:%d"
,
pAlter
->
user
,
pConn
->
pUser
->
user
,
code
);
}
else
{
}
else
{
...
@@ -1244,11 +1271,14 @@ void mgmtEstablishConn(SConnObj *pConn) {
...
@@ -1244,11 +1271,14 @@ void mgmtEstablishConn(SConnObj *pConn) {
if
(
strcmp
(
pConn
->
pUser
->
user
,
"root"
)
==
0
)
{
if
(
strcmp
(
pConn
->
pUser
->
user
,
"root"
)
==
0
)
{
pConn
->
superAuth
=
1
;
pConn
->
superAuth
=
1
;
pConn
->
writeAuth
=
1
;
pConn
->
writeAuth
=
1
;
pConn
->
auditAuth
=
1
;
}
else
{
}
else
{
pConn
->
superAuth
=
pConn
->
pUser
->
superAuth
;
pConn
->
superAuth
=
pConn
->
pUser
->
superAuth
;
pConn
->
writeAuth
=
pConn
->
pUser
->
writeAuth
;
pConn
->
writeAuth
=
pConn
->
pUser
->
writeAuth
;
pConn
->
auditAuth
=
pConn
->
pUser
->
auditAuth
;
if
(
pConn
->
superAuth
)
{
if
(
pConn
->
superAuth
)
{
pConn
->
writeAuth
=
1
;
pConn
->
writeAuth
=
1
;
pConn
->
auditAuth
=
1
;
}
}
}
}
...
...
src/system/detail/src/mgmtUser.c
浏览文件 @
0cd99ea7
...
@@ -128,8 +128,10 @@ int mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
...
@@ -128,8 +128,10 @@ int mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
pUser
->
createdTime
=
taosGetTimestampMs
();
pUser
->
createdTime
=
taosGetTimestampMs
();
pUser
->
superAuth
=
0
;
pUser
->
superAuth
=
0
;
pUser
->
writeAuth
=
1
;
pUser
->
writeAuth
=
1
;
pUser
->
auditAuth
=
0
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
==
0
||
strcmp
(
pUser
->
user
,
pUser
->
acct
)
==
0
)
{
if
(
strcmp
(
pUser
->
user
,
"root"
)
==
0
||
strcmp
(
pUser
->
user
,
pUser
->
acct
)
==
0
)
{
pUser
->
superAuth
=
1
;
pUser
->
superAuth
=
1
;
pUser
->
auditAuth
=
1
;
}
}
code
=
TSDB_CODE_SUCCESS
;
code
=
TSDB_CODE_SUCCESS
;
...
@@ -227,6 +229,8 @@ int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
...
@@ -227,6 +229,8 @@ int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
strcpy
(
pWrite
,
"super"
);
strcpy
(
pWrite
,
"super"
);
}
else
if
(
pUser
->
writeAuth
)
{
}
else
if
(
pUser
->
writeAuth
)
{
strcpy
(
pWrite
,
"write"
);
strcpy
(
pWrite
,
"write"
);
}
else
if
(
pUser
->
auditAuth
)
{
strcpy
(
pWrite
,
"audit"
);
}
else
{
}
else
{
strcpy
(
pWrite
,
"read"
);
strcpy
(
pWrite
,
"read"
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录