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
実践ARMアーキテクチャ移行
pyama86
2
2k
リモートワーク時代の守護神 PHP開発者のためのセキュリティ強化術
pyama86
3
900
実践DevSecOps~クラウドネイティブとオンプレミスの間から~
pyama86
1
48
ペパボOpenTelemetry革命
pyama86
2
1.8k
Site Reliability Engineering for GMO
pyama86
10
1.2k
PHPアプリケーションのスケーラビリティと 信頼性を革新する nginx+ngx_mrubyとGoの融合
pyama86
2
410
ペパボOpenTelemetry革命
pyama86
0
860
ChatGPTの活用を体現し、 組織に浸透する技術
pyama86
1
1.1k
リリースフラグと プログレッシブデリバリーを活用した 安全なWEBアプリケーションデプロイ
pyama86
2
270
Other Decks in Technology
See All in Technology
セキュリティ監視の内製化 効率とリスク
mixi_engineers
PRO
7
790
contenteditableと向き合う
kikuchikakeru
2
210
LLMに日本語テキストを学習させる意義
ksaito
13
3.6k
MySQLのあらたしいリリースモデル LTSとIR
sakaik
1
120
Estrategias de escalabilidade para projetos web
jessilyneh
2
190
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
39k
SHIFTの課題と目指したい組織像 / 20240827 Rinto Ikenoue
shift_evolve
0
150
Our Journey from in-House CD System to Open Source
ffjlabo
0
110
四国クラウドお遍路 2024 in 高知 エンディング
yukataoka
0
110
なぜクラウドサービスで Web コンソールを提供するのか
shuta13
4
1.9k
[RSJ24] Object Segmentation from Open-Vocabulary Manipulation Instructions Based on Optimal Transport Polygon Matching with Foundation Models
keio_smilab
PRO
0
130
SORACOMで実現するIoTのマルチクラウド対応 - IoTでのクリーンアーキテクチャの実現 -
kenichirokimura
0
220
Featured
See All Featured
5 minutes of I Can Smell Your CMS
philhawksworth
201
19k
Infographics Made Easy
chrislema
239
18k
Intergalactic Javascript Robots from Outer Space
tanoku
268
26k
Why You Should Never Use an ORM
jnunemaker
PRO
53
8.9k
Visualization
eitanlees
142
15k
It's Worth the Effort
3n
182
27k
The Illustrated Children's Guide to Kubernetes
chrisshort
46
48k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
42
2k
Testing 201, or: Great Expectations
jmmastey
35
6.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
122
18k
WebSockets: Embracing the real-time Web
robhawkes
59
7.3k
Mobile First: as difficult as doing things right
swwweet
220
8.8k
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 ɾόΠφϦ ɾڞ௨ϥΠϒϥϦ ɾαʔό ɾΫϩείϯύΠϧ ɾѹతੜ࢈ੑ
৽͍͠ݴޠͰ ৽͍͠ՁΛੜΊͨ