Enterprise Cloud Mgmt Platform (CMP)

๐Ÿ’ก Enterprise Cloud Mgmt Platform (CMP) โ€” Executive Summary

Technical architectural analysis, practical configuration manifests, and deployment instructions for Enterprise Cloud Mgmt Platform (CMP).

TLS

Sample
Show
Get certificate information from specific TLS port
bash
ip=
port=
openssl s_client -connect ${ip}:${port} -showcerts
Main
References and Guidelines (NOTE)

Even if the CA certificate expires, the certificate is valid if signed before expiration.
In other words, even if the CA certificate is 10 years old, signing is possible by renewing the client certificate after 100 years.

subCommand & flags
bash
#sub-command
openssl genrsa # rsa ๊ฐœ์ธํ‚ค ์ƒ์„ฑ
openssl genpkey # ๊ฐœ์ธํ‚ค ์ƒ์„ฑ
openssl rsa # rsa ๊ฐœ์ธํ‚ค ์ž‘์—…
openssl req # CSR ์ž‘์—…
openssl x509 # ์ธ์ฆ์„œ ์ž‘์—…

#flags
-in ${file} # ํŒŒ์ผ ์ž…๋ ฅ
-out ${file} # ํŒŒ์ผ ์ถœ๋ ฅ
-outform ${type} # ์ถœ๋ ฅ ํƒ€์ž… ์ง€์ •
-noout # ํŒŒ์ผ ์ถœ๋ ฅ ํ•˜์ง€ ์•Š์Œ
-text # ํ‘œ์ค€์ถœ๋ ฅ?
-aes256 # ๊ฐœ์ธํ‚ค ์•”ํ˜ธํ™”ํ•˜์—ฌ ๋ณด์•ˆ๊ณ„์ธต ์ถ”๊ฐ€
-nodes # No DES : (Enter PEM pass phrase: ์ž…๋ ฅ๋ž€)์•”ํ˜ธ ์—†์ด ์‹คํ–‰
View
sql
# ์ธ์ฆ๊ธฐ๊ฐ„ ํ™•์ธ
sudo openssl x509 -in ${crt} -noout -text

# csr ๋‚ด์šฉ ์กฐํšŒ
sudo openssl req -in ${csr} -noout -text

# ์œ ํšจ์„ฑ ์ฒดํฌ
sudo openssl verify -CAfile ${ca.crt} ${target.crt}
to PEM file
bash
# crt to pem
sudo openssl x509 -inform PEM -in ca.crt > public.pem

# key to pem
sudo openssl rsa -in ca.key -text > private.pem
feature
key=ecparam
bash
#๋ฃจํŠธ์ธ์ฆ์„œ
openssl ecparam -out rootca.key -name prime256v1 -genkey
openssl req -new -sha256 -key rootca.key -out rootca.csr -subj "/C=KR/L=Seoul/O=fredric/CN=fredrics.playground"
openssl x509 -req -sha256 -days 3650 -in rootca.csr -signkey rootca.key -out rootca.crt

#์„œ๋ฒ„์ธ์ฆ์„œ
openssl ecparam -out server.key -name prime256v1 -genkey
openssl req -new -sha256 -key server.key -out server.csr -subj "/C=KR/L=Seoul/O=fredric/CN=*.fredric.playground.cld"
openssl x509 -req -sha256 -days 3650 -in server.csr -CA rootca.crt -CAkey rootca.key -CAcreateserial -out server.crt

#์„œ๋ฒ„์ธ์ฆ์„œ ์ •๋ณด ์ถœ๋ ฅ
openssl x509 -in server.crt -text -noout

#๋ฃจํŠธ์ธ์ฆ์„œ์™€ ์„œ๋ฒ„์ธ์ฆ์„œ๋ฅผ ๋ชจ๋‘ ํฌํ•จํ•˜๋Š” pemํŒŒ์ผ ์ œ์ž‘
cat server.crt rootac.crt > server.pem
key=genrsa
bash
#๋ฃจํŠธ์ธ์ฆ์„œ
openssl genpkey -algorithm RSA -out rootca.key -pkeyopt rsa_keygen_bits:2048
openssl req -new -sha256 -key rootca.key -out rootca.csr -subj "/C=KR/L=Seoul/O=fredric/CN=fredrics.playground"
openssl x509 -req -sha256 -days 3650 -in rootca.csr -signkey rootca.key -out rootca.crt

