ノート:

Use OCI Certificates for Internal CA Setup, Creation, and Installation of certificates on Apache Web Server

イントロダクション

急速に進化するクラウド・コンピューティングとデジタル・セキュリティの世界では、デジタル証明書を管理するための堅牢で柔軟なソリューションの必要性はかつてないほど重要になっています。Oracle Cloud Infrastructure (OCI) Certificate Serviceは、Oracle Cloudエコシステム内の証明書ライフサイクル管理の複雑なタスクを合理化するように設計された強力で信頼性の高いツールとして登場します。OCI Certificates is a service for creating and managing Transport Layer Security (TLS) certificates.This free-of-cost service enables organizations to create private Certificate Authorities (CA) hierarchies and TLS certificates, that can be deployed and renewed automatically in the customer tenancy, integrated with OCI services such as OCI Load Balancer, OCI API Gateway, Web Application Firewall and Others.

In this tutorial, we will explore the utilization of the OCI Certificates Service as an enterprise certificate management solution. We will delve into the process of creating an internal CA by administrators and guide server administrators on generating Certificate Signing Requests (CSRs) for their Apache Web Servers. Furthermore, we will cover the steps involved in creating certificates using the internal CA and demonstrate how to install these certificates on the Apache Web Servers.

An administrator with the necessary privileges will create a CA to issue internal certificates for internal web servers. Additionally, the administrator will create a dynamic group and set up policies to grant this dynamic group access to the OCI Certificates service. By adding an instance to the dynamic group and applying the necessary policies, an application running on that instance can access the OCI Certificates service without the need for user credentials or a configuration file.

管理者は、コンパートメントの詳細と認証局識別情報(特にOracle Cloud Identifier (OCID)をサーバー管理者と共有します。The OCID functions as a unique identifier for the Certificate Authority.この情報を使用して、サーバー管理者はシステムにOracle Cloud Infrastructureコマンドライン・インタフェース(OCI CLI)をインストールできます。Once installed, server administrators utilize the OCI CLI to request certificates from the Certificate Authority previously created by the administrators.この体系的なアプローチにより、認証局が適切に識別され、Oracle Cloud Infrastructure環境内の証明書の安全で効率的な発行が促進されます。

目的

前提条件

ノート:

タスク1: 認証局の作成

次のコマンドを使用して認証局を作成します(ルート認証局を参照)。

コマンド・フォーマット:

oci certs-mgmt certificate-authority create-root-ca-by-generating-config-details --compartment-id <compartment_OCID> --name <CA_display_name> --subject <CA_subject_information> --kms-key-id <Vault_encryption_key_OCID>

Note: Subject is a complex type whose value must be valid JSON.値は、コマンドラインで文字列として指定するか、またはfile://path/to/file構文を使用してファイルとして渡すことができます。このチュートリアルでは、ファイル・アプローチに従います。

Sample Command:

次の情報を使用して、サンプル・ファイルsubject.jsonを作成します。

{
  "commonName": "INTERNAL-ROOTCA"
}
oci certs-mgmt certificate-authority create-root-ca-by-generating-config-details --compartment-id ocid1.compartment.oc1..aaaaaaaabcdefghij12abcdefgh78abcde --name INTERNAL-ROOTCA --subject file://subject.json --kms-key-id ocid1.key.oc1.iad.abcdefghijklm.abcdefghijklmnop12abcdiklmnop56abcdef

タスク2: 動的グループの作成

次のコマンドを使用して動的グループを作成します(動的グループを参照)。

コマンド・フォーマット:

oci iam dynamic-group create --compartment-id <Tenancy OCID> --description <description> --name <DG Name> --matching-rule <Matching Rule>

Sample Command:

oci iam dynamic-group create --compartment-id ocid1.tenancy.oc1..aaaaaaaabbbbcdefgh12abcdabcdefghijkl --description Web-servers --name Web-servers-DG --matching-rule "instance.compartment.id = 'ocid1.compartment.oc1..aaaaaaaabcdefghij12abcde6abcdefghij78abcde'"

Task 3: Create necessary policies to grant this dynamic group access to the OCI Certificates service

Create OCI IAM policies using the following commands, see OCI IAM policies.

コマンド・フォーマット:

oci iam policy create --compartment-id <compartment_id> --description <description> --name <name> --statements file://statements.json

Sample Command:

次の情報を使用してファイルstatements.jsonを作成します。

[
"Allow dynamic-group Web-servers-DG to manage leaf-certificate-family in compartment chaitanyachintala",
"Allow dynamic-group Web-servers-DG to use certificate-authority-family in compartment chaitanyachintala"
]
oci iam policy create --compartment-id ocid1.compartment.oc1..aaaaaaaabcdefgh56abcdefghij78abcde --description Create-Certficate --name Cert-policies --statements file://statements.json

Task 4: Install OCI CLI on Compute Instance (Apache Web Server)

Install and configure the OCI Command Line Interface (CLI).

After connecting to the compute instance, run the following commands to install and verify Python and OCI CLI packages on Linux instance.

sudo dnf -y install oraclelinux-developer-release-el8
sudo dnf install python36-oci-cli

タスク5: Apache WebサーバーのOpenSSLを使用した証明書署名リクエスト(CSR)の作成

  1. ディレクトリを変更します。

    cd /etc/pki/tls/private/
    
  2. 次の情報を使用してファイルexamplecert.cnfを作成し、サブジェクト代替名(SAN)で証明書パラメータを指定します。

    Note: The SAN extension enables the attachment of additional identities, such as domain names or IP addresses, to the certificate subject.The use of the SAN extension is standard practice for SSL certificates, and it’s on its way to replacing the use of the common name.

    [req]
    distinguished_name = req_distinguished_name
    req_extensions = v3_req
    prompt = no
    
    [req_distinguished_name]
    C = US
    ST = Texas
    L = Texas
    O = Elpmaxe
    CN = www.example.com
    
    [v3_req]
    basicConstraints = CA:FALSE
    keyUsage = nonRepudiation, digitalSignature, keyEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_names
    
    [alt_names]
    DNS.1 = example.com
    IP.1 = 1.1.1.1
    
  3. Create CSR using following command.

    openssl req -out example.csr -newkey rsa:2048 -nodes -keyout example.key -config examplecert.cnf
    
  4. (Optionally) Verify the CSR using the following command.

    openssl req -noout -text -in example.csr
    

Task 6: Create a certificate using the CA created by OCI administrator

  1. 次のコマンドを使用して、example.csrファイルの内容を変数examplecsrに取得します。

    examplecsr=$(cat example.csr)
    
  2. Create certificate managed externally issued by internal CA.

    コマンド・フォーマット:

    oci certs-mgmt certificate create-certificate-managed-externally-issued-by-internal-ca --compartment-id  <compartment_OCID>  --csr-pem <csr_pem> --issuer-certificate-authority-id <CA_OCID> --name <Certificate-name>
    

    Sample Command:

    oci certs-mgmt certificate create-certificate-managed-externally-issued-by-internal-ca --compartment-id ocid1.compartment.oc1..aaaaaaaabcdefghhij78abcde --csr-pem "$examplecsr" --issuer-certificate-authority-id ocid1.certificateauthority.oc1.iad.abcdefghi56abcdefghijklmnop --name example.com --auth instance_principal
    

Note: Copy the OCID of the certificate created.

タスク7: 証明書および証明書チェーンのダウンロード

ノート: rootユーザーとして次のコマンドを実行します。

証明書および証明書チェーンをダウンロードするコマンド。

コマンド・フォーマット:

oci certificates certificate-bundle get --certificate-id <Certificate_OCID>

サンプル・コマンド- 証明書:

oci certificates certificate-bundle get --certificate-id ocid1.certificate.oc1.iad.abcdefghijbcdefghijk --raw-output --query 'data."certificate-pem"' > certificate.crt --auth instance_principal

サンプル・コマンド- 証明書チェーン:

oci certificates certificate-bundle get --certificate-id ocid1.certificate.oc1.iad.abcdefghip56abcdefghijk --raw-output --query 'data."cert-chain-pem"' > certificate-chain.pem --auth instance_principal

タスク8: 証明書を使用したApache Webサーバーのインストールおよび構成

  1. Install the httpd package, HTTPS add-on for Apache and its dependencies.

    sudo dnf install httpd
    sudo dnf install mod_ssl
    

    As a best practice, secure all communications between a web browser and Apache server by using HTTPS with a TLS certificate generated earlier.

    Webサーバーのルート・パスを変更するには、/etc/httpd/conf/httpd.confファイルを直接編集しないでください。かわりに、推奨される方法として、/etc/httpd/conf.dディレクトリにサイト固有の構成ファイルを作成します。次の例では、ファイル/etc/httpd/conf.d/example.com.confが作成され、仮想ホストの構成が含まれます。

  2. /etc/httpd/conf.d/example.com.confに次の情報を追加して、仮想ホストを作成します。

    Listen *:443
    
    <VirtualHost *:443>
      ServerName example.com
      ServerAlias www.example.com
      SSLEngine on
      SSLCertificateFile /etc/pki/tls/private/certificate.crt
      SSLCertificateKeyFile /etc/pki/tls/private/example.key
      DocumentRoot /var/www/example.com/html/
      ErrorLog /var/log/httpd/example.com_error.log
      CustomLog /var/log/httpd/example.com_access.log combined
    </VirtualHost>
    
  3. ドキュメント・ルート・フォルダを作成します。ルート・フォルダは、Apacheがブラウザに提供するWebページをホストします。

    sudo mkdir -p /var/www/example.com/html
    sudo echo "example.com" > /var/www/example.com/html/index.html
    sudo chown -R apache:apache /var/www/example.com/html
    
  4. Apacheサービスを再起動して、新しい構成をロードします。

    sudo systemctl restart httpd
    

    ノート: 「Cannot define multiple Listeners on the same IP:port」というエラーが表示される場合は、ファイル/etc/httpd/conf.d/ssl.conf「Listen 443 https」行をコメント化します。

  5. ファイアウォールを構成します。These commands enable the firewall port 443 for the Apache HTTPS service and reloads the default firewall service.

    sudo firewall-cmd --add-service=https --permanent
    sudo firewall-cmd --reload
    

    Note: Ensure that the Security List associated with the subnet and the Security Groups associated with the VNIC allow traffic on port 443.

タスク9: Webページのテスト

All the errors stem from the fact that the certificate installed on the web server is not issued by a public Certificate Authority, and the root certificate of the internal CA is not present in the certificate store.

確認

その他の学習リソース

docs.oracle.com/learnの他のラボをご覧いただくか、Oracle Learning YouTubeチャネルで無料のラーニング・コンテンツにアクセスしてください。また、education.oracle.com/learning-explorerにアクセスしてOracle Learning Explorerになります。

製品ドキュメントは、Oracle Help Centerを参照してください。