openstack 遇到的问题一

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介:

1 keystone-manage db_sync 这个已经是最全面的了。

Solution MySQL ERROR 1045 Access denied for 'user'@'localhost' - breaks OpenStack


mysql -u root -p
. . .
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu)
. . .

mysql> SELECT user,host,password FROM mysql.user;
+------------------+------------+-------------------------+
| user             | host       | password                |
+------------------+------------+-------------------------+
| root             | localhost  | *77B48D6366D102139D3719 |
| root             | mysqltests | *77B48D6366D102139D3719 |
| root             | 127.0.0.1  | *77B48D6366D102139D3719 |
| root             | ::1        | *77B48D6366D102139D3719 |
|                  | localhost  |                         |
|                  | mysqltests |                         |
| debian-sys-maint | localhost  | *04D30B480932109EFD77E1 |
+------------------+------------+-------------------------+
7 rows in set (0.00 sec)

mysql> show grants;
+---------------------------------------------------------+
| Grants for root@localhost                               |
+---------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'       |

|       IDENTIFIED BY PASSWORD '*77B48D6366D102139D3719'  |

|       WITH GRANT OPTION                                 |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT   |

|                                       OPTION            |
+---------------------------------------------------------+
2 rows in set (0.00 sec)


The mysql.user Table

At first glance, we have 2 users (root and debian-sys-maint). That's wrong, because mysql's "user" is a 'user'@'host' pair association. So we have 7 in total: 'root' is defined (with the same password) for any combination of 'localhost' (the first 4 lines), then we have 2 strange lines with empty username, and finally the debian backdoor 'debian-sys-maint'.


The grants

The 'show grants' above shows only grants for 'root'. But if we run the next staement, we see what access is provided to any user connecting from 'localhost':

mysql> show grants for ''@'localhost';
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+

Which (indirectly) explains why running this command (as Linux user 'ori') doesn't require a password:

[16:16:57]ori@mysqltests[~]

mysqladmin ping
mysqld is alive


Where this one fails:

[16:14:59]ori@mysqltests[~]
mysqladmin -uroot ping
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'


Honestly, in the beginning i thought there's some balck magic here related to the user ('ori', in this case) defined during ubuntu installation, or a special Linux group memebership, or some apparmor profile or god-knows what else.


But there's no black magic after all, and it's all inside mysql:

The first thing to bear in mind is that the empty USER field '' is a wildcard, same as '%' for host.

The second is that mysql prefers the explicit match over the wildcard. For example, user 'root' can match either [1] the explicit 'root'@localhost' row or [2] the wildcard ''@'localhost' row. Since there's an explicit entry for [1] in the table mysql.user, it'll be used. This in turn requires a password so when i try to connect as 'root' without a password i'm rejected.

When i connect as 'ori' - which isn't even a mysql user, there's only one possible match - ''@'localhost' and this line in the table doesn't have a password.

This nicely explains why the above mysqladmin command works for 'ori' and fails for 'root'.


To sum it up: mysql controls access (or connection request) based on the USER table. Which user, from which host and whether a password is required.

Once connected, the GRANTS determine what the user is allowed to do. When connected as 'ori' i'm limited to "USAGE" (e.g. check if server is up, what version and the like of inoffensive commands).


So far so good - but why 'glance'@'localhost' is denied access on the OpenStack controller?

When the static IP address of the conroller wasn't in /etc/hosts (or after it was commented-out), there was only one match for 'glance' = 'glance'@'%'

This, in turn, comes from the connection string (in /etc/glance/glance-registry.conf) which is:

sql_connection = mysql://glance:openstack@10.0.0.40/glance

It specifies user, password and host.

The line I've added for 10.0.0.40 in /etc/hosts, told mysql (indirectly) that host 'ostk-controller1' is actually 'localhsot'. From now on, there are 2 possible matches for 'glance', and the one picked by mysql is ''@'localhost'. This row, however, doesn't require a password - which the sql_connection string provide.

And that's why all OpenStack services couldn't connect to mysql.


Check against the USER table below, this was taken from ostk-controller (not the test VM):

mysql> SELECT user,host,password FROM mysql.user;
+------------------+------------------+-------------------------+
| user 
| host             | password |

+------------------+------------------+-------------------------+
| root 
| localhost        | *3A4A03AC22526F6B591010 |

| root | ostk-controller1 | *3A4A03AC22526F6B591010 |

| root | 127.0.0.1        | *3A4A03AC22526F6B591010 |

| root             | ::1              | *3A4A03AC22526F6B591010 |
|                  | localhost        | 
|

|                  | ostk-controller1 |                         |
| debian-sys-maint | localhost        | *F714636CE8A7836873F7C8 |
| nova             | %                | *3A4A03AC22526F6B591010 |
| glance           | %                | *3A4A03AC22526F6B591010 |
| keystone         | %                | *3A4A03AC22526F6B591010 |
+------------------+------------------+-------------------------+
10 rows in set (0.00 sec)

Solution for ERROR 1045

After understanding why, let's improve on the poor workaround.

I'd like to credit an answer by Paul DuBois from 2004 for this solution(it's worth noting that the subject was "Re: Any way to make anyhost '%' include localhost").


Borrowing from there, here's the remedy:

in MySQL:

mysql -uroot -p

