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言語で実装するLinuxNameServer
Search
Kazuhiko Yamashita
May 21, 2016
Technology
2
4k
Go言語で実装するLinuxNameServer
PHPカンファレンス福岡で発表したGo言語とSTNSに関する話です。
言語カンファレンスなのですこしだけ技術的な側面に触れています。
Kazuhiko Yamashita
May 21, 2016
Tweet
Share
More Decks by Kazuhiko Yamashita
See All by Kazuhiko Yamashita
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
Tuning GraphQL on Rails
pyama86
2
1.2k
ttlcacheのここがスゴい
pyama86
1
71
クラウドサービスの 利用コストを削減する技術 - 円安の真南風を感じて -
pyama86
3
470
実践ARMアーキテクチャ移行
pyama86
2
2.2k
リモートワーク時代の守護神 PHP開発者のためのセキュリティ強化術
pyama86
3
1k
実践DevSecOps~クラウドネイティブとオンプレミスの間から~
pyama86
1
65
ペパボOpenTelemetry革命
pyama86
2
2k
Site Reliability Engineering for GMO
pyama86
10
1.3k
Other Decks in Technology
See All in Technology
地理情報データをデータベースに格納しよう~ GPUを活用した爆速データベース PG-Stromの紹介 ~
sakaik
1
150
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
0
980
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
Can We Measure Developer Productivity?
ewolff
1
150
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
180
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Into the Great Unknown - MozCon
thekraken
32
1.5k
The Language of Interfaces
destraynor
154
24k
How to Ace a Technical Interview
jacobian
276
23k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
What's new in Ruby 2.0
geeforr
343
31k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Making Projects Easy
brettharned
115
5.9k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Transcript
ʙීஈPHPॻ͍ͯ·͢ฤʙ GoݴޠͰ࣮͢ΔLinuxNameServer
hi! GMO Pepabo, Inc. ϗεςΟϯάࣄۀ෦ ϜʔϜʔυϝΠϯάϧʔϓ γχΞΤϯδχΞ @pyama86
blog https://ten-snapon.com
Go 1.5
-buildmode=c-shared Go 1.5͔ΒCGOΛར༻͠ڞ༗ϥΠϒϥϦΛ࡞Մೳʹ http://qiita.com/masakielastic/items/09018646d7d34996190a
Go?
ϫϯόΠφϦͰΠέͯΔίϚϯυ peco pt ghq ghr
ઌਐతWeb։ൃʁ
Linux Middleware
Before Go 1.5 LinuxͷOSϨΠϠͷ༷Λม͑Δʹɺਂ͘ͳΕ ͳΔ΄ͲCݴޠͷ΄΅ಠஃͰ͋ͬͨͱࢥ͏
After Go 1.5 GoݴޠΛ༻͍ͯɺLightweight LanguageͷΑ͏ͳॻ͖ ຯͰɺLinuxOSͷϛυϧΣΞ։ൃ͕Մೳʹͳͬͨ package main /* #include
<pwd.h> #include <sys/types.h> */ import "C" //export _nss_stns_getpwnam_r func _nss_stns_getpwnam_r(name *C.char, pwd *C.struct_passwd) int { return set(&Passwd{pwd, result}, "user", "name", C.GoString(name)) }
None
STNS LinuxͷϢʔβʔɺάϧʔϓͷ໊લղܾɺೝূػೳΛ ఏڙ͢ΔLinuxNameService % ls -ltr -rw-r--r-- 1 pyama wheel
0 May 8 00:09 php_fukuoka.txt % ls -ltr -rw-r--r-- 1 1000 1000 0 May 8 00:09 php_fukuoka.txt id:1000 to pyamaͷ໊લղܾ
STNSͷഎܠ 1.DevOpsɺσϓϩΠڥͷભҠʹΑͬͯSSHϩάΠ ϯ͕ඞཁͳϢʔβʔͷ૿Ճ 2.Ϣʔβʔ૿Ճ࿈ܞઌ૿Ճʹ͍ഁ͔͚ͨ͠ LDAP͔ΒͷҠߦઌ 3.ͱʹ͔͘ͱ͍͏࠽ೳΛӡ༻ཧͱ͔ʹ͍ͨ͘ ͳ͔ͬͨ
ίϯηϓτ ໊લղܾɺެ։伴औಘɺsudoೝূͷΈΛఏڙ͢Δɻ ଟ͘ΛΒͣɺγϯϓϧʹอͭ͜ͱͰཧɺ Έ߹ΘͤΛ༰қʹɻ https://github.com/STNS/STNS
ΞʔΩςΫνϟ STNS http(1104) Client ls libnss-stns libpam-stns query-wrapper key-wrapper /user/name/pyama
{ name:pyama, id: 1000, dir:/home/pyama … }
ΞʔΩςΫνϟ STNS http(1104) Client ls libnss-stns libpam-stns query-wrapper key-wrapper /user/name/pyama
{ name:pyama, id: 1000, dir:/home/pyama … }
nss Network Security Service libnss_<name>.so.2(version)ͷϥΠϒϥϦΛಡΈࠐ Έɺ໋໊نʹ߹கͨ͠γϯϘϧ͕ଘࡏ͢Δ߹ίʔ ϧͯ͘͠ΕΔ http://www.gnu.org/software/libc/manual/html_node/NSS- Modules-Interface.html
nss passwd _nss_stns_getpwnam_r _nss_stns_getpwuid_r _nss_stns_setpwent _nss_stns_endpwent _nss_stns_getpwent_r group _nss_stns_getgrnam_r _nss_stns_getgrgid_r
_nss_stns_setgrent _nss_stns_endgrent _nss_stns_getgrent_r shadow _nss_stns_getspnam_r _nss_stns_setspent _nss_stns_endspent _nss_stns_getspent_r libnss_stns.so ͜ͷ໊લͷfunctionΛఆٛ͢Δ͚ͩͰ STNS࡞ΕΔ
stns.conf(αʔό) port = 1104 include = "/etc/stns/conf.d/*" # ϕʔγοΫೝূΛαϙʔτ user
= "basic_user" password = "basic_password" [users.example] id = 1001 group_id = 1001 keys = ["ssh-rsa XXXXX…"] [groups.example] id = 1001 users = ["example"] [sudoers.example] password = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" hash_type = "sha256"
ࠓ෩ͳػೳ
ΞϓϦέʔγϣϯσϓϩΠ
[email protected]
[email protected]
[email protected]
/home/deploy/.ssh/authrized_keys ʹ֤Ϣʔβʔͷެ։伴Λొ
σϓϩΠϢʔβʔͷཧ ࡢࠓͷWebαʔϏεͰσϓϩΠઐ༻ϢʔβʔΛઃ ͚ͯσϓϩΠ͢Δ͜ͱ͕ଟ͍ɻ ͔͠͠ɺطଘͷΈͰ࣮ݱ͢ΔʹσϓϩΠϢʔ βʔͷ~/.ssh/authorized_keysʹσϓϩΠ͢ΔϢʔ βʔͷެ։伴ΛฒͨΓ͢Δඞཁ͕͋ͬͨ
σϓϩΠϢʔβʔͷཧ [users.deploy] id = 1000 group_id = 1000 link_users =
[“example1","example2"] [users.foo] keys = ["ssh-rsa aaa”] [users.bar] keys = ["ssh-rsa bbb"] deployϢʔβʔͰSSHϩάΠϯ͢Δࡍʹɺlink_usersͰ ࢦఆͨ͠Ϣʔβʔͷެ։伴Λར༻͢Δ͜ͱ͕ग़དྷΔ →authorized_keysʹॻ͔ͳͯ͘ྑ্͍ʹɺ ɹ୭͕σϓϩΠग़དྷΔͷ͔Ұྎવ
ͬͯΈΔʁ
ಋೖͷखܰ͞ 1ίϚϯυͰϦϙδτϦΛՃ͠ɺ yumɺaptͰ࠷৽൛Λར༻Մೳ
ಋೖͷखܰ͞ puppetϚχϑΣετɺchefΫοΫϒοΫΛఏڙ Ճ͑ͯຊޠΠϯετʔϧυΩϡϝϯτ https://github.com/STNS/STNS/blob/master/docs/install_ja.md
ৄࡉઌि౦ژʹஔ͍͖ͯͨ https://www.youtube.com/watch?v=ZBuEsQ3rnm4
ͯ͞ΓɺGo
CGOʹز੍͔͕ͭ͋Δ 1.ڞ༗ϥΠϒϥϦʹग़དྷΔͷmainύοέʔδͷΈ 2.CGOtestʹؚΊΒΕͳ͍ 3.Go 1.5Ͱ32bitͷڞ༗ϥΠϒϥϦ͕αϙʔτ͞Ε ͍ͯͳ͍(1.6OK)
LinuxϛυϧΣΞ࡞Δʹ֮ޛ͕͍Δ ʮ$ ls ~ʯͷΑ͏ʹೖྗޙλϒิͨ͠ࡍʹɺ bash͕clone͞Εͯɺΰϧʔνϯ͕ແݶϧʔϓͨ͠Γ
$ strace getent passwd
$ LD_DEBUG=symbols,bindings id
$ vim ldap-pwd.c
࠶ܝ ͨͩ͠ɺCݴޠͷ࠷ݶͷࣝɺ ૬Ԡͷσόοάೳྗඞཁ
ʹͱͬͯGo͕ ࠷ޙͷҰຕͩͬͨ
Go ɾόΠφϦ ɾڞ௨ϥΠϒϥϦ ɾαʔό ɾΫϩείϯύΠϧ ɾѹతੜ࢈ੑ
৽͍͠ݴޠͰ ৽͍͠ՁΛੜΊͨ