Coder Social home page Coder Social logo

okta-ssh-oauth-example's Introduction

DeviceFlowSSH

Change SSH login to use Okta Device Flow to authenticate instead of using the normal password.

This is a pluggable PAM module. It is tested on Ubuntu 20.04.2 LTS, may need tweaking on other platforms.

This login experience looks like the following screenshot:

device flow SSH screenshot

how to run

First we need to bypass the normal password authentication. In /etc/pam.d/sshd, find a line with @include common-auth, comment it out. Then, add auth required deviceflow.so, where deviceflow.so is a module that we will compile shortly. The file should look like this:

# @include common-auth    # Disable password authentication
auth       required     deviceflow.so   # Plug in our authentication module

Next, we need to make sure PAM modules are enabled. In /etc/ssh/sshd_config, we should change ChallengeResponseAuthentication no to ChallengeResponseAuthentication yes. Also, we need to make sure there is a line UsePAM yes. The file should look like this:

ChallengeResponseAuthentication yes
UsePAM yes

Compile and install deviceflow.so

deviceflow.so is the PAM module that handles authentication with Okta's Device Flow capability. Check the tutorial to make sure you have enabled Device Flow grant type on your authentication server. To compile this module, you need a few packages, install these in Ubuntu:

apt install build-essential libpam0g-dev libcurl4-openssl-dev libqrencode-dev libssl-dev -y

There are two source files.

  • deviceflow.c: This has all the logic to handle device flow and PAM interactions.
  • qr.c: This is used to generate ASCII QR code. It is borrowed from here (changed main function to turn it into a function call).

To compile:

gcc -fPIC -c deviceflow.c qr.c
sudo ld -x --shared -o /lib/security/deviceflow.so deviceflow.o qr.o -lm -lqrencode -lcurl -lssl -lcrypto

You need to restart sshd server for the change to take effect, e.g., /etc/init.d/ssh restart depending on your SSHD setup.

Experiment with Docker

Instead of messing around on a Ubuntu server, you can also try out the flow in a Docker container. The Dockerfile is included.

Build the docker image:

 docker build -t ubuntuwithdeviceflowssh .  

Run the docker image:

docker run -d -it -v ~/workspace/deviceflow/:/home/ubuntu -v ~/workspace/deviceflowsecurity/:/lib/security -p 1022:22  ubuntuwithdeviceflowssh

where ~/workspace/deviceflow contains the source files (this repo) locally, and ~/workspace/deviceflowsecurity/ is a directory to hold the compiled deviceflow.so file.

Then, you can login:

ssh test@localhost -p 1022

okta-ssh-oauth-example's People

Contributors

drhuanliu avatar

Stargazers

Owen Hael avatar

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.