zoukankan      html  css  js  c++  java
  • Mysql:logging 安全问题:server & client


    6.1.2.3 Passwords and Logging

    Passwords can be written as plain text in SQL statements such as CREATE USER, GRANT and SET PASSWORD. If such statements are logged by the MySQL server as written, passwords in them become visible to anyone with access to the logs.

    Statement logging avoids writing passwords as cleartext for the following statements:

    CREATE USER ... IDENTIFIED BY ...
    ALTER USER ... IDENTIFIED BY ...
    SET PASSWORD ...
    SLAVE START ... PASSWORD = ...
    CREATE SERVER ... OPTIONS(... PASSWORD ...)
    ALTER SERVER ... OPTIONS(... PASSWORD ...)

    Passwords in those statements are rewritten to not appear literally in statement text written to the general query log, slow query log, and binary log. Rewriting does not apply to other statements. In particular, INSERT or UPDATE statements for the mysql.user system table that refer to literal passwords are logged as is, so you should avoid such statements. (Direct modification of grant tables is discouraged, anyway.)

    For the general query log, password rewriting can be suppressed by starting the server with the --log-raw option. For security reasons, this option is not recommended for production use. For diagnostic purposes, it may be useful to see the exact text of statements as received by the server.

    By default, contents of audit log files produced by the audit log plugin are not encrypted and may contain sensitive information, such as the text of SQL statements. For security reasons, audit log files should be written to a directory accessible only to the MySQL server and to users with a legitimate reason to view the log. See Section 6.4.5.3, “MySQL Enterprise Audit Security Considerations”.

    Statements received by the server may be rewritten if a query rewrite plugin is installed (see Query Rewrite Plugins). In this case, the --log-raw option affects statement logging as follows:

    • Without --log-raw, the server logs the statement returned by the query rewrite plugin. This may differ from the statement as received.

    • With --log-raw, the server logs the original statement as received.

    An implication of password rewriting is that statements that cannot be parsed (due, for example, to syntax errors) are not written to the general query log because they cannot be known to be password free. Use cases that require logging of all statements including those with errors should use the --log-raw option, bearing in mind that this also bypasses password rewriting.

    Password rewriting occurs only when plain text passwords are expected. For statements with syntax that expect a password hash value, no rewriting occurs. If a plain text password is supplied erroneously for such syntax, the password is logged as given, without rewriting.

    To guard log files against unwarranted exposure, locate them in a directory that restricts access to the server and the database administrator. If the server logs to tables in the mysql database, grant access to those tables only to the database administrator.

    Replication slaves store the password for the replication master in the master info repository, which by default is a table in the mysql database named slave_master_info. The use of a file in the data directory for the master info repository is now deprecated, but still possible (see Section 17.2.4, “Replication Relay and Status Logs”). Ensure that the master info repository can be accessed only by the database administrator. An alternative to storing the password in the master info repository is to use the START SLAVE statement to specify credentials for connecting to the master.

    Use a restricted access mode to protect database backups that include log tables or log files containing passwords.

    4.5.1.3 mysql Client Logging

    The mysql client can do these types of logging for statements executed interactively:

    • On Unix, mysql writes the statements to a history file. By default, this file is named .mysql_history in your home directory. To specify a different file, set the value of the MYSQL_HISTFILE environment variable.

    • On all platforms, if the --syslog option is given, mysql writes the statements to the system logging facility. On Unix, this is syslog; on Windows, it is the Windows Event Log. The destination where logged messages appear is system dependent. On Linux, the destination is often the /var/log/messages file.

    The following discussion describes characteristics that apply to all logging types and provides information specific to each logging type.

    How Logging Occurs

    For each enabled logging destination, statement logging occurs as follows:

    • Statements are logged only when executed interactively. Statements are noninteractive, for example, when read from a file or a pipe. It is also possible to suppress statement logging by using the --batch or --execute option.

    • Statements are ignored and not logged if they match any pattern in the ignore” list. This list is described later.

    • mysql logs each nonignored, nonempty statement line individually.

    • If a nonignored statement spans multiple lines (not including the terminating delimiter), mysql concatenates the lines to form the complete statement, maps newlines to spaces, and logs the result, plus a delimiter.

    Consequently, an input statement that spans multiple lines can be logged twice. Consider this input:

    mysql> SELECT
        -> 'Today is'
        -> ,
        -> CURDATE()
        -> ;
    

    In this case, mysql logs the SELECT”, 'Today is'”, ,”, CURDATE()”, and ;” lines as it reads them. It also logs the complete statement, after mapping SELECT 'Today is' , CURDATE() to SELECT 'Today is' , CURDATE(), plus a delimiter. Thus, these lines appear in logged output:

    SELECT
    'Today is'
    ,
    CURDATE()
    ;
    SELECT 'Today is' , CURDATE();

    mysql ignores for logging purposes statements that match any pattern in the ignore” list. By default, the pattern list is "*IDENTIFIED*:*PASSWORD*", to ignore statements that refer to passwords. Pattern matching is not case-sensitive. Within patterns, two characters are special:

    • ? matches any single character.

    • * matches any sequence of zero or more characters.

    To specify additional patterns, use the --histignore option or set the MYSQL_HISTIGNORE environment variable. (If both are specified, the option value takes precedence.) The value should be a list of one or more colon-separated patterns, which are appended to the default pattern list.

    Patterns specified on the command line might need to be quoted or escaped to prevent your command interpreter from treating them specially. For example, to suppress logging for UPDATE and DELETE statements in addition to statements that refer to passwords, invoke mysql like this:

    shell> mysql --histignore="*UPDATE*:*DELETE*"
    
    Controlling the History File

    The .mysql_history file should be protected with a restrictive access mode because sensitive information might be written to it, such as the text of SQL statements that contain passwords. See Section 6.1.2.1, “End-User Guidelines for Password Security”. Statements in the file are accessible from the mysql client when the up-arrow key is used to recall the history. See Disabling Interactive History.

    If you do not want to maintain a history file, first remove .mysql_history if it exists. Then use either of the following techniques to prevent it from being created again:

    • Set the MYSQL_HISTFILE environment variable to /dev/null. To cause this setting to take effect each time you log in, put it in one of your shell's startup files.

    • Create .mysql_history as a symbolic link to /dev/null; this need be done only once:

      shell> ln -s /dev/null $HOME/.mysql_history
      
    syslog Logging Characteristics

    If the --syslog option is given, mysql writes interactive statements to the system logging facility. Message logging has the following characteristics.

    Logging occurs at the information” level. This corresponds to the LOG_INFO priority for syslog on Unix/Linux syslog capability and to EVENTLOG_INFORMATION_TYPE for the Windows Event Log. Consult your system documentation for configuration of your logging capability.

    Message size is limited to 1024 bytes.

    Messages consist of the identifier MysqlClient followed by these values:

    • SYSTEM_USER

      The operating system user name (login name) or -- if the user is unknown.

    • MYSQL_USER

      The MySQL user name (specified with the --user option) or -- if the user is unknown.

    • CONNECTION_ID:

      The client connection identifier. This is the same as the CONNECTION_ID() function value within the session.

    • DB_SERVER

      The server host or -- if the host is unknown.

    • DB

      The default database or -- if no database has been selected.

    • QUERY

      The text of the logged statement.

    Here is a sample of output generated on Linux by using --syslog. This output is formatted for readability; each logged message actually takes a single line.

    Mar  7 12:39:25 myhost MysqlClient[20824]:
      SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23,
      DB_SERVER:'127.0.0.1', DB:'--', QUERY:'USE test;'
    Mar  7 12:39:28 myhost MysqlClient[20824]:
      SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23,
    DB_SERVER:'127.0.0.1', DB:'test', QUERY:'SHOW TABLES;'
  • 相关阅读:
    Andrew Ng机器学习week4(Neural Networks: Representation)编程习题
    linux系统下crontab 配置启动定时任务
    在python中配置tornado服务
    在python中Flask配置服务
    ltp的使用
    查看文件内容- 删除某个运行程序的所有进程-nohup后台执行程序
    机器学习和深度学习资料整理
    配置linux服务器和pycharm的连接
    计算 24 点是一种扑克牌益智游戏,随机抽出 4 张扑克牌,通过加 (+) ,减 (-) ,乘 ( * ), 除 (/) 四种运算法则计算得到整数 24 ,本问题中,扑克牌通过如下字符或者字符串表示,其中,小写 joker 表示小王,大写 JOKER 表示大王:
    机器人的运动范围 剑指offer66题
  • 原文地址:https://www.cnblogs.com/jinzhenshui/p/12485886.html
Copyright © 2011-2022 走看看