All Projects → banzaicloud → Jwt To Rbac

banzaicloud / Jwt To Rbac

Licence: apache-2.0
JWT-to-RBAC lets you automatically generate RBAC resources based on JWT tokens

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Jwt To Rbac

Dokit
基于 Spring Boot2、 Jpa、 Spring Security、JWT、redis、Vue的前后端分离的后台管理系统开发平台, 用户管理、菜单管理、角色管理、字典管理、权限控制的方式为RBAC,操作日志、异常日志、接口限流、项目支持数据权限管理,支持一键生成前后端代码(支持在线预览及打包下载),支持前端菜单动态路由 可一键部署服务器应用,数据库。系统中活跃用户状态监控,监视当前系统CPU、内存、磁盘、堆栈等相关信息,基于Element UI在线表单设计及生成Vue代码。
Stars: ✭ 348 (+291.01%)
Mutual labels:  jwt, rbac
Caddy Auth Jwt
JWT Authorization Plugin for Caddy v2
Stars: ✭ 127 (+42.7%)
Mutual labels:  jwt, rbac
Gin Web
由gin + gorm + jwt + casbin组合实现的RBAC权限管理脚手架Golang版, 搭建完成即可快速、高效投入业务开发
Stars: ✭ 107 (+20.22%)
Mutual labels:  jwt, rbac
Microservices Platform
基于SpringBoot2.x、SpringCloud和SpringCloudAlibaba并采用前后端分离的企业级微服务多租户系统架构。并引入组件化的思想实现高内聚低耦合,项目代码简洁注释丰富上手容易,适合学习和企业中使用。真正实现了基于RBAC、jwt和oauth2的无状态统一权限认证的解决方案,面向互联网设计同时适合B端和C端用户,支持CI/CD多环境部署,并提供应用管理方便第三方系统接入;同时还集合各种微服务治理功能和监控功能。模块包括:企业级的认证系统、开发平台、应用监控、慢sql监控、统一日志、单点登录、Redis分布式高速缓存、配置中心、分布式任务调度、接口文档、代码生成等等。
Stars: ✭ 3,274 (+3578.65%)
Mutual labels:  jwt, rbac
Blog.core
💖 ASP.NET Core 6.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
Stars: ✭ 3,542 (+3879.78%)
Mutual labels:  jwt, rbac
Maxkey
MaxKey is Single Sign On(SSO) System,Leading-Edge Enterprise-Class open source IAM(Identity and Access management) product.
Stars: ✭ 274 (+207.87%)
Mutual labels:  jwt, rbac
Lazy Mock
一个快速生成后端模拟数据的懒人工具,支持代码生成器模板开发
Stars: ✭ 236 (+165.17%)
Mutual labels:  jwt, rbac
Go Admin
go web api,包含gin+gorm+jwt+rbac等。
Stars: ✭ 298 (+234.83%)
Mutual labels:  jwt, rbac
Spring Security Rbac Jwt
springboot2项目的脚手架工程(包含security + jwt方式的动态权限校验)
Stars: ✭ 21 (-76.4%)
Mutual labels:  jwt, rbac
Deno crud jwt
🦕 basic jwt implementation with CRUD operations using deno + postgres
Stars: ✭ 80 (-10.11%)
Mutual labels:  jwt
Angular Jwt
Library to help you work with JWTs on AngularJS
Stars: ✭ 1,264 (+1320.22%)
Mutual labels:  jwt
Nestjs Roles
Type safe roles guard and decorator made easy
Stars: ✭ 78 (-12.36%)
Mutual labels:  rbac
Python Jwt
JSON Web Token library for Python
Stars: ✭ 81 (-8.99%)
Mutual labels:  jwt
Sjwt
Simple JWT Golang
Stars: ✭ 86 (-3.37%)
Mutual labels:  jwt
Kikoeru Express
kikoeru 后端,不再维护,请到https://github.com/umonaca/kikoeru-express 获取更新
Stars: ✭ 79 (-11.24%)
Mutual labels:  jwt
Buddy Sign
High level message signing library.
Stars: ✭ 86 (-3.37%)
Mutual labels:  jwt
Laravel Vue Starter
Well Documented Laravel Starter App From Development to Production. For Full Blown RESTFUL API and SPA with Beautiful UI Using Buefy / ElementUi For Reusable Vue Components
Stars: ✭ 76 (-14.61%)
Mutual labels:  jwt
Express Jwt Authz
Validate the JWT scope to authorize access to an endpoint
Stars: ✭ 74 (-16.85%)
Mutual labels:  jwt
Aspnetcore Ddd
Full ASP.NET Core 3.1 LTS application with DDD, CQRS and Event Sourcing
Stars: ✭ 88 (-1.12%)
Mutual labels:  jwt
Spring Boot Jwt Demo
Simplest jwt demo with only 3 classes. Simple but product-level .
Stars: ✭ 86 (-3.37%)
Mutual labels:  jwt

CircleCI Go Report Card Docker Automated build

JWT-to-RBAC

