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

1030 - Refactor SMTP settings to be outside of passcode config #1121

Merged
merged 7 commits into from
Jan 30, 2024

Conversation

irby
Copy link
Contributor

@irby irby commented Oct 21, 2023

Description

As discussed in #1030 , when security notifications are introduced, SMTP settings would no longer be strictly applicable to passcodes. I propose we break SMTP settings into its own section in the configuration file.

Implementation

In this PR, I have moved SMTP up to the base level of the configuration and reflected this change in all config yaml files

Additional refactors:

  • Add a SmtpHost value to the test mailslurper struct. This will allow consuming tests to reference this host value in their configurations
  • Updated .nvmrc file in e2e to Node value described in its README

@FreddyDevelop
Copy link
Contributor

Hey @irby, the changes are looking good, but IMO it would be good if we can do it without breaking changes.

My preferred solution would be, that the old smtp config is marked as deprecated and when someone uses it, that we log a deprecation message that the new smtp path should be used.

@irby
Copy link
Contributor Author

irby commented Oct 27, 2023

Hi @FreddyDevelop sure I understand that. Im traveling for a conference today so I may have to address this sometime early next week.

If you could, could you provide me with some rules around the config? Do you want me to override the values of root level SMTP config with passcode config if that level is filled out? Do you want to prefer root level SMTP config over passcode SMTP config if root level SMTP config is provided?

@FlxMgdnz
Copy link
Member

Hey @irby, the changes are looking good, but IMO it would be good if we can do it without breaking changes.

My preferred solution would be, that the old smtp config is marked as deprecated and when someone uses it, that we log a deprecation message that the new smtp path should be used.

Sorry @irby @FreddyDevelop I should have thought about that when we talked about it in the other thread.

@FreddyDevelop
Copy link
Contributor

Hey @irby, sorry for the late response.

If you could, could you provide me with some rules around the config? Do you want me to override the values of root level SMTP config with passcode config if that level is filled out? Do you want to prefer root level SMTP config over passcode SMTP config if root level SMTP config is provided?

I would say we should use the root level SMTP config when it is filled otherwise use the passcode SMTP config. When both are set, the root level SMTP config should be used.

@FlxMgdnz
Copy link
Member

FlxMgdnz commented Jan 9, 2024

Hey @irby any news?

@irby
Copy link
Contributor Author

irby commented Jan 12, 2024

Hey @FlxMgdnz, haven't been able to touch this in some time to commitments at work keeping me busy.
I was running into an issue with compatibility of the SMTP settings at the root and Passcode levels. I'll need to look back into this one when my time opens back up. I might need to code pair to get the issue resolved.

My schedule should be clearing up in the next couple weeks.

@FlxMgdnz
Copy link
Member

Hey @FlxMgdnz, haven't been able to touch this in some time to commitments at work keeping me busy. I was running into an issue with compatibility of the SMTP settings at the root and Passcode levels. I'll need to look back into this one when my time opens back up. I might need to code pair to get the issue resolved.

My schedule should be clearing up in the next couple weeks.

Thanks @irby. Would be awesome if this gets resolved. Let us know as soon as you'll find the time. Someone from the team will happily pair up with you anytime.

@irby
Copy link
Contributor Author

irby commented Jan 15, 2024

Hi @FlxMgdnz I have pushed a new commit that will allow for compatibility for SMTP settings defined in the Passcode section. The approach for this is as follows:

  • Error if SMTP settings are found for both root-level SMTP and Passcode-level SMTP config.
  • If SMTP settings are found at the root level, it will keep these settings
  • If SMTP settings are found at the Passcode level, it will copy these settings to the root-level SMTP configuration
  • The Passcode-level SMTP configuration is marked as deprecated, letting users know to move to the root-level configuration.

Copy link
Contributor

@FreddyDevelop FreddyDevelop left a comment

Choose a reason for hiding this comment

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

Please also update the deploy/k8s/base/hanko/config.yaml to use the root SMTP settings.

@@ -638,6 +648,16 @@ func (c *Config) PostProcess() error {

}

func (c *Config) arrangeSmtpSettings() error {
if c.Smtp.Validate() == nil && c.Passcode.Smtp.Validate() == nil {
return fmt.Errorf("conflicting smtp settings found, please remove either smtp or passcode.smtp from the config")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't return an error here, instead log a warning or ignore this case. IMO there is no benefit of returning an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, would you want the root level SMTP to override passcode SMTP settings?

I'm fine with logging a warning here, I think we should let users know the config is potentially conflicting.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, in this case the root level smtp config should be used.

Yeah, would be good to let users know that there is a conflict in the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a preferred way to format a warning message in this project? Do you use fmt to log these?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, we have zerolog in place and log in json as format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FreddyDevelop Updated per feedback.

func (c *Config) arrangeSmtpSettings() {
if c.Passcode.Smtp.Validate() == nil {
if c.Smtp.Validate() == nil {
zeroLogger.Warn().Msg("Both smtp and passcode.smtp are set. Using smtp settings from passcode.smtp")
Copy link
Contributor

Choose a reason for hiding this comment

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

This warning message is wrong, the root smtp settings will be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thank you. Updated.

@FreddyDevelop FreddyDevelop merged commit 97ba5cf into teamhanko:main Jan 30, 2024
12 checks passed
irby added a commit to irby/hanko that referenced this pull request Feb 5, 2024
…anko#1121)

* 1030 - Refactor SMTP settings to be outside of passcode config

* Backwards compatibility of SMTP settings

* Do not error if root smtp and passcode smtp are defined. Log warning instead

* Update warning message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants