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
990
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
非コンテナ環境において宣言的Deploymentを手軽に実現する / Declarative deployment in non-container environments
linyows
0
21
メール送信サーバの集約における透過型SMTP プロキシの定量評価 / Quantitative Evaluation of Transparent SMTP Proxy in Email Sending Server Aggregation
linyows
0
400
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
260
研究の再現性を高める 仕組みをGoでつくる / Creating a system to improve the reproducibility of research using go
linyows
1
140
奥が深いメールのシステム / The depth of Email system
linyows
4
450
IaCにおけるテスト考察 / Tests in IaC
linyows
2
480
リバースエンジニアリングとGoでSlackの認知負荷を下げる / Reducing cognitive load in Slack with Reverse-engineering and Go
linyows
2
300
透過型SMTPプロキシによる送信メールの可観測性向上 / Improved observability of outgoing emails with transparent smtp proxy
linyows
2
1k
プロダクションで使うGo Pluginの利便性とパフォーマンス性 / Simplicity and Performance of Go plugin for Production
linyows
0
540
Other Decks in Programming
See All in Programming
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
ドメインイベント増えすぎ問題
h0r15h0
1
220
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
命名をリントする
chiroruxx
1
390
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
Haze - Real time background blurring
chrisbanes
1
510
42 best practices for Symfony, a decade later
tucksaun
1
180
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
520
39k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Optimizing for Happiness
mojombo
376
70k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Into the Great Unknown - MozCon
thekraken
33
1.5k
How to Ace a Technical Interview
jacobian
276
23k
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 \ʕ⊙౪⚆ʔ/