模块:Mongo::Monitoring::Event::Secure

包含在:
CommandFailed, CommandStarted, CommandSucceeded, Protocol::Msg, Protocol::Query
定义于:
lib/ Mongo/ 监控/mongoing/ 事件/secure.rb

Overview

提供从命令和回复中编辑敏感信息的行为。

由于:

  • 2.1.0

常量摘要折叠

REDACTED_COMMANDS =

为了安全起见,对数据进行编辑的命令列表。

由于:

  • 2.1.0

[
  ' authenticate ',
  ' saslStart ',
  ' saslContinue ',
  ' getnonce ',
  ' createUser ',
  ' updateUser ',
  ' copydbgetnonce ',
  'copydbsaslstart',
  ' copydb '
].冻结

实例方法摘要折叠

实例方法详细信息

#compression_allowed? (command_name) ⇒ true , false

给定命令消息是否允许压缩。

例子:

确定给定命令是否允许压缩。

secure.compression_allowed?(selector)

参数:

  • command_name ( string , Symbol )

    命令名称。

返回:

  • ( true , false )

    是否可以使用压缩。

由于:

  • 2.5.0



106
107
108
# File 'lib/ Mongo/ 监控/ 事件/secure.rb', line 106

def compression_allowed?(command_name)
  @compression_allowed ||= !REDACTED_COMMANDS.包括?(command_name.to_s)
end

# redacted (command_name, document) ⇒ BSON::Document

如果出现以下情况,请编辑文档中的安全信息:

- its command is in the sensitive commands;
- its command is a hello/legacy hello command, and
  speculative authentication is enabled;
- corresponding started event is sensitive.

例子:

获取编辑后的文档。

secure.redacted(command_name, document)

参数:

  • command_name ( string , Symbol )

    命令名称。

  • 文档 ( BSON::Document )

    文档。

返回:

  • ( BSON::Document )

    编辑后的文档。

由于:

  • 2.1.0



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ Mongo/ 监控/ 事件/secure.rb', line 83

def redacted(command_name, 文档)
  if %w(1 true ).包括?(ENV['MONGO_RUBY_DRIVER_UNREDACT_EVENTS']&。Downcase)
    文档
  elsif respond_to?(:started_event) && started_event.敏感
    return BSON::文档.new
  elsif 敏感?(command_name: command_name, 文档: 文档)
    BSON::文档.new
  else
    文档
  end
end

#敏感? (command_name:, 文档:) ⇒ true | false

检查该命令在命令监控规范方面是否敏感。 如果命令位于列表中或者是 hello/legacy hello 命令,并且启用了推测性身份验证,则该命令被检测为敏感。

参数:

  • command_name ( string , Symbol )

    命令名称。

  • 文档 ( BSON::Document )

    文档。

返回:

  • ( true | false )

    命令是否敏感。

由于:

  • 2.1.0



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ Mongo/ 监控/ 事件/secure.rb', line 52

def 敏感?(command_name:, 文档:)
  if REDACTED_COMMANDS.包括?(command_name.to_s)
    true
  elsif %w(hello isMaster isMaster).包括?(command_name.to_s) &&
    文档[' speculativeAuthenticate ']
    then
    # 根据命令监控规范,针对 hello/legacy hello 命令
    # 当 speculativeAuthenticate 存在时,他们的命令 AND 回复
    # 必须从事件中编辑。
    # 请参阅 https://github.com/mongodb/specifications/blob/master/source/command-logging-and-monitoring/command-logging-and-monitoring.md#security
    true
  else
    false
  end
end