そういうのがいいブログ

SIerで働く30代サラリーマンSEがインフラエンジニアに憧れてLinux・クラウド・AWSの勉強をするブログ

有効期限が切れたサーバ証明書の更新手順(その3)GitLabサーバ

※[PR]当ブログの記事の中にはプロモーションが含まれています。

有効期限が切れたサーバ証明書の更新手順を知りたい。

こういった疑問に答えます。

本記事の内容

  1. 有効期限が切れたサーバ証明書の更新手順

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

有効期限が切れたサーバ証明書の更新手順

社内ローカルの環境のWEBサーバ、メールサーバ、GitLabサーバの各サーバの証明書が有効期限切れになりました。
毎年、12月に更新をしています。

毎年の作業なので、自分のメモ用に作業手順を記事にておきます。

前回までの手順

前回の手順で、ルートCAの自己証明書と、中間CAの証明書を更新しました。

souiunogaii.hatenablog.com

GitLabサーバの証明書を更新

GitLabサーバの秘密鍵と署名要求CSRファイルを同時に作成

SSLEAY_CONFIG="-config /etc/pki/tls/openssl-req.cnf" /etc/pki/tls/misc/CA -newreq
[root@SV-MARS ~]# SSLEAY_CONFIG="-config /etc/pki/tls/openssl-req.cnf" /etc/pki/tls/misc/CA -newreq
Ignoring -days; not generating a certificate
Generating a RSA private key
..........................................................................................................................+++++
.............................................................................................+++++
writing new private key to 'newkey.pem'
Enter PEM pass phrase: ★★★秘密鍵のパスワード★★★
Verifying - Enter PEM pass phrase: ★★★秘密鍵のパスワード★★★
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Shinagawa-ku
Organization Name (eg, company) [Default Company Ltd]:PLANET Inc.
Organizational Unit Name (eg, section) []:PLANET SYSTEM Git
Common Name (eg, your name or your server's hostname) []:*.sv-mars.planet.space.com
Email Address []:gitadmin@space.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: ☆☆☆何も入力せず[Enter]☆☆☆
An optional company name []: ☆☆☆何も入力せず[Enter]☆☆☆
Request is in newreq.pem, private key is in newkey.pem

GitLabサーバの署名要求ファイルを、認証局サーバにアップロード

中間CAがGitLabサーバからの署名要求CSRファイルに署名し、サーバ証明書を作成

openssl ca -in /etc/pki/interCA/sv-mars/newreq.pem \
-out /etc/pki/interCA/sv-mars/newcert.pem \
-keyfile /etc/pki/interCA/private/interCA_key.pem \
-cert /etc/pki/interCA/interCA_cert.pem \
-config /etc/pki/tls/openssl-sv-mars.cnf \
-policy policy_anything
[root@SV-IXION sv-mars]# openssl ca -in /etc/pki/interCA/sv-mars/newreq.pem \
> -out /etc/pki/interCA/sv-mars/newcert.pem \
> -keyfile /etc/pki/interCA/private/interCA_key.pem \
> -cert /etc/pki/interCA/interCA_cert.pem \
> -config /etc/pki/tls/openssl-sv-mars.cnf \
> -policy policy_anything
Using configuration from /etc/pki/tls/openssl-sv-mars.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 8 (0x8)
        Validity
            Not Before: Dec 18 01:31:01 2021 GMT
            Not After : Dec 18 01:31:01 2022 GMT
        Subject:
            countryName               = JP
            stateOrProvinceName       = Tokyo
            localityName              = Shinagawa-ku
            organizationName          = PLANET Inc.
            organizationalUnitName    = PLANET SYSTEM Git
            commonName                = *.sv-mars.planet.space.com
            emailAddress              = gitadmin@space.com
        X509v3 extensions:
            X509v3 Basic Constraints: critical
                CA:FALSE
            Netscape Cert Type:
                SSL Server
            X509v3 Key Usage: critical
                Digital Signature
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                6F:CE:E6:6C:45:96:31:51:06:A9:DF:82:6C:60:B9:75:FF:8C:4D:B0
            X509v3 Authority Key Identifier:
                keyid:E1:27:D2:7C:8A:39:86:AA:51:44:CB:D5:B0:CF:16:34:A0:9A:94:77

            X509v3 Extended Key Usage:
                TLS Web Server Authentication, TLS Web Client Authentication
            X509v3 Subject Alternative Name:
                DNS:*.sv-mars.planet.space.com
Certificate is to be certified until Dec 18 01:31:01 2022 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

中間CAで作成した証明書ファイルをGitLabサーバにアップロードして名前を変更

秘密鍵ファイルのパスワード除去

openssl rsa -in /etc/gitlab/ssl/gitlab.planet.space.com.key -out /etc/gitlab/ssl/gitlab.planet.space.com.key
[root@SV-MARS ssl]# openssl rsa -in /etc/gitlab/ssl/gitlab.planet.space.com.key -out /etc/gitlab/ssl/gitlab.planet.space.com.key
Enter pass phrase for /etc/gitlab/ssl/gitlab.planet.space.com.key: ★★★秘密鍵のパスワード★★★
writing RSA key

GitLabの再起動

gitlab-ctl reconfigure
[root@SV-MARS ssl]# gitlab-ctl reconfigure
Starting Chef Infra Client, version 15.14.0
resolving cookbooks for run list: ["gitlab"]
Synchronizing Cookbooks:
  - gitlab (0.0.1)
  - package (0.1.0)
  - logrotate (0.1.0)
  - postgresql (0.1.0)
  - redis (0.1.0)
  - monitoring (0.1.0)
  - registry (0.1.0)
  - mattermost (0.1.0)
  - consul (0.1.0)
  - gitaly (0.1.0)
  - praefect (0.1.0)
  - gitlab-kas (0.1.0)
  - gitlab-pages (0.1.0)
  - letsencrypt (0.1.0)
  - nginx (0.1.0)
  - runit (5.1.3)
  - acme (4.1.1)
  - crond (0.1.0)
(中略)
Running handlers:
Running handlers complete
Chef Infra Client finished, 7/800 resources updated in 34 seconds
gitlab Reconfigured!
gitlab-ctl restart
[root@SV-MARS ssl]# gitlab-ctl restart
ok: run: alertmanager: (pid 3182281) 0s
ok: run: gitaly: (pid 3182289) 0s
ok: run: gitlab-exporter: (pid 3182319) 0s
ok: run: gitlab-workhorse: (pid 3182321) 1s
ok: run: grafana: (pid 3182331) 0s
ok: run: logrotate: (pid 3182338) 1s
ok: run: nginx: (pid 3182350) 0s
ok: run: node-exporter: (pid 3182355) 1s
ok: run: postgres-exporter: (pid 3182363) 0s
ok: run: postgresql: (pid 3182371) 0s
ok: run: prometheus: (pid 3182378) 0s
ok: run: puma: (pid 3182391) 0s
ok: run: redis: (pid 3182400) 0s
ok: run: redis-exporter: (pid 3182410) 0s
ok: run: sidekiq: (pid 3182508) 1s

ブラウザで表示確認

「Git for Windows」に信頼できる認証局として再登録

GitLabサーバーの証明書を更新すると、
「fatal: unable to access 'https://gitlab.xxxxxxxxxxx.git/': SSL certificate problem: unable to get local issuer certificate」エラーが出るので、
WindowsPCの「Git for Windows」に、信頼できる認証局として登録し直す必要があります。

souiunogaii.hatenablog.com