-
Notifications
You must be signed in to change notification settings - Fork 576
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
Conversation
20b62fe
to
6b30161
Compare
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
6b30161
to
820c10a
Compare
There was a problem hiding this 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 ` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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:
Type of Changes:
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)?
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