Code Monkey home page Code Monkey logo

keycloak-apb's Introduction

Keycloak APB

Build Status License

keycloak image

Overview

This APB aims to deploy Keycloak on OpenShift and allow any application to provide Single Sign-On capabilities. In case an existing Keycloak instance exists somewhere else (even outside of OpenShift) this APB will allow configuring applications to connect to it.

For an overview of what each task does, please check the APB overview file.

Requirements

Usage

NOTE: Make sure your Ansible Service Broker is running with the property launch_apb_on_bind: true

In the Openshift control panel, find and select the Keycloak (APB) and fill in the required fields.

Plans

Common configuration

  • admin_username: Name of the username that will have the administrator role in Keycloak
  • admin_password: Password to authenticate the administrator user
  • keycloak_uri: URL accessible from the browser where the client application should redirect users for authentication. This URL should also be reachable from the application pod as it will be used to validate the token.
  • keycloak_users: Pre-provisioned users and role bindings
  • keycloak_roles: Pre-provisioned roles

Ephemeral

Allows you to deploy a Keycloak server with a pre-provisioned Realm with the name of the namespace. No persistence is configured, therefore once the application is restarted, all the provisioned data will be lost. Not suitable for production

Persistent

Allows you to deploy a Keycloak server with a pre-provisioned Realm with the name of the namespace. A Postgresql instance will also be deployed and configured so that configuration is not lost upon restarts.

Additional variable:

  • pvc_size: Size of the Persistent Volume Claim that will be created

External

An existing instance of Keycloak can be used for authentication/authorization. This plan will create the Realm during provisioning so that future bindings can create the clients.

Pre-provision users and roles

Users example:

  {
      "username" : "kermit",
      "enabled": true,
      "email" : "kermit@example",
      "firstName": "Kermit",
      "lastName": "The Frog",
      "credentials" : [
          { "type" : "password",
            "value" : "piggy" }
      ],
      "realmRoles": [ "user", "admin" ]
  },
  {
      "username" : "gonzo",
      "enabled": true,
      "email" : "gonzo@example",
      "firstName": "Gonzo",
      "lastName": "The Great",
      "credentials" : [
          { "type" : "password",
            "value" : "camilla" }
      ],
      "realmRoles": [ "user" ]
  }

Roles example:

 {
    "name": "user",
    "description": "User privileges"
  },
  {
    "name": "admin",
    "description": "Administrator privileges"
  }

Bind an application

After provisioning Keycloak and deploying an application bindings shall be created in order to provide the application with the required environment variables or files (depending on the type of the binding).

In order to create a binding, the following variables must be provided:

  • Provision variables: Used to create the client in Keycloak
    • service_name: Name of the service that will be created in order to include it in the auth redirection.
    • redirect_uris: URL to which redirect upon authentication.
    • web_origins: Allowed CORS origins. To permit all origins of Valid Redirect URIs add '+'. To permit all origins add '*'.
  • Binding varaibles: Used to create the secret that will be bound to the application
    • sso_url_name: Name of the variable that will be used to refer to the Keycloak endpoint
    • sso_realm_name: Name of the variable that will be used to refer to the Keycloak realm
    • sso_client_name: Name of the variable that will be used to refer to the Keycloak client

After the binding is created, the following variables are defined:

  • SSO_URL: Keycloak URL
  • SSO_REALM: Name of the realm within Keycloak. i.e. the namespace
  • SSO_CLIENT: Name of the client provisioned. i.e. namespace-application_name

With this, the secret can be added to an application as environment variables or as a volume.

Testing

An example application can be deployed as follows:

$ oc new-app https://raw.githubusercontent.com/ruromero/quickstarts/master/springboot-keycloak/springboot-keycloak-template.yaml

Once deployed, it won't become ready as the readinessProbe will fail. It will be required to create the binding providing the redirect uri and service name.

E.g. http://springboot-myproject.example.com/* and springboot

Finally, after the secret is created, you will be able to Add to application as environment variables. This change triggers a new deployment and it will be possible to navigate to / for the public URL and to /private where the authentication page is prompted.

For more information about the test application check springboot-keycloak quickstart

For more information about testing of APBs, check ansible-playbook-bundle documentation.

keycloak-apb's People

Contributors

djzager avatar philbrookes avatar ruromero avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

keycloak-apb's Issues

provisioning error on openshift v3.9

when i provision the keycloack i get the error The service failed. Provision call failed: Error occurred during provision. Please contact administrator if it persists.
A pod that is automatically created is exiting with the error

DEPRECATED: APB playbooks should be stored at /opt/apb/project
cp: omitting directory ‘/opt/apb/actions/vars’
ERROR! vars file vars/common.yml was not found on the Ansible Controller.
If you are using a module and expect the file to exist on the remote, see the remote_src option

Undefined variable - apb_external_keycloak_uri

I have searched the project for this variable and I cannot find it. Maybe the latest image hasn't been built with what has been merged in the repo?

cc: @ruromero

From Pod:

        docker://54cf23fa7b58f1014626a29b0671cf1ca0f913f8f244f05e0c54d23306078914
      image: 'docker.io/ansibleplaybookbundle/keycloak-apb:latest'
      imageID: >-
        docker-pullable://docker.io/ansibleplaybookbundle/keycloak-apb@sha256:bc32ceb0a915f9dd5fb38112f4da1c6c9bc85781c169e865cf4d80c7b318540b

Output:

TASK [provision-keycloak-apb : Encode provision credentials] *******************
--
  | fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {{ apb_external_keycloak_uri }}: 'apb_external_keycloak_uri' is undefined\n\nThe error appears to have been in '/opt/ansible/roles/provision-keycloak-apb/tasks/provision-keycloak.yml': line 39, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# New encoding task makes admin credentials available to future bind operations\n- name: Encode provision credentials\n  ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: {{ apb_external_keycloak_uri }}: 'apb_external_keycloak_uri' is undefined"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.