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

Set the default PostgreSQL sslMode to verify-full #86

Merged
merged 3 commits into from
May 11, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
# this action because it leaves 'annotations' (i.e. it comments on PRs to
# point out linter violations).
- name: Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCI_VERSION }}
skip-go-installation: true
Expand Down
5 changes: 3 additions & 2 deletions apis/postgresql/v1alpha1/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ type ProviderConfigSpec struct {
// Defines the SSL mode used to set up a connection to the provided
// PostgreSQL instance
// +kubebuilder:validation:Enum=disable;require;verify-ca;verify-full
// +optional
SSLMode string `json:"sslMode"`
// +kubebuilder:default=verify-full
// +kubebuilder:validation:Optional
SSLMode *string `json:"sslMode,omitempty"`
}

const (
Expand Down
5 changes: 5 additions & 0 deletions apis/postgresql/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ spec:
description: Defines the database name used to set up a connection to the provided PostgreSQL instance. Same as PGDATABASE environment variable.
type: string
sslMode:
default: verify-full
description: Defines the SSL mode used to set up a connection to the provided PostgreSQL instance
enum:
- disable
Expand Down
26 changes: 26 additions & 0 deletions pkg/clients/sql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2022 The Crossplane Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clients

// ToString converts the supplied string pointer to a string,
// returning an empty string if the pointer is nil.
func ToString(s *string) string {
if s != nil {
return *s
}
return ""
}
3 changes: 2 additions & 1 deletion pkg/controller/postgresql/database/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -119,7 +120,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.Wrap(err, errGetSecret)
}

return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode)}, nil
return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode))}, nil
}

type external struct{ db xsql.DB }
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/postgresql/extension/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -112,10 +113,10 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
// We do not want to create an extension on the default DB
// if the user was expecting a database name to be resolved.
if cr.Spec.ForProvider.Database != nil {
return &external{db: c.newDB(s.Data, *cr.Spec.ForProvider.Database, pc.Spec.SSLMode)}, nil
return &external{db: c.newDB(s.Data, *cr.Spec.ForProvider.Database, clients.ToString(pc.Spec.SSLMode))}, nil
}

return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode)}, nil
return &external{db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode))}, nil
}

type external struct{ db xsql.DB }
Expand Down Expand Up @@ -179,7 +180,7 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
return managed.ExternalCreation{}, errors.Wrap(c.db.Exec(ctx, xsql.Query{String: b.String()}), errCreateExtension)
}

func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.ExternalUpdate, error) { //nolint:gocyclo
func (c *external) Update(_ context.Context, mg resource.Managed) (managed.ExternalUpdate, error) { //nolint:gocyclo
_, ok := mg.(*v1alpha1.Extension)
if !ok {
return managed.ExternalUpdate{}, errors.New(errNotExtension)
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/postgresql/grant/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -120,7 +121,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
return nil, errors.Wrap(err, errGetSecret)
}
return &external{
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode),
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode)),
kube: c.kube,
}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/postgresql/role/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/resource"

"github.com/crossplane-contrib/provider-sql/apis/postgresql/v1alpha1"
"github.com/crossplane-contrib/provider-sql/pkg/clients"
"github.com/crossplane-contrib/provider-sql/pkg/clients/postgresql"
"github.com/crossplane-contrib/provider-sql/pkg/clients/xsql"
)
Expand Down Expand Up @@ -122,7 +123,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
}

return &external{
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, pc.Spec.SSLMode),
db: c.newDB(s.Data, pc.Spec.DefaultDatabase, clients.ToString(pc.Spec.SSLMode)),
kube: c.kube,
}, nil
}
Expand Down