window下生成SANs证书给ingress用

news2024/11/17 21:23:53

1.安装openssl

openssl下载地址:http://slproweb.com/products/Win32OpenSSL.html

http://slproweb.com/products/Win32OpenSSL.html
在这里插入图片描述

下载指定版本exe安装。

2. 修改openssl配置

为了方便我们copy一份openssl.cfg,用来修改

C:\Users\vamcl\Desktop\fsdownload\sans>openssl.cfg

  1. 找到 [ CA_default ],打开 copy_extensions = copy

  2. 找到[ req ],打开 req_extensions = v3_req # The extensions to add to a certificate request

  3. 找到[ v3_req ],添加 subjectAltName = @alt_names

  4. 添加新的标签 [ alt_names ] , 和标签字段,这里填入需要加入到 Subject Alternative Names 段落中的域名名称,可以写入多个。

修改后的内容如下:

#
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#

# Note that you can include other files from the main configuration
# file using the .include directive.
#.include filename

# This definition stops the following lines choking if HOME isn't
# defined.
HOME			= .

# Extra OBJECT IDENTIFIER info:
#oid_file		= $ENV::HOME/.oid
oid_section		= new_oids

# To use this configuration file with the "-extfile" option of the
# "openssl x509" utility, name here the section containing the
# X.509v3 extensions to use:
# extensions		=
# (Alternatively, use a configuration file that has only
# X.509v3 extensions in its main [= default] section.)

[ new_oids ]

# We can add new OIDs in here for use by 'ca', 'req' and 'ts'.
# Add a simple OID like this:
# testoid1=1.2.3.4
# Or use config file substitution like this:
# testoid2=${testoid1}.5.6

# Policies used by the TSA examples.
tsa_policy1 = 1.2.3.4.1
tsa_policy2 = 1.2.3.4.5.6
tsa_policy3 = 1.2.3.4.5.7

####################################################################
[ ca ]
default_ca	= CA_default		# The default ca section

####################################################################
[ CA_default ]

dir		= ./demoCA		# Where everything is kept
certs		= $dir/certs		# Where the issued certs are kept
crl_dir		= $dir/crl		# Where the issued crl are kept
database	= $dir/index.txt	# database index file.
#unique_subject	= no			# Set to 'no' to allow creation of
					# several certs with same subject.
new_certs_dir	= $dir/newcerts		# default place for new certs.

certificate	= $dir/cacert.pem 	# The CA certificate
serial		= $dir/serial 		# The current serial number
crlnumber	= $dir/crlnumber	# the current crl number
					# must be commented out to leave a V1 CRL
crl		= $dir/crl.pem 		# The current CRL
private_key	= $dir/private/cakey.pem# The private key

x509_extensions	= usr_cert		# The extensions to add to the cert

# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt 	= ca_default		# Subject Name options
cert_opt 	= ca_default		# Certificate field options

# Extension copying option: use with caution.
copy_extensions = copy

# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions	= crl_ext

default_days	= 365			# how long to certify for
default_crl_days= 30			# how long before next CRL
default_md	= default		# use public key default MD
preserve	= no			# keep passed DN ordering

# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy		= policy_match

# For the CA policy
[ policy_match ]
countryName		= match
stateOrProvinceName	= match
organizationName	= match
organizationalUnitName	= optional
commonName		= supplied
emailAddress		= optional

# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName		= optional
stateOrProvinceName	= optional
localityName		= optional
organizationName	= optional
organizationalUnitName	= optional
commonName		= supplied
emailAddress		= optional

####################################################################
[ req ]
default_bits		= 2048
default_keyfile 	= privkey.pem
distinguished_name	= req_distinguished_name
attributes		= req_attributes
x509_extensions	= v3_ca	# The extensions to add to the self signed cert

# Passwords for private keys if not present they will be prompted for
# input_password = secret
# output_password = secret

# This sets a mask for permitted string types. There are several options.
# default: PrintableString, T61String, BMPString.
# pkix	 : PrintableString, BMPString (PKIX recommendation before 2004)
# utf8only: only UTF8Strings (PKIX recommendation after 2004).
# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
# MASK:XXXX a literal mask value.
# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
string_mask = utf8only

req_extensions = v3_req # The extensions to add to a certificate request

[ req_distinguished_name ]
countryName			= Country Name (2 letter code)
countryName_default		= AU
countryName_min			= 2
countryName_max			= 2

