数据消隐
1.功能说明
在accesslog的记录中,对于敏感字段,如client_ip, query_param等敏感信息进行隐藏展示
以“*“展示被隐藏的内容。access日志存储到文件的格式有配置的format定义,根据需求,需要对于变量和query_param两种情况做filter过滤。
2.依赖模块
数据消隐无依赖模块
3.指令说明
njt_http_log_module新增一个配置数据隐藏的指令log_data_hidden
Syntax | log_data_hidden {hidden_type} {hidden_data}; |
---|---|
Default | - |
Context | http ,server, location |
参数介绍:
参数 | 取值 | 说明 |
---|---|---|
hidden_type | [var|query_param] | var: 将整个变量隐藏,替换为’‘query_param:对url后面的query_param对应的值隐藏,替换为’’ //后续可增加类型url对url location敏感信息过滤 |
hidden_data | 变量name或者是query_param的key |
说明:
该指令可配置在http块的任何位置,可配置多条
http块的配置对所有的server和location生效
server块的配置对该server块下所有的location生效
location块的配置只对该location生效
4.配置样例
控制面和数据面都可配置,以控制面access_log配置为例(数据面也是一样的配置)说明:
njet_ctrl.conf
...
http {
...
log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
log_data_hidden var status; //所有的status隐藏
...
server {
location /test1 {
...
log_data_hidden query_param a; //query_param a隐藏
log_data_hidden query_param b; //query_param b隐藏
...
}
//对比上面的test, test2 不隐藏任何query_param
location /test2 {
...
...
}
}
}
5.调用样例
使用curl访问端口8081/test1
curl localhost:8081/test1?a=12345676\&b=falfdkjsf\&c=abcf\&dc=1234566\&aa=1234566\&0a=1234566
查看access.log日志:
127.0.0.1 - - [24/May/2024:16:31:52 +0800] "GET /test1?a=*&b=*&c=abcf&dc=1234566&aa=1234566&0a=1234566 HTTP/1.1" * 8 "-" "curl/7.29.0"
127.0.0.1 - - [24/May/2024:16:31:53 +0800] "GET /test1?a=*&b=*&c=abcf&dc=1234566&aa=1234566&0a=1234566 HTTP/1.1" * 8 "-" "curl/7.29.0"
使用curl访问端口8081/test2
curl localhost:8081/test2?a=12345676\&b=falfdkjsf\&c=abcf\&dc=1234566\&aa=1234566\&0a=1234566
查看access.log日志:
127.0.0.1 - - [24/May/2024:16:32:53 +0800] "GET /test2?a=12345676&b=falfdkjsf&c=abcf&dc=1234566&aa=1234566&0a=1234566 HTTP/1.1" * 8 "-" "curl/7.29.0"