#์„œ๋ฒ„์ธ์ฆ์„œ
openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048
openssl req -new -sha256 -key server.key -out server.csr -subj "/C=KR/L=Seoul/O=fredric/CN=*.fredric.playground.cld"
openssl x509 -req -sha256 -days 3650 -in server.csr -CA rootca.crt -CAkey rootca.key -CAcreateserial -out server.crt

#์„œ๋ฒ„์ธ์ฆ์„œ ์ •๋ณด ์ถœ๋ ฅ
openssl x509 -in server.crt -text -noout

#๋ฃจํŠธ์ธ์ฆ์„œ์™€ ์„œ๋ฒ„์ธ์ฆ์„œ๋ฅผ ๋ชจ๋‘ ํฌํ•จํ•˜๋Š” pemํŒŒ์ผ ์ œ์ž‘
cat server.crt rootac.crt > server.pem
Generate self-signed certificate and key
bash
openssl req -x509 \
  -newkey rsa:2048 \
  -keyout example.key \
  -out example.crt \
  -days 3650 \
  -nodes \
  -subj "/C=KR/L=Seoul/O=fredric/CN=*.fredric.playground.cld"
Create certificate after creating organization certificate and CSR (step by step)
bash
#๊ฐœ์ธํ‚ค ์ƒ์„ฑ
openssl genrsa -aes256 -out private.key 2048
openssl rsa -in private.key -pubout -out public.key
openssl req -new -key private.key -out private.csr

#CA key ์ƒ์„ฑ
openssl genrsa -aes256 -out root.ca.key 2048
#CA 10๋…„ ์„œ๋ช…์š”์ฒญ
openssl req -x509 -new -nodes -key root.ca.key -days 3650 -out root.ca.pem
#๊ธฐ๊ด€์„œ๋ช…๋œ 10๋…„ ์ธ์ฆ์„œ ์ƒ์„ฑ
openssl x509 -req -in private.csr -CA root.ca.pem -CAkey root.ca.key -CAcreateserial -out private.crt -days 3650
Configure CA

Step 1 โ€“ Creating a private key for Certificate Authority:

txt
mkdir /root/certificates
cd /root/certificates

Step 2 โ€“ Creating Private Key and CSR:

txt
openssl genrsa -out ca.key 2048
openssl req -new -key ca.key -subj "/CN=KUBERNETES-CA" -out ca.csr

Step 3 โ€“ Self-Sign the CSR:

txt
openssl x509 -req -in ca.csr -signkey ca.key -out ca.crt -days 1000

Step 4 โ€“ Remove the CSR

txt
rm -f ca.csr

Step 5 โ€“ Check Contents of Certificate

bash
openssl x509 -in ca.crt -text -noout

Secret

bash
# ์ž„์˜์˜ 16๋ฐ”์ดํŠธ 16์ง„์ˆ˜ ๋ฌธ์ž์—ด ์ƒ์„ฑ (ENCRYPTION_KEY)
openssl rand -hex 16

# ์ž„์˜์˜ 32๋ฐ”์ดํŠธ base64 ๋ฌธ์ž์—ด ์ƒ์„ฑ (AUTH_SECRET)
openssl rand -base64 32


Super old


K8s Secret

1. Create private key and public key using Openssl
bash
#- Private Key ์ƒ์„ฑ ๋ช…๋ น์–ด
openssl genrsa -out [ํŒŒ์ผ๋ช…] [bit๊ธธ์ด]
    #์˜ˆ์‹œ) openssl genrsa -out test.key 2048
#- Public Key ์ƒ์„ฑ ๋ช…๋ น์–ด
openssl rsa -in [privateKey ํŒŒ์ผ๋ช…] -pubout -out [ํŒŒ์ผ๋ช…]
    #์˜ˆ์‹œ) openssl rsa -in test.key -pubout -out test_pub.key
