Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Parameterise ClusterIssuer for Dex, Gangway, HTTPBin #482

Merged
merged 4 commits into from
May 26, 2020
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: 2 additions & 0 deletions ci/aks/aks-cluster.lokocfg.envsubst
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ component "external-dns" {

component "httpbin" {
ingress_host = "httpbin.${var.cluster_name}.${var.aws_dns_zone}"

certmanager_cluster_issuer = "letsencrypt-staging"
}
6 changes: 6 additions & 0 deletions ci/aws/aws-cluster.lokocfg.envsubst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ component "dex" {

issuer_host = "$ISSUER_HOST"

certmanager_cluster_issuer = "letsencrypt-staging"

connector "github" {
id = "github"
name = "GitHub"
Expand Down Expand Up @@ -110,6 +112,8 @@ component "gangway" {

ingress_host = "$GANGWAY_INGRESS_HOST"

certmanager_cluster_issuer = "letsencrypt-staging"

session_key = "$GANGWAY_SESSION_KEY"

api_server_url = "$API_SERVER_URL"
Expand All @@ -132,4 +136,6 @@ component "flatcar-linux-update-operator" {}

component "httpbin" {
ingress_host = "httpbin.$CLUSTER_ID.$AWS_DNS_ZONE"

certmanager_cluster_issuer = "letsencrypt-staging"
}
6 changes: 6 additions & 0 deletions ci/packet/packet-cluster.lokocfg.envsubst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ component "dex" {

issuer_host = "$ISSUER_HOST"

certmanager_cluster_issuer = "letsencrypt-staging"

connector "github" {
id = "github"
name = "GitHub"
Expand Down Expand Up @@ -117,6 +119,8 @@ component "gangway" {

ingress_host = "$GANGWAY_INGRESS_HOST"

certmanager_cluster_issuer = "letsencrypt-staging"

session_key = "$GANGWAY_SESSION_KEY"

api_server_url = "$API_SERVER_URL"
Expand Down Expand Up @@ -155,4 +159,6 @@ component "cluster-autoscaler" {

component "httpbin" {
ingress_host = "httpbin.$CLUSTER_ID.$AWS_DNS_ZONE"

certmanager_cluster_issuer = "letsencrypt-staging"
}
1 change: 1 addition & 0 deletions docs/configuration-reference/components/dex.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Example:
|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------:|:--------:|
| `ingress_host` | Used as the `hosts` domain in the ingress resource for dex that is automatically created. | - | true |
| `issuer_host` | Dex's issuer URL. | - | true |
| `certmanager_cluster_issuer` | `ClusterIssuer` to be used by cert-manager while issuing TLS certificates. Supported values: `letsencrypt-production`, `letsencrypt-staging`. | `letsencrypt-production` | false |
| `connector` | Dex implements connectors that target OpenID Connect and specific platforms such as GitHub, Google etc. Currently only GitHub and OIDC (Google) are supported from lokoctl. | - | true |
| `connector.id` | ID of the connector. | - | true |
| `connector.name` | Name of the connector. | - | true |
Expand Down
1 change: 1 addition & 0 deletions docs/configuration-reference/components/gangway.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Example:
|------------------|-----------------------------------------------------------------------------------------------|:-------:|:--------:|
| `cluster_name` | The name of the cluster. | - | true |
| `ingress_host` | Used as the `hosts` domain in the ingress resource for gangway that is automatically created. | - | true |
| `certmanager_cluster_issuer` | `ClusterIssuer` to be used by cert-manager while issuing TLS certificates. Supported values: `letsencrypt-production`, `letsencrypt-staging`. | `letsencrypt-production` | false |
| `sesion_key` | Gangway session key. | - | true |
| `api_server_url` | URL of Kubernetes API server. | - | true |
| `authorize_url` | Auth endpoint of Dex. | - | true |
Expand Down
1 change: 1 addition & 0 deletions docs/configuration-reference/components/httpbin.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Example:
| Argument | Description Default | Required |
|--------------------|-----------------------------------------------------------------------------------------------|:------------:|:--------:|
| `ingress_host` | Used as the `hosts` domain in the ingress resource for httpbin that is automatically created. | - | true |
| `certmanager_cluster_issuer` | `ClusterIssuer` to be used by cert-manager while issuing TLS certificates. Supported values: `letsencrypt-production`, `letsencrypt-staging`. | `letsencrypt-production` | false |

## Applying

Expand Down
17 changes: 10 additions & 7 deletions pkg/components/dex/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ metadata:
annotations:
kubernetes.io/ingress.class: contour
kubernetes.io/tls-acme: "true"
cert-manager.io/cluster-issuer: "letsencrypt-production"
cert-manager.io/cluster-issuer: {{ .CertManagerClusterIssuer }}
spec:
tls:
- hosts:
Expand Down Expand Up @@ -245,19 +245,22 @@ type staticClient struct {
}

type component struct {
IngressHost string `hcl:"ingress_host,attr"`
IssuerHost string `hcl:"issuer_host,attr"`
Connectors []connector `hcl:"connector,block"`
StaticClients []staticClient `hcl:"static_client,block"`
GSuiteJSONConfigPath string `hcl:"gsuite_json_config_path,optional"`
IngressHost string `hcl:"ingress_host,attr"`
IssuerHost string `hcl:"issuer_host,attr"`
Connectors []connector `hcl:"connector,block"`
StaticClients []staticClient `hcl:"static_client,block"`
GSuiteJSONConfigPath string `hcl:"gsuite_json_config_path,optional"`
CertManagerClusterIssuer string `hcl:"certmanager_cluster_issuer,optional"`

// Those are fields not accessible by user
ConnectorsRaw string
StaticClientsRaw string
}

func newComponent() *component {
return &component{}
return &component{
CertManagerClusterIssuer: "letsencrypt-production",
}
}

func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContext) hcl.Diagnostics {
Expand Down
25 changes: 14 additions & 11 deletions pkg/components/gangway/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ metadata:
namespace: gangway
annotations:
kubernetes.io/tls-acme: "true"
cert-manager.io/cluster-issuer: "letsencrypt-production"
cert-manager.io/cluster-issuer: {{ .CertManagerClusterIssuer }}
kubernetes.io/ingress.class: contour
spec:
tls:
Expand Down Expand Up @@ -275,19 +275,22 @@ func init() {
}

type component struct {
ClusterName string `hcl:"cluster_name,attr"`
IngressHost string `hcl:"ingress_host,attr"`
SessionKey string `hcl:"session_key,attr"`
APIServerURL string `hcl:"api_server_url,attr"`
AuthorizeURL string `hcl:"authorize_url,attr"`
TokenURL string `hcl:"token_url,attr"`
ClientID string `hcl:"client_id,attr"`
ClientSecret string `hcl:"client_secret,attr"`
RedirectURL string `hcl:"redirect_url,attr"`
ClusterName string `hcl:"cluster_name,attr"`
IngressHost string `hcl:"ingress_host,attr"`
SessionKey string `hcl:"session_key,attr"`
APIServerURL string `hcl:"api_server_url,attr"`
AuthorizeURL string `hcl:"authorize_url,attr"`
TokenURL string `hcl:"token_url,attr"`
ClientID string `hcl:"client_id,attr"`
ClientSecret string `hcl:"client_secret,attr"`
RedirectURL string `hcl:"redirect_url,attr"`
CertManagerClusterIssuer string `hcl:"certmanager_cluster_issuer,optional"`
}

func newComponent() *component {
return &component{}
return &component{
CertManagerClusterIssuer: "letsencrypt-production",
}
}

func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContext) hcl.Diagnostics {
Expand Down
9 changes: 6 additions & 3 deletions pkg/components/httpbin/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ metadata:
namespace: httpbin
annotations:
kubernetes.io/tls-acme: "true"
cert-manager.io/cluster-issuer: "letsencrypt-production"
cert-manager.io/cluster-issuer: {{ .CertManagerClusterIssuer }}
kubernetes.io/ingress.class: contour
spec:
tls:
Expand All @@ -117,11 +117,14 @@ func init() {
}

type component struct {
IngressHost string `hcl:"ingress_host,attr"`
IngressHost string `hcl:"ingress_host,attr"`
CertManagerClusterIssuer string `hcl:"certmanager_cluster_issuer,optional"`
}

func newComponent() *component {
return &component{}
return &component{
CertManagerClusterIssuer: "letsencrypt-production",
}
}

func (c *component) LoadConfig(configBody *hcl.Body, evalContext *hcl.EvalContext) hcl.Diagnostics {
Expand Down
53 changes: 52 additions & 1 deletion test/ingress/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package aws

import (
"crypto/tls"
"crypto/x509"
"fmt"
"net/http"
"testing"
Expand All @@ -42,9 +44,10 @@ func TestAWSIngress(t *testing.T) {
}

h := i.Spec.Rules[0].Host
c := getHTTPClient()

err = retryutil.Retry(retryIntervalSeconds*time.Second, maxRetries, func() (bool, error) {
resp, err := http.Get(fmt.Sprintf("https://%s/get", h))
resp, err := c.Get(fmt.Sprintf("https://%s/get", h))
if err != nil {
t.Logf("got an HTTP error: %v", err)
return false, nil
Expand All @@ -67,3 +70,51 @@ func TestAWSIngress(t *testing.T) {
t.Fatal("could not get a successful HTTP response in time")
}
}

// getHTTPClient creates a HTTP client with LetsEncrypt Staging Root PEM certificate.
func getHTTPClient() *http.Client {
// Get this Root PEM from https://letsencrypt.org/docs/staging-environment/#root-certificate
letsEncryptStagingRootPEM := `-----BEGIN CERTIFICATE-----
MIIFATCCAumgAwIBAgIRAKc9ZKBASymy5TLOEp57N98wDQYJKoZIhvcNAQELBQAw
GjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMB4XDTE2MDMyMzIyNTM0NloXDTM2
MDMyMzIyNTM0NlowGjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMIICIjANBgkq
hkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA+pYHvQw5iU3v2b3iNuYNKYgsWD6KU7aJ
diddtZQxSWYzUI3U0I1UsRPTxnhTifs/M9NW4ZlV13ZfB7APwC8oqKOIiwo7IwlP
xg0VKgyz+kT8RJfYr66PPIYP0fpTeu42LpMJ+CKo9sbpgVNDZN2z/qiXrRNX/VtG
TkPV7a44fZ5bHHVruAxvDnylpQxJobtCBWlJSsbIRGFHMc2z88eUz9NmIOWUKGGj
EmP76x8OfRHpIpuxRSCjn0+i9+hR2siIOpcMOGd+40uVJxbRRP5ZXnUFa2fF5FWd
O0u0RPI8HON0ovhrwPJY+4eWKkQzyC611oLPYGQ4EbifRsTsCxUZqyUuStGyp8oa
aoSKfF6X0+KzGgwwnrjRTUpIl19A92KR0Noo6h622O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w1VrejtwclobqNMVtG3EiPUIpJGpbMcJgbiLSmKkrvQtGng==
-----END CERTIFICATE-----`

rootCAs := x509.NewCertPool()
if ok := rootCAs.AppendCertsFromPEM([]byte(letsEncryptStagingRootPEM)); !ok {
// This should fail in the developer testing itself.
panic("Failed to parse root certificate")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using t.Fatal() would be better here, as panic will abort all the tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think panic is ok here. This function decodes a PEM-encoded certificate which is statically defined in code so it should not fail during regular testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's very nit-picking from my side 😂

}

return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
},
}
}