Upgrade to Pro — share decks privately, control downloads, hide ads and more …

アルプの 認証/認可分離戦略と手法

アルプの 認証/認可分離戦略と手法

C6a8cb5e13aa716521d522471ec4e4cd?s=128

ma2k8
PRO

May 19, 2022
Tweet

More Decks by ma2k8

Other Decks in Technology

Transcript

  1. Ξϧϓͷ ೝূ/ೝՄ෼཭ઓུͱख๏ SaaS.tech #3 @ma2k8

  2. About me > দ઒ཌྷ ΞϧϓͰόοΫΤϯυΤϯδχΞΛ͠ ͍ͯ·͢ ࢠڙͷࠒͷ໊͋ͩͰ·ͬͪΎʔͱݺ͹ Ε͍ͯ·͢ @wing_007 @ma2k8

  3. > ɹ AlpͰ͸Scalebaseͱ͍͏αϒεΫϦϓγϣϯܾࡁ؅ཧɺܦӦ෼ੳͷ SaaSϓϩμΫτΛఏڙ͍ͯ͠·͢ɻ Our Products

  4. > ೝূ/ೝՄ͓͞Β͍ > ೝূ/ೝՄͷίϯςΩετ෼཭ʹ͍ͭͯ > ΞϧϓͰͷ෼཭ઓུ > ΞϧϓͰͷ෼཭ख๏ > ͍͞͝ʹ

    Agenda
  5. ೝূ/ೝՄͷ͓͞Β͍

  6. ೝূ ~AutheNtication ~ ର৅͕ʮ୭ʯͰ͋Δ͔Λಛఆ͢Δ

  7. ೝՄ ~AuthoriZation ~ ೚ҙͷϦιʔεʹର͠ɺ ೚ҙͷΞΫγϣϯͷڐՄ/ڋ൱Λ੍ޚ͢Δ

  8. ೝূ/ೝՄͷ ίϯςΩετ෼཭ʹ͍ͭͯ

  9. γϯϓϧͳཁ݅Ͱ͸ ೝূͱೝՄ͕ͪ͝Όࠞͥʹ ͳ͍ͬͯΔ͜ͱ͕͋Γ·͢ (ͦΕͰ΋ࠔΒͳ͍)

  10. ೝՄνΣοΫ͕ͳ͘ɺ ೝূ͑͞௨Ε͹ɺશૢ࡞OKͷέʔε

  11. γϯϓϧͳೝূ/ೝՄ ᶃೝূཁٻ(ID/Pass౳) ᶄϢʔβʔAͰ͋Δ͜ͱΛೝূ ᶅϢʔβʔA͸ ੍ݶͳ͘શૢ࡞Մೳ ϢʔβʔA ͘͢͝γϯϓϧͳγεςϜ

  12. ͪΐͬͱͨ͠ݖݶ൑ఆ͸͜ͷԆ௕ઢ ͰରԠՄೳ APIΩʔൃߦ౳ɺݖݶҕৡͷཁ͕݅ ग़ͯ͘Δͱ࿩͕೉͘͠ͳΓ·͢

  13. ҕৡ༗Γೝূ/ೝՄ ᶃӾཡݖݶΛҕৡͨ͠ΩʔΛൃߦ ϢʔβʔA bot౳ͷ೚ҙͷ࣮ߦऀ APIΩʔ ᶄAPIΩʔΛར༻͠ɺҕৡ͞ΕͨΞΫγϣϯΛ࣮ߦ͢Δɻ ɹAPIΩʔͷೝূ͸ߦ͏͕ɺϢʔβʔAͰ͋Δ͔൱͔΍ɺ ɹ࣮ߦऀ͕୭Ͱ͋Δ͔ͷೝূ͸ߦΘͳ͍ɻ ෳࡶͳγεςϜ

  14. Ͳ͕͜೉͘͠ͳΔͷͰ͠ΐ͏͔

  15. ෳࡶԽ͢Δ఺ᶃ APIΩʔೝূ Ϣʔβʔೝূ > Ϣʔβʔೝূͱ"1*Ωʔೝূ͕ͦΕͧΕඞཁʹͳΔ

  16. ෳࡶԽ͢Δ఺ᶄ > ϢʔβʔͷೝՄ৘ใͱ"1*ΩʔͷೝՄ৘ใΛͦΕͧ Ε؅ཧ͢Δඞཁ͕͋ΔͷͰɺ1SJODJQBM(ೝՄओମ)͕ ૿͑Δ APIΩʔʹ ඥͮ͘ೝՄ৘ใ Ϣʔβʔʹ ඥͮ͘ೝՄ৘ใ

  17. ෳࡶԽ͢Δ఺ᶅ > ϢʔβʔͷݖݶΛຖճશͯҕৡͨ͠Γɺҕৡ͢Δݖݶ͕ Α΄ͲߜΒΕ͍ͯͳ͍ݶΓ͸"#"$Ͱͷ࣮૷͕ඞཁʹͳΔ > ABACͷ࣮૷͸ෳࡶʹͳΓ͕ͪ Ӿཡݖݶ͚ͩҕৡ

  18. ෳࡶԽ͢Δ఺ᶆ > ݖݶΛ෇༩͢ΔλΠϛϯάʹɺA"1*Ωʔൃߦ࣌A ͕௥Ճ͞ΕΔ > ෇༩λΠϛϯά͸ଞʹ΋Ϣʔβʔͷ՝ۚ੒ޭ࣌ɺ։ൃ༻ʹ෇༩͢Δ έʔεͳͲɺ͞·͟·ͳλΠϛϯάͰݖݶΛ෇༩͢ΔՄೳੑ͕͋Δ ՝ۚ੒ޭ࣌ ։ൃ༻ APIΩʔ΁ͷҕৡ

    ݖݶ" Ϣʔβʔ࡞੒࣌
  19. ଞʹ΋ଟ෼ͨ͘͞Μ͋Δɻɻɻ

  20. ͜Ε͸ෳࡶԽ͢Δཁ݅ͷ Ұ෦Ͱ͔͋͠Γ·ͤΜɾɾ

  21. Presenter Controller Adapter (DB, Redis, etc..) UseCase Domain ߲໨ͷϚεΩϯά ΤϯυϙΠϯτͷ࣮ߦՄ൱

    ϦιʔεͷϑΟϧλ ಡऔ/ॻࠐͷ࣮ߦՄ൱ UseCaseͷ࣮ߦՄ൱ υϝΠϯϩδοΫͷ෼ذ υϝΠϯϩδοΫͷ࣮ߦՄ൱ ಛʹೝՄ͸ີ݁߹͠΍͍͢ ҎԼ͸ฐࣾͷίϯςΩετʹ͓͚ΔΞʔΩςΫνϟͷ֊૚ਤͰ͕͢ɺ֤૚Ͱ༷ʑͳೝՄͷཁ݅ ͕ߟ͑ΒΕ·͢ɻ ؔ৺͕֤ॴʹݱΕΔͨΊɺ۪௚ʹ࣮૷͢Δͱมߋ͕೉͍͠ঢ়ଶʹͳΓ΍͍͢ɻ ͜ΕΒΛผʑͷ࢓૊ΈͰ࣮૷͢Δͱख਺͕ଟ͘ͳΓ͗͢ɺ੔߹ੑͷ֬อ΋೉͘͠ͳΔͰ͠ΐ͏ɻ
  22. ີ݁߹ͳೝՄ൑ఆ ྫ͑͹ɺʮܾࡁͷσʔλ͕͋Δ͔Βʯͱ͍ͬͨ ؔ৺Λ෼཭͠ͳ͍ϩδοΫͰೝՄ൑ఆΛ͢Δ ͱɺҎԼͷΑ͏ͳ໰୊͕ൃੜ͠·͢ > ։ൃ༻ͷݖݶ෇༩ʹܾࡁσʔλੜ੒͠ͳ͍ͱ͍͚ͳ͍ > ՝ۚͷखஈ͕૿͑ͨ৔߹ɺશͯͷखஈΛ໢ཏతʹ֬ೝ͠ͳ͍ͱݖݶ൑ఆ͕ߦ͑ͳ͍ > APIΩʔͷೝՄ൑ఆ࣌ʹɺൃߦऀͷ৘ใΛ֬ೝ͠ͳ͍ͱ͍͚ͳ͍

    > BANͳͲɺܾࡁ৘ใͱ͸ผ࣠ͰೝՄΛ੍ޚ͍ͨ͠έʔεʹରԠ͠ʹ͍͘
  23. ෼཭ɾ෼཭ɾ෼཭ ೝূ/ೝՄ ίΞυϝΠϯ > ڥք͚ͮΒΕͨίϯςΩετͱͯ͠෼཭͢Δ͜ͱͰɺೝՄ͸ೝՄͷσʔλͱͯ͠؅ཧ͠ ΍͘͢ͳΓɺ൑ఆϩδοΫ΋ೝՄίϯςΩετ಺ʹΧϓηϧԽ͢Δ͜ͱ͕Ͱ͖Δ > ͜ΕʹΑΓɺෳࡶੑ͔ΒίΞυϝΠϯΛ੾Γ཭͢͜ͱ͕Ͱ͖ɺอकੑͷߴ͍ঢ়ଶ͕อͪ ΍͘͢ͳΔ 


    > ෼཭ʹ΋άϥσʔγϣϯ͕͋ΔͷͰɺଈίϯςΩετ෼ׂʹ૸Βͳͯ͘΋ྑ͍͕ɺͦ͏ ͢Δ͜ͱ͕Ͱ͖Δঢ়ଶ͸อ͓͍ͬͯͨํ͕ྑ͍ > Ұ൪ॏཁͳͷ͸ͲΜͳखஈʹͤΑɺίΞυϝΠϯ͔Βೝূ/ೝՄ͕੾Γ཭͞Ε͍ͯΔ͜ͱ ܾࡁ
  24. ΞϧϓͰͷ෼཭ઓུ

  25. มಈੑ ೝূ/ೝՄʹݶΒͣͰ͕͢ɺͲ͏෼཭͢Δͷ͔ʹ͍ͭͯ ͸ ’มಈੑ’ Λࢦඪʹ͍ͯ͠·͢ɻ

  26. มಈੑʹΑΔ෼཭ ’มಈੑ’ ʹ͍ͭͯ͸ɺॻ੶ Righting Software Ͱ஌ Γ·ͨ͠ɻ(ݩʑ͜ͷݴ༿Λ஌Βͳ͔ͬͨͷͰ͢ ͕ɺ͜ΕΛ࢖͏ͱઆ໌͠΍͔ͬͨ͢ͷͰѪ༻ͯ͠ ͍·͢) ʮγεςϜશମʹ೾ٴ͢Δ༷ͳมߋ͞ΕΔՄೳੑ

    ͕͋ΔྖҬΛ໌Β͔ʹ͠ɺͦͷ෦෼ΛαʔϏε΍ γεςϜͷ෦඼ͱͯ͠ΧϓηϧԽ͢Δʯ ͜Εʹै͏ͱɺ࠶ར༻ੑ&อकੑ͕ߴ͘ɺෳࡶ౓ Λίϯτϩʔϧ͠΍͍͢෼཭͕Ͱ͖·͢ɻ
  27. ೝূ/ೝՄͷมಈੑ શ͘෼཭͠ͳ͍έʔεͰߟ͑ΔͱɺೝূೝՄͷཁ݅͸ΞʔΩςΫνϟΛ༳Δ͕ ͢ɺେ͖ͳมಈੑΛ๊͍͑ͯΔ͜ͱ͕Θ͔Γ·͢ɻ > ೝূखஈ͕૿͑ͨ ɹ-> ೝূखஈ͝ͱʹಉ͡ػೳΛ࣮૷͢Δͷ͔ʁ > ಡऔઐ༻ϢʔβʔΛ௥Ճ͍ͨ͠ ɹ->

    ࠓ·Ͱॻ͍͖ͯͨॲཧશͯʹ෼ذΛ଍͢ͷ͔ʁ
  28. ඇػೳཁ݅ͷมಈੑ ٻΊΒΕΔඇػೳཁ͕݅ണ཭͢ΔՄೳੑ͕ߴ͍΋ͷ΋มಈੑ ͕ߴ͍ͱ൑அ͠ɺ෼཭͢Δ༷ʹ͍ͯ͠·͢ɻ ΞϧϓͰ͸࢖༻ྔΛ΋ͱʹ੥ٻֹΛܾΊΔػೳ͕͋Γ·͕͢ɺ ࢖༻ྔΠϕϯτ͸͓٬༷ͷγεςϜʹΑͬͯ͸େྔͷσʔλΛ औΓѻ͏͜ͱʹͳΔͷͰɺมಈੑ͕ߴ͍ͱͯ͠ίϯςΩετ෼ ཭Λ͍ͯ͠·͢ɻ ͜ΕʹΑͬͯޙͷϦιʔε࠷దԽΛεϜʔζʹߦ͏͜ͱ͕Ͱ͖ ·͢ɻ

  29. ΞϧϓͰͷ෼཭ख๏

  30. ΞϧϓͰߦ͍ͬͯΔ ೝՄͷ෼཭ͷख๏Λ͝঺հ͠·͢

  31. ᶃೝՄΛڥք͚ͮΒΕͨίϯςΩετ ͱͯ͠෼཭ ฐࣾ͸ϞδϡϥϞϊϦεΛ࠾༻͍ͯͯ͠ɺೝՄ͸ͭͷϞδϡʔ ϧͱͯ͠෼཭͍ͯ͠·͢ɻ ೝՄ൑ఆ͸ͦΕͧΕͷίϯςΩετ͔ΒೝՄίϯςΩετʹϦΫ ΤετΛ౤͛ΔܗͰߦΘΕ·͢ɻ Presenter Controller Adapter UseCase

    Domain Lib Subscription-ctx Presenter Controller Adapter UseCase Domain Lib Authz-ctx ೝՄϦΫΤετ
  32. ᶃೝՄΛڥք͚ͮΒΕͨίϯςΩετ ͱͯ͠෼཭ υϝΠϯ૚Ͱߦ͏Α͏ͳίϯςΩετಛ༗ͷೝՄ൑ఆͳͲ͸ɺ"VUI[-ctx͚ͩͰͷ൑ఆ͕೉͍͠৔߹΋͋ Γ·͢ɻ ೝՄϦΫΤετͷ݁Ռ͸CPPMFBOͰ΋ฦͤΔΑ͏ʹ͍ͯ͠ΔͷͰɺίϯςΩετಛ༗ͷ൑ఆͱ߹੒ͯ͠ ೝՄͷ൑ఆΛߦ͏͜ͱͰ͜ΕΛճආ͍ͯ͠·͢ɻ ※(Subscription-ctxͷೝՄ൑ఆ1 && authz-ctxͷೝՄ൑ఆ) ||

    Subscription-ctxͷೝՄ൑ఆ2 ͷΑ͏ͳܗ Presenter Controller Adapter UseCase Domain Lib Subscription-ctx Presenter Controller Adapter UseCase Domain Lib Authz-ctx ೝՄϦΫΤετ
  33. ᶄೝՄଐੑΛLibͱͯ͠ఏڙ͢Δ ೝՄͷ൑ఆʹ࢖͏ଐੑ৘ใ͸ɺ͍Θ͹ͨͩͷλά ͷΑ͏ͳγϯϓϧͳ৘ใͱͯ͠औΓѻ͍ɺ֤ίϯ ςΩετͰར༻͢ΔϥΠϒϥϦͱͯ͠ఏڙ͠·͢ɻ

  34. ᶄೝՄଐੑΛLibͱͯ͠ఏڙ͢Δ ͜͏͢Δ͜ͱʹΑͬͯɺͲͷ૚Ͱ΋ଐੑΛѻ͑ Δঢ়ଶΛ࡞Γ·͢ɻ Presenter Controller Adapter UseCase Domain Lib Լํ޲΁ͷґଘ͸ڐՄ͍ͯ͠ΔͷͰLibʹஔ͘ͱɺ

    Ͳͷ૚Ͱ΋ࢀরͰ͖Δ ֤૚͝ͱʹઐ༻ͷଐੑΛ༻ҙͯ͠΋ྑ͍͕ϝϦο τͱίετ͕ݟ߹Θͳ͍ͱ൑அͨ͠
  35. ᶄೝՄଐੑΛLibͱͯ͠ఏڙ͢Δ ൑ఆ͢Δ࣌͸ɺ͜ͷଐੑ৘ใΛ1SJODJQBMͷ৘ใͱڞʹೝՄίϯ ςΩετʹ౉ͯ͠൑ఆͯ͠΋Β͍ɺͦͷ݁ՌΛ΋ͱʹೝՄ൑ఆ Λߦ͍·͢ɻ ͜ΕʹΑͬͯଐੑ৘ใͱ൑ఆϩδοΫ͕෼཭Ͱ͖·͢ɻ Presenter Controller Adapter UseCase Domain

    Lib HogeίϯςΩετ Presenter Controller Adapter UseCase Domain Lib ೝՄίϯςΩετ ೝՄϦΫΤετ
  36. ᶅPolicyͱScopeΛ۠ผ͢Δ ಉ͡ೝՄଐੑΛར༻͠·͕͢ɺׂΓ౰ͯΔର৅ʹΑͬͯ1PMJDZͱ4DPQFͱͯ۠͠ ผ͍ͯ͠·͢ɻ > Policy Principal(User,ApiKey etc..)ʹׂΓ౰ͯΒΕΔೝՄଐੑ > Scope γεςϜ্ͷϦιʔεʹׂΓ౰ͯΒΕΔೝՄଐੑ

  37. ᶅPolicyͱScopeΛ۠ผ͢Δ Resource(ओʹυϝΠϯϞσϧ)ʹରͯ͠4DPQFΛઃఆ͓ͯ͘͠ͱɺࣗಈͰ1PMJDZͱ ಥ߹ͯ͠ೝՄ൑ఆΛߦ͏Α͏ʹ͍ͯ͠·͢ɻ ͜͏͢Δ͜ͱʹΑΓɺ4DPQFͷઃఆ͓͚ͯ͠͹ɺಡऔઐ༻ݖݶ͸3FBE͚ͩՄೳ౳ ͷॲཧΛ࣮૷ऀ͕ҙࣝͤͣͱ΋ߦͳͬͯ͘Ε·͢ɻ

  38. ᶆ֤૚ʹઃఆ͞Ε͍ͯΔScopeΛूΊɺ ൑ఆΛ1౓ͷܭࢉʹ·ͱΊΔ ೝՄ͸֤૚ʹإΛग़͠·͢ɻ ֤૚ʹ͋Δ4DPQFΛܭࢉ࣌ʹͭʹूΊΔ͜ͱͰɺ౓ͷೝ Մ൑ఆͰࡁΉΑ͏ʹ͍ͯ͠·͢ɻ Presenter Controller Adapter(DB etc..) UseCase

    Domain Set Scope A Set Scope B Set Scope C,D Set Scope E Set Scope F State[List[A,B,C,D,E,F], X]
  39. ᶆ֤૚ʹઃఆ͞Ε͍ͯΔScopeΛूΊɺ ൑ఆΛ1౓ͷܭࢉʹ·ͱΊΔ ೝՄ͸֤૚ʹإΛग़͠·͢ɻ ֤૚ʹ͋Δ4DPQFΛܭࢉ࣌ʹͭʹूΊΔ͜ͱͰɺ౓ͷೝՄ൑ఆͰࡁΉΑ͏ʹ͍ͯ͠·͢ɻ ೝՄଐੑͷ"OEͱ0SΛදݱͰ͖Δܕ΋༻ҙ͠ɺ౓ͷ൑ఆͷදݱྗΛ͋͛ΔࢼΈ΋͓͜ͳ͍ͬͯ· ͢ɻ(༏ઌ͸ະ࣮૷) Presenter Controller Adapter(DB etc..)

    UseCase Domain Set Scope A Set Scope B Set Scope C,D Set Scope E Set Scope F State[List[A,B,C,D,E,F], X]
  40. ᶇೝՄ༻ͷܕʹแΉͱ ೝՄ൑ఆͷର৅ͱ͢Δ ᶆͰ঺հͨ͠4DPQFΛूΊΔର৅Λࢦఆ͢Δͷʹઐ༻ͷܕΛ༻ҙ͍ͯ͠·͢ɻ ܭࢉࣜͷதʹ͋Δɺ͜ͷܕʹแ·Εͨ3FTPVSDFͷ4DPQFΛूΊΔಈ͖Λ͠·͢ɻ ͜ΕʹΑͬͯܭࢉʹ࢖͏3FTPVSDFʹରͯࣗ͠ಈͰೝՄ൑ఆΛߦͳͬͯ͘ΕΔͷͰ࿙Ε͕͋Γ·ͤΜɻ RepositoryͷΠϯλʔϑΣʔεͳͲ͸ɺ͜ͷܕΛฦΓ஋ʹͱ͍ͬͯͳ͍ͱLinterͰΤϥʔʹ͢Δ࢓૊Έ ΋ಋೖ͍ͯ͠·͢ɻ

  41. ҎԼͷ޻෉Λͯ͠·͕͢ɺ͔ͳΓ4DBMBͷؔ਺ܕϓϩάϥϛϯάدΓͷදݱྗ (Extensible Effect౳)Λར༻͓ͯ͠Γɺษڧձͷओࢫ͔ΒζϨͦ͏ͳͷͰ͜͜Ͱ͸ׂѪ͞ ͍͖ͤͯͨͩ·͢ɻ ᶈ൑ఆॲཧͷΤϑΣΫτந৅Խ(͜ΕʹΑͬͯͲͷ૚Ͱ΋ೝՄΛѻ͍΍͘͢ͳΔ) ᶉ࣮૷Λ෼͚ͣʹɺόονॲཧͳͲೝՄ൑ఆΛߦ͍ͨ͘ͳ͍έʔεʹରԠ͢Δ (ScalaMatsuriͰൃදͨ͠ࢿྉͱɺࣾ಺ษڧձͷࢿྉ͕͋ΔͷͰڵຯͷ͋Δํ͸͝ࢀর ͍ͩ͘͞ɾɾɾʂ) https://speakerdeck.com/ma2k8/explain-authzctx-in-alp (ࣾ಺༻ͳͷͰগ͠ࡶͰ͢

    🙏) https://speakerdeck.com/ma2k8/alp-original-eff-pearls ଞʹ΋ɾɾɾ
  42. ͍͞͝ʹ

  43. ೝূ͸*%BB4ͳͲͰ͔ͳΓָʹͳ͖ͬͯͨҹ৅͕͋Δ͕ɺ ೝՄ͸֓೦͕ᐆດͰݕ౼͢Δ͜ͱ͕ଟ͘ͱͯ΋೉͍͠ɻɻ ·ͩ·ͩೝՄ࣮૷ͷҰൠతͳղ͕গͳ͘ɺࢀߟʹͳΔ৘ใ ͕ݶΒΕ͍ͯΔͷͰੵۃతʹφϨοδΛڞ༗͠ɺΑΓྑ͍ ղΛ໛ࡧ͍ͯ͘͠ྲྀΕ͕Ͱ͖Δͱྑ͍ͳͱࢥ͓ͬͯΓ· ͢ʂ

  44. Thanks!