2. CSR (Certificate Signing Request Generation) using Private Key
bash
#- CSR์ƒ์„ฑ ๋ช…๋ น์–ด
openssl req -new -key [privateKey ํŒŒ์ผ๋ช…] -out [ํŒŒ์ผ๋ช…]
#    ์˜ˆ์‹œ) openssl req -new -key test.key -out test.csr
#- ์ƒ์„ฑ ์˜ต์…˜ ์ž…๋ ฅ
   # // ์ด ๋ถ€๋ถ„์€ ์ž„์‹œ๋กœ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.
   # // ์™ธ๋ถ€๋กœ ์„œ๋น„์Šค ํ•  ๋•Œ๋Š” ๊ณต์ธ ์‚ฌ์ดํŠธ์—์„œ ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ ๋ฐ›์•„์„œ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
   # // ์ง์ ‘ ์ž‘์„ฑํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์‚ฌ์„ค ์„œ๋ฒ„์—์„œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
    Country Name (2 letter code) [AU]: KR
    State or Province Name (full name) [Some-State]: Seoul
    Locality Name (eg, city) []: Seoul
    Organization Name (eg, company) [Internet Widgits Pty Ltd]: example
    Organization Unit Name (eg, section) []: example
    Common Name (eg, YOUR name) []: test
    Email Address []: [email protected]
    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []: test
3. Create a CRT certificate
bash
openssl req -x509 -days [์œ ํšจ๊ธฐ๊ฐ„] -key [privateKey ํŒŒ์ผ๋ช…] -in [csrํŒŒ์ผ๋ช…] -out [ํŒŒ์ผ๋ช…] -days [์œ ํšจ๊ธฐ๊ฐ„]
# ์˜ˆ์‹œ) openssl req -x509 -days 365 -key test.key -in test.csr -out test.crt -days 365
4. Convert CRT file to PEM file
bash
openssl x509 -in [crtํŒŒ์ผ๋ช…] -out [ํŒŒ์ผ๋ช…] -outform PEM
# ์˜ˆ์‹œ) openssl x509 -in test.crt -out test.pem -outform PEM
5. Create secret in Kubernetes
bash
# ์ด๋ฏธ ๋™์ผํ•œ ์ด๋ฆ„์˜ secret์ด ์กด์žฌํ•œ๋‹ค๋ฉด ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋กœ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.
# kubectl delete secret [secret๋ช…] -n [namespace๋ช…]
kubectl create secret tls [secret๋ช…] --key [privateKey ํŒŒ์ผ๋ช…] --cert [crt ํŒŒ์ผ๋ช…] -n [kubernetes namespace๋ช…]
์˜ˆ์‹œ) kubectl create secret tls test-secret --key test.key --cert test.crt -n dev


K8s client certificate

