Add support of sensitive data for external Database #279

Closed
fkocik wants to merge 3 commits from fkocik/gitea-helm-chart:feature/external-database into main
First-time contributor

Hi,

When using Gitea with an external database instance, it may be necessary to manipulate sensitive data that should not appear in the values.yaml file.

The purpose of this PR is to allow externalDatabase configuration injection in a secure way.

For each token, it will be possible to use a literal value (directly readable from the values.yaml file) or a secret reference (using name and key) in order to reuse existing data from Kubernetes engine.

Regards.

Hi, When using Gitea with an external database instance, it may be necessary to manipulate sensitive data that should not appear in the `values.yaml` file. The purpose of this PR is to allow `externalDatabase` configuration injection in a secure way. For each token, it will be possible to use a *literal* value (directly readable from the `values.yaml` file) or a *secret* reference (using `name` and `key`) in order to reuse existing data from **Kubernetes** engine. Regards.
fkocik added 1 commit 2022-01-18 08:52:18 +00:00
Add support of sensitive data for external Database
All checks were successful
continuous-integration/drone/pr Build is passing
8ed963bdcb
fkocik added 1 commit 2022-01-18 08:55:19 +00:00
fix readme about literals/secret usage
Some checks failed
continuous-integration/drone/pr Build is failing
a5e255aa55
fkocik changed title from WIP: Add support of sensitive data for external Database to Add support of sensitive data for external Database 2022-01-18 08:55:33 +00:00
fkocik added 1 commit 2022-01-18 08:59:05 +00:00
fix markdown lint failed
All checks were successful
continuous-integration/drone/pr Build is passing
78428e7bf6
Member

imho it would be better to allow using secrets for values without changing existing structure

imho it would be better to allow using secrets for values without changing existing structure
Author
First-time contributor

It still remains possible through additionalConfigSources.

Yet, when using Kubernetes native approach (such as database operators) : it requires to synchronize data between database secrets and Gitea secrets.

The idea here is to reuse the same secrets using SecretKeySelector yaml style notation in values.yaml.

It still remains possible through `additionalConfigSources`. Yet, when using **Kubernetes** native approach (such as database operators) : it requires to synchronize data between database secrets and **Gitea** secrets. The idea here is to reuse the same secrets using [SecretKeySelector](https://pkg.go.dev/k8s.io/client-go/pkg/api#SecretKeySelector) yaml style notation in `values.yaml`.
Member

I understand but why we could not extend it to support such syntax:

gitea:
  config:
    database:
      DB_TYPE: mysql
      HOST: 127.0.0.1:3306
      NAME: gitea
      USER: root
      PASSWD:
        secret:
          name: mysql-admin
          key: admin
      SCHEMA: gitea

while still supporting also

      PASSWD: gitea
I understand but why we could not extend it to support such syntax: ```yaml gitea: config: database: DB_TYPE: mysql HOST: 127.0.0.1:3306 NAME: gitea USER: root PASSWD: secret: name: mysql-admin key: admin SCHEMA: gitea ``` while still supporting also ```yaml PASSWD: gitea ```
Member

As far as I see this whole litetal vs. Kubernetes resource distinction is already possible through additionalConfigSources. I understand your idea to reuse such secrets and appreciate your invested time to contribute this. But implementing it that way seems like stepping back to previous configurations which were eliminated by additionalConfigSources. Is there a need for a more fine grained mapping of such additional sources to fit your need?

As far as I see this whole litetal vs. Kubernetes resource distinction is already possible through `additionalConfigSources`. I understand your idea to reuse such secrets and appreciate your invested time to contribute this. But implementing it that way seems like stepping back to previous configurations which were eliminated by `additionalConfigSources`. Is there a need for a more fine grained mapping of such additional sources to fit your need?
Author
First-time contributor

Thanks all for your feedback.

I did not succeed to perform such configuration using additionalConfigSources. Perhaps caused by my misunderstanding of the existing mechanisms.

My need is to avoid intermediate process that generate a secret from another existing secret and only describe the desired system state. So, I agree with @justusbunsi that more fine grained mapping of additionalConfigSources could be the solution.

I can try to review my PR in order to see if it is possible to use thoses resources.

Thanks all for your feedback. I did not succeed to perform such configuration using `additionalConfigSources`. Perhaps caused by my misunderstanding of the existing mechanisms. My need is to avoid intermediate process that generate a secret from another existing secret and only describe the desired system state. So, I agree with @justusbunsi that more fine grained mapping of `additionalConfigSources` could be the solution. I can try to review my PR in order to see if it is possible to use thoses resources.
Member

It might not that easy to reuse an existing Kubernetes secret storing data for another application, e.g. database. The data structure necessary for additionalConfigSources is more or less an app.ini that got cut into pieces allowing to store settings from one section as Kubernetes Secret or ConfigMap or both. The keys for each entry in such Kubernetes resource must be the section name. Otherwise the data collecting won't work.

But I could be wrong and you find a neat way to achieve it. ?

It might not that easy to reuse an existing Kubernetes secret storing data for another application, e.g. database. The data structure necessary for `additionalConfigSources` is more or less an app.ini that got cut into pieces allowing to store settings from one section as Kubernetes Secret or ConfigMap or both. The keys for each entry in such Kubernetes resource must be the section name. Otherwise the data collecting won't work. But I could be wrong and you find a neat way to achieve it. ?
Contributor

Hi, this solution would really help. I'm using postgres operator that creates DB connect info as secret. To use them I have used

statefulset:
    env:
      - name: GITEA_database_HOST
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: host
      - name: GITEA_database_NAME
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: dbname
      - name: GITEA_database_USER
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: user
      - name: GITEA_database_PASSWD
        valueFrom:
          secretKeyRef:
            name: giteadb-pguser-giteadb
            key: password

But still everything is in crashloop because scipts and other things don't get this envs into consideration. This PR would really help with that.

Hi, this solution would really help. I'm using postgres operator that creates DB connect info as secret. To use them I have used ``` statefulset: env: - name: GITEA_database_HOST valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: host - name: GITEA_database_NAME valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: dbname - name: GITEA_database_USER valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: user - name: GITEA_database_PASSWD valueFrom: secretKeyRef: name: giteadb-pguser-giteadb key: password ``` But still everything is in crashloop because scipts and other things don't get this envs into consideration. This PR would really help with that.
Member

Hey 👋. This PR got stuck in our heads and with the next release the Helm Chart respects specific environment variables during app.ini creation (see #298). This allows to reuse existing secrets from other applications and much more. Feel free to check it out and give us feedback.

Considering that, this PR is not necessary anymore. Right?

Hey :wave:. This PR got stuck in our heads and with the next release the Helm Chart respects specific environment variables during _app.ini_ creation (see #298). This allows to reuse existing secrets from other applications and much more. Feel free to check it out and give us feedback. Considering that, this PR is not necessary anymore. Right?
Member

Closing with regards to this comment.

Feel free to reopen this PR if necessary.

Closing with regards to [this comment](https://gitea.com/gitea/helm-chart/pulls/279#issuecomment-693733). Feel free to reopen this PR if necessary.
justusbunsi closed this pull request 2022-04-21 10:35:20 +00:00
Some checks are pending
continuous-integration/drone/pr Build is passing
check-and-test / check-and-test (pull_request)
Required

Pull request closed

Sign in to join this conversation.
No description provided.