INTRO
앞에 글에서 RBAC을 알아보았고 이 글에서 소개드릴 내용은 RBAC을 이용하여 RHOCP ID Provider을 생성하는 내용입니다.
RHOCP) RBAC이란? (Rules, Roles 포함)
INTRO RHOCP를 처음 구축하고나면 kubeadmin을 비활성화하고 개인 혹은 조직이 사용할 계정을 만들어야합니다. 제가 공부할 때 처음으로 만난 난관은 권한부여였는데 RHOCP의 경우 RBAC(Role-based access cont
lilo.tistory.com
ID Provider 구성에 관한 글은 아래의 문서를 참고하였습니다.
Configuring an htpasswd identity provider - Configuring identity providers | Authentication and authorization | OpenShift Contai
By default, only a kubeadmin user exists on your cluster. To specify an identity provider, you must create a custom resource (CR) that describes that identity provider and add it to the cluster. OpenShift Container Platform user names containing /, :, and
docs.openshift.com
ID Provider 구성
kubeadmin 계정을 추후에 비활성화할 예정이기 때문에 미리 cluster-admin 계정을 생성하여야합니다. 이러한 계정을 추가하려면 CR(Custom Resource)를 생성해야 합니다.
많은 ID Provider들이 있지만 소개드릴 내용은 가장 많이 사용되는 htpasswd, LDAP입니다.
ID Provier | 설명 |
htpasswd | htpasswd를 사용하여 생성된 파일에 대한 계정과 암호의 유효성을 검사하여 ID Provier 구성 |
LDAP | LDAP v3 서버에 대한 계정과 암호를 검증하여 ID Provider를 구성 (Windows Active Directory도 LDAP 프로토콜을 이용한 서비스이므로 포함됨) |
ID Provider에 대한 더 많은 종류와 내용은 아래의 문서를 참고바랍니다.
Understanding identity provider configuration | Authentication and authorization | OpenShift Container Platform 4.13
Configure a request-header identity provider to identify users from request header values, such as X-Remote-User. It is typically used in combination with an authenticating proxy, which sets the request header value.
docs.openshift.com
ID Provider 구성 - htpasswd 사용
별도로의 AD 서버도 없고 LDAP 서버도 없을 경우에 간단하게 사용할 수 있는 방법이고 보편적으로 많이 사용됩니다.
물론 보안적인 요소에서는 LDAP 서버에서 계정을 관리하는 것이 더 좋은 방법입니다. (OpenLDAP, FREEIPA, AD 등)
htpasswd를 사용하기 위해 httpd-tools 패키지를 설치합니다.
# dnf install httpd-tools
htpasswd를 이용한 계정 정보 및 CR이 저장될 디렉토리를 생성합니다. 앞전에 RHOCP와 관련된 config는 "/root/ocp"에 저장해놓아서 이 디렉토리에 생성할 예정입니다.
# mkdir -p /root/ocp/htpasswd
htpasswd를 이용하여 계정과 암호를 생성합니다.
# htpasswd -c -B -b /root/ocp/htpasswd/users.htpasswd <유저> <암호>
추가로 계정 생성이 필요한 경우 아래의 명령을 수행하면 됩니다. (Optional)
# htpasswd -B -b /root/ocp/htpasswd/users.htpasswd <유저> <암호>
앞에서 생성한 계정 정보를 기반으로 secret을 생성합니다.
<OC 명령어를 이용하여 secret 생성>
# oc create secret generic htpass-secret --from-file=htpasswd=/root/ocp/htpasswd/users.htpasswd -n openshift-config
<YAML을 작성하여 secret 생성>
cat << EOF > /root/ocp/htpasswd/htpass_secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: htpass-secret
namespace: openshift-config
type: Opaque
data:
htpasswd: `base64 -w0 /root/ocp/htpasswd/users.htpasswd` ## htpasswd.user file
EOF
# oc apply -f /root/ocp/htpasswd/htpass_secret.yaml
# oc get secrets -n openshift-config htpass-secret
NAME TYPE DATA AGE
htpass-secret Opaque 1 17s
앞에서 생성한 Secret을 기반으로 CR을 생성합니다.
<htpasswd CR 생성 - ORG는 조직 이름으로 지정>
# ORG=OCP-TB
# cat <<EOF > /root/ocp/htpasswd/htpasswd_cr.yaml
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: ${ORG}
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpass-secret
EOF
# oc apply -f /root/ocp/htpasswd/htpasswd_cr.yaml
Warning: resource oauths/cluster is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by oc apply. oc apply should only be used on resources created declaratively by either oc create --save-config or oc apply. The missing annotation will be patched automatically.
oauth.config.openshift.io/cluster configured
새로운 CR 생성시 다음과 같은 경고가 출력될 수도 있는데 무시해도 됩니다.
생성한 'admin'이라는 계정에 cluster-admin role을 binding합니다. cluster-admin role을 binding한 이유는 추후 kubeadmin 계정을 제거할 예정이기 때문입니다.
# oc adm policy add-cluster-role-to-user cluster-admin admin
웹 콘솔에 접속한 후 설정한 정보대로 정상적으로 되는지 확인합니다. (ID Provider name인 OCP-TB 확인)
OC 명령어로 login시 인증서 에러 발생
계정을 생성한 후 웹 콘솔 접속은 잘 되는데 OC 명령어로 login이 안되는 현상이 발생합니다.
아래와 같이 OC 명령어로 접속을 시도합니다. X.509 인증서가 익명의 사용자에 의해 사인되었다고 출력됩니다.
# oc login -u admin
error: x509: certificate signed by unknown authority
에러에 대한 Log level을 올려서 실패에 대한 분석을 시도합니다.
API 서버와의 통신은 정상적으로 되었지만 kubeconfig에 CA가 포함되어 있지 않다는 로그가 출력되었습니다.
해결 방법
☞ "--insecure-skip-tls-verify=true" 명령을 통해 일시적으로 insecure 접속
☞ Incress CA를 기반으로 로그인을 시도하는 방법 (추천)
# oc login --loglevel 6 -u admin
I0726 06:30:15.610249 63442 loader.go:373] Config loaded from file: /root/ocp/config/auth/kubeconfig
I0726 06:30:15.621072 63442 round_trippers.go:553] HEAD https://api.ocp4.example.com:6443/ 403 Forbidden in 10 milliseconds
I0726 06:30:15.635261 63442 round_trippers.go:553] GET https://api.ocp4.example.com:6443/apis/user.openshift.io/v1/users/~ 200 OK in 13 milliseconds
I0726 06:30:15.635978 63442 request_token.go:93] GSSAPI Enabled
I0726 06:30:15.637250 63442 round_trippers.go:553] GET https://api.ocp4.example.com:6443/.well-known/oauth-authorization-server 200 OK in 1 milliseconds
I0726 06:30:15.681138 63442 request_token.go:467] falling back to kubeconfig CA due to possible x509 error: x509: certificate signed by unknown authority
I0726 06:30:15.691027 63442 round_trippers.go:553] GET https://oauth-openshift.apps.ocp4.example.com/oauth/authorize?client_id=openshift-challenging-client&code_challenge=O7VdkvM_uLl6TUUXSc_VOyiviOsRhOz3Da1QWjFGMiI&code_challenge_method=S256&redirect_uri=https%3A%2F%2Foauth-openshift.apps.ocp4.example.com%2Foauth%2Ftoken%2Fimplicit&response_type=code in 9 milliseconds
I0726 06:30:15.693460 63442 round_trippers.go:553] GET https://api.ocp4.example.com:6443/api/v1/namespaces/openshift/configmaps/motd 403 Forbidden in 1 milliseconds
error: x509: certificate signed by unknown authority
Ingress CA를 추출하여 CA 인증서를 생성하는 작업을 합니다.
<oauth 인증 pod 조회>
# oc get pod -n openshift-authentication
NAME READY STATUS RESTARTS AGE
oauth-openshift-684d4c7745-6hg6l 1/1 Running 0 34m
oauth-openshift-684d4c7745-bkzdh 1/1 Running 0 35m
oauth-openshift-684d4c7745-pm4rr 1/1 Running 0 34m
<Ingress CA를 추출 후 인증서 파일 생성>
# oc rsh -n openshift-authentication oauth-openshift-684d4c7745-6hg6l cat /run/secrets/kubernetes.io/serviceaccount/ca.crt > /root/ocp/config/auth/ingress-ca.crt
OC 명령어를 통해 앞에서 생성한 인증서 파일을 사용하여 API 서버에 접속합니다.
# oc login -u <유저> -p <패스워드> https://api.ocp4.example.com:6443 --certificate-authority=/root/ocp/config/auth/ingress-ca.crt
Login successful.
You have access to 67 projects, the list has been suppressed. You can list all projects with 'oc projects'
Using project "default".
error: x509 certificate signed by unknown authority when logging in OpenShift 4 using the installation kubeconfig file - Red Hat
When logging as a user using the kubeconfig from the installation (auth/kubeconfig) an error is shown: error: x509 certificate signed by unknown authority error.. Using a separate kubeconfig allows logging but then the new kubeconfig doesnt contain the inf
access.redhat.com
kubeadmin 계정 제거 (주의 필요)
앞에서 cluster-admin 계정 생성을 완료하였으면 kubeadmin 계정을 제거합니다.
cluster-admin role을 가진 계정이 생성되고 로그인 되는 것까지 확인해야되며 만약 정상적으로 만들어지지 않았는데 kubeadmin 계정을 삭제하게되면 RHOCP 클러스터를 재구축해야합니다.
kubeadmin Secret을 제거합니다.
# oc delete secrets kubeadmin -n kube-system
secret "kubeadmin" deleted
<OC 명령어를 통해 kubeadmin 계정이 로그인 되지 않는 로그 출력 확인>
# oc login -u kubeadmin -p $(cat /root/ocp/config/auth/kubeadmin-password )
Login failed (401 Unauthorized)
Verify you have provided the correct credentials.
<OC 명령어를 통해 cluster-admin role을 가진 계정 로그인>
# oc login -u admin -p redhat
Login successful.
You have access to 67 projects, the list has been suppressed. You can list all projects with 'oc projects'
Using project "default".
Understanding identity provider configuration | Authentication and authorization | OpenShift Container Platform 4.13
Configure a request-header identity provider to identify users from request header values, such as X-Remote-User. It is typically used in combination with an authenticating proxy, which sets the request header value.
docs.openshift.com
'Linux > OpenShift' 카테고리의 다른 글
RHOCP) Machine Config를 이용한 Chrony 설정 (0) | 2023.07.26 |
---|---|
RHOCP) Machine Config Operator (MCO) (0) | 2023.07.26 |
RHOCP) RBAC이란? (Rules, Roles 포함) (0) | 2023.07.26 |
RHOCP Installation (9) - OCP 클러스터 설치 (0) | 2023.07.25 |
RHOCP Installation (8) - Install Config 및 Ignition 파일 생성 (0) | 2023.07.25 |