Automatic renewal
Manual renewal
bash
mkdir ~/crtTestPath-20230825
export CRT_TEST_PATH=$HOME/crtTestPath-20230825
Reference existing data when configuring openssl.cnf
bash
# ๊ธฐ์กด ์ธ์ฆ์„œ ์ •๋ณด๋ฅผ ํ™•์ธํ•œ ํ›„ ์ œ์ž‘ ํ•„์š”.
openssl x509 -in /etc/kubernetes/pki/apiserver.crt -noout -text
>>>
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 284673793232647265 (0x3f35d4e827eb461)
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: CN=kubernetes
        Validity
            Not Before: Aug 24 10:12:30 2023 GMT
            Not After: Aug 23 10:15:09 2024 GMT
        Subject: CN=kube-apiserver
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (2048 bit)
                Modulus:
                    00:d9:ca:16:53:50:6e:78:d8:b9:4d:ab:89:36:e3:
                    f8:8d:5e:0a:42:5e:7a:39:e2:b9:3f:57:cd:0e:d8:
                    01:27:b2:34:a1:f0:76:e6:4c:6a:4d:d5:03:4a:17:
                    ce:c9:68:06:a6:6c:af:b9:14:15:ce:e7:d5:89:74:
                    bb:4e:33:09:33:55:ea:36:5e:33:d3:df:c8:7b:fb:
                    a7:69:dc:f7:ba:40:30:3e:0f:a8:09:67:86:8b:25:
                    fc:e9:6d:c5:a5:5b:74:15:56:77:1e:16:11:f0:1d:
                    c7:48:ce:e0:18:7f:57:63:36:8d:df:70:f5:77:91:
                    83:f1:e7:26:5c:fa:6a:8d:89:b2:d9:75:fd:93:35:
                    ef:90:21:e9:b3:02:5f:02:0e:2a:f4:f2:24:7c:99:
                    c2:2d:e4:da:20:22:8e:6c:c3:8f:16:b8:bb:8e:10:
                    e8:62:e6:ec:12:5a:1c:a8:1b:04:20:09:fa:eb:0f:
                    dc:d6:8a:2e:5d:21:07:a3:5e:ee:00:a9:2d:df:30:
                    a7:cc:88:34:ca:13:5d:52:62:c4:d7:67:55:78:8f:
                    31:07:38:ce:fb:8d:d4:e8:2f:26:02:c6:3e:ae:7e:
                    c3:25:34:9b:7a:44:83:01:f1:75:c7:43:7e:ce:12:
                    bf:8b:17:72:8e:00:a5:1c:d5:39:e3:80:13:ae:a3:
                    c5:4f
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
            X509v3 Basic Constraints: critical
                CA:FALSE
            X509v3 Authority Key Identifier:
                keyid:03:62:D9:03:14:6E:D2:E4:49:3C:EE:AE:82:B0:48:75:A5:A6:91:CA

            X509v3 Subject Alternative Name:
                DNS:kubernetes, DNS:kubernetes.default, DNS:kubernetes.default.svc, DNS:kubernetes.default.svc.cluster.local, DNS:platform-k8s-master-2, IP Address:10.96.0.1, IP Address: 192.168.50.11, IP Address:192.168.50.10
    Signature Algorithm: sha256WithRSAEncryption
         c9:40:18:85:17:c7:64:8a:7a:28:63:0d:fa:9c:76:d9:cf:84:
         e7:16:11:45:4f:3a:00:89:4a:c8:b3:19:52:bc:8d:5e:9c:1b:
         52:6e:12:72:84:82:34:3a:0b:56:d7:a0:4c:1f:a0:0d:cb:a6:
         93:83:08:40:5f:26:d5:eb:a5:dc:91:81:b8:8b:84:65:b8:bd:
         9f:2f:c1:c1:a7:3a:67:4e:a0:51:78:f7:43:55:fc:8a:c6:4c:
         63:5a:4f:94:1c:85:cd:1c:ff:5e:c0:c3:1d:a0:f3:41:3d:91:
         d4:c5:5c:f7:0d:be:63:1f:60:ce:22:78:ba:ab:4d:9e:44:01:
         0d:56:8e:2f:fb:2e:64:25:f1:d7:10:cd:2d:1d:51:16:02:c8:
         99:f8:ac:f4:3b:22:19:a5:51:a3:07:89:20:f7:70:08:7d:75:
         55:a1:cc:21:19:82:a4:16:0f:0a:af:1c:3a:79:90:26:a8:6b:
         a6:e3:07:20:a7:87:72:6c:89:7d:0c:f9:69:9b:13:e1:6a:40:
         3b:d4:50:96:e7:d0:a1:ec:5d:9a:fe:ed:78:1d:1d:ff:11:9c:
         23:6c:aa:9f:56:e6:d5:e5:73:bd:d8:86:09:ba:69:02:12:94:
         15:f2:88:24:04:b2:97:19:1c:51:95:41:e8:1e:12:39:d4:d8:
         ae:58:46:01
<<<

