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

Cannot "inject" values for email templates from files #665

Open
4 of 5 tasks
till opened this issue Jan 30, 2024 · 5 comments
Open
4 of 5 tasks

Cannot "inject" values for email templates from files #665

till opened this issue Jan 30, 2024 · 5 comments
Labels
bug Something is not working.

Comments

@till
Copy link
Contributor

till commented Jan 30, 2024

Preflight checklist

Ory Network Project

No response

Describe the bug

I am trying to customize the email templates using external files as the values file from your helm chart gets longer and longer, and longer.

So far, I only get a config map rendered that contains the values from the file though, e.g. {{.Values.email_recovery}} but I expected to see the values of the files I inject with --set-file.

Reproducing the bug

kratos:
  emailTemplates:
    recovery:
      valid:
        subject: Recover access to your account
        body: |-
          {{ .Values.email_recovery }}
        plainBody: |-
          {{ .Values.email_recovery_txt }}
      invalid:
        subject: Account access attempted
        body: |-
          {{ .Values.email_recovery_invalid }}
        plainBody: |-
          {{ .Values.email_recovery_invalid_txt }}

I tried it with:

        helm template --debug
        --values kratos/values.yml
        --values kratos/values.local.yml
        --set-file user_schema=kratos/chema.json,email_recovery=kratos/emails/recovery.html,email_recovery_txt=kratos/emails/recovery.txt,email_recovery_invalid=kratos/emails/recovery-invalid.html,email_recovery_invalid_txt=kratos/emails/recovery-invalid.txt,email_verification=kratos/emails/verification.html,email_verification_txt=kratos/emails/verification.txt,email_verification_invalid=kratos/emails/verification-invalid.html,email_verification_invalid_txt=kratos/emails/verification-invalid.txt
        --version 0.37.0
        ory-kratos ory/kratos

This renders a config map like:

# Source: kratos/templates/configmap-templates.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ory-kratos-template-recovery-invalid
  namespace: default
  labels:
    app.kubernetes.io/name: kratos
    helm.sh/chart: kratos-0.37.0
    app.kubernetes.io/instance: ory-kratos
    app.kubernetes.io/version: "v1.0.0"
    app.kubernetes.io/managed-by: Helm
  annotations:
data:
  "email.subject.gotmpl": |
    Account access attempted
  "email.body.gotmpl": |-
    {{ .Values.email_recovery_invalid }}
  "email.body.plaintext.gotmpl": |-
    {{ .Values.email_recovery_invalid_txt }}
---
# Source: kratos/templates/configmap-templates.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ory-kratos-template-recovery-valid
  namespace: default
  labels:
    app.kubernetes.io/name: kratos
    helm.sh/chart: kratos-0.37.0
    app.kubernetes.io/instance: ory-kratos
    app.kubernetes.io/version: "v1.0.0"
    app.kubernetes.io/managed-by: Helm
  annotations:
data:
  "email.subject.gotmpl": |
    Recover access to your account
  "email.body.gotmpl": |-
    {{ .Values.email_recovery }}
  "email.body.plaintext.gotmpl": |-
    {{ .Values.email_recovery_txt }}
---
# Source: kratos/templates/configmap-templates.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ory-kratos-template-verification-invalid
  namespace: default
  labels:
    app.kubernetes.io/name: kratos
    helm.sh/chart: kratos-0.37.0
    app.kubernetes.io/instance: ory-kratos
    app.kubernetes.io/version: "v1.0.0"
    app.kubernetes.io/managed-by: Helm
  annotations:
data:
  "email.subject.gotmpl": |
    Email verification failed
  "email.body.gotmpl": |-
    {{ .Values.email_verification_invalid }}
  "email.body.plaintext.gotmpl": |-
    {{ .Values.email_verification_invalid_txt }}
---
# Source: kratos/templates/configmap-templates.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ory-kratos-template-verification-valid
  namespace: default
  labels:
    app.kubernetes.io/name: kratos
    helm.sh/chart: kratos-0.37.0
    app.kubernetes.io/instance: ory-kratos
    app.kubernetes.io/version: "v1.0.0"
    app.kubernetes.io/managed-by: Helm
  annotations:
data:
  "email.subject.gotmpl": |
    Please verify your email address
  "email.body.gotmpl": |-
    {{ .Values.email_verification }}
  "email.body.plaintext.gotmpl": |-
    {{ .Values.email_verification_txt }}

Relevant log output

No error

Relevant configuration

No response

Version

0.37.0

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Kubernetes with Helm

Additional Context

No response

@till till added the bug Something is not working. label Jan 30, 2024
@till
Copy link
Contributor Author

till commented Jan 30, 2024

It seems like the --set-file for the schema is a special case, the emails work like this:

        --set-file kratos.emailTemplates.recovery.valid.body=kratos/emails/recovery.html
        --set-file kratos.emailTemplates.recovery.valid.plainBody=kratos/emails/recovery.txt
        --set-file kratos.emailTemplates.recovery.invalid.body=kratos/emails/recovery-invalid.html
        --set-file kratos.emailTemplates.recovery.invalid.plainBody=kratos/emails/recovery-invalid.txt
        --set-file kratos.emailTemplates.verification.valid.body=kratos/emails/verification.html
        --set-file kratos.emailTemplates.verification.valid.plainBody=kratos/emails/verification.txt
        --set-file kratos.emailTemplates.verification.invalid.body=kratos/emails/verification-invalid.html
        --set-file kratos.emailTemplates.verification.invalid.plainBody=kratos/emails/verification-invalid.txt

At least that renders the ConfigMap resources correctly. But kratos still doesn't use "new" these emails.

@till
Copy link
Contributor Author

till commented Jan 30, 2024

So, the last bit was missing:

kratos:
  config:
    courier:
      template_override_path: /conf/courier-templates

I think the first bit could probably be docs?

The one remaining problem is that the config mentions the following templates:

  • kratos.emailTemplates.recovery.valid
  • kratos.emailTemplates.recovery.invalid
  • kratos.emailTemplates.verification.valid
  • kratos.emailTemplates.verification.invalid

Is there more? Because I just tried a verification flow and the email includes a code?

@till
Copy link
Contributor Author

till commented Jan 30, 2024

Maybe this could be added to the values file:
https://github.com/ory/kratos/tree/master/courier/template/courier/builtin/templates

Following the naming of the directories, you can set any other template, e.g.:

        --set-file kratos.emailTemplates.verification_code.valid.body=kratos/emails/verification_code.html
        --set-file kratos.emailTemplates.verification_code.valid.plainBody=kratos/emails/verification_code.txt
        --set-file kratos.emailTemplates.verification_code.invalid.body=kratos/emails/verification-invalid.html
        --set-file kratos.emailTemplates.verification_code.invalid.plainBody=kratos/emails/verification-invalid.txt

@Demonsthere
Copy link
Collaborator

Hi there!
The configmap implementation for the templates is quite flexible and simply traverses through the config using a for-each structure. Do you think this is a documentation issue, and we should reword it to make it clear that the examples in values.yaml and the docs are just examples and not all fields that can be set using this mechanism?

@till
Copy link
Contributor Author

till commented Feb 16, 2024

Yeah, another example and maybe a link to kratos source would be sufficient IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
None yet
Development

No branches or pull requests

2 participants