JWT-to-RBAC lets you automatically generate RBAC resources based on JWT token.

Context

For authentication we use Dex with the LDAP and GitHub connectors. The users in LDAP have group memberships, GitHub users can be members of a team in an organization and Dex issues a JWT token containing these memberships. The JWT-to-RBAC project can create ServiceAccount, ClusterRoles and ClusterroleBindings based on JWT tokens. When we create a new ServiceAccount K8s automatically generates a service account token.

For more information and context please read the Provider agnostic authentication and authorization in Kubernetes post.

JWT-to-RBAC is a core part of Banzai Cloud Pipeline, a Cloud Native application and devops platform that natively supports multi- and hybrid-cloud deployments with multiple authentication backends. Check out the developer beta:

Requirements:

There are some pre-requirements to kick this of for your own testing.

  • Configured Dex server as OIDC provider which issues JWT tokens. If you want to issue tokens with Dex you have to configure it with LDAP connector. You can use the Banzai Cloud Dex chart.
  • GitHub account assigned for an organization or configured LDAP server - you can use the openldap Docker image
  • Authentication application which uses Dex as an OpenID connector (in our case is Pipeline.

Dex acts as a shim between a client app and the upstream identity provider. The client only needs to understand OpenID Connect to query Dex.

The issued ID tokens must contain the following claims:

  • name: string
  • email: string
  • email_verified: bool
  • groups: list of strings
  • federated_claims: object

federated_claims must contain:

  • connector_id: string (github/ldal/local)
  • user_id: string

The whole process is broken down to two main parts:

  • Dex (OIDC) auth flow
  • jwt-to-rbac ServiceAccount creation flow

Dex authentication flow:

  1. User visits Authentication App.
  2. Authentication App redirects user to Dex with an OAuth2 request.
  3. Dex determines user's identity.
  4. Dex redirects user to Authentication App with a code.
  5. Authentication App exchanges code with Dex for an ID token.

jwt-to-rbac Flow:

  1. Authentication App has ID token (JWT)
  2. POST ID token to jwt-to-rbac App
  3. jwt-to-rbac validates ID token with Dex or other OIDC prvider
  4. jwt-to-rbac extracts username, groups and so on from the token
  5. jwt-to-rbac calls API server to crate ServiceAccount, ClusterRoles and ClusterRoleBindings
  6. jwt-to-rbac get service account token and sends it to Authentication App
  7. Authentication App sends back the service account token to User
  8. User authenticate on K8s using service account token

The ID token issued by Dex has a following content:

{
  "iss": "http://dex/dex",
  "sub": "CiNjbj1qYW5lLG91PVBlb3BsZSxkYz1leGFtcGxlLGRjPW9yZxIEbGRhcA",
  "aud": "example-app",
  "exp": 1549661603,
  "iat": 1549575203,
  "at_hash": "_L5EkeNocRsG7iuUG-pPpQ",
  "email": "[email protected]",
  "email_verified": true,
  "groups": [
    "admins",
    "developers"
  ],
  "name": "jane",
  "federated_claims": {
    "connector_id": "ldap",
    "user_id": "cn=jane,ou=People,dc=example,dc=org"
  }
}

After jwt-to-rbac extracts the information from the token, creates ServiceAccount and ClusterRoleBinding using one of the default K8s ClusterRole as roleRef or generate one defined in configuration if it does't exist.

Default K8s ClusterRoles used by jwt-to-rbac

The JWT-to-RBAC dos not create a new ClusterRole in every case; for example if a user is a member of admin group, it doesn't create this ClusterRole because K8s has already one by default.

Default ClusterRole Description
cluster-admin Allows super-user access to perform any action on any resource.
admin Allows admin access, intended to be granted within a namespace using a RoleBinding.
edit Allows read/write access to most objects in a namespace.
view Allows read-only access to see most objects in a namespace.

jwt-to-rbac crate custom ClusterRole defined in config

In most of the cases there are different LDAP groups, so custom groups can be configured with custom rules.

[[rbachandler.customGroups]]
groupName = "developers"
[[rbachandler.customGroups.customRules]]
verbs = [
  "get",
  "list"
]
resources = [
  "deployments",
  "replicasets",
  "pods"
]
apiGroups = [
  "",
  "extensions",
  "apps"
]

define GitHub custom roles in config

[[rbachandler.customGroups]]
groupName = "githubOrg-githubTeam"
[[rbachandler.customGroups.customRules]]
verbs = [
  "get",
  "list"
]
resources = [
  "deployments",
  "replicasets",
  "pods"
]
apiGroups = [
  "",
  "extensions",
  "apps"
]

or specify GitHub organization as default org

[rbachandler]
githubOrg = "github_organization"
[[rbachandler.customGroups]]
groupName = "githubTeam"
[[rbachandler.customGroups.customRules]]
verbs = [
  "get",
  "list"
]
resources = [
  "deployments",
  "replicasets",
  "pods"
]
apiGroups = [
  "",
  "extensions",
  "apps"
]

Example configuration in yaml using default GitHub org

issued jwt:

{
  "iss": "http://dex/dex",
  "sub": "xxxxxxxxxxxxxxxxxxxxx",
  "aud": "example-app",
  "exp": 1551179050,
  "iat": 1551092650,
  "at_hash": "xxxxxxxxxxxxxxxxxxx",
  "email": "[email protected]",
  "email_verified": true,
  "groups": [
    "pokeorg",
    "pokeorg:admin",
    "pokeorg:developer"
  ],
  "name": "Peter Balogh",
  "federated_claims": {
    "connector_id": "github",
    "user_id": "13311234"
  }
}

example config:

app:
  addr: ":5555"

log:
  level: "4"
  format: "json"
  noColor: true

tokenhandler:
  oidc:
    clientID: example-app
    issuerURL: "http://dex/dex"

rbachandler:
  githubOrg: "pokeorg"
  customGroups:
  - groupName: developer
    customRules:
    - verbs: [ "get", "list" ]
      resources: [ "deployments", "replicasets", "pods" ]
      apiGroups: [ "", "extensions", "apps" ]
    namespaces: ["example_namespace"] # Only if you want to isolate the customRules to some namespaces, if you want that the customRules to apply to all namespaces delete this hole line...
  kubeConfig: "/Users/poke/.kube/config"

Define custom CA cert or set insecure connection

[tokenhandler]
caCertPath = "/path/to/tls.crt"
insecure = false

Setting insecure conection in command line:

jwt-to-rbac --tokenhandler.insecure=true

So to conclude on the open source JWT-to-RBAC project - follow these stpes if you would like to try it or check it out already in action by subscribing to our free developer beta at https://beta.banzaicloud.io/.

1. Deploy jwt-to-rbac to Kubernetes

After you cloning the GitHub repository you can compile a code and make a docker image with one command.

make docker

If you are using docker-for-desktop or minikube, you'll be able to deploy it using locally with the newly built image.

kubectl create -f deploy/rbac.yaml
kubectl create -f deploy/configmap.yaml
kubectl create -f deploy/deployment.yaml
kubectl create -f deploy/service.yaml
# port-forward locally
kubectl port-forward svc/jwt-to-rbac 5555

Now you can communicate with the jwt-to-rbac app.

2. POST ID token issued by Oidc to jwt-to-rbac API

curl --request POST \
  --url http://localhost:5555/rbac/ \
  --header 'Content-Type: application/json' \
  --data '{"token": "example.jwt.token"}'

# response:
{
    "Email": "[email protected]",
    "Groups": [
        "admins",
        "developers"
    ],
    "FederatedClaims": {
        "connector_id": "ldap",
        "user_id": "cn=jane,ou=People,dc=example,dc=org"
    }
}

The ServiceAccount, ClusterRoles (if ID token has some defined custom groups we discussed) and ClusterRoleBindings are created.

Listing the created K8s resources:

curl --request GET \
  --url http://localhost:5555/rbac \
  --header 'Content-Type: application/json'

#response:
{
    "sa_list": [
        "janedoe-example-com"
    ],
    "crole_list": [
        "developers-from-jwt"
    ],
    "crolebind_list": [
        "janedoe-example-com-admin-binding",
        "janedoe-example-com-developers-from-jwt-binding"
    ]
}

3. GET the default K8s token of ServiceAccount

curl --request GET \
  --url http://localhost:5555/tokens/janedoe-example-com \
  --header 'Content-Type: application/json'

# response:
[
    {
        "name": "janedoe-example-com-token-m4gbj",
        "data": {
            "ca.crt": "example-ca-cer-base64",
            "namespace": "ZGVmYXVsdA==",
            "token": "example-k8s-sa-token-base64"
        }
    }
]

4. Generate a ServiceAccount token with TTL

curl --request POST \
  --url http://localhost:5555/tokens/janedoe-example-com \
  --header 'Content-Type: application/json'
  --data '{"duration": "12h30m"}'

# response:
[
    {
        "name": "janedoe-example-com-token-df3re",
        "data": {
            "ca.crt": "example-ca-cer-base64",
            "namespace": "ZGVmYXVsdA==",
            "token": "example-k8s-sa-token-with-ttl-base64"
        }
    }
]

Now you have a base64 encoded service account token.

5. Accessing with ServiceAccount token

You can use service account token from command line:

kubectl --token $TOKEN_TEST --server $APISERVER get po

Or create kubectl context with it:

export TOKEN=$(echo "example-k8s-sa-token-base64" | base64 -D)
kubectl config set-credentials "janedoe-example-com" --token=$TOKEN
# with kubectl config get-clusters you can get cluster name
kubectl config set-context "janedoe-example-com-context" --cluster="clustername" --user="janedoe-example-com" --namespace=default
kubectl config use-context janedoe-example-com-context
kubectl get pod

As a final note - since we use Dex, which is an identity service that uses OpenID Connect to drive authentication for other apps, any other supported connector can be used for authentication to Kubernetes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].