Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Goでつくる透過型SMTPプロキシ / Transparent SMTP proxy in Go
Search
linyows
June 10, 2021
Programming
1
960
Goでつくる透過型SMTPプロキシ / Transparent SMTP proxy in Go
Fukuoka.go #17 Jun 10, 2021 の発表資料です。
linyows
June 10, 2021
Tweet
Share
More Decks by linyows
See All by linyows
研究の再現性を高める 仕組みをGoでつくる / Creating a system to improve the reproducibility of research using go
linyows
1
110
奥が深いメールのシステム / The depth of Email system
linyows
3
410
IaCにおけるテスト考察 / Tests in IaC
linyows
2
420
リバースエンジニアリングとGoでSlackの認知負荷を下げる / Reducing cognitive load in Slack with Reverse-engineering and Go
linyows
2
270
透過型SMTPプロキシによる送信メールの可観測性向上 / Improved observability of outgoing emails with transparent smtp proxy
linyows
2
940
プロダクションで使うGo Pluginの利便性とパフォーマンス性 / Simplicity and Performance of Go plugin for Production
linyows
0
500
求められるソフトウェアエンジニア像とキャリア戦略 / Engineers and Career Strategies Required Now
linyows
2
470
CloudflareのCAPTCHAを使って ユーザ体験を下げず不正利用を排除する / Cloudflare's captcha case study that does not degrade ux
linyows
0
350
なぜNotionを使うのか2022 / Why use notion as our workspace in 2022
linyows
3
6k
Other Decks in Programming
See All in Programming
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
530
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
810
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
220
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.1k
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
Synchronizationを支える技術
s_shimotori
1
150
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
910
Featured
See All Featured
Building Your Own Lightsaber
phodgson
102
6k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
Code Review Best Practice
trishagee
64
17k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
Designing for humans not robots
tammielis
249
25k
Facilitating Awesome Meetings
lara
49
6k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Music & Morning Musume
bryan
46
6.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Fireside Chat
paigeccino
32
3k
Building an army of robots
kneath
302
42k
Transcript
Fukuoka.go #17 Tomohisa Oda / Jun 10, 2021 Transparent SMTP
Proxy in Go GoͰͭ͘ΔಁաܕSMTPϓϩΩγ
Fukuoka.go #17 @linyows Blog: tomohisaoda.com Af fi liation: GMO pepabo,
inc. Fukuoka.go and Fukuoka.ts Organizer
Fukuoka.go #17 @linyows Blog: tomohisaoda.com Af fi liation: GMO pepabo,
inc. Fukuoka.go and Fukuoka.ts Organizer ࠷ۙɺNotionʹࣅإֆΛॻ͍ͯΒ͍·ͨ͠ɻ
Fukuoka.go #17 ๏ ϗεςΟϯάࣄۀ෦ Senior Engineering Lead ࣄۀ෦ͷCTOVPoEͷΑ͏ͳͷ ๏ ϖύϘݚڀॴ
भେֶڞಉݚڀ 2020 Պݚඅ࠾ https://kaken.nii.ac.jp/grant/KAKENHI-PROJECT-20K11791/ ܰྔίϯςφʹΑΔେنߴूੵϝʔϧϗεςΟϯάج൫ʹ͓͚Δૹ৴ػೳͷߴػೳԽ In Pepabo…
Fukuoka.go #17 Private Projects ΞϓϦέʔγϣϯ͕ࣗϦϙδτϦ͔ Β࠷৽ͷίʔυΛݕͯࣗ͠ಈͰσϓϩ ΠͱσϦόϦʔΛߦ͏πʔϧ linuxͷuser໊લղܾΛGitHubͷ TeamϝϯόʔϦϙδτϦͷΞΫηε ݖݶऀ͔Βߦ͏πʔϧ
ϝʔϧૹ৴༻ͷಁաܕSMTPϓϩΩγͰ ϦΫΤετͱϨεϙϯεΛϩάσʔλ ϕʔεʹग़ྗ͢Δ͜ͱ͕Ͱ͖Δ New!!
Fukuoka.go #17 ϝʔϧͷΈͱϝʔϧϗεςΟϯάͷ՝
Fukuoka.go #17 ✉ Architecture 💻 🖥 Mail Submission Agent :587
Mail Transfer Agent :25 Mail Delivery Agent :993 Postfix Postfix Dovecot ✉ ✉ SMTP SMTP LMTP IMAP 📱 📱 DNS MX TXT(SPF, DKIM, DMARC…)
Fukuoka.go #17 ✉ Architecture 💻 🖥 Mail Submission Agent :587
Mail Transfer Agent :25 Mail Delivery Agent :993 Postfix Postfix Dovecot ✉ ✉ SMTP SMTP LMTP IMAP 📱 📱
[email protected]
DNS MX TXT(SPF, DKIM, DMARC…)
[email protected]
Bob Alice ϝʔϧϗεςΟϯάʹ͓͍ͯ ϝʔϧΛ૬खઌʹ ౸ୡͤ͞Δ͜ͱ͕ॏཁ
Fukuoka.go #17 ϝʔϧͷ౸ୡੑʹӨڹΛ༩͑Δ̐ͭͷ͜ͱ via: https://sendgrid.kke.co.jp/blog/?p=4494 by Jillian Smith ๏ ϝʔϧΠϯϑϥͷ݈શੑʢωοτϫʔΫͱDNSʣ
๏ ϝʔϧͷίϯςϯπʢఴϑΝΠϧ, ຊจ, ϔομʔͳͲʣ ๏ ϝʔϧͷૹ৴ݩʢૹ৴ݩIP, υϝΠϯ, ૹ৴ྔͳͲʣ ๏ ड৴ଆαʔόͷՄ༻ੑ
Fukuoka.go #17 ๏ ϝʔϧΠϯϑϥͷ݈શੑʢωοτϫʔΫͱDNSʣ ๏ ϝʔϧͷίϯςϯπʢఴϑΝΠϧ, ຊจ, ϔομʔͳͲʣ ๏ ϝʔϧͷૹ৴ݩʢૹ৴ݩIP,
υϝΠϯ, ૹ৴ྔͳͲʣ ๏ ड৴ଆαʔόͷՄ༻ੑ ϝʔϧͷ౸ୡੑʹӨڹΛ༩͑Δ̐ͭͷ͜ͱ via: https://sendgrid.kke.co.jp/blog/?p=4494 by Jillian Smith %/4#-ʹొ͞ΕΔͳͲ ϨϐϡςʔγϣϯʢධʣʹӨڹ͢Δ
Fukuoka.go #17 ๏ ༷ʑͳϢʔβ͕͏ϚϧνςφϯτͰ͋ΔͨΊɺϝʔϧΛৗతʹͨ͘͞Μૹ৴͢ ΔΞΧϯτ͋Εɺීஈগͳ͍͕ͨ·ʹେྔૹ৴͢ΔΞΧϯτ͋Δ ๏ ͦͦΞΧϯτΛͬऔΒΕΔέʔε͋Δ ๏ ड৴ऀ͕ͳͥड͚औΓڋ൱Λͨ͠ͷ͔͕͔Γʹ͍͘ʢDMARCରԠ͕͋Εผʣ ๏
ϝʔϧํͷΓͱΓͳͷͰɺૹ৴ଆ͕εύϜߦҝͱࢥ͍ͬͯͳͯ͘ड৴ऀ͕ εύϜߦҝͩͱײ͡Δ͜ͱ͋Γ͏Δ ϝʔϧϗεςΟϯάʹ͓͚Δ՝
Fukuoka.go #17 ๏ ༷ʑͳϢʔβ͕͏ϚϧνςφϯτͰ͋ΔͨΊɺϝʔϧΛৗతʹͨ͘͞Μૹ৴͢ ΔΞΧϯτ͋Εɺීஈগͳ͍͕ͨ·ʹେྔૹ৴͢ΔΞΧϯτ͋Δ ๏ ͦͦΞΧϯτΛͬऔΒΕΔέʔε͋Δ ๏ ड৴ऀ͕ͳͥड͚औΓڋ൱Λͨ͠ͷ͔͕͔Γʹ͍͘ʢDMARCରԠ͕͋Εผʣ ๏
ϝʔϧํͷΓͱΓͳͷͰɺૹ৴ଆ͕εύϜߦҝͱࢥ͍ͬͯͳͯ͘ड৴ऀ͕ εύϜߦҝͩͱײ͡Δ͜ͱ͋Γ͏Δ ϝʔϧϗεςΟϯάʹ͓͚Δ՝ ϝʔϧૹ৴࣌ͷͲΜͳৼΔ͍͕ड৴ڋ൱ʹࢸ͔ͬͨʁ ੳ͠ݕͰ͖ΔΑ͏ʹ͍ͨ͠ʂ
Fukuoka.go #17 ✉ Architecture 💻 🖥 Mail Submission Agent :587
Mail Transfer Agent :25 Mail Delivery Agent :993 Postfix Postfix Dovecot ✉ ✉ SMTP SMTP LMTP IMAP 📱 📱
[email protected]
DNS MX TXT(SPF, DKIM, DMARC…)
[email protected]
Bob Alice ͜ͷΓͱΓΛੳͰ͖Δɺ͔ͭ ΛݕͰ͖Ε ૹ৴ΛϒϩοΫͰ͖ΔΈ͕ඞཁ
Fukuoka.go #17 ࣮ݱํ๏ͷൺֱ
Fukuoka.go #17 ϝʔϧϦϨʔ vs. ಁաܕϓϩΩγ Mail Transfer Agent :25 Mail
Transfer Agent :25 Postfix Postfix
[email protected]
Transparent Proxy :25 Mail Transfer Agent :25 ? Postfix
[email protected]
Mail Submission Agent :587 Postfix
[email protected]
Mail Submission Agent :587 Postfix
[email protected]
✉ ✉ ✉ ✉ ϝʔϧϦϨʔΛߦ͏ͱϗοϓ͕૿͑ ϝʔϧΩϡʔͷཧ͕ෳࡶʹͳΔ 4.51ड͚ྲྀ͢ಁաܕϓϩΩγͩͱ ϝʔϧΩϡʔཧ͕ݱߦͱมΘΒͣ γϯϓϧͰ͋Δɻ͔͠͠ɺͦͷΑ͏ ͳϛυϧΣΞ͕ݟͨΒͳ͍ɻ
Fukuoka.go #17 ϝʔϧϦϨʔ vs. ಁաܕϓϩΩγ Mail Transfer Agent :25 Mail
Transfer Agent :25 Postfix Postfix
[email protected]
Transparent Proxy :25 Mail Transfer Agent :25 ? Postfix
[email protected]
Mail Submission Agent :587 Postfix
[email protected]
Mail Submission Agent :587 Postfix
[email protected]
✉ ✉ ✉ ✉ ϝʔϧϦϨʔΛߦ͏ͱϗοϓ͕૿͑ ϝʔϧΩϡʔͷཧ͕ෳࡶʹͳΔ 4.51ड͚ྲྀ͢ಁաܕϓϩΩγͩͱ ϝʔϧΩϡʔཧ͕ݱߦͱมΘΒͣ γϯϓϧͰ͋Δɻ͔͠͠ɺͦͷΑ͏ ͳϛυϧΣΞ͕ݟͨΒͳ͍ɻ
Fukuoka.go #17 GoͰͭ͘ΔಁաܕSMTPϓϩΩγ
Fukuoka.go #17 Ͳ͏ͬͯಁաܕϓϩΩγΛ࣮ݱ͢Δ͔ ๏ Port25൪ѼΛDNATͰશͯProxyʹૹΔ ๏ getsockopt(2)ͰѼઌมߋલͷΞυϨεΛऔಘ͢Δ
Fukuoka.go #17 SMTP Example via: https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol 4.5104*-ͷͱͯγϯϓϧͳϓϩτίϧ
Fukuoka.go #17 Goͷio.CopyΛָ͑উͳΜ͡Όͳ͍ʁ
Fukuoka.go #17 Transparent Proxy Go Mail Transfer Agent Postfix
[email protected]
Mail Submission Agent Postfix
[email protected]
io.Copy(internalConn, externalConn) io.Copy(externalConn, internalConn)
Fukuoka.go #17 PoC ී௨ʹϝʔϧΛૹड৴Ͱ͖ͨͷͰશʹ͏·͍ͬ͘ ͨͱࢥͬͨɻ ͔͠͠ɺHPSPVUJOFͷมΛग़ྗͯ͠ΈΔͱɺ ్த͔Βจࣈ͕ಡΊͳ͍ײ͡ʹ
Fukuoka.go #17 STARTTLSͷ͜ͱΛΕ͍ͯͨ!!!
Fukuoka.go #17 μϯάϨʔυ߈ܸରԠʹ͢Δ
Fukuoka.go #17 ୯ʹJP$PQZͰͳ͘ 5-4ίωΫγϣϯ·Ͱ ੍ޚ͢Δඞཁ͕͋ͬͨ
Fukuoka.go #17 45"355-4ʹରԠͯ͠ͳ͍ Ϩεϙϯεʹ͢Δ
Fukuoka.go #17 όοϑΝϦϯάͨ͠σʔλΛ5-4 ίωΫγϣϯͱͦͷޙͷఆܕΓ औΓޙʹૹ৴͢Δ
Fukuoka.go #17 Demo: ࣌ؒͳ͍͔
Fukuoka.go #17 ๏ Integration Testͷख๏Λߟ͑ΔʢPostfix ґଘΛͲ͏͖͔͢ʣ ๏ ऩूͨ͠ใΛDatabaseʹੵͱੳ ๏ IptablesґଘϧʔςΟϯάΛBPF/XDPΛ
͏Α͏ʹ͢Δ ๏ ProductionΧφϦΞϦϦʔε ࠓޙͷܭը — github.com/linyows/warp
Fukuoka.go #17 ๏ ϝʔϧͷ౸ୡੑʹؔΘΔ̐ͭͷ߲͕͋Δ ๏ ϝʔϧϗεςΟϯάʹ͓͚Δ՝ड৴ڋ൱ͷཧ༝͕Θ͔Βͳ͍͜ͱ ๏ ϝʔϧૹ৴࣌ͷΞΧϯτ͝ͱͷৼΔ͍ͱड৴ڋ൱ͷؔΛݟ͚ͭΔͨΊͷಁաܕϓϩ Ωγ ๏
ಁաܕϓϩΩγʹ͢ΔʹDNATͱgetsockoptΛͬͨ ๏ SMTPͷಁաܕϓϩΩγͷ࣮io.Copy͢Δ͚ͩͰμϝͰμϯάϨʔυ߈ܸΛରԠ ͢Δඞཁ͕͋Γ࣮͕গ͠ෳࡶ Conclusion
Fukuoka.go #17 Thank you \ʕ⊙౪⚆ʔ/