mirror of
https://github.com/eliasstepanik/caddy-ingess.git
synced 2026-01-10 20:18:28 +00:00
* Update to caddy v2.0.0 * Fixes from #24 * Update rbac api and move ingresses from extensions api to networking * Fix matchers * Allow default backend * Use caddyconfig.JSON * Fix issuer * Use empty image for docker
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package caddy
|
|
|
|
import (
|
|
"github.com/caddyserver/caddy/v2"
|
|
"github.com/caddyserver/caddy/v2/caddyconfig"
|
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
|
"github.com/caddyserver/caddy/v2/modules/caddytls"
|
|
)
|
|
|
|
// StorageValues represents the config for certmagic storage providers.
|
|
type StorageValues struct {
|
|
Namespace string `json:"namespace"`
|
|
}
|
|
|
|
// Storage represents the certmagic storage configuration.
|
|
type Storage struct {
|
|
System string `json:"module"`
|
|
StorageValues
|
|
}
|
|
|
|
// Config represents a caddy2 config file.
|
|
type Config struct {
|
|
Storage Storage `json:"storage"`
|
|
Apps map[string]interface{} `json:"apps"`
|
|
}
|
|
|
|
// ControllerConfig represents ingress controller config received through cli arguments.
|
|
type ControllerConfig struct {
|
|
Email string
|
|
AutomaticTLS bool
|
|
TLSUseStaging bool
|
|
WatchNamespace string
|
|
}
|
|
|
|
// NewConfig returns a plain slate caddy2 config file.
|
|
func NewConfig(namespace string, cfg ControllerConfig) *Config {
|
|
acmeIssuer := caddytls.ACMEIssuer{
|
|
CA: getCAEndpoint(cfg.TLSUseStaging),
|
|
Email: cfg.Email}
|
|
|
|
return &Config{
|
|
Storage: Storage{
|
|
System: "secret_store",
|
|
StorageValues: StorageValues{
|
|
Namespace: namespace,
|
|
},
|
|
},
|
|
Apps: map[string]interface{}{
|
|
"tls": caddytls.TLS{
|
|
Automation: &caddytls.AutomationConfig{
|
|
Policies: []*caddytls.AutomationPolicy{
|
|
{
|
|
IssuerRaw: caddyconfig.JSONModuleObject(acmeIssuer, "module", "acme", nil),
|
|
},
|
|
},
|
|
},
|
|
CertificatesRaw: caddy.ModuleMap{},
|
|
},
|
|
"http": caddyhttp.App{
|
|
Servers: map[string]*caddyhttp.Server{
|
|
"ingress_server": &caddyhttp.Server{
|
|
AutoHTTPS: &caddyhttp.AutoHTTPSConfig{
|
|
Disabled: !cfg.AutomaticTLS,
|
|
Skip: make([]string, 0),
|
|
},
|
|
Listen: []string{":80", ":443"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func getCAEndpoint(useStaging bool) string {
|
|
if useStaging {
|
|
return "https://acme-staging-v02.api.letsencrypt.org/directory"
|
|
}
|
|
return ""
|
|
}
|