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.4k
Tuning GraphQL on Rails
pyama86
2
1.4k
ttlcacheのここがスゴい
pyama86
1
84
クラウドサービスの 利用コストを削減する技術 - 円安の真南風を感じて -
pyama86
3
510
実践ARMアーキテクチャ移行
pyama86
2
2.3k
リモートワーク時代の守護神 PHP開発者のためのセキュリティ強化術
pyama86
3
1k
実践DevSecOps~クラウドネイティブとオンプレミスの間から~
pyama86
1
75
ペパボOpenTelemetry革命
pyama86
2
2k
Site Reliability Engineering for GMO
pyama86
10
1.3k
Other Decks in Technology
See All in Technology
C++26 エラー性動作
faithandbrave
2
670
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.2k
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
CustomCopを使ってMongoidのコーディングルールを整えてみた
jinoketani
0
220
ハイテク休憩
sat
PRO
2
120
アップデート紹介:AWS Data Transfer Terminal
stknohg
PRO
0
170
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
530
kargoの魅力について伝える
magisystem0408
0
200
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
.NET 9 のパフォーマンス改善
nenonaninu
0
440
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Building an army of robots
kneath
302
44k
Six Lessons from altMBA
skipperchong
27
3.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Embracing the Ebb and Flow
colly
84
4.5k
Why Our Code Smells
bkeepers
PRO
335
57k
How to Ace a Technical Interview
jacobian
276
23k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Pragmatic Product Professional
lauravandoore
32
6.3k
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 ɾόΠφϦ ɾڞ௨ϥΠϒϥϦ ɾαʔό ɾΫϩείϯύΠϧ ɾѹతੜ࢈ੑ
৽͍͠ݴޠͰ ৽͍͠ՁΛੜΊͨ