-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add an example of access control at the API Gateway level with …
…APISIX and the plugin authz-openfga, based on the article Mastering Access Control: Implementing Low-Code Authorization Based on ReBAC and the Decoupling Pattern.
- Loading branch information
Showing
17 changed files
with
2,257 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
KC_VERSION=25.0.1 | ||
OPENFGA_VERSION=v1.5.5 | ||
|
||
AM_INTERNAL_URL=http://keycloak:8080 | ||
OPENFGA_HOST=http://openfga:8080 | ||
STORE_API=host.docker.internal:8091 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ echo "Creating PoC Users, Role Model, User Role Assigments and Clients" | |
|
||
# Clients | ||
/opt/keycloak/bin/kcadm.sh create clients -r master -s clientId=portal -s publicClient=true -s 'redirectUris=["http://store:9090/callback"]' -s 'webOrigins=["http://store:9090"]' -s 'attributes={ "post.logout.redirect.uris": "http://store:9090/home?action=logout", "access.token.lifespan": 3600}' -o | ||
/opt/keycloak/bin/kcadm.sh create clients -r master -s clientId=apisix -s 'redirectUris=["http://localhost:9980/callback"]' -s 'secret=jnxDqhu0GTaCCWuKxodUnSdKzEIBquKT' -o | ||
|
||
# Users | ||
/opt/keycloak/bin/kcadm.sh create users -r master -s username=paula -s firstName=Paula -s lastName=Von -s enabled=true -s [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM node:16.0.0 | ||
# FROM --platform=linux/amd64 node:16.0.0 | ||
LABEL maintainer="[email protected]" | ||
|
||
WORKDIR /app | ||
COPY package*.json ./ | ||
RUN npm install | ||
COPY . . | ||
|
||
CMD [ "npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: Products API | ||
description: 'API Products (secured using OAuth) protected by ReBAC (Zanzibar)' | ||
version: 1.0.0 | ||
servers: | ||
- url: http://localhost:9980/api/products | ||
tags: | ||
- name: Product | ||
description: Operations about identity and access platform | ||
paths: | ||
/products: | ||
get: | ||
tags: | ||
- Product | ||
summary: Get products | ||
security: [] | ||
x-apisix-plugins: | ||
authz-rebac: | ||
object_type: role | ||
object: products-view | ||
responses: | ||
401: | ||
$ref: '#/components/responses/UnauthorizedError' | ||
200: | ||
description: successful operation | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/Product' | ||
/product: | ||
post: | ||
tags: | ||
- Product | ||
summary: "Add a new product" | ||
security: [] | ||
x-apisix-plugins: | ||
authz-rebac: | ||
object_type: role | ||
object: products-editor | ||
requestBody: | ||
description: Information about a new user in the system | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Product" | ||
responses: | ||
"405": | ||
description: "Invalid input" | ||
"201": | ||
description: Created | ||
put: | ||
tags: | ||
- Product | ||
summary: Update an existing product | ||
description: Update an existing product by Id | ||
x-apisix-plugins: | ||
authz-rebac: | ||
object_type: role | ||
object: products-editor | ||
requestBody: | ||
description: Update an existent product in the store | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Product' | ||
required: true | ||
responses: | ||
'200': | ||
description: Successful operation | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Product' | ||
'400': | ||
description: Invalid ID supplied | ||
'404': | ||
description: Product not found | ||
'/product/{product_id}': | ||
delete: | ||
tags: | ||
- Product | ||
summary: "Delete a product" | ||
x-apisix-plugins: | ||
authz-rebac: | ||
object_type: role | ||
object: products-editor | ||
responses: | ||
"200": | ||
description: Created | ||
parameters: | ||
- schema: | ||
type: integer | ||
name: product_id | ||
in: path | ||
required: true | ||
components: | ||
responses: | ||
UnauthorizedError: | ||
description: Access token is missing or invalid | ||
schemas: | ||
Product: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
name: | ||
type: string | ||
xml: | ||
name: User | ||
securitySchemes: | ||
bearerOAuth: | ||
type: http | ||
scheme: bearer | ||
bearerFormat: JWT |
Oops, something went wrong.