openssl x509 -in /etc/kubernetes/pki/ca.crt -noout -text
>>>
Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 0 (0x0)
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: CN=kubernetes
        Validity
            Not Before: Aug 24 10:12:30 2023 GMT
            Not After: Aug 21 10:12:30 2033 GMT
        Subject: CN=kubernetes
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (2048 bit)
                Modulus:
                    00:f3:b4:2a:b5:b1:7e:8d:23:ac:0d:14:73:72:68:
                    7b:d5:52:06:6c:22:53:8c:90:3a:30:92:c4:88:b9:
                    38:a1:b5:56:ad:82:44:84:67:2f:d7:68:1c:c1:8e:
                    3e:1f:bd:ac:a4:dc:4b:bf:b2:2c:01:8b:f9:5c:bb:
                    59:0c:00:9c:2e:f6:f6:6c:d2:f8:fd:3a:7e:29:78:
                    9b:cb:5c:5f:21:5a:4f:60:ae:bd:dc:29:8e:bf:55:
                    23:50:ec:f7:c4:2e:d3:23:de:99:8e:fd:56:83:02:
                    c9:e8:29:f5:ab:78:5b:10:14:c6:1e:63:6a:02:61:
                    23:1d:72:e0:71:61:41:ad:bd:53:fa:81:96:4e:f8:
                    6d:94:51:ff:92:81:13:46:a7:73:bc:3f:32:58:75:
                    dc:01:71:19:53:4d:af:4a:11:24:68:ee:47:37:2d:
                    95:63:b7:e9:07:85:6c:22:e2:6c:d7:01:47:c6:aa:
                    41:41:4d:24:ca:0f:cc:5a:3a:4f:2d:43:2c:32:e4:
                    07:c4:57:29:44:c1:94:c9:6a:8c:69:bc:6f:3f:71:
                    40:12:74:e5:24:e8:60:60:89:cc:69:5b:4a:08:68:
                    13:b7:7e:96:22:55:15:f9:70:4d:7b:7b:a6:5c:71:
                    b2:64:29:68:86:62:d1:d9:90:f3:08:ce:b7:c9:45:
                    18:c5
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment, Certificate Sign
            X509v3 Basic Constraints: critical
                CA:TRUE
            X509v3 Subject Key Identifier:
                03:62:D9:03:14:6E:D2:E4:49:3C:EE:AE:82:B0:48:75:A5:A6:91:CA
            X509v3 Subject Alternative Name:
                DNS:kubernetes
    Signature Algorithm: sha256WithRSAEncryption
         c9:18:da:8c:b3:b7:41:65:45:65:81:4d:d7:6d:86:16:95:ee:
         8b:56:81:90:7d:2b:32:f7:d6:2c:be:d8:1f:0c:eb:d2:94:d4:
         a9:0a:0e:87:d1:6f:50:9c:7a:e6:ce:f7:a0:e2:d1:93:85:84:
         65:22:78:81:09:f1:29:03:a1:f0:1b:65:49:93:d6:22:06:7e:
         92:6d:85:59:6a:3d:47:0e:10:1f:3e:8d:5d:56:e3:da:9e:47:
         d4:34:6c:dd:33:e9:eb:09:93:9e:48:05:6f:04:f5:11:5a:5c:
         96:cf:ad:4b:cb:17:20:6b:69:64:c6:20:7e:30:bb:98:11:1b:
         97:54:b3:33:5d:54:e2:28:62:35:f4:ca:1d:e9:cf:6b:96:21:
         a5:09:b9:25:66:74:2e:22:71:30:ee:27:0e:d8:84:0f:0b:f3:
         b6:1d:b4:5f:e4:a8:2a:31:41:55:8e:57:56:ed:38:d5:21:ee:
         d5:82:a2:31:53:46:db:7f:d2:3e:4d:17:a9:f5:2f:81:32:e8:
         7f:fd:bb:42:90:c4:94:b4:a6:a0:97:d5:39:9b:73:6f:29:ca:
         60:f1:bf:fa:aa:b8:e9:57:3d:70:1b:f9:70:42:0e:27:f7:d1:
         18:cf:52:5c:aa:f0:43:7b:c8:95:43:30:36:67:18:e4:4c:7c:
         5f:68:6f:21
<<<
bash
vi $CRT_TEST_PATH/openssl.cnf
---
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no

[req_distinguished_name]
CN = kube-apiserver

[v3_req]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[alt_names]
DNS.1 = kubernetes
DNS.2 = kubernetes.default
DNS.3 = kubernetes.default.svc
DNS.4 = kubernetes.default.svc.cluster.local

#> master 1
DNS.5 = platform-k8s-master-1

IP.1 = 10.96.0.1
IP.2 = 192.168.50.10

#> master 2
DNS.5 = platform-k8s-master-2

IP.1 = 10.96.0.1
IP.2 = 192.168.50.11
IP.2 = 192.168.50.10

#> master 3
DNS.5 = platform-k8s-master-3

