Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: auto certs #1911

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ default: help
VERSION ?= 1.6.0


TARGET_APISIX_VERSION ?= "3.1.0-centos"
TARGET_APISIX_VERSION ?= "3.4.1-centos"
APISIX_ADMIN_API_VERSION ?= "v3"

ifeq ($(APISIX_ADMIN_API_VERSION),"v2")
Expand Down
96 changes: 95 additions & 1 deletion test/e2e/scaffold/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *Scaffold) GenerateCert(t ginkgo.GinkgoTInterface, dnsNames []string) (c
Organization: []string{"Acme Co"},
},
NotBefore: time.Now(),
NotAfter: time.Now().Add(time.Hour),
NotAfter: time.Now().Add(24 * time.Hour),

KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
Expand All @@ -189,3 +189,97 @@ func (s *Scaffold) GenerateCert(t ginkgo.GinkgoTInterface, dnsNames []string) (c

return
}

// GenerateMACert used for generate MutualAuthCerts
func (s *Scaffold) GenerateMACert(t ginkgo.GinkgoTInterface, dnsNames []string) (caCertBytes, serverCertBytes, serverKeyBytes, clientCertBytes, clientKeyBytes bytes.Buffer) {
// CA cert
caKey, err := rsa.GenerateKey(rand.Reader, 2048)
assert.NoError(t, err)
caPub := caKey.Public()

serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
assert.NoError(t, err)

caTemplate := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
CommonName: dnsNames[0] + "-ca",
Organization: []string{"Acme Co"},
},
NotBefore: time.Now(),
NotAfter: time.Now().Add(24 * time.Hour),

KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
BasicConstraintsValid: true,
}

caTemplate.IsCA = true
caTemplate.KeyUsage |= x509.KeyUsageCertSign

caBytes, err := x509.CreateCertificate(rand.Reader, &caTemplate, &caTemplate, caPub, caKey)
assert.NoError(t, err)
err = pem.Encode(&caCertBytes, &pem.Block{Type: "CERTIFICATE", Bytes: caBytes})
assert.NoError(t, err)

// Server cert
serverKey, err := rsa.GenerateKey(rand.Reader, 2048)
assert.NoError(t, err)

serialNumber, err = rand.Int(rand.Reader, serialNumberLimit)
assert.NoError(t, err)

serverTemplate := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
CommonName: dnsNames[0],
Organization: []string{"Acme Co"},
},
NotBefore: time.Now(),
NotAfter: time.Now().Add(24 * time.Hour),

KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment | x509.KeyUsageCertSign,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
BasicConstraintsValid: true,
}

serverBytes, err := x509.CreateCertificate(rand.Reader, &serverTemplate, &caTemplate, &serverKey.PublicKey, caKey)
assert.NoError(t, err)
err = pem.Encode(&serverCertBytes, &pem.Block{Type: "CERTIFICATE", Bytes: serverBytes})
assert.NoError(t, err)
serverKeyBytesD, err := x509.MarshalPKCS8PrivateKey(serverKey)
assert.NoError(t, err)
err = pem.Encode(&serverKeyBytes, &pem.Block{Type: "PRIVATE KEY", Bytes: serverKeyBytesD})

// Client cert
clientKey, err := rsa.GenerateKey(rand.Reader, 2048)
assert.NoError(t, err)

serialNumber, err = rand.Int(rand.Reader, serialNumberLimit)
assert.NoError(t, err)

clientTemplate := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
CommonName: dnsNames[0] + "-client",
Organization: []string{"Acme Co"},
},
NotBefore: time.Now(),
NotAfter: time.Now().Add(24 * time.Hour),

KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
BasicConstraintsValid: true,
}

clientBytes, err := x509.CreateCertificate(rand.Reader, &clientTemplate, &caTemplate, &clientKey.PublicKey, caKey)
assert.NoError(t, err)
err = pem.Encode(&clientCertBytes, &pem.Block{Type: "CERTIFICATE", Bytes: clientBytes})
assert.NoError(t, err)
clientKeyBytesD, err := x509.MarshalPKCS8PrivateKey(clientKey)
assert.NoError(t, err)
err = pem.Encode(&clientKeyBytes, &pem.Block{Type: "PRIVATE KEY", Bytes: clientKeyBytesD})

