K8s์˜ CertificateSigningRequest ๋ฆฌ์†Œ์Šค๋Š” .csr ํŒŒ์ผ๊ณผ ๋™์ผํ•œ ๋…€์„์ด๋‹ค!

2 minute read

K8s์˜ CertificateSigningRequest ๋ฆฌ์†Œ์Šค๋Š” .csr ํŒŒ์ผ๊ณผ ๋™์ผํ•œ ๋…€์„์ด๋‹ค!

CertificateSigningRequest ๋ฆฌ์†Œ์Šค๋ฅผ ์ž‘์„ฑํ•  ๋•Œ spec.request ํ•ญ๋ชฉ์— .csr ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ base64๋กœ ์ธ์ฝ”๋”ฉํ•œ ๊ฐ’์ด ํ•„์š”ํ•˜๋‹ค.

apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: akshay
spec:
  request: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS # base64 ์ธ์ฝ”๋”ฉ๋œ .csr ํŒŒ์ผ

์œ„์˜ ๋‚ด์šฉ๋Œ€๋กœ CSR ๋ฆฌ์†Œ์Šค๋ฅผ ๋งŒ๋“ค๊ณ , Approve๋ฅผ ํ•ด์ฃผ๋ฉด K8s์˜ certificate๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค! ํ•ด๋‹น ๋‚ด์šฉ์€ k get csr -o yaml์„ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

$ k get csr akshay -o yaml
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
spec:
  groups:
  - system:masters
  - system:authenticated
  request: xxxx
  signerName: kubernetes.io/kube-apiserver-client
  usages:
  - client auth
status:
  certificate: this-is-your-cert! # ์š”๊ธฐ!

๋งŒ์•ฝ K8s์˜ Certificate API๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด, openssl๋กœ .crt ํŒŒ์ผ๊นŒ์ง€ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ์„ ๊ฒƒ์ด๋‹ค. ๊ทธ๋Ÿฐ ๊ท€์ฐฎ์Œ์„ CSR ๋ฆฌ์†Œ์Šค๊ฐ€ ํ•ด๊ฒฐํ•ด์ค€ ๊ฒƒ!

User ๋ฆฌ์†Œ์Šค์˜ ์ด๋ฆ„์„ ์–ด๋””์— ์ •์˜?

RBAC์—์„œ RoleBinding ๋ฆฌ์†Œ์Šค๋ฅผ ์ •์˜ํ•˜๋‹ค๋ณด๋ฉด, ์ด๋Ÿฐ User ๋ฆฌ์†Œ์Šค๋ฅผ ๋ณด๊ฒŒ ๋œ๋‹ค.

apiVersion: rbac.authorization.k8s.io/v1
# This role binding allows "jane" to read pods in the "default" namespace.
# You need to already have a Role named "pod-reader" in that namespace.
kind: RoleBinding
metadata:
  name: read-pods
  namespace: default
subjects:
# You can specify more than one "subject"
- kind: User
  name: jane # "name" is case sensitive
  apiGroup: rbac.authorization.k8s.io
roleRef:
  # "roleRef" specifies the binding to a Role / ClusterRole
  kind: Role #this must be Role or ClusterRole
  name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
  apiGroup: rbac.authorization.k8s.io

๊ทธ๋Ÿฐ๋ฐ K8s๋Š” User ๋ฆฌ์†Œ์Šค๋ฅผ ๋”ฐ๋กœ ์ •์˜ํ•˜์ง€ ์•Š๋Š”๋ฐ, User ์ด๋ฆ„์€ ์–ด๋””์„œ ์•Œ ์ˆ˜ ์žˆ๋Š” ๊ฑธ๊นŒ? ์ด๊ฒƒ๋„ CSR ๋ฆฌ์†Œ์Šค๋ฅผ ํ†ตํ•ด ์•Œ ์ˆ˜ ์žˆ๋‹ค!!

k describe csr์„ ํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด CN(Common Name)์— ๋Œ€ํ•œ ํ•ญ๋ชฉ์ด ์žˆ๋Š”๋ฐ, ์ด๊ฒŒ User ๋ฆฌ์†Œ์Šค์˜ ์ด๋ฆ„์ด๋‹ค!

$ k describe csr akshay
Name:                akshay
Requesting User:     kubernetes-admin
Signer:              kubernetes.io/kube-apiserver-client
Subject:
         Common Name:    akshay # ์š”๊ธฐ์—์„œ ํ™•์ธ!

์ด CN์€ .csr ํŒŒ์ผ์„ ๋งŒ๋“ค๋•Œ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ฐธ๊ณ ๋กœ CN๊ณผ CSR ๋ฆฌ์†Œ์Šค์˜ ์ด๋ฆ„์ด ๋‹ค๋ฅผ ์ˆ˜๋„ ์žˆ๋‹ค!