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

Reject invalid Postgres user specs #3899

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

cbandy
Copy link
Member

@cbandy cbandy commented Apr 22, 2024

The PASSWORD option was never effective. CEL validation rules, available in beta since Kubernetes 1.25, can detect and reject values that the RE2 pattern validation of github.com/go-openapi could not.

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • Bug fix
  • Testing enhancement

What is the current behavior (link to any open issues here)?

The PASSWORD option and SQL comments are accepted in Postgres user specs on the PostgresCluster object.

What is the new behavior (if this is a feature change)?

  • Breaking change (fix or feature that would cause existing functionality to change)

These values are now rejected at the Kubernetes API and removed before being sent to Postgres.

A new package checks CRD validation using envtest.

Other Information:

Issue: PGO-1094

internal/postgres/users.go Outdated Show resolved Hide resolved
@cbandy cbandy force-pushed the options-validation branch 2 times, most recently from 20b62fe to 6b30161 Compare April 24, 2024 20:55
These values will be rejected in the future.

Issue: PGO-1094
This uses a Postgres SQL parser to remove the PASSWORD option and any
SQL comments. These values will be rejected in the future.

Issue: PGO-1094
The PASSWORD option was never effective. CEL validation rules, available
in beta since Kubernetes 1.25, can detect and reject values that the RE2
pattern validation of "github.com/go-openapi" could not.

Issue: PGO-1094
See: https://pkg.go.dev/github.com/go-openapi/validate@v0.24.0#hdr-Known_limitations
Copy link
Contributor

@tjmoore4 tjmoore4 left a comment

Choose a reason for hiding this comment

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

Looks good to me. One non-blocking question.


"github.com/crunchydata/postgres-operator/internal/logging"
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
)

func sanitizeAlterRoleOptions(options string) string {
const AlterRolePrefix = `ALTER ROLE "any" WITH `
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 Just to make sure I understand, since you're just passing in the options and not the entire statement, you have to append this prefix in order to use the GetAlterRoleStmt().GetOptions() functions of pg_query. Or is there more to it than that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly right. The parser works only on complete statements.

@cbandy cbandy merged commit 990631f into CrunchyData:master Apr 25, 2024
13 checks passed
@cbandy cbandy deleted the options-validation branch April 25, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants