unable to login with `system:admin`
$ oc login https://127.0.0.1:8443 -u system:admin
The server uses a certificate signed by an unknown authority.
You can bypass the certificate check, but any data you send to the server could be intercepted by others.
Use insecure connections? (y/n): y
Authentication required for https://127.0.0.1:8443 (openshift)
Username: system:admin
Password:
error: username system:admin is invalid for basic auth
Now magically it worked,
$ oc login -u system:admin
Logged into "https://127.0.0.1:8443" as "system:admin" using existing credentials.
You have access to the following projects and can switch between them with 'oc project <projectname>':
default
kube-dns
kube-proxy
kube-public
kube-service-catalog
kube-system
* myproject
openshift
openshift-apiserver
openshift-automation-service-broker
openshift-controller-manager
openshift-core-operators
openshift-infra
openshift-node
openshift-template-service-broker
openshift-web-console
Using project "myproject".
can someone please explain reason or cure for this flaky behavior?
system:admin is cert based user. login just uses the correct context if you have it available:
$ export KUBECONFIG=<...>/openshift.local.config/master/admin.kubeconfig
$ oc config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* default/192-168-43-69:8443/system:admin 192-168-43-69:8443 system:admin/192-168-43-69:8443 default
$ oc config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: REDACTED
server: https://192.168.43.69:8443
name: 192-168-43-69:8443
contexts:
- context:
cluster: 192-168-43-69:8443
namespace: default
user: system:admin/192-168-43-69:8443
name: default/192-168-43-69:8443/system:admin
current-context: default/192-168-43-69:8443/system:admin
kind: Config
preferences: {}
users:
- name: system:admin/192-168-43-69:8443
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
what if I dont have kubeconfig and I did,
oc login https://127.0.0.1:8443 -u system:admin
what will happen ?
what if I dont have kubeconfig and I did,
oc login https://127.0.0.1:8443 -u system:adminwhat will happen ?
It will fail since you cannot get a token for system:admin. You must have the correct kubeconfig file already available for it to switch to the appropriate user.
Can't connect with system:admin , the result of oc config view is :
apiVersion: v1
clusters:
- cluster:
insecure-skip-tls-verify: true
server: https://192.168.99.100:8443
name: 192-168-99-100:8443
- cluster:
certificate-authority: C:\Users\Slim\.minikube\ca.crt
server: https://192.168.99.100:8443
name: minikube
contexts:
- context:
cluster: 192-168-99-100:8443
user: admin/192-168-99-100:8443
name: /192-168-99-100:8443/admin
- context:
cluster: 192-168-99-100:8443
user: dev/192-168-99-100:8443
name: /192-168-99-100:8443/dev
- context:
cluster: 192-168-99-100:8443
user: system/192-168-99-100:8443
name: /192-168-99-100:8443/system
- context:
cluster: minikube
user: minikube
name: minikube
- context:
cluster: 192-168-99-100:8443
namespace: myproject
user: developer/192-168-99-100:8443
name: myproject/192-168-99-100:8443/developer
current-context: /192-168-99-100:8443/system
kind: Config
preferences: {}
users:
- name: admin/192-168-99-100:8443
user:
token: xxx
- name: dev/192-168-99-100:8443
user:
token: xyx
- name: developer/192-168-99-100:8443
user:
token: zycv
- name: minikube
user:
client-certificate: C:\Users\Slim\.minikube\client.crt
client-key: C:\Users\Slim\.minikube\client.key
- name: system/192-168-99-100:8443
user:
token: dfsds
How can I fix that?
In my case, I just had to login in superuser context to run the command so that it can pick up the right certificate for automatic authentication credentials. Use "sudo" in front of your command as in "sudo oc login https://127.0.0.1:8443 -u system:admin"
sudo oc login -u system:admin