IP.1 = 10.96.0.1
IP.2 = 192.168.50.12
IP.2 = 192.168.50.10
bash
openssl req -new \
    -key /etc/kubernetes/pki/apiserver.key \
    -out $CRT_TEST_PATH/apiserver.csr \
    -subj "/CN=kube-apiserver" \
    -config $CRT_TEST_PATH/openssl.cnf

openssl x509 -req \
    -in $CRT_TEST_PATH/apiserver.csr \
    -CA /etc/kubernetes/pki/ca.crt \
    -CAkey /etc/kubernetes/pki/ca.key \
    -CAcreateserial \
    -out $CRT_TEST_PATH/apiserver.crt \
    -days 3650 \
    -extensions v3_req \
    -extfile $CRT_TEST_PATH/openssl.cnf


Failed Process Stack

1. RSA key and CSR
bash
# 1.๊ฐœ์ธํ‚ค ์ƒ์„ฑ
sudo openssl genrsa -out ${keyfile} 2048
#sudo openssl genpkey -algorithm RSA -out ${keyfile} -outform PEM -aes256

# 2.์„œ๋ช…์š”์ฒญ(csr) ์ƒ์„ฑ: ca.cert ํŒŒ์ผ๊ณผ ์ผ์น˜ํ•˜๋Š” ์ •๋ณด ์ž…๋ ฅ: ์ผ๋ฐ˜ ์ด๋ฆ„(CN), ์กฐ์ง(O) ๋“ฑ
sudo openssl req -new -key ${keyfile} -out ${csrfile}

# 1. ์ƒˆ๋กœ์šด ํ‚ค๋กœ csr ์ƒ์„ฑ
#sudo openssl req -new -newkey rsa:2048 -keyout ${keyfile} -out ${csrfile} -subj "/CN=192.168.50.10" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=IP:192.168.50.10")) -nodes
#sudo openssl req -new -newkey rsa:2048 -keyout ${keyfile} -out ${csrfile} -subj "/CN=192.168.50.10" -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=IP:192.168.50.10")) -reqexts SAN -nodes
#sudo openssl req -new -newkey rsa:2048 -keyout ${keyfile} -out ${csrfile} -subj "/CN=192.168.50.10" -config <(printf "[req]\ndistinguished_name=req\n[ SAN]\nsubjectAltName=IP:192.168.50.10\n") -reqexts SAN -nodes
2. Create x509 certificate
bash
# CA ์—†์ด ์ธ์ฆ์„œ ์ƒ์„ฑ
sudo openssl x509 -req -in ${csrfile} -signkey ${keyfile} -out ${crtfile} -days 3650

# CA์ธ์ฆ์„œ๋กœ ์ธ์ฆ์„œ ์ƒ์„ฑ
# 1.CA ์ธ์ฆ์„œ์šฉ ์‹œ๋ฆฌ์–ผ๋„˜๋ฒ„ ์ƒ์„ฑ
echo 'B4A3E792F8D1C6A9' > ca.srl 

# 2.CA ์ธ์ฆ์„œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆ์„œ ์ƒ์„ฑ
sudo openssl x509 -req -in ${csrfile} -CA ca.crt -CAkey ca.key -out ${crtfile} -days 3650 -sha256
โ€”temp
bash
# 1.์„œ๋ช…์š”์ฒญ(csr) ์ƒ์„ฑ: ca.cert ํŒŒ์ผ๊ณผ ์ผ์น˜ํ•˜๋Š” ์ •๋ณด ์ž…๋ ฅ: ์ผ๋ฐ˜ ์ด๋ฆ„(CN), ์กฐ์ง(O) ๋“ฑ
sudo openssl req -new -key ${keyfile} -out ${csrfile}

# 2.CA ์ธ์ฆ์„œ์šฉ ์‹œ๋ฆฌ์–ผ๋„˜๋ฒ„ ์ƒ์„ฑ
echo 'B4A3E792F8D1C6A9' > ca.srl 

# 3.CA ์ธ์ฆ์„œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ฆ์„œ ์ƒ์„ฑ
sudo openssl x509 -req -in ${csrfile} -CA ca.crt -CAkey ca.key -out ${crtfile} -days 3650 -sha256

!!

bash
# openssl.conf
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no

[req_distinguished_name]
CN = kube-apiserver

