Security

hahic·2023년 1월 9일
0

Kubernetes/CKA

목록 보기
7/13
post-thumbnail

View Certificate Details

openssl x509 -in XXXXX.crt -text -noout 명령어로 인증서에 대한 정보를 볼 수 있다

apiserver

  • certificate

  • openssl x509 인증서

etcd

  • certificate

  • openssl x509 인증서

핵심 명령어

  • crictl ps -a
  • crictl logs XXXXXXX

Reference

https://kubernetes.io/ko/docs/tasks/debug/debug-cluster/crictl/ -> crictl로 kubernetes node 디버깅하는 법
https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md -> crictl 관련 github

Certificates API

핵심 명령어

  • cat > akshay.yaml
  • cat akshay.csr | base64 -w 0
  • k certificate approve akshay
  • kubectl certificate deny agent-smith
  • k delete csr agent-smith
  • k get csr

Reference

https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/

KubeConfig

KubeConfig은 $root/.kube/config에 있다

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMvakNDQWVhZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJek1ERXdPVEE0TlRRMU5sb1hEVE16TURFd05qQTROVFExTmxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBUDV2ClJieThGZGlZeTg4Q2oxNURkN0l6QWlaSWdpanhHb0RkRTJkek5nWjNPd3Vya2tiWlIxdlpldlliRTBqaDU0Q08KUjRsMVNZK3lRYmJPOEFvTEpIZk9QeU04R2xPYjlqVS8vT3VxQUR4Q2YySmRBb1N4Zm5qcS9BMFZzZm00bXZ2TQp0YlpRVlZDdjB0ZndJN1BxbUZHSU4wVGNxbTVTZmN5RjUvSXZXNjlMUFZGclhpOWVBMFlQR2h3TDZvUlJlc3pqCkIxYzJQYm5KRTA5M1hxaEZUWEExVXEwYlFSK3REVDl3dDZCaGdHQmxqajA5WGp5TENwU2I2RG9KK0FZT2hlNDkKZ1NHZk5JY21WM00rNHhrbm1HZ2dzM2MrcmhjcHNERlBTOFNTNHlmQ3FsWTVHR3lyYVZmalVvN0dGeFlOZldiNAo2aXJYOHJpbEdKODdFeDNidmljQ0F3RUFBYU5aTUZjd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZPZDVVbmJwaktRdUZmeURXRy9HMkZKcHNNS3BNQlVHQTFVZEVRUU8KTUF5Q0NtdDFZbVZ5Ym1WMFpYTXdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBTWxoZnBGZ1VTSW8xMjI3SmxvcApSVEw0NHVVdXUzRVNPOUtYekVMZTAxTC9mVGtPTDUxVUgyTUxjUDNjdHNPeDIxUWhoY21XTUNLdllzYlNsZVErCmViTFhBc0NySHpiMXYvS0IwU2VIaWczTENXWGIrSnZDMnNjdWNGRnUvbHA0T3AyQ0VtclRRQ0hERTFyVWJEWXYKeTNKbEpSMlZ3bEtLM0Nha2xGTDkvSytoeXNZckpHZTZ4K3JvVFY1VnNqYmQ5OE9Nakhrem90a25FM2U5eXNqWQprUHRGUlJrSVVnOGtUb2MyVERxaHd3dDRpQUxaZ1BGZElVRXg0T1V0OE1Xdm42TUV1bnRGaURpcUhGbVBMUHdYCkZFVmlEMmh4UGpHMmVUc2t5UXRiVVRnTURLd01ack5QYU1sYzAzcnZzWU91aldjYmt4MFpBY2lvLzM3V1FWOE0KSUxrPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://controlplane:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDR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mdOMkVjVUpYYTRLa0Erb1ZCbGg0dzl5K0d2WFFPClF2MVFBR0hEQkNORGlRekhFRG9QQXdLQmdGYjUxNjZkRmMzdTVrUG0zREYzQmk2UzZNaW02V0lRK1gwakNIeHUKUE5UbjNxMk41MVVBNG9KenJvdExhQ3MybVZWYUtlVUZRUGkrdmJxcUwvUDliUWM0cXh2N3V2QTNuWG9mbnNKUQpPMzdXbWZiYnM5QTlHd1FURHJRUnhVWXpiU1ZxUitydTFJUUpDQXZnUzdLZWhFSTZvUEpKV0d5YTAzS0JZUlFWCjBBb0JBb0dBQmx0Z002ZllJRDhkWXBoSENyeVlDY0xKUEtyY25xT2xVeXk0MjY1T3VqbUQ0enBnSnlmK2pwcmIKVFE3WUJCYmVHRWNoM0VjWUlINDhQR0s3QWt1aHhlWU42KzNMWFRPWnh1ZzBQRXIyRE11V3ZvVXBET05aT0RDYQpPd2syVVltU1lkRE5ZV2dsV2dRZVZjaGdWdVp2TlREeHJGeFBUTGsycHRIYnc5MUpTZW89Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==

