Skip to content

feat(settings): 1239 let the email sender skip auth and choose a tls policy - #682

Merged
github-actions[bot] merged 1 commit into
developfrom
1236-smtp-anonymous-tls
Oct 12, 2026
Merged

github-actions[bot] merged 1 commit into
developfrom
1236-smtp-anonymous-tls

Conversation

@lizzy-liang-bigstack

@lizzy-liang-bigstack lizzy-liang-bigstack commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

feature


Which issue(s) this PR fixes?

Fixes bigstack-oss/cubecos#1239 (part of the story bigstack-oss/cubecos#1236)


What this PR does?

An email sender can now skip authentication and choose a TLS policy, and the test mail honours both. Today Sender.UserAuth() always hands smtp.SendMail a PlainAuth, which refuses to send credentials over a plaintext link, so a relay that accepts anonymous submission but still advertises AUTH fails the test mail. There is also no way to pick a TLS policy.

  • email.Sender gains auth and tls (none / opportunistic / mandatory), the field names and values of bigstack-dependency-go/pkg/email/v2.
  • The test mail moves to pkg/email/v2, and Sender.UserAuth() is gone. With auth: false go-mail stays on NoAuth and AUTH is never attempted. With auth: true over tls: none it uses PLAIN-NOENC.
  • POST:
    • unset auth → true if a username is given
    • unset tls → mandatory, matching the v2 helper, so an old client never silently downgrades
    • an unknown tls → 400 with the allowed values
  • PATCH: unset auth and tls keep the sender's current values.
  • Password: an omitted password is still carried forward (as before). An explicit "" clears it on purpose, which is what the UI's "leave empty to clear it" tooltip already promises.
  • auth: false: username and password are dropped, since they are never sent.
  • The hex payload is now an explicit struct with every field present. An unset password used to be omitted from the JSON and land in the policy as the literal string null.
  • A sender read from hex without tls predates the field and is reported as opportunistic, which is how it was sent before.
  • bigstack-dependency-go moves to 596a0a8. That is the first commit with the v2 interface and Cc, and it predates the August dependency bumps, so go.mod only adds go-mail. The latest version would have also bumped slack 0.16 → 0.29 and k8s 0.33 → 0.36.
  • api/cube-cos-openapi → feat(settings): add auth and tls to the email sender cube-cos-openapi#122 (b22e829, which also carries develop's bps ranking examples).
  • develop merged in (4d475ad) for #1746's SAML assertion decryption. go.mod keeps both develop's github.com/beevik/etree and this branch's bigstack-dependency-go bump.

Test results (optional)

1). make sure the api docs have been updated — api/cube-cos-openapi points at bigstack-oss/cube-cos-openapi#122, which adds auth / tls to the three sender schemas. api/docs.json is regenerated from it in CI.


2). make sure the api works properly

Done

  • internal/definition/v1/email/email_test.go (table-driven):
    • Normalize: auth unset with and without a username, auth off drops credentials, unset fields keep the current sender's, explicit fields override them, all three TLS values, unknown and wrong-case TLS rejected
    • the hex payload never carries a null password
    • a hex sender without tls reads back as opportunistic
  • internal/apis/v1/handlers/settings/trial_test.go sends real mail through a fake plaintext relay that advertises AUTH PLAIN and no STARTTLS:
    • auth: false, tls: none delivers and never sends AUTH
    • auth: false, tls: opportunistic delivers in plaintext
    • auth: true, tls: none delivers and authenticates
    • tls: mandatory fails, since STARTTLS is not offered
  • GOWORK=off go test ./internal/... passes
  • go vet is clean on the touched packages

On a cluster — 3-node HA (cube45/46/47, CUBE_3.2.0_20261008-0240, Keycloak 26), with bigstack-oss/cubecos#1810 and bigstack-oss/cube-cos-ui#892 deployed. The relay was a loopback test relay on each node that logs every SMTP command; port 2526 advertises AUTH PLAIN LOGIN and no STARTTLS. Restored afterwards; every file matched the backup.

  • Upgrade: an authenticated sender written by the old build reads back as auth: true, tls: opportunistic (UI: Opportunistic / On).
  • Save from the UI with auth off and TLS None: hex stores auth: "false", tls: "none", an empty username, and "password": "" (not "null").
  • Test mail to the AUTH-advertising relay: delivered. The relay saw EHLO → MAIL → DATA, with no AUTH and no STARTTLS. The sender then shows as verified.
  • SAML login works on Keycloak 26 with develop merged in. The pre-merge build failed at /saml/acs because it lacked #1746.
  • Test mail to an authenticated TLS relay: skipped on the cluster (see below). Covered locally against real relays: go-mail with mailpit, auth: true over none and opportunistic, and mandatory failing when STARTTLS is not offered.
  • PATCH with "tls": "starttls" → 400: covered by unit tests, not exercised on the cluster.
[Verify] Test mail to the anonymous relay [Verified] Sender marked verified
Send test email dialog After verify: sender verified
# loopback test relay, port 2526 advertises AUTH PLAIN LOGIN, no STARTTLS
01:42:39 > EHLO cube45
01:42:39 > NOOP
01:42:39 > MAIL FROM:<cos-alert@example.com>
01:42:39 > RCPT TO:<admin@example.com>
01:42:39 > DATA
01:42:39 DELIVERED tls=False subject='Test Email'

Seen on the cluster, not changed here: PATCH forwards to peer controllers, and cube46/47 answered 400 sender not found, because the alert sender only exists on the VIP node. This is the existing isSenderExist check on the peers.
Why step 3 was skipped: every save triggers alert_sync_tenant, and Kapacitor 1.8.6 deadlocked under the overlapping syncs. This is a separate, pre-existing issue that is being filed on its own.

Alert mail is not sent by this API. Kapacitor sends it from the hex [smtp] config, and Kapacitor 1.5.7 can only do opportunistic STARTTLS. The cubecos PR covers that path; the spec's tls description and the UI tooltip state the limit.

🤖 Generated with Claude Code

@arasHi87 arasHi87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Lizzy Liang <lizzy.liang@bigstack.co>
@lizzy-liang-bigstack lizzy-liang-bigstack added the done Merge the pull request label Oct 12, 2026
@github-actions
github-actions Bot merged commit 37ab0b7 into develop Oct 12, 2026
7 of 8 checks passed
@github-actions
github-actions Bot deleted the 1236-smtp-anonymous-tls branch October 12, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

done Merge the pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] cube-cos-api: extend the EmailSender contract and send through pkg/email/v2

2 participants