stateOrProvinceName		= State or Province Name (full name)
stateOrProvinceName_default	= Some-State

localityName			= Locality Name (eg, city)

0.organizationName		= Organization Name (eg, company)
0.organizationName_default	= Internet Widgits Pty Ltd

# we can do this but it is not needed normally :-)
#1.organizationName		= Second Organization Name (eg, company)
#1.organizationName_default	= World Wide Web Pty Ltd

organizationalUnitName		= Organizational Unit Name (eg, section)
#organizationalUnitName_default	=

commonName			= Common Name (e.g. server FQDN or YOUR name)
commonName_max			= 64

emailAddress			= Email Address
emailAddress_max		= 64

# SET-ex3			= SET extension number 3

[ req_attributes ]
challengePassword		= A challenge password
challengePassword_min		= 4
challengePassword_max		= 20

unstructuredName		= An optional company name

[ usr_cert ]

# These extensions are added when 'ca' signs a request.

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType			= server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.
nsComment			= "OpenSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer

# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy
# An alternative to produce certificates that aren't
# deprecated according to PKIX.
# subjectAltName=email:move

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl		= http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

# This is required for TSA certificates.
# extendedKeyUsage = critical,timeStamping

[ v3_req ]
subjectAltName = @alt_names
# Extensions to add to a certificate request

basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
# alt_names 注意写在最下面,basicConstraints和keyUsage的下面
[ alt_names ]
DNS.1 = test.localhost.com
DNS.2 = test.remote.com
[ v3_ca ]


# Extensions for a typical CA


# PKIX recommendation.

subjectKeyIdentifier=hash

authorityKeyIdentifier=keyid:always,issuer

basicConstraints = critical,CA:true

# Key usage: this is typical for a CA certificate. However since it will
# prevent it being used as an test self-signed certificate it is best
# left out by default.
# keyUsage = cRLSign, keyCertSign

# Some might want this also
# nsCertType = sslCA, emailCA

# Include email address in subject alt name: another PKIX recommendation
# subjectAltName=email:copy
# Copy issuer details
# issuerAltName=issuer:copy

# DER hex encoding of an extension: beware experts only!
# obj=DER:02:03
# Where 'obj' is a standard or added object
# You can even override a supported extension:
# basicConstraints= critical, DER:30:03:01:01:FF

[ crl_ext ]

# CRL extensions.
# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.

# issuerAltName=issuer:copy
authorityKeyIdentifier=keyid:always

[ proxy_cert_ext ]
# These extensions should be added when creating a proxy certificate

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType			= server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.
nsComment			= "OpenSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer

# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy
# An alternative to produce certificates that aren't
# deprecated according to PKIX.
# subjectAltName=email:move

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl		= http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

# This really needs to be in place for it to be a proxy certificate.
proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo

####################################################################
[ tsa ]

default_tsa = tsa_config1	# the default TSA section

[ tsa_config1 ]

# These are used by the TSA reply generation only.
dir		= ./demoCA		# TSA root directory
serial		= $dir/tsaserial	# The current serial number (mandatory)
crypto_device	= builtin		# OpenSSL engine to use for signing
signer_cert	= $dir/tsacert.pem 	# The TSA signing certificate
					# (optional)
certs		= $dir/cacert.pem	# Certificate chain to include in reply
					# (optional)
signer_key	= $dir/private/tsakey.pem # The TSA private key (optional)
signer_digest  = sha256			# Signing digest to use. (Optional)
default_policy	= tsa_policy1		# Policy if request did not specify it
					# (optional)
other_policies	= tsa_policy2, tsa_policy3	# acceptable policies (optional)
digests     = sha1, sha256, sha384, sha512  # Acceptable message digests (mandatory)
accuracy	= secs:1, millisecs:500, microsecs:100	# (optional)
clock_precision_digits  = 0	# number of digits after dot. (optional)
ordering		= yes	# Is ordering defined for timestamps?
				# (optional, default: no)
tsa_name		= yes	# Must the TSA name be included in the reply?
				# (optional, default: no)
ess_cert_id_chain	= no	# Must the ESS cert id chain be included?
				# (optional, default: no)
ess_cert_id_alg		= sha1	# algorithm to compute certificate
				# identifier (optional, default: sha1)

3. 生成证书

  1. 生成根证书:
openssl genrsa -out ca.key 2048
openssl req -new -x509 -days 3650 -key ca.key -out ca.pem
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) [AU]:cn
State or Province Name (full name) [Some-State]:beijing
Locality Name (eg, city) []:beijing
Organization Name (eg, company) [Internet Widgits Pty Ltd]:custer
Organizational Unit Name (eg, section) []:custer
Common Name (e.g. server FQDN or YOUR name) []:test.localhost.com
Email Address []:
  1. 用 openssl 生成 ca 和双方 SAN 证书
 openssl genpkey -algorithm RSA -out server.key
 
openssl req -new -nodes -key server.key -out server.csr -days 3650 -subj "/C=cn/OU=custer/O=custer/CN=test.localhost.com" -config ./openssl.cfg -extensions v3_req
 
openssl x509 -req -days 3650 -in server.csr -out server.pem -CA ca.pem -CAkey ca.key -CAcreateserial -extfile ./openssl.cfg -extensions v3_req

server.csr是上面生成的证书请求文件。ca.pem/ca.key是CA证书文件和key,用来对server.csr进行签名认证。这两个文件在之前生成的

  1. 生成客户端证书
openssl genpkey -algorithm RSA -out client.key
 
openssl req -new -nodes -key client.key -out client.csr -days 3650 -subj "/C=cn/OU=custer/O=custer/CN=test.localhost.com" -config ./openssl.cfg -extensions v3_req
 
openssl x509 -req -days 3650 -in client.csr -out client.pem -CA ca.pem -CAkey ca.key -CAcreateserial -extfile ./openssl.cfg -extensions v3_req

4.创建kubernetes TLS sercet

把SSL证书作为kubernetes sercet添加到kubernetes里面。这样,ingress的TLS就能引用SSL证书了。

在dev的namespace里,我们用server.crt和server.key文件创建一个TLS类型的kubernetes sercet。注意,hello app也在dev的namespace里。

在server.crt和server.key文件所在的路径下执行下面的kubectl命令,hello-app-tls可以是任意的名字。

kubectl create secret tls tls-secret \
    --key server.key \
    --cert server.pem

创建ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: echo-ingress
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - test.local.com
    secretName: tls-secret
  rules:
  - host: "test.local.com"
    http:
      paths:
        - pathType: Prefix
          path: "/"
          backend:
            service:
              name: echo-service
              port:
                number: 80

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/82733.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

做自媒体18个月,倒欠38万,一个自媒体创作者的自述

做自媒体18个月,倒欠38万,一个自媒体创作者的自述 疫情开始后,长期居家,工作和生活都受到了明显影响,偶然在网上看到了自媒体这个行业,号称日入几千几万。 前前后后花非不少钱买设备、买课、买会员等等,花费近40w颗粒…

Java网络编程,超详细

计算机网络分为网络协议和网络体系结构 通过网络发送数据是一项复杂的操作,必须仔细地协调网络的物理特性以及所发送数据的逻辑特征。通过网络将数据从一台主机发送到另外的主机,这个过程是通过计算机网络通信来完成。 网络通信的不同方面被分解为多个…

爆火的OpenAI及ChatGPT注册详细说明

1 准备条件 ① 需要梯子 ② 准备一个能够接收openai的手机号,用于接收注册验证码 (如果没有也不要紧,下面会介绍通过第三方接码平台来注册) 2 注册手机号接收验证码 网址:https://sms-activate.org/cn/getNumber 2.1 点击右上角注册 这里…

在word表格中一键生成序号,如何操作?

在word表格中一键生成序号,如何操作? 目录 在word表格中一键生成序号,如何操作? 1、首先选中需要填序号的这一列​ 2、在【开始】菜单中找到【多级列表】点击,再点击【定义新的多级列表】​ 3、点击【修改级别中的1…

ELK企业级日志收集

目录 一、ELK简介 二、ELK各组件介绍 ElasticSearch: Kibana: Logstash: 三、ELK可以添加的其他组件 Filebeat: 缓存/消息队列(redis、kafka、RabbitMQ等): Fluentd: 四、为…

【C初阶】第五篇——数组

一维数组的创建和初始化 数组的创建 数组的初始化 一维数组的使用 一维数组在内存中的存储 二维数组的创建和初始化 二维数组的创建 二维数组的初始化 二维数组的使用 二维数组在内存中的存储 数组越界 数组作为函数参数 冒泡排序函数的错误设计 数组名是什么? …

[附源码]Python计算机毕业设计SSM基于的汉服服装租赁系统(程序+LW)