핵심 명령어

  • kubectl config --kubeconfig=config-demo view
  • mv my-kube-config .kube/config

Reference

https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/ -> config에 대한 문서

Role Based Access Controls

/etc/kubernetes/manifest/kube-apiserver.yaml에서 authorization 확인 가능하다

--as dev-user은 dev-user 사용자로 해당 명령어를 실행하는 것과 같은 결과를 보여준다

핵심 명령어

  • k get roles
  • k get roles -A --no-headers | wc -l
  • k describe role -n kube-system kube-proxy
  • k get rolebindings
  • k describe rolebindings -n kube-system kube-proxy
  • k config view
  • k get pods --as dev-user
  • kubectl create role developer --verb=list,create,delete --resource=pods
  • kubectl create rolebinding dev-user-binding --role=developer --user=dev-user

Reference

https://kubernetes.io/docs/reference/access-authn-authz/rbac/ -> role, rolebinding에 관한 공식 문서

Cluster Roles

clusterrole과 clusterrolebinding은 role과 rolebinding과 다르게 namespace에 한정되지 않는다

핵심 명령어

  • k get clusterrole
  • k get clusterrole --no-headers | wc -l
  • k get clusterrolebindings
  • k get clusterrolebindings --no-headers | wc -l
  • kubectl create clusterrole storage-admin --verb=get,list,watch,create,delete --resource=persistentvolumes,storageclasses
  • kubectl create clusterrolebinding michelle-storage-admin --clusterrole=storage-admin --user=michelle

Reference

https://kubernetes.io/docs/reference/access-authn-authz/rbac/ -> clusterrole, clusterrolebinding에 관한 공식 문서

Service Account

Reference

https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/

Image Security

Private Image를 다운받기 위한 방법

핵심 명령어

  • k get secret
  • kubectl create secret docker-registry private-reg-cred --docker-server=myprivateregistry.com:5000 --docker-username=dock_user --docker-password=dock_password --docker-email=dock_user@myprivateregistry.com

Reference

https://kubernetes.io/ko/docs/concepts/containers/images/#%EC%9D%B4%EB%AF%B8%EC%A7%80-%ED%92%80-pull-%EC%A0%95%EC%B1%85 -> imagePullSecrets 설정 방법

Security Contexts

Pod 수준의 Security Contexts와 Container 수준의 Security Contexts이 존재한다

핵심 명령어

  • k exec ubuntu-sleeper -- whoami

Reference

https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/learn/lecture/32211174#overview -> security context 설정하는 방법

Network Policies

핵심 명령어

  • k get networkpolicies
  • k get netpol
  • k describe networkpolicy payroll-policy
  • k get ingresses
  • k get pods --show-labels

https://kubernetes.io/docs/concepts/services-networking/network-policies/

profile
👩‍💻 Junior Backend Developer

0개의 댓글