return
}
3 changes: 2 additions & 1 deletion test/e2e/suite-features/external-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"reflect"
"strings"
"time"

"github.com/apache/apisix-ingress-controller/pkg/id"
Expand Down Expand Up @@ -385,7 +386,7 @@ spec:
for _, header := range value {
switch vv := header.(type) {
case string:
if vv == "httpbun" {
if strings.HasPrefix(vv, "httpbun") {
hasPoweredBy = true
break forloop
}
Expand Down
221 changes: 7 additions & 214 deletions test/e2e/suite-ingress/suite-ingress-resource/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,230 +246,23 @@ var _ = ginkgo.Describe("suite-ingress-resource: ApisixTls mTLS Test", func() {
// RootCA -> UserCert
// These certs come from mTLS practice

rootCA := `-----BEGIN CERTIFICATE-----
MIIF7DCCA9SgAwIBAgIUAhSL3pkpTz4F9pNyis+TD6HUQOAwDQYJKoZIhvcNAQEL
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ThNoov2SMB2y7073Bnun
Vjw3oOgUkXpd/qgVDITsJgMz25qn7WfYQQUuYf7ehNB7/Bz/u5iIg7WqtjfJSyp+
SkV5LJrOsGyIoXcCAwEAAaM6MDgwDAYDVR0TBAUwAwEB/zAoBgNVHREEITAfghJt
dGxzLmh0dHBiaW4ubG9jYWyCCWxvY2FsaG9zdDANBgkqhkiG9w0BAQsFAAOCAgEA
a0fIFgRpP4jEdXNE55jt0DBfuiWfaHMNmjChugKX64WHYlig+7591gKcATYkciE2
f9bSWp65UxMex4u1sg7iGS31Muq0ayArDsD+EH+DPnhWECnXarq6R03/XYOpUGsC
Mcqs99bBxjB6GpPFz+C/IFYjSDO9e9xt+Y5JJ88yhlOMslZj873lNOTDHpwq60YR
MU9uIG1FtTuZcaKnnEAxoO+Z/rEdYbMXUp1eukSCRFidjKX2mK45CvzxCxuTouyO
XAp3EXcE5M6jX6gVuPIQGg2t+wL1YW2mQQuokSQhvDGHi62KPnWSRbYZ3sb5163O
RGSQmruQRJzLuQLpck4zF6jU1zuLt3Vqz1jN28GxTdVNOnnV1x9TM/wR5stl/3zX
tGuhKGVkSo6yja5FgYGTRWp/QxaMzXGbUxaZqH3gLp8JmuN+X3mmbQ8VEHkcINdN
kRKIoaIQTjhu8524GO//bsmKEZg+eCJ0RqLi3A0uH/xAq513zejNw6Ij30EGH9Qu
oVUuT4oL/s7yDtDeI5Nkolf+Ue8utKXPEIbNYlo/XUtbYQ4oChunuyKeKgCAN+HI
onTtJIlTwQI0r79pbJ5KpUPcHzKWeX5PHQnYFe0vzFXhRCfof898AMhRT0f7Mvkc
bAupufi5aCbmxOo/CFWHDMsWNv9RueSjwC/8R7n7z8M=
-----END CERTIFICATE-----`

serverCertSecret := `server-secret`
serverCert := `-----BEGIN CERTIFICATE-----
MIIF5jCCA86gAwIBAgIUBigWd84H8JCiKERdO40wSZ1JgP0wDQYJKoZIhvcNAQEL
BQAwgZExCzAJBgNVBAYTAkNOMREwDwYDVQQIDAhaaGVqaWFu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AC09cwKJyRZBP7aUm
hknMk9yCCS+JC2bXkiwl7ZmIokaJXofDs12Lc5SX5CAleWs3ChIUfxUt/4HokjZa
sSHNZAYHx36ZadyoUqMQcWZHjxPi/iaxRgZZA4G/Cv0IIM7W3aicKxyaqQyXShLi
H2UwuQKCAQA2Cx71plS6uVBYEW/xrGLFMfqWKkJmyldEC8IlBxLQ/J5aLf+5dTbS
c6RxaL0cvLJ+iO9tT9U5IFMztM7vbv3Rcc90A5iw6WkYbsLTb8D1qAJhktJhsnFj
pSVINczr4q6gh39Za7a0k7k/qpKvuj4kLvjamFlwGveSD128wUelE8DZXEpUioAm
6NoyV+3+/69OpRJpJkTGDPm4GveCzdc+6cY4JIaYpV6Q/pw9/WYgPGqSJZCjFYeU
nSoiH4JDISuxtNynIEmhEFf3a+G+2q7U6Y8koNCGSfF8t9Ke4y4RRBudY2Ca7cBs
IaPirtpmmJ/YKUHFpqFzs3X3uY+qiZE5AoIBAE7PevOHRncpX9jJrLcOdv5QmuI7
zZoWkJKPT+Ih8sBtwHZ89IHpQvhzPAaLJ6zev52QvSyxHW0TQnNWIGh5zdBdeGqX
gCVY/RmHFeDouuVDtesvCi0bfYgDGZsYeV1v83gOmcF+/+QjGT57ifmtnsIvnq5v
A9bsKwgSLrjTJswy2s1oXeoGk5WvZEzbNr9yui9j2DpS9YZX2cpw6B8umIAB4s2M
6pjGUQy6XsCOY8z1rzemk/EiEWN7+CdnaAm9hcOxDNWCBDNiyW3LUSpS0DRi+lKL
jzit3pB5lp13YaVOoUil5Nvrp42M6MgJiVnu4a8s2d4fSoPfBzsKcstIQPU=
-----END RSA PRIVATE KEY-----
`

suites := func(scaffoldFunc func() *scaffold.Scaffold) {
s := scaffoldFunc()
ginkgo.It("create a SSL with client CA", func() {
// create secrets
err := s.NewSecret(serverCertSecret, serverCert, serverKey)
host := "mtls.httpbin.local"
rootCA, serverCert, serverKey, clientCert, clientKey := s.GenerateMACert(ginkgo.GinkgoT(), []string{host})

err := s.NewSecret(serverCertSecret, serverCert.String(), serverKey.String())
assert.Nil(ginkgo.GinkgoT(), err, "create server cert secret error")
err = s.NewClientCASecret(clientCASecret, rootCA, "")
err = s.NewClientCASecret(clientCASecret, rootCA.String(), "")
assert.Nil(ginkgo.GinkgoT(), err, "create client CA cert secret error")

// create ApisixTls resource
tlsName := "tls-with-client-ca"
host := "mtls.httpbin.local"
err = s.NewApisixTlsWithClientCA(tlsName, host, serverCertSecret, clientCASecret)
assert.Nil(ginkgo.GinkgoT(), err, "create ApisixTls with client CA error")
// check ssl in APISIX
Expand Down Expand Up @@ -504,10 +297,10 @@ spec:

// With client cert
caCertPool := x509.NewCertPool()
ok := caCertPool.AppendCertsFromPEM([]byte(rootCA))
ok := caCertPool.AppendCertsFromPEM([]byte(rootCA.String()))
assert.True(ginkgo.GinkgoT(), ok, "Append cert to CA pool")

cert, err := tls.X509KeyPair([]byte(clientCert), []byte(clientKey))
cert, err := tls.X509KeyPair([]byte(clientCert.String()), []byte(clientKey.String()))
assert.Nil(ginkgo.GinkgoT(), err, "generate cert")

s.NewAPISIXHttpsClientWithCertificates(host, true, caCertPool, []tls.Certificate{cert}).
Expand Down