[v3_req]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
X509v3 extensions:
keyUsage = critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
basicConstraints = critical CA:FALSE
            X509v3 Authority Key Identifier:
                keyid:40:67:1D:8C:A5:70:E4:39:8D:8C:FD:49:B9:DC:9E:AE:7D:E3:5F:38

            X509v3 Subject Alternative Name:
                DNS:kubernetes, DNS:kubernetes.default, DNS:kubernetes.default.svc, DNS:kubernetes.default.svc.cluster.local, DNS:lb-apiserver.kubernetes.local, DNS:localhost, DNS:platform-k8s-master-1, DNS:platform-k8s-master-1.cluster.local, DNS:platform-k8s-master-2, DNS:platform-k8s-master-2.cluster.local, DNS:platform-k8s-master-3, DNS:platform-k8s-master-3.cluster.local, IP Address:10.233.0.1, IP Address:172.16.0.189, IP Address:172.16.0.162, IP Address:127.0.0.1, IP Address:172.16.0.137


[alt_names]
DNS.1 = kubernetes
DNS.2 = kubernetes.default
DNS.3 = kubernetes.default.svc
DNS.4 = kubernetes.default.svc.cluster.local
DNS.5 = lb-apiserver.kubernetes.local
DNS.6 = localhost
DNS.7 = platform-k8s-master-1
DNS.8 = platform-k8s-master-1.cluster.local
DNS.9 = platform-k8s-master-2
DNS.10 = platform-k8s-master-2.cluster.local
DNS.11 = platform-k8s-master-3
DNS.12 = platform-k8s-master-3.cluster.local
IP.1 = 10.233.0.1
IP.2 = 172.16.0.189
IP.3 = 172.16.0.162
IP.4 = 127.0.0.1
IP.5 = 172.16.0.137
bash
openssl req -new -key apiserver.key -out apiserver.csr -config openssl.conf
openssl x509 -req -in apiserver.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out aiserver.crt -days 3650 -extensions v3_req -extfile openssl.conf

openssl req -new \
    -key apiserver.key \
    -out apiserver.csr \
    -subj "/CN=kube-apiserver" \
    -config <(cat /etc/kubernetes/openssl.conf <(printf "[alt_names]\nDNS=kubernetes\nDNS=kubernetes.default\nDNS=kubernetes.default.svc\nDNS=kubernetes.default.svc.cluster.local\nDNS=platform-k8s-master-3\nIP.1=10.96.0.1\nIP.2=192.168.50.12\nIP.3=192.168.50.10"))
Renew with existing key and CA certificate
bash
#!/bin/bash

cd /etc/kubernetes/pki/

subj="CN = kube-apiserver"

cert_days=3650
ca_cert="ca.crt"
ca_key="ca.key"
key="apiserver.key"
csr="apiserver.csr"
cert="apiserver.crt"

common_csr_conf='distinguished_name = dn\n[dn]\n[v3_ext]\nkeyUsage = critical, digitalSignature, keyEncipherment\n'
cert_type="server"
case "${cert_type}" in
client)
  csr_conf=$(printf "%bextendedKeyUsage = clientAuth\n" "${common_csr_conf}")
  ;;
server)
  csr_conf=$(printf "%bextendedKeyUsage = serverAuth\nsubjectAltName = %b\n" "${common_csr_conf}" "${alt_name}")
  ;;
peer)
  csr_conf=$(printf "%bextendedKeyUsage = serverAuth, clientAuth\nsubjectAltName = %b\n" "${common_csr_conf}" "${alt_name}")
  ;;
*)
  log::err "unknow, unsupported certs type: ${YELLOW}${cert_type}${NC}, supported type: client, server, peer"
  exit 1
  ;;
esac

rm ${cert}

  # gen csr
  openssl req -new -key "${key}" -subj "${subj}" -reqexts v3_ext \
    -config <(printf "%b" "${csr_conf}") \
    -out "${csr}" >/dev/null 2>&1

  # gen cert
  openssl x509 -in "${csr}" -req -CA "${ca_cert}" -CAkey "${ca_key}" -CAcreateserial -extensions v3_ext \
    -extfile <(printf "%b" "${csr_conf}") \
    -days "${cert_days}" -out "${cert}" >/dev/null 2>&1

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *