问题描述
今天收到告警,vcenter链接状态异常,检查从center发现,输入正确的用户名和密码后,无法登录,提示:User name and password are required(用户名和密码被需要),即等同你未输入用户名和密码;输入错误的密码会提示身份认证非法,说明身份认证还是起作用的,服务状态可判断为正常。
页面强行登录时,报400错误。
问题分析:
1、vcenter输入正确的用户名和密码,无法登录,且提示需要用户名和密码,明明输入了为啥会不识别呢?后沟通确认无人修改过密码;即时修改过,应该提示密码不正确才对;
2、输入错误的密码,提示认证非法,即密码不正确,说明身份认证还是起作用的,服务状态可判断为正常;
3、重启vc和psc,提示“”Your clock is ahead“”,管理机本地时间与vc不一致,页面无法打开,vca 5480页面同样无法打开;
4、ssh登录vc和psc,执行timedatectl修改系统时区为CST,
#timedatectl set-timezone “Asia/Shanghai”
#timedatectl set-time ‘2020-08-31 12:08:30’
#timedatectl status //验证
#timedatectl set-local-rtc 1 //将硬件时钟设置为本地时区
#timedatectl | grep local //验证
#timedatectl set-ntp true //开启自动时间同步到远程NTP服务器
#hwclock --set --date=“20/08/31 12:08” //将硬件时钟设置为 -date选项指定的时间
#hwclock --hctosys //将硬件时钟设置为系统时间,利用–systohc参数, 将当前的系统时间设置为硬件时钟
设置后验证未果;
5、检查https证书,发现证书日期,到期,恰好是今天;修改本地时间为前一天,打开vca网页正常,登录闪跳弹出登录,且无法访问vcenter,因系统内部时间比当前时间早,系统服务还是通信异常;
6、初步判断为vc的https 证书过期原因导致的身份验证失败,需重新生成证书文件。
问题原因
VMware 已经于2020 年4 ⽉2 ⽇发布了全新设计的vSphere 7 系统。针对vSphere 6 会存在一些问题,其中关于证书,官方提到,从vCenter 6.5 Update2 (GA Date : 2018 年5 ⽉3 号) 及后⾯的版本,透过VC ⾃带的VMCA 签发的证书,有效期均为2 年;vCenter 的证书在安装部署时,⼀般是默认10 年的,vCenter 6.5 以后的部分版本存在证书只有 2 年有效期;vsphere 6.5~6.7 版本遇到两年证书有效期的问题是客户部署的 vCenter 6.5 系统突然无法登录的主要体现。但从老版本升级的例外,以下是相关说明:
版本\CA有效期 | 2年 | 10年 |
---|---|---|
6.5 | 全新安装 6.5U2 及之后的版本 | 从 6.5U2 之前版本升级上来 |
6.7 | 全新安装 6.7U3g 及之后的版本 全新安装 6.7 – 6.7U3g 之间的版本 |
从 6.5U2 及之后的版本升级上来 从 6.5U2 之前版本升级上来 |
注意:vCenter Server不会在升级时刷新STS证书。
处理和预防
1)日常运维,可以登录vCenter 时验证证书有效期,并记录管理,位置如下:
HTML5界面(无法查看STS证书):主页 – 系统管理 – 证书 – 证书管理
Flash界面:主页 – 系统管理 – Single Sign-on – 配置 – 证书 – STS证书
注意:证书过期警报不代表STS证书。确定STS证书到期日期的唯一方法:
从官网 下载脚本checksts.py,上传到vCenter Server or external PSC的/tmp目录,运行 python checksts.py,对于Windows Server里,在命令行运行 %VMWARE_PYTHON_BIN% checksts.py
从脚本结果里,可以看到证书的有效期。
或执行:
/usr/lib/vmware-vmafd/bin/vecs-cli entry list --store vpxd-extension --text | less
VMware建议偶尔检查STS证书以确保它不会过期,如果证书将在6个月内过期,建议更换它。
2)vcenter可正常登录,但证书即将到期,可更换或续订;vcenter重新生成和更换证书:
6.5 及以下: https://vc-ip-address/psc,登录后点击:证书 - 证书管理– 选择证书 – 续订
6.7:主页 – 系统管理 – 证书 – 证书管理 – 选择证书 – 操作 – 续订
3)vc证书已过期且无法web登录时:
当STS(Security Token Service,安全令牌服务)证书过期时,不会再有告警。2年时间一到,会立即导致vCenter不可用。
检查/var/log/vmware/vpxd-svcs/vpxd-svcs.log日志,可看到类似错误:
ERROR com.vmware.vim.sso.client.impl.SecurityTokenServiceImpl$RequestResponseProcessor o pId=] Server rejected the provided time range. Cause:ns0:InvalidTimeRange: The token authority rejected an issue request for TimePeriod [startTime=Thu Jan 02 09:22:13 EST 2020, endTime=Fri Jan 03 09:22:13 EST 2020] :: Signing certificate is not valid at Thu Jan 02 09:22:13 EST 2020, cert validity: TimePeriod [startTime=Wed
Aug 06 20:44:39 EST 2010, endTime=Wed Aug 01 20:54:23 EST 2020] 注意:证书过期时,endTime应该是某个过去的时间。
页面登录时遇到以下报错:
HTTP Status 400 – Bad Request Message BadRequest, Signing certificate is not valid 目标:重新产生证书并替换已过期的证书。
后果:证书过期后,内部服务和解决方案用户无法获取有效的令牌,无法正常工作。
如果通过 WebClient or UI Client 登录vc,会显示503错误,这是因为vmware-vpxd会因证书过期不再运行所导致:
503 Service Unavailable (Failed to connect to endpoint: [N7Vmacore4Http20NamedPipeServiceSpecE:0x00007fb444041040] _serverNamespace = / action = Allow _pipeName =/var/run/vmware/vpxd-webserver-pipe)
脚本地址:
A)fixsts.sh:
wget https://kb.vmware.com/sfc/servlet.shepherd/version/download/068f400000JAn50AAD2
B)
wget https://kb.vmware.com/sfc/servlet.shepherd/version/download/068f400000HW9InAAL9
运行脚本的风险:这个脚本将影响VMDIR数据库,且只能一个SSo域内运行一次,在运行脚本之前,务必对vCenter Server和PSC Server 做离线快照;执行有问题后恢复快照,重新执行。
1)下载 "fixsts.sh"后,上传到vCenter/PSC Server上的临时目录/tmp下,赋予执行权限:
chmod +x fixsts.sh && ./fixsts.sh
2)脚本执行完成后,在vc和PSC上重启所有服务:
service-control --stop --all
service-control --start --all
报错:
Service-control failed. Error Failed to start vmon services.vmon-cli RC=1, stderr=Failed to start sca, cm, vapi-endpoint services. Error: Operation timed out
3)重启vCenter/PSC Server
4)验证:
for i in $(/usr/lib/vmware-vmafd/bin/vecs-cli store list); do echo STORE $i; /usr/lib/vmware-vmafd/bin/vecs-cli entry list --store $i --text | egrep “Alias|Not After”; done
上述脚本要求SSO administrator password 然后 重新生成和替换STS certificate,以下是示例:
NOTE: This works on external and embedded PSCs
This script will do the following
1: Regenerate STS certificate
What is needed?
1: Offline snapshots of VCs/PSCs
2: SSO Admin Password
IMPORTANT: This script should only be run on a single PSC per SSO domain
==================================
Resetting STS certificate for vcsa1.gsslabs.org started on Fri May 22 14:39:40 UTC 2020
Detected DN: cn=vcsa1.gsslabs.org,ou=Domain Controllers,dc=vsphere,dc=local
Detected PNID: vcsa1.gsslabs.org
Detected PSC: vcsa1.gsslabs.org
Detected SSO domain name: vsphere.local
Detected Machine ID: ce510c87-35e6-444e-82f0-60a7527608a3
Detected IP Address: 192.168.0.51
Domain CN: dc=vsphere,dc=local
==================================
==================================
Detected Root's certificate expiration date: 2030 May 16
Detected today's date: 2020 May 22
==================================
Exporting and generating STS certificate
Status : Success
Using config file : /tmp/vmware-fixsts/certool.cfg
Status : Success
Enter password for [email protected]:
Amount of tenant credentials: 1
Exporting tenant and trustedcertchain 1 to /tmp/vmware-fixsts
Deleting tenant and trustedcertchain 1
Applying newly generated STS certificate to SSO domain
adding new entry "cn=TenantCredential-1,cn=vsphere.local,cn=Tenants,cn=IdentityManager,cn=Services,dc=vsphere,dc=local"
adding new entry "cn=TrustedCertChain-1,cn=TrustedCertificateChains,cn=vsphere.local,cn=Tenants,cn=IdentityManager,cn=Services,dc=vsphere,dc=local"
Replacement finished - Please restart services on all vCenters and PSCs in your SSO domain
==================================
IMPORTANT: In case you're using HLM (Hybrid Linked Mode) without a gateway, you would need to re-sync the certs from Cloud to On-Prem after following this procedure
==================================
==================================
注意:你可能会遇到bash: ./recreate_machine.sh: /bin/bash^M: bad interpreter: No such file or directory的报错,这是因在windows txt编辑时,默认追加的换行符与linux系统字符不兼容所致,可以执行:
sed -i -e ‘s/\r$//’ fixsts.sh
然后再重复上述步骤。
5) 正常这时,vCenter就可以正常登录了。
附录:Appliance Shell与bash shell切换
chsh -s /bin/bash root //切换到bash shell
chsh -s /bin/appliancesh root //切回到Appliance Shell
通过wincp 的scp上传脚本文件到psc和vc appliance时,会报错:
Host is not communicating for more than 15 seconds. If the problem repeats, try turning off ‘Optimize connection buffer size’.
可切换到bash shell后再次连接即可。