Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Email hosting service with golang.
Search
rhykw
July 13, 2019
Technology
440
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Email hosting service with golang.
rhykw
July 13, 2019
More Decks by rhykw
See All by rhykw
Identifying and Analyzing Fake OSS with Malware - fukuoka.go#21
rhykw
0
1.1k
Messaging Reliability Engineering with Go
rhykw
0
82
Other Decks in Technology
See All in Technology
AIエージェントの自己改善をどう設計するか / How to Design Self-Improvement for AI Agents
22mi
26
17k
Deployment の 先にある AI Agent 基盤 - kagent vNext、Agent Substrate、Hermes から読み解く Agent Runtime の現在地 / k8s-matsuri-2-ai-agent-platform-amsy810
masayaaoyama
5
720
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
20k
GoのInterface内部構造から学ぶ!最高パフォーマンスを出すコード設計
yappli_developers
1
270
Claude Codeを「使うほど育つ」AI秘書にするノウハウ
minorun365
PRO
33
31k
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
9
1.1k
C#未経験の僕がAIに読めるコードを書かせるまで
maguroalternative
0
260
2026-09-18 gotanda.sre Terraformで複数環境作ったり、複数Stateに分割したりそれとTerragrunt / Terraform multi envs and multi states
masasuzu
4
710
AIで社員の自主発信に広報目線を組み込む
_mossann_t
0
140
EventBridge に「合流」はない ― サーバーレスのワークフローを育てるということ / No Join in EventBridge
yusukeshimizu
2
510
リアーキテクチャ後の障害ゼロを目指したShadow Testingの取り組み
nihonbuson
PRO
1
170
メルカリにおけるAI時代の高速プロトタイピング基盤「Arca」
ryotarai
4
2k
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Typedesign – Prime Four
hannesfritz
42
3.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Language of Interfaces
destraynor
162
27k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Thoughts on Productivity
jonyablonski
76
5.4k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Faster Mobile Websites
deanohume
310
32k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
470
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Transcript
1 ホスティングにおける メールサービスの運用と Go Go Conference'19 Summer in Fukuoka GMOペパボ
株式会社 ホスティング事業部インフラチーム rhykw
2 本日の内容 • メールサービスの裏側 • メールサービスの敵 • nginxをmail proxy serverとして使う
• PostfixとSMTP Access Policy Delegation
3 ホスティングとは? ホスティングサーバ(レンタルサーバー、共用サー バーとも)とは、複数のユーザーが利用するサーバー のことで、WebサイトやWebアプリケーションをイ ンターネットで一般公開するために使われる。ホスティ ングサービスとはサーバの利用者自身でサーバの運営・ 管理をしなくてもいいように、有料または無料でサー バ機のHDDの記憶スペースや情報処理機能などを利 用させるサービスを言う。(Wikipediaより引用)
4 メールサービスの裏側 SMTP(MX) Server Anti Virus Anti Spam Mail Server
Load balancer POP/IMAP Proxy SMTP Server Anti Virus Anti Spam POP/IMAP Proxy SMTP Server Anti Virus Anti Spam SMTP(MX) Server Anti Virus Anti Spam Mail Server Mail Server
5 メールサービスの裏側 POP/IMAP Proxy SMTP Server Anti Virus Anti Spam
Mail Server Database SMTP(MX) Server Anti Virus Anti Spam ೝূใɾଓઌ ೝূใ ૹઌ
6 メールサービスの敵 • ひとことで言うとSPAM
7 メールサービスの敵 • ひとことで言うとSPAM • 契約者がメールの大量配信を行うケースもあ るが圧倒的に多いのは「乗っ取り」
8 メールサービスの敵 • ひとことで言うとSPAM • 契約者がメールの大量配信を行うケースもあ るが圧倒的に多いのは「乗っ取り」 • 脆弱なパスワードのアカウントが狙われる
9 メールサービスの敵 • ひとことで言うとSPAM • 契約者がメールの大量配信を行うケースもあ るが圧倒的に多いのは「乗っ取り」 • 脆弱なパスワードのアカウントが狙われる •
[email protected]
のパスワードがinfoとか • qwerty1234 みたいなパスワードとか
10 メールサービスの敵 • ひとことで言うとSPAM • 契約者がメールの大量配信を行うケースもあ るが圧倒的に多いのは「乗っ取り」 • 脆弱なパスワードのアカウントが狙われる •
[email protected]
のパスワードがinfoとか • qwerty1234 みたいなパスワードとか • 攻撃の多くは日本国外から
11 メールサービスの敵 SPAMメールの送信を許して しまうとBlockList(BlackList とも)に登録され、メールの 到達率の低下(=サービス品質 の低下)を招く
12 メールの 治安を 回復したい!!
13 ホスティングにおける メールサービスの治安と Go Go Conference'19 Summer in Fukuoka
14 いかにして治安を取り戻すか • 脆弱なパスワードをなくす。
15 いかにして治安を取り戻すか • 脆弱なパスワードをなくす。啓蒙大事。 → ユーザーの行動に依存
16 いかにして治安を取り戻すか • 脆弱なパスワードをなくす。啓蒙大事。 → ユーザーの行動に依存 • 不審なログイン試行を適切にブロックする • 国内からの利用がメインのアカウントにおい
ては国外からの接続を拒否すると効果がある のでは?
17 nginxをmail proxy serverとして使う POP/IMAP Proxy SMTP Server Anti Virus
Anti Spam メールソフトが接続する部分に nginx を採用した
18 nginxをmail proxy serverとして使う nginx • nginx自体は直接DBと通信するような認証の 仕組みを持たない • nginxのmail
proxyで認証を橋渡しするのが 「ngx_mail_auth_http_module」 Auth Server MySQL Postfix ユーザー(メールソフト)
19 nginxをmail proxy serverとして使う • nginxとAuth Server間はHTTPで通信 • 認証はリクエストもレスポンスもHTTPヘッ ダで
• 単一のURLに対するGETリクエスト なんだ、簡単じゃん!!
20 Auth Serverの設計 HTTP Server: RESTfulなAPIの開発ではechoとかGinとか使 うけど正直今回はそこまで大袈裟なものは要ら ない。標準パッケージでも事足りそう。 →近くの席の人が gorilla/mux
使っていたので 自分も gorilla/mux を選択。 https://github.com/gorilla/mux (★9,475)
21 Auth Serverの設計 DB周り: (開発当初)発行するクエリが1クエリしかなかっ た。のでORM使うほどでもないかなぁと思い 標準パッケージ database/sql を選択。
22 Auth Serverの設計 なんだ、簡単じゃん!! ??
23 Auth Serverの設計 > 認証はリクエストも レスポンスも HTTP ヘッダで これが曲者
24 Auth Serverの設計 type AuthRequest struct { Method string `json:"method"`
Protocol string `json:"protocol"` User string `json:"user"` Pass string `json:"password"` Salt string `json:"salt"` LoginAttempt int `json:"login_attempt"` ClientIP net.IP `json:"clinet_ip"` ClientHost string `json:"client_host"` } ... var authReq AuthRequest if err := json.Unmarshal(jsonBytes, &authReq); err != nil { // Τϥʔॲཧ } 普通はこんな感じで書く?
25 Auth Serverの設計 func (a *AuthRequest) New(r *http.Request) *AuthRequest {
a.Method = r.Header.Get("Auth-Method") a.Protocol = r.Header.Get("Auth-Protocol") a.User = r.Header.Get("Auth-User") a.Pass = r.Header.Get("Auth-Pass") a.Salt = r.Header.Get("Auth-Salt") a.LoginAttempt, _ = strconv.Atoi(r.Header.Get("Auth-Login-Attempt")) a.Client.IP = net.ParseIP(r.Header.Get("Client-Ip")) a.Client.Host = r.Header.Get("Client-Host") return a } json形式のAPIならjson.Unmarshalで済むところが 面倒くさい感じに... 何か良い方法ないですかねー?
26 Auth Serverの設計 Goでは周辺ライブラリも充実しており、前述の「国 外からの接続を拒否」なども容易。 この手の処理でお馴染みのMaxMind DBも oschwald/maxminddb-golang でサクッと使え る。
https://dev.maxmind.com/geoip/geoip2/downloadable/ https://github.com/oschwald/maxminddb-golang
27 PostfixとSMTP Access Policy Delegation • SMTPの特定の命令について拒否・許可を行う ための機構がPostfixに組み込まれている。 • Postfixはこの判断を外部サーバに移譲出来る
ように作られている。
28 Policy Delegationがあると何が嬉しいか? • SMTPの命令毎にフック出来る • 例えば End of DATAのタイミングで、一定期
間内の累積送信通数をチェックして大量送信 を抑制する、など
29 PostfixとSMTP Access Policy Delegation • PostfixとPolicy Serverのやり取りはいたっ てシンプル。 •
一連のやり取りは、`name=value` 属性が改 行で区切られ、空行で終端される。 http://www.postfix.org/SMTPD_POLICY_README.html
30 Policy Serverの設計 なんだ簡単じゃん!! と言いたいところですが... まだ完成しておりません。
31 おまけ(監視周りの話) Prometheus+Grafanaでパフォーマンスをモニ タリングするなどGoが大活躍
32 まとめ • ユーザーがメールソフトで接続する smtp/ pop/imap のフロントサーバにnginxを採用 • nginxのmail proxyで認証を橋渡しするのが
「ngx_mail_auth_http_module」 • 自前で認証の仕組みを作らないといけないが 大きな自由度が得られる • 大量のリクエストを捌く力とデプロイの容易 さから認証サーバの開発にGoを採用
33 まとめ • MTAには使い慣れたPostfixを採用 • PostfixはSMTP Access Policy Delegationと いう機構がある
• SMTPの各命令段階でフックし、配送を拒否 したり配送ルートを変えたりすることが可能 • ここでもリクエストを捌く力とデプロイの容 易さからPolicy Delegationサーバの開発にGo を採用
34 ご静聴ありがとうございました