【问题标题】:FreeIPA request certificate with cnameFreeIPA 请求带有 cname 的证书
【发布时间】:2018-12-18 16:48:56
【问题描述】:

前段时间我想知道如何为 cname 创建 ssl 证书。这是因为我们总是为我们的虚拟机使用通用的 a 记录。用户应通过 SSL 上的服务名称访问在这些虚拟机上运行的服务。我们使用 FreeIPA 作为我们的证书颁发机构。

【问题讨论】:

    标签: ssl certificate cname a-records freeipa


    【解决方案1】:

    有时您搜索了很长时间的答案,并在多个不太清楚的网站上找到了答案。我将通过一个示例来解释我的答案,以显示从 FreeIPA with cname 和 without cname 请求证书的区别。

    我们制作了一个虚构的虚拟机,其 a-record 为 abc955-xy.example.com。在这台机器上,我们将运行 postgres。因此,为方便起见,cname 将是 postgresql.example.com。首先我们为 abc955-xy.example.com 创建一个证书,它只对 fqdn 有效。其次,我们为cname创建一个证书,它对fqdn也有效。

    没有 cname 的证书

    # Generate a private key
    openssl genrsa -out abc955-xy.example.com.key 4096
    
    # Add the host to FreeIPA
    ipa host-add abc955-xy.example.com --force
    
    # Create a host principal for the service HTTP
    ipa service-add HTTP/abc955-xy.example.com
    
    # Add the host principal to the host
    ipa service-add-host HTTP/abc955-xy.example.com --host abc955-xy.example.com
    
    # Request a certificate for the host, using the principal and private key
    ipa-getcert request -r -f abc955-xy.example.com.crt -k abc955-xy.example.com.key \ 
    -K HTTP/abc955-xy.example.com -D abc955-xy.example.com
    

    包含 cname 的证书

    # Generate a private key
    openssl genrsa -out postgresql.example.com.key 4096
    
    # Add the host to FreeIPA, using the cname
    ipa host-add postgresql.example.com --force
    
    # Create a host principal for the service HTTP
    ipa service-add HTTP/abc955-xy.example.com
    
    # Create a principal for the service HTTP with the cname
    ipa service-add HTTP/postgresql.example.com --force
    
    # Add the cname principal to the host
    ipa service-add-host HTTP/postgresql.example.com --host abc955-xy.example.com
    
    # Request a certificate for the host, using the principal and private key and cname
    ipa-getcert request -r -f postgresql.example.com.crt -k postgresql.example.com.key\
    -K HTTP/postgresql.example.com -D postgresql.example.com -D abc955-xy.example.com
    

    除了一些命名差异之外,两个选项之间的主要区别在于您将带有 cname 的 HTTP-principal 添加到主机而不是带有 fqdn 的 HTTP-principal。

    注意:由于 Chrome 和 Chromium 等浏览器从 65 版起只接受具有主题备用名称 (SAN) 的证书,因此您还需要将主题备用名称添加到没有 cname 的证书中。这就是 ipa-getcert 请求中选项 -D 的来源。对于没有 cname 的证书,您必须提供 fqdn。

    【讨论】:

    • openssl genrsa... 部分的目的是什么?在我遇到的其他教程中,这并不存在(或不需要)。也许是因为房东已经注册了 IPA?
    • 这也可能是由于密钥存储在 NSS 数据库中,该数据库存储了实际密钥。然后请求看起来像: ipa-getcert request -d /path/to/database
    【解决方案2】:
    # Set variables
    DOMAIN=domain.name
    CNAME=cname
    DEST_MACHINE=dest-machine
    
    # Add CNAME DNS-record
    # $CNAME => $DEST_MACHINE
    ipa dnsrecord-add $DOMAIN $CNAME --cname-hostname=$DEST_MACHINE
    
    # Generate a private key
    ## to /etc/pki/tls/private
    ## or another dir (*selinux fcontext* of that dir should be *cert_t*)
    sudo openssl genrsa -out /etc/pki/tls/private/$CNAME\_$DEST_MACHINE.key 4096
    
    # Create HTTP service for $DEST_MACHINE\.$DOMAIN
    ipa service-add HTTP/$DEST_MACHINE\.$DOMAIN
    
    # Add alias HTTP/$CNAME\.$DOMAIN for HTTP/$DEST_MACHINE\.$DOMAIN
    ipa service-add-principal HTTP/$DEST_MACHINE\.$DOMAIN HTTP/$CNAME\.$DOMAIN
    
    # Request a certificate for HTTP/$DEST_MACHINE\.$DOMAIN
    # for a DNSNAMEs:
    ## $DEST_MACHINE\.$DOMAIN
    ## $CNAME\.$DOMAIN
    sudo ipa-getcert request -r \
    -f /etc/pki/tls/private/$CNAME\_$DEST_MACHINE.crt \
    -k /etc/pki/tls/private/$CNAME\_$DEST_MACHINE.key \
    -K HTTP/$DEST_MACHINE\.$DOMAIN \
    -D $DEST_MACHINE\.$DOMAIN \
    -D $CNAME\.$DOMAIN
    
    # Show info about certificate requests
    sudo ipa-getcert list
    
    # List content of certificates dir
    ls /etc/pki/tls/private/
    
    # Now just use that certificates with your web-services
    

    【讨论】:

      猜你喜欢
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      • 1970-01-01
      • 2018-08-18
      • 2023-04-04
      • 1970-01-01
      • 2018-09-29
      相关资源
      最近更新 更多