1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[IBMCloud] もう期限切れで焦らない!IKSのTLS証明書を自動更新する仕組みを作る Part1

Last updated at Posted at 2025-05-20

目的

以前はSecret Managerを利用した証明書の自動更新がサポートされていなかった
しかし、現在はSecretManagerで証明書の自動更新が行えるようになっているため、更新失敗や有効期限の忘れによる証明書の失効を防ぐことが可能になっている。この機能とIKS/ROKSを連携させ、パブリックサービスで必要となる証明書の自動更新を実施する

全体の流れ

ボリュームがあるので、全5回で記事を記載します。
本記事では「1. 自動証明書管理環境(ACME)のセットアップと認証局の構成」の内容を記載

1.自動証明書管理環境(ACME)のセットアップと認証局の構成
2.DNS Providerの設定と自動更新カスタムドメイン証明書(パブリック)の発行
3.IKSとSecret Managerの連携設定と自動更新の確認
4.IKSからパブリック証明書の参照と自動更新
5.IngressALBから証明書の利用とアプリケーションへのHTTPS動作確認

全体図
IKSでSecret Managerを利用して、IngressALBにPublic証明書を適用し、証明書の自動更新を行う一例
image.png

ACMEツールのセットアップとアカウント作成

証明書を自動更新するために、SecretManagerを利用する。
SecretManagerは、無料でSSL/TLS証明書を発行してくれる認証局(Certificate Authority: CA)であるLet's Encryptを利用している。

この手順では、SecretManagerで証明書を自動更新するには、SecretManagerからLet's Encryptに接続するためのACMEアカウントが必要となるため、アカウントの作成を実施する

ACMEツールのダウンロード

参考ページ:サード・パーティー認証局の接続

下記のページを参照し、ソースをダウンロードしていく
https://github.com/ibm-cloud-security/acme-account-creation-tool

ソースのダウンロード

% git clone https://github.com/ibm-cloud-security/acme-account-creation-tool.git
Cloning into 'acme-account-creation-tool'...
remote: Enumerating objects: 147, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 147 (delta 14), reused 0 (delta 0), pack-reused 120 (from 1)
Receiving objects: 100% (147/147), 407.98 KiB | 11.33 MiB/s, done.
Resolving deltas: 100% (64/64), done.

ダウンロードしたソースがあるフォルダに移動

% cd acme-account-creation-tool
acme-account-creation-tool % ls
LICENSE			go.mod			specifics_unix.go
README.md		go.sum			specifics_windows.go
acme-account.go		goreleaser.yaml

ツールの実行

ツールをコンパイルする

% go build
acme-account-creation-tool %

ツールを実行する。オプションの詳細は下記の通り

Usage of acme-account-creation-tool:
-o, --outputFilenamePrefix   file name prefix to store the account details  

[-e], [--email]  email to be registered for the account  

[-d], [--directoryURL]  acme directory URL of the CA. Following alias are defined: "letsencrypt-prod", "letsencrypt-stage"  (default letsencrypt-prod) 

[-g], [--keyTypeToGenerate]  key type to generate. Supported values - rsa2048, rsa3072, rsa4096, ec256, ec384 (default ec256) 

[-k], [--privateKeyPath]  path to the private key in PKCS1/PKCS8 PEM format to be used. If an account with this private key exists, the account will be retrieved. This flag overrides the -g flag  

ツールの実行

% ./acme-account-creation-tool -e xxx@ibm.com -o my-letsencrypt -d letsencrypt-prod
INFO[2025-03-05T10:29:02+09:00] Registering a new account with the CA
INFO[2025-03-05T10:29:03+09:00] Account information written to file : my-letsencrypt-account-info.json
INFO[2025-03-05T10:29:03+09:00] Private key written to file : my-letsencrypt-private-key.pem

Account Info
{
	"email": "xxx@ibm.com",
	"registration_uri": "https://acme-v02.api.letsencrypt.org/acme/acct/2263237xxx",
	"registration_body": {
		"status": "valid",
		"contact": [
			"mailto:xxx@ibm.com"
		]
	}
}%

実行フォルダに以下のファイルが作成されたことを確認する
・my-letsencrypt-private-key.pem
・my-letsencrypt-account-info.json

SecretManagerをLet's Encryptに接続する

参考ページ:UIを使用した認証局構成の追加

Secret engines -> Public certificates -> Certificate authorities -> Addを選択
image.png

Nameに任意の名前を入力、Certificate authorityをLet's Encryptを選択肢、Nextを選択
image.png

Enter valueにPrivate keyを入力する
これは、先ほどACMEツールで作成したpemの中身をコピペし、Addを選択

% cat my-letsencrypt-private-key.pem
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg3JeVnYx5CFxPlzt9
m73fp+ueiKe69nkHWMeuXQMZ5fOhRANCAxxxxxxxxxxxxxxxxx
-----END PRIVATE KEY-----

image.png

Nameで指定した「ProdCA」等が追加されれば完了


続き「2.DNS Providerの設定と自動更新カスタムドメイン証明書(パブリック)の発行

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?