项目运行 环境配置: Jdk1.8 Tomcat7.0 Mysql HBuilderX(Webstorm也行) Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。 项目技术: SSM mybatis Maven Vue 等等组成,B/S模式 M…

[附源码]Python计算机毕业设计Django大学生志愿者服务管理系统

项目运行 环境配置: Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术: django python Vue 等等组成,B/S模式 pychram管理等等。 环境需要 1.运行环境:最好是python3.7.7,…

配置vue3适用的vue-devtools

1、下载最新的vue/devtools的github项目库 项目库地址为 :GitHub - vuejs/devtools: ⚙️ Browser devtools extension for debugging Vue.js applications. 2、安装yarn vue/devtools的项目库,必须使用yarn来编译,npm会报错。 npm i 会报…

SQLyog Ultimate最流行的数据库管理工具之一

SQLyog Ultimate最流行的数据库管理工具之一 SQLyog是为Windows提供的最流行的SQL数据库管理工具之一。该软件是世界上任何地方的数据库管理工具,非常快速,易于使用和维护图形环境。使用此程序,您可以构建漂亮的数据,并在可视摄像…

Java教程-特性/语法/对象和类/基本数据类型/变量修饰符运算符/循环结构和条件语句/数组/正则/文件IO/异常处理详细总结

文章目录教程简介主要特性Java 语言是简单的:Java 语言是面向对象的:Java语言是分布式的:Java 语言是健壮的:Java语言是安全的:Java 语言是体系结构中立的:Java 语言是可移植的:Java 语言是解释…

stm32 如何查看系统各个时钟

在主函数main中会通过定义SystemInit()函数中设置的系统时钟大小: SYSCLK(系统时钟) 72MHz AHB 总线时钟(使用 SYSCLK) 72MHz APB1 总线时钟(PCLK1) 36MHz APB2 总线时钟(PCLK2) 72MH…

消息队列---MQ介绍

文章目录前言一、MQ是什么?1.1基本概念1.2MQ的优势和劣势优势应用解耦异步提速削峰填谷劣势二、常见的MQ产品总结前言 实习之MQ学习历程 一、MQ是什么? 1.1基本概念 MQ全称Message Queue(消息队列),是在消息的传输过程中保存消息的容器。多用于分布式系…

【数据结构】堆排序 (超详细)

前言:      前几次讲了如何构建一个堆以及TopK算法,那么这次给大家分享一下堆排序的两种方法。 方法一 直接暴力解决,建一个小堆,把数组的数据依次push,随后每次Pop堆顶,放进数组里。不过该方法因为建堆有消耗&…

字体图标、平面转换、渐变

1、字体图标 字体图标 字体图标展示的是图标,本质是字体。处理简单的、颜色单一的图片 1.1、字体图标的优点: 灵活性:灵活地修改样式,例如:尺寸、颜色等轻量级:体积小、渲染快、降低服务器请求次数兼容性…

SQL ALTER TABLE 语句

📒博客主页: ​​开心档博客主页​​ 🎉欢迎关注🔎点赞👍收藏⭐留言📝 📌本文由开心档原创! 📆51CTO首发时间:🌴2022年12月12日🌴 ✉…

华硕编程竞赛11月JAVA专场 J题再见天空 题解

作者主页:Designer 小郑 作者简介:Java全栈软件工程师一枚,来自浙江宁波,负责开发管理公司OA项目,专注软件前后端开发(Vue、SpringBoot和微信小程序)、系统定制、远程技术指导。CSDN学院、蓝桥云…

回归测试对比确认测试的区别

回归测试和确认测试是软件测试工作流程中的经常会做的两件事情,这两个环节也是代表软件测试的两个分类,那么他们之间的区别是什么?这篇文章咱们分析一下。回归测试与确认测试的区别?确认测试我们先说确认测试,它是软件…

表格解析 概览

表格解析发展至今,仍然是一项很年轻的研究领域,出现了大量解决方案,常用的技术包括:线检测、box检测、分割、多模态融合、GCN、img2seq。以下按我的理解梳理一下表格解析各个流派,从中了解这项任务背后所采用的技术。在…

28130-13-4,Val-Val-Val,H2N-VVV-OH

As trileucine, trivaline self-assembles into monolayers on highly ordered pyrolytic graphite (HOPG).三缬氨酸在高度有序的热解石墨(HOPG)上自组装成单层。 编号: 179127中文名称: 三肽Val-Val-Val英文名: Val-Val-ValCAS号: 28130-13-4单字母: H2N-VVV-OH三字母: H2N-Va…