openshift / community.okd

OKD/Openshift collection for Ansible
http://galaxy.ansible.com/community/okd
GNU General Public License v3.0
56 stars 36 forks source link

.strip method must not be used to trim the prefix of sha256~ from token #239

Closed vahidmohsseni closed 4 months ago

vahidmohsseni commented 4 months ago

From time to time, I was receiving "Couldn't delete user oauth access token...". After checking the source code, the source of the problem has been found in https://github.com/openshift/community.okd/blob/adfb5ee140ac39b7ad46e330779c16f5665d1c02/plugins/modules/openshift_auth.py#L227

According the python documents, the argument for .strip method is "The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped" in which it results to delete any chars of s, h, a, 2, 5, 6 after the "sha256~" prefix.

For example:

token: sha256~2dUaKIReqcoPjJoKPXxdTxGXTyF5-VILay9KEQ-Plco
result: dUaKIReqcoPjJoKPXxdTxGXTyF5-VILay9KEQ-Plco

The fix should not be that complicated. As of python 3.9+, the removeprefix method has been added for string. However, I suggest to simply trim based on the length of the prefix.

gravesm commented 4 months ago

Duplicate of #194