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

Add flag to skip CA certificates #2341

Merged
merged 1 commit into from
May 2, 2022
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
`allowedRoutes` filters are merged into generated listeners with the same
protocol.
[#2389](https://github.com/Kong/kubernetes-ingress-controller/issues/2389)
- Added `--skip-ca-certificates` flag to ignore CA certificate resources for
[use with multi-workspace environments](https://github.com/Kong/deck/blob/main/CHANGELOG.md#v1120).
[#2341](https://github.com/Kong/kubernetes-ingress-controller/issues/2341)

#### Fixed

Expand Down
23 changes: 15 additions & 8 deletions internal/dataplane/kong_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type KongClient struct {
// updates to the data-plane.
enableReverseSync bool

// skipCACertificates disables CA certificates, to avoid fighting over configuration in multi-workspace
// environments. See https://github.com/Kong/deck/pull/617
skipCACertificates bool

// requestTimeout is the maximum amount of time that should be waited for
// requests to the data-plane to receive a response.
requestTimeout time.Duration
Expand Down Expand Up @@ -99,20 +103,22 @@ func NewKongClient(
timeout time.Duration,
ingressClass string,
enableReverseSync bool,
skipCACertificates bool,
diagnostic util.ConfigDumpDiagnostic,
kongConfig sendconfig.Kong,
) (*KongClient, error) {
// build the client object
cache := store.NewCacheStores()
c := &KongClient{
logger: logger,
ingressClass: ingressClass,
enableReverseSync: enableReverseSync,
requestTimeout: timeout,
diagnostic: diagnostic,
prometheusMetrics: metrics.NewCtrlFuncMetrics(),
cache: &cache,
kongConfig: kongConfig,
logger: logger,
ingressClass: ingressClass,
enableReverseSync: enableReverseSync,
skipCACertificates: skipCACertificates,
requestTimeout: timeout,
diagnostic: diagnostic,
prometheusMetrics: metrics.NewCtrlFuncMetrics(),
cache: &cache,
kongConfig: kongConfig,
}

// download the kong root configuration (and validate connectivity to the proxy API)
Expand Down Expand Up @@ -305,6 +311,7 @@ func (c *KongClient) Update(ctx context.Context) error {
&c.kongConfig,
c.kongConfig.InMemory,
c.enableReverseSync,
c.skipCACertificates,
targetConfig,
c.kongConfig.FilterTags,
nil,
Expand Down
6 changes: 4 additions & 2 deletions internal/dataplane/sendconfig/sendconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func PerformUpdate(ctx context.Context,
kongConfig *Kong,
inMemory bool,
reverseSync bool,
skipCACertificates bool,
targetContent *file.Content,
selectorTags []string,
customEntities []byte,
Expand Down Expand Up @@ -77,7 +78,7 @@ func PerformUpdate(ctx context.Context,
err = onUpdateInMemoryMode(ctx, log, targetContent, customEntities, kongConfig)
} else {
metricsProtocol = metrics.ProtocolDeck
err = onUpdateDBMode(ctx, targetContent, kongConfig, selectorTags)
err = onUpdateDBMode(ctx, targetContent, kongConfig, selectorTags, skipCACertificates)
}
timeEnd := time.Now()

Expand Down Expand Up @@ -199,8 +200,9 @@ func onUpdateDBMode(ctx context.Context,
targetContent *file.Content,
kongConfig *Kong,
selectorTags []string,
skipCACertificates bool,
) error {
dumpConfig := dump.Config{SelectorTags: selectorTags}
dumpConfig := dump.Config{SelectorTags: selectorTags, SkipCACerts: skipCACertificates}
// read the current state
rawState, err := dump.Get(ctx, kongConfig.Client, dumpConfig)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
AnonymousReports bool
EnableReverseSync bool
SyncPeriod time.Duration
SkipCACertificates bool

// Kong Proxy configurations
APIServerHost string
Expand Down Expand Up @@ -122,6 +123,7 @@ func (c *Config) FlagSet() *pflag.FlagSet {
flagSet.BoolVar(&c.AnonymousReports, "anonymous-reports", true, `Send anonymized usage data to help improve Kong`)
flagSet.BoolVar(&c.EnableReverseSync, "enable-reverse-sync", false, `Send configuration to Kong even if the configuration checksum has not changed since previous update.`)
flagSet.DurationVar(&c.SyncPeriod, "sync-period", time.Hour*48, `Relist and confirm cloud resources this often`) // 48 hours derived from controller-runtime defaults
flagSet.BoolVar(&c.SkipCACertificates, "skip-ca-certificates", false, `disable syncing CA certificate syncing (for use with multi-workspace environments)`)

flagSet.StringVar(&c.KongAdminAPIConfig.TLSClientCertPath, "kong-admin-tls-client-cert-file", "", "mTLS client certificate file for authentication.")
flagSet.StringVar(&c.KongAdminAPIConfig.TLSClientKeyPath, "kong-admin-tls-client-key-file", "", "mTLS client key file for authentication.")
Expand Down
5 changes: 4 additions & 1 deletion internal/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic) e
if !ok {
return fmt.Errorf("invalid database configuration, expected a string got %T", kongRootConfig["database"])
}
if dbmode == "off" && c.SkipCACertificates {
return fmt.Errorf("--skip-ca-certificates is not available for use with DB-less Kong instances")
}

setupLog.Info("configuring and building the controller manager")
controllerOpts, err := setupControllerOptions(setupLog, c, scheme, dbmode)
Expand All @@ -125,7 +128,7 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic) e
if err != nil {
return fmt.Errorf("%f is not a valid number of seconds to the timeout config for the kong client: %w", c.ProxyTimeoutSeconds, err)
}
dataplaneClient, err := dataplane.NewKongClient(deprecatedLogger, timeoutDuration, c.IngressClassName, c.EnableReverseSync, diagnostic, kongConfig)
dataplaneClient, err := dataplane.NewKongClient(deprecatedLogger, timeoutDuration, c.IngressClassName, c.EnableReverseSync, c.SkipCACertificates, diagnostic, kongConfig)
if err != nil {
return fmt.Errorf("failed to initialize kong data-plane client: %w", err)
}
Expand Down