DELETE FROM mysql.user WHERE Host='localhost' AND User='';

DELETE FROM mysql.user WHERE Host='ostk-controller1' AND User='';

FLUSH PRIVILEGES;


in /etc/hosts:

Replace the line

127.0.1.1ostk-controller1

by this one:

10.0.0.40 ostk-controller1

Quoting from Debian's reference manual:

For a system with a permanent IP address, that permanent IP address should be used here instead of 127.0.1.1


finally restart networking and mysqld - or simply reboot.


A Second Solution

Months after going through the above study, i found out why some OpenStack installations don't hit this issue; The keystone installation instructions (from Ubuntu, for Essex, can be found here) create each OSTK user in mysql twice, as in:

mysql> CREATE DATABASE keystone;
CREATE USER ‘keystone’@’localhost’ IDENTIFIED BY ‘Secret_pass’;
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone’@’localhost’
WITH GRANT OPTION;
CREATE USER ‘keystone’@’%’ IDENTIFIED BY ‘Secret_pass’;
GRANT ALL PRIVILEGES ON keystone.* TO ‘keystone’@’%’
IDENTIFIED BY ‘Secret_pass’;
FLUSH PRIVILEGES;


本文转自luojinghappy 51CTO博客,原文链接:http://blog.51cto.com/luojinghappy/1342663,如需转载请自行联系原作者
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
3月前
|
运维 安全 测试技术
Hydra-SSH 漏洞安全防范
Hydra 是由 THC 组织开发的强力网络安全测试工具,主要用于对 SSH、FTP、HTTP 等协议进行认证爆破,适用于授权渗透测试与弱口令检测。其高效性依赖于优化的字典策略,强调质量优先,结合目标信息定制密码列表,提高破解成功率。
417 1
|
3月前
|
数据可视化 数据挖掘 关系型数据库
借助 MCP 赋能数据可视化,让数据‘燃’起来
在数字化时代,数据成为企业竞争的关键资源。MCP工具作为“数据中转站”和“智能翻译官”,可连接阿里云PolarDB MySQL数据库,通过拖拽操作实现零代码数据分析,降低技术门槛。结合阿里云百炼大模型,用户只需输入自然语言即可生成可视化图表,快速获取数据洞察,助力企业高效决策。
|
4月前
|
存储 Ubuntu 安全
Linux中Centos和Ubuntu的区别
CentOS主要面向服务器环境,而Ubuntu适用于服务器和桌面环境。   CentOS提供更精简的安装,而Ubuntu提供更广泛的开箱即用功能。   CentOS遵循RHEL的所有安全实践,而Ubuntu在安全方面采取更积极的方法。
|
9月前
|
机器人 数据安全/隐私保护
基于PID控制器的六自由度串联机器人控制系统的simulink建模与仿真
本课题基于MATLAB2022a的Simulink环境,对六自由度串联机器人控制系统进行建模与仿真,采用PID控制器实现关节的位置、速度或力矩控制。PID控制器通过比例、积分、微分三种策略有效减小系统误差,提高响应速度和稳定性。仿真结果显示系统运行良好,无水印。尽管PID控制简单实用,但在复杂动力学环境下,常结合其他控制策略以增强鲁棒性。
|
10月前
|
JSON 监控 API
虾皮(shopee)商品列表接口(虾皮API 系列)
虾皮(Shopee)是东南亚及台湾地区的知名电商平台,提供丰富的商品数据。通过其API接口,开发者可合法获取商品列表信息,包括商品ID、名称、价格等,支持按分类、关键词、价格范围等条件筛选。Python示例代码展示了如何使用API进行请求,并解析返回的JSON数据。应用场景涵盖市场调研、竞品分析、选品决策、价格监控及数据可视化,帮助电商从业者和分析师更好地理解市场动态,优化运营策略。
|
开发工具 git
git分支管理master/hotfix/develop/feature/release
采用合理的Git分支管理模型可以显著提升团队协作效率和代码管理的质量。本文介绍的 `master`、`develop`、`feature`、`release`和 `hotfix`分支模型是一个行之有效的方法,适用于大多数软件开发项目。通过清晰地划分各个分支的职责,团队成员可以更专注于各自的开发任务,同时确保代码库的稳定性和可维护性。
1205 2
|
12月前
|
机器学习/深度学习 传感器 自动驾驶
基于深度学习的图像识别技术及其在自动驾驶中的应用####
本文深入探讨了深度学习驱动下的图像识别技术,特别是在自动驾驶领域的革新应用。不同于传统摘要的概述方式,本节将直接以“深度学习”与“图像识别”的技术融合为起点,简述其在提升自动驾驶系统环境感知能力方面的核心作用,随后快速过渡到自动驾驶的具体应用场景,强调这一技术组合如何成为推动自动驾驶从实验室走向市场的关键力量。 ####
371 24
|
机器学习/深度学习 数据采集 数据可视化
智能食品消费行为分析:基于Python与深度学习的实现
智能食品消费行为分析:基于Python与深度学习的实现
314 7
|
人工智能 运维 安全
科技云报到:数字化转型,从不确定性到确定性的关键路径
科技云报到:数字化转型,从不确定性到确定性的关键路径
180 6
|
弹性计算 网络协议 UED
SLB-Backend会话保持
【10月更文挑战第21天】
331 7