Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apisix/plugins/authz-keycloak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ local schema = {
cache_ttl_seconds = {type = "integer", minimum = 1, default = 24 * 60 * 60},
keepalive = {type = "boolean", default = true},
keepalive_timeout = {type = "integer", minimum = 1000, default = 60000},
keepalive_pool = {type = "integer", minimum = 1, default = 5}
},
keepalive_pool = {type = "integer", minimum = 1, default = 5},
access_token_expires_in = {type = "integer", minimum = 1, default = 300},
access_token_expires_leeway = {type = "integer", minimum = 0, default = 0},
refresh_token_expires_in = {type = "integer", minimum = 1, default = 3600},
refresh_token_expires_leeway = {type = "integer", minimum = 0, default = 0},

},
allOf = {
-- Require discovery or token endpoint.
{
Expand Down
4 changes: 4 additions & 0 deletions docs/en/latest/plugins/authz-keycloak.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ For more information on Keycloak, refer to [Keycloak Authorization Docs](https:/
| lazy_load_paths | boolean | optional | false | | Dynamically resolve the request URI to resource(s) using the resource registration endpoint instead of using the static permission. |
| http_method_as_scope | boolean | optional | false | | Map HTTP request type to scope of same name and add to all permissions requested. |
| timeout | integer | optional | 3000 | [1000, ...] | Timeout(ms) for the http connection with the Identity Server. |
| access_token_expires_in | integer | optional | 300 | [1, ...] | The expiration time of the access token |
| access_token_expires_leeway | integer | optional | 0 | [0, ...] | Expiration leeway for access_token renewal. If this is set, renewal will happen access_token_expires_leeway seconds before the token expiration. This avoids errors in case the access_token just expires when arriving to the OAuth Resource Server.|
| refresh_token_expires_in | integer | optional | 3600 | [1, ...] | The expiration time of the refresh token |
| refresh_token_expires_leeway | integer | optional | 0 | [0, ...] | Expiration leeway for refresh_token renewal. If this is set, renewal will happen refresh_token_expires_leeway seconds before the token expiration. This avoids errors in case the refresh_token just expires when arriving to the OAuth Resource Server.|
| ssl_verify | boolean | optional | true | | Verify if TLS certificate matches hostname. |
| cache_ttl_seconds | integer | optional | 86400 (equivalent to 24h) | positive integer >= 1 | The maximum period in seconds up to which the plugin caches discovery documents and tokens, used by the plugin to authenticate to Keycloak. |
| keepalive | boolean | optional | true | | Enable HTTP keep-alive to keep connections open after use. Set to `true` if you expect a lot of requests to Keycloak. |
Expand Down
25 changes: 15 additions & 10 deletions docs/zh/latest/plugins/authz-keycloak.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ title: authz-keycloak

## 属性

| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| ----------------------- | ------------- | ------ | ----------- | --------------------------- | ----------------------------------------------------------------------------------------------- |
| token_endpoint | string | 必须 | | [1, 4096] | 接受 OAuth2 兼容 token 的接口,需要支持 `urn:ietf:params:oauth:grant-type:uma-ticket` 授权类型 |
| grant_type | string | 可选 | "urn:ietf:params:oauth:grant-type:uma-ticket" | ["urn:ietf:params:oauth:grant-type:uma-ticket"] | |
| audience | string | 可选 | | | 客户端应用访问相应的资源服务器时所需提供的身份信息。当 permissions 参数有值时这个参数是必填的。 |
| permissions | array[string] | 可选 | | | 描述客户端应用所需访问的资源和权限范围的字符串。格式必须为:`RESOURCE_ID#SCOPE_ID` |
| timeout | integer | 可选 | 3000 | [1000, ...] | 与身份认证服务器的 http 连接的超时时间 |
| ssl_verify | boolean | 可选 | true | | 验证 SSL 证书与主机名是否匹配 |
| policy_enforcement_mode | string | 可选 | "ENFORCING" | ["ENFORCING", "PERMISSIVE"] | |
| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| ----------------------- | ------------- | ------ | ----------- | --------------------------- | ----------------------------------------------------------------------------------------------- |
| token_endpoint | string | 必须 | | [1, 4096] | 接受 OAuth2 兼容 token 的接口,需要支持 `urn:ietf:params:oauth:grant-type:uma-ticket` 授权类型 |
| grant_type | string | 可选 | "urn:ietf:params:oauth:grant-type:uma-ticket" | ["urn:ietf:params:oauth:grant-type:uma-ticket"] | |
| audience | string | 可选 | | | 客户端应用访问相应的资源服务器时所需提供的身份信息。当 permissions 参数有值时这个参数是必填的。 |
| permissions | array[string] | 可选 | | | 描述客户端应用所需访问的资源和权限范围的字符串。格式必须为:`RESOURCE_ID#SCOPE_ID` |
| timeout | integer | 可选 | 3000 | [1000, ...] | 与身份认证服务器的 http 连接的超时时间 |
| access_token_expires_in | integer | 可选 | 300 | [1, ...] | access token的过期时间
| access_token_expires_leeway | integer | 可选 | 0 | [0, ...] | access token提前到期时间(如果设置了此值,允许在该时间段内使用相同的access token令牌来解决潜在的网络并发问题) |
| refresh_token_expires_in | integer | 可选 | 3600 | [1, ...] | refresh token的过期时间 |
| refresh_token_expires_leeway| integer | 可选 | 0 | [0, ...] | refresh token提前更新时间(如果设置了此值,允许在该时间段内使用相同的refresh token令牌来解决潜在的网络并发问题) |
| ssl_verify | boolean | 可选 | true | [0, ...] | 验证 SSL 证书与主机名是否匹配 |
| policy_enforcement_mode | string | 可选 | "ENFORCING" | ["ENFORCING", "PERMISSIVE"] | |

### 策略执行模式

Expand Down Expand Up @@ -123,6 +127,7 @@ docker run -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=123456 -p 8090:8080 sshni

## 后续开发

- 目前 `authz-plugin` 仅支持通过定义资源名和访问权限范畴来应用 `route` 的访问策略。但是 Keycloak 官方适配的其他语言的客户端 (Java, JS) 还可以通过动态查询 Keycloak 路径以及懒加载身份资源的路径来支持路径匹配。未来版本的 `authz-plugin` 将会支持这项功能。
- 目前 `authz-plugin` 仅支持通过定义资源名和访问权限范畴来应用 `route` 的访问策略。但是 Keycloak 官方适配的其他语言的客户端 (Java, JS) 还可以通过动态查询 Keycloak
路径以及懒加载身份资源的路径来支持路径匹配。未来版本的 `authz-plugin` 将会支持这项功能。

- 支持从 Keycloak JSON 文件中读取权限范畴和其他配置项。
6 changes: 5 additions & 1 deletion t/plugin/authz-keycloak.t
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ done
cache_ttl_seconds = 1000,
keepalive = true,
keepalive_timeout = 10000,
keepalive_pool = 5
keepalive_pool = 5,
access_token_expires_in = 300,
access_token_expires_leeway = 0,
refresh_token_expires_in = 3600,
refresh_token_expires_leeway = 0,
})
if not ok then
ngx.say(err)
Expand Down