oak-block-account

NAME

oak-block-account: block or release MySQL users accounts, disabling them or enabling them to login

SYNOPSIS

Disable the user web@webhost1.com from logging into MySQL:
oak-block-account --block --account-user=web --account-host=webhost1.com
Re-enable the user web@webhost1.com to log into MySQL:
oak-block-account --release --account-user=web --account-host=webhost1.com
Disable the user 'web' on any host from logging into MySQL:
oak-block-account --block --account-user=web
Disable the user 'web' on any host from logging into MySQL, and kill any existing connection for that user:
oak-block-account --block --account-user=web --kill
Same as above, provide connection parameters, prompt for password:
oak-block-account --user=root --ask-pass --socket=/tmp/mysql.sock -b --account-user=web
Same as above, use defaults file:
oak-block-account --defaults-file=/home/myuser/.my-oak.cnf -b --account-user=web

DESCRIPTION

A long time missing functionality from MySQL is the ability to temporarily block connections for specific accounts, without changing their security privileges.

oak-block-account addresses this issue by utilizing the way MySQL passwords are stored. Essentially, to block an account, this tool changes the account's password into a blocked-password value in such way that:

  • It is impossible to log in to the account with the original password
  • It is impossible to log in to the account with any other password
  • It is possible to detect that the password is a blocked-password
  • It is possible to recover the original password

When a "release" action is requested, oak-block-account checks on the current password. If it identifies it as a blocked-password, it re institutes the original password. In both cases the tool utilizes the SET PASSWORD command. The required privilege is an UPDATE on the mysql.user table, usually reserved to the `root` user.

Connections which are open at the time of executing oak-block-account are unaffected.

Either --block, --release or --list must be specified.

OPTIONS

--account-user=ACCOUNT_USER

Mandatory: the user (login) name to block/release

--account-host=ACCOUNT_HOST

The account's host. Leave blank to apply for all hosts

--ask-pass

Prompt for password.

-b, --block

Block the specified account. If the account is already block nothing will change.

--defaults-file=DEFAULTS_FILE

Read from MySQL configuration file. Overrides --user, --password, --socket, --port.

Configuration needs to be in the following format:

--block

Print debug messages

[client]
user=my_user
password=my_pass
socket=/tmp/mysql.sock
port=3306

-H HOST, --host=HOST

MySQL host (default: localhost)

-l, --list

List accounts and their status (blocked/released).

-k, --kill

(With --block) kill any existing connection for the blocked account.

-p PASSWORD, --password=PASSWORD

MySQL password

-P PORT, --port=PORT

TCP/IP port (default: 3306)

--print-only

Do not execute. Only print statement

-r, --release

Release a blocked account. If the account is not blocked nothing will change.

-S SOCKET, --socket=SOCKET

MySQL socket file. Only applies when host is localhost

-u USER, --user=USER

MySQL user

-v, --verbose

Print user friendly messages

ENVIRONMENT

Requires MySQL 5.0 or newer, python 2.3 or newer. python-mysqldb must be installed in order to use this tool. You can
apt-get install python-mysqldb
or
yum install mysql-python

SEE ALSO

oak-kill-slow-queries

oak-security-audit

LICENSE

This tool is released under the BSD license.
Copyright (c) 2008 - 2010, Shlomi Noach
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

AUTHOR

Shlomi Noach
 
openark kit documentation