ReactMasters / study

์Šคํ„ฐ๋”” ๊ธฐ๋ก
1 stars 0 forks source link

2022-07-30 Production Ready GraphQL #42

Open jordan-choi opened 2 years ago

jordan-choi commented 2 years ago

Authorization

๐Ÿ“˜ Authentication vs Authorization

  • Authentication: ์œ ์ €๊ฐ€ ๋ˆ„๊ตฌ์ธ์ง€, ๋กœ๊ทธ์ธ ์—ฌ๋ถ€๋ฅผ ์ •ํ•˜๋Š” ํ–‰์œ„
  • Authorization: ์œ ์ €๊ฐ€ ํŠน์ • ๋ฆฌ์†Œ์Šค์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ํ–‰์œ„
  • GraphQL ๋‹จ๊ณ„์—์„œ authorization ๋กœ์ง์„ ํฌํ•จํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜์ง€ ์•Š๋Š”๋‹ค. GraphQL์€ ๋ณดํ†ต ๋„๋ฉ”์ธ ๋กœ์ง์— ์ ‘๊ทผํ•˜๋Š” ํ•œ ๋ฐฉ๋ฒ•์ผ ๋ฟ์ด๋‹ค.
  • authroization์€ ์–ด๋–ค ํ•„๋“œ๋‚˜ ํƒ€์ž…์— ์œ ์ €๊ฐ€ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ์ง€ ์ •ํ•˜๋Š” API scopes์™€ ๋„๋ฉ”์ธ๊ณผ ๊ด€๋ จ๋œ authorization์ด ์žˆ๋‹ค.
  • API scopes๋Š” GraphQL ๋ ˆ์ด์–ด์— ๊ตฌํ˜„ํ•˜๋ฉด ์ข‹์œผ๋‚˜, ๋„๋ฉ”์ธ๊ณผ ๊ด€๋ จ๋œ ๋น„์ฆˆ๋‹ˆ์Šค ๊ทœ์น™์€ ์ตœ๋Œ€ํ•œ GraphQL ๋กœ์ง๊ณผ ๋ถ„๋ฆฌ๋˜์–ด์•ผ ํ•œ๋‹ค.
  • GraphQL ๋ ˆ์ด์–ด์— authorization์„ ๊ตฌํ˜„ํ•  ๋•Œ ๊ณ ๋ คํ•  ์‚ฌํ•ญ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค:
  • ํ•„๋“œ๋งˆ๋‹ค(per-field) authroization ๊ทœ์น™์„ ์ ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํƒ€์ž…๋งˆ๋‹ค(per-type) ๊ทœ์น™์„ ์ ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.
  • ๊ฐ์ฒด ํƒ€์ž…์ด API scopes์— ์ž˜ ๋งž๋Š”๋‹ค.
  • ๊ฐ์ฒด์— ์ ‘๊ทผํ•˜๋Š” ๋ชจ๋“  ๊ฒฝ๋กœ๋ฅผ ์ถ”์ ํ•˜๋Š” ๊ฒƒ์€ ์–ด๋ ต๋‹ค; ํ•„๋“œ ๋ ˆ๋ฒจ๋กœ ์ฒดํฌํ•˜๋ฉด ์˜ˆ์ƒํ•˜์ง€ ๋ชปํ•œ ์ ‘๊ทผ ํŒจํ„ด์— ๋…ธ์ถœ๋  ์ˆ˜ ์žˆ๋‹ค.
    
    type Query {
    adminThings: AdminOnlyType!
    @authorization(scopes: ["read:admin_only_types"])
    product: Product!
    @authorization(scopes: ["read:products"])
    }
type Product {
  name: String
  settings: AdminOnlyType!
}
```

Blocking Introspection

๐Ÿ“˜ Introspection (์Šคํ‚ค๋งˆ ํ™•์ธ) GraphQL์—์„œ ์Šคํ‚ค๋งˆ๊ฐ€ ์–ด๋–ค ์ฟผ๋ฆฌ๋ฅผ ์ง€์›ํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์š”์ฒญํ•  ์ˆ˜ ์žˆ๋Š” (GraphQL์—์„œ ์ œ๊ณตํ•˜๋Š”) ๊ธฐ๋Šฅ.

  • Introspection์€ end users๊ฐ€ ์•„๋‹Œ ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํˆด์ด๋‹ค. ์ฆ‰, development ํ™˜๊ฒฝ์—์„œ๋Š” ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ด์•ผ๊ฒ ์ง€๋งŒ production ํ™˜๊ฒฝ์—์„œ ์—ด์–ด๋‘˜ ํ•„์š”๋Š” ์—†๋‹ค (ํŠนํžˆ internal API).
  • ์ฝ์–ด๋ณด๋ฉด ์ข‹์€ ๊ธ€: Why You Should Disable GraphQL Introspection In Production โ€“ GraphQL Security
  • Public GraphQL API์˜ ๊ฒฝ์šฐ, ์ด๋ฏธ schema๊ฐ€ ๋…ธ์ถœ๋˜์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์— introspection์„ ์ œํ•œํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.

Persisted Queries

Summary