Skip to content

Cloud native postgres#15

Closed
poomdech-opsta wants to merge 5 commits intomainfrom
cloudNativePostgres
Closed

Cloud native postgres#15
poomdech-opsta wants to merge 5 commits intomainfrom
cloudNativePostgres

Conversation

@poomdech-opsta
Copy link
Copy Markdown

Add Cloud Native Postgres Template

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new Helm chart for Cloud Native PostgreSQL (CNPG) and integrates it into the onechart dependency list. The review identifies several critical issues, including hardcoded sensitive credentials, an invalid image tag, and non-idempotent password generation that would cause unintended rotations during upgrades. Additionally, the feedback suggests cleaning up unused variables, unreachable template logic, and correcting placeholder metadata in the Chart.yaml file.

type: {{ .Values.postgresAuth.type | default "kubernetes.io/basic-auth" }}
stringData:
username: {{ .Values.postgresAuth.username | quote }}
password: {{ .Values.postgresAuth.password | quote }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

To prevent deployments with weak or empty default passwords, it's crucial to enforce that a password is provided by the user. Using the required function will cause the Helm release to fail if the password is not set, ensuring a secure configuration.

  password: {{ required "A password is required for .Values.postgresAuth.password" .Values.postgresAuth.password | quote }}

enabled: true

cluster:
imageName: ghcr.io/cloudnative-pg/postgresql:16.8-13-bullseye
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The image tag 16.8-13-bullseye for ghcr.io/cloudnative-pg/postgresql appears to be invalid. The standard tags for this image are typically just the PostgreSQL version number (e.g., 16.2). An incorrect image tag will prevent pods from starting with an ImagePullBackOff error. Please use a valid image tag.

  imageName: ghcr.io/cloudnative-pg/postgresql:16.2

postgresAuth:
create: true
username: cnpg
password: P@ssw0rd123
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Hardcoding a default password is a critical security vulnerability. This value should be removed, and the chart should require the user to provide a password. I've added a separate comment in templates/secret-postgres.yaml to enforce this with a required check.

  password: ""

Comment on lines +36 to +37
accessKeyValue: accesskey
secretKeyValue: secretkey
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Default credentials (accesskey and secretkey) are hardcoded in the values file. This is a critical security risk. These should be removed to force the user to provide their own credentials. The template templates/secret-s3.yaml already correctly uses the required function, so this change will enforce that credentials are provided.

      accessKeyValue: ""
      secretKeyValue: ""

type: {{ default "kubernetes.io/basic-auth" }}
stringData:
username: postgres
password: {{ randAlphaNum 8 | quote }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using randAlphaNum here will generate a new password on every helm upgrade. This non-idempotent behavior will cause the postgres superuser password to be rotated with every deployment, which can lead to service disruptions for any applications that rely on this password. Additionally, a password length of 8 characters is insufficient for production environments.

For a more robust solution, consider generating the password only on initial installation and keeping it stable for subsequent upgrades. A common pattern is to use the lookup function to check if the secret already exists.

As a minimal improvement, please increase the password length.

  password: {{ randAlphaNum 32 | quote }}

@@ -0,0 +1,8 @@
apiVersion: v1
description: CNPG (China Postgres)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The description "CNPG (China Postgres)" is likely a misunderstanding. CNPG stands for "Cloud Native PostgreSQL". Using an incorrect name can be misleading for users of this chart.

description: A Helm chart for Cloud Native PostgreSQL (CNPG)

Comment on lines +7 to +8
- name: Developer
email: dev@opsta.in.th
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The maintainer information appears to be using placeholder values. Please update this section with the actual maintainer's details for proper ownership and contact purposes.

  - name: <Your Name>
    email: <your-email@example.com>

@@ -0,0 +1,69 @@
{{- if .Values.enabled }}
#{{- $cnpg := .Values.cnpg -}}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The variable $cnpg is defined here but is not used anywhere in the template. This unused variable should be removed to improve code clarity and maintainability.

Comment on lines +11 to +13
{{- if and $backup.enabled (not $s3SecretName) -}}
{{- fail "backup.enabled=true but S3 secret name resolved empty (unexpected)" -}}
{{ end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This conditional check is currently unreachable. The variable $s3SecretName is always assigned a value from printf, so (not $s3SecretName) will never evaluate to true. This block of code serves no purpose and should be removed.

@winggundamth
Copy link
Copy Markdown

Please use cnpg-chart repo instead.

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.

2 participants