diff --git a/README.md b/README.md index 73fb4da..c3e7f22 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,7 @@ To streamline your setup, it is suggested to have Docker installed on your local To deploy on Kubernetes, read the [Kubernetes example](https://github.com/1Password/scim-examples/tree/master/kubernetes) -To deploy with Docker Swarm, read the [Docker Swarm example](https://github.com/1Password/scim-examples/tree/master/docker-swarm) - -To deploy with Docker Compose, read the [Docker Compose example](https://github.com/1Password/scim-examples/tree/master/docker-compose) +To deploy with Docker, read the [Docker example](https://github.com/1Password/scim-examples/tree/master/docker) To deploy with AWS and Terraform, read the [AWS and Terraform example](https://github.com/1Password/scim-examples/tree/master/aws-terraform) diff --git a/docker-compose/README.md b/docker-compose/README.md deleted file mode 100644 index c36b749..0000000 --- a/docker-compose/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Deploying the 1Password SCIM Bridge using Docker Compose - -This example describes the simplest method of deploying the 1Password SCIM bridge, using Docker Compose. These instructions require a remote Docker host be set up and configured to be accessed by the Docker CLI. - -Note that this deployment strategy is very useful for testing, but it is not reccomended for use in a production environment. The scimsession file is passed into the container via an environment variable, which is less secure than Docker Swarm secrets or Kubernetes secrets, both of which are supported, and reccomended. - -## Create your DNS record - -The 1Password SCIM bridge requires SSL/TLS in order to communicate with your IdP. You must create a DNS record that points to your Docker node. _Do not attempt to perform a provisioning sync before the DNS records have been propogated_. The record must exist and the SCIM bridge server must be running in order for LetsEncrypt to issue a certificate. - -## Create your scimsession file - -Use the Linux Bash [scim-setup.sh](../session/scim-setup.sh) script or Windows PowerShell [create-session-file.bat](../session/create-session-file.bat) batch file while connected to the Docker host on your local machine to set up your account and generate a `scimsession` file. This script uses a Docker container to run the `op-scim setup` command and writes the scimsession file back to your local machine using a mounted volume. Your bearer token will be printed to the console. Save your bearer token, as it will be needed to authenticate with your IdP. - -The scimsession file is equivalent to your Master Password and Secret Key when combined with the bearer token, therefore they should never be stored in the same place. - -Example: -``` -scim-setup.sh -[account sign-in] -Bearer token: jafewnqrrupcnoiqj0829fe209fnsoudbf02efsdo -``` - -## Deploy the SCIM bridge - -Once your scimsession file has been created, copy it into this directory (next to docker-compose.yml), as we need to populate some ENV variables in the container. Linux Bash `generate-env.sh` script or Windows PowerShell `generate-env.bat` batch file will create a `scim.env` file, allowing docker-compose to pass the scimsession file into the container without writing it to the container filesystem, leading to insecure storage of the file. The scimsession is base64 encoded before being put into the .env file. - -Next, edit `docker-compose.yml`, replacing `{YOUR-DOMAIN-HERE}` with the domain name indicated by the DNS record created for your SCIM bridge. This will configure LetsEncrypt to automatically issue a certificate for your bridge. - -Running `docker-compose up --build` will now create a container from the `1password/scim` image. A redis container will also be started automatically to be used by the SCIM bridge. _After the DNS record has been propogated_, you can continue setting up your IdP with the SCIM bridge Administration Guide while monitoring the logs from the bridge on your local machine. - -Once you have tested the configuration, the bridge can be exited using ctrl/cmd-c, and restarted in daemon mode using `docker-compose up -d, or deployed for production use with Docker Swarm or Kubernetes. You can access logs using `docker-compose logs` at any point in the future. - -## Automatically starting the SCIM bridge upon startup - -In order to automatically launch the 1Password SCIM bridge upon startup when using docker-compose you'll need to automatically start the Docker daemon, then start op-scim. - -### Systemd - -1. Install the service file for op-scim. A [sample](op-scim.service) is provided and you'll need to change the path. -2. Reload systemd: `systemctl daemon-reload` -3. Enable the op-scim service: `systemctl enable op-scim` - diff --git a/docker-swarm/README.md b/docker-swarm/README.md deleted file mode 100644 index 51ea996..0000000 --- a/docker-swarm/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Deploying the 1Password SCIM Bridge using Docker Swarm - -This example describes deploying the 1Password SCIM bridge using Docker Swarm. These instructions require a remote Docker Swarm cluster be set up and configured to be accessed by the Docker CLI. - -## Create your DNS record - -The 1Password SCIM bridge requires SSL/TLS in order to communicate with your IdP. You must create a DNS record that points to your Docker cluster. _Do not attempt to perform a provisioning sync before the DNS records have been propogated_. The record must exist and the SCIM bridge server must be running in order for LetsEncrypt to issue a certificate. - -## Create your scimsession file - -Use the [scim-setup.sh](https://github.com/1Password/scim-examples/tree/master/scim-setup.sh) script while connected to the Docker host on your local machine to set up your account and generate a `scimsession` file. This script uses a Docker container to run the `op-scim setup` command and writes the scimsession file back to your local machine using a mounted volume. Your bearer token will be printed to the console. Save your bearer token, as it will be needed to authenticate with your IdP. - -The scimsession file is equivalent to your Master Password and Secret Key when combined with the bearer token, therefore they should never be stored in the same place. - -Example: -``` -scim-setup.sh -[account sign-in] -Bearer token: jafewnqrrupcnoiqj0829fe209fnsoudbf02efsdo -``` - -## Deploy the SCIM bridge - -Once your scimsession file has been created, copy it into this directory (next to docker-compose.yml), as we need to populate a Docker Swarm secret in order to securely deploy your scimsession. `generate-secret.sh` will create a secret called `scimsession`, which the op-scim container will then read from `/run/secrets`, as defined in docker-compose.yml. - -Next, edit `docker-compose.yml`, replacing `{YOUR-DOMAIN-HERE}` with the domain name indicated by the DNS record created for your SCIM bridge. This will configure LetsEncrypt to automatically issue a certificate for your bridge. - -Running `docker stack deploy -c docker-compose.yml op-scim` will now create a container from the `1password/scim` image. A redis container will also be started automatically to be used by the SCIM bridge. _After the DNS record has been propogated_, you can continue setting up your IdP with the SCIM bridge Administration Guide while monitoring the logs from the bridge on your local machine using `docker service logs -f op-scim_scim`. \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..4ac59bc --- /dev/null +++ b/docker/README.md @@ -0,0 +1,67 @@ +# Deploying the 1Password SCIM Bridge using Docker + +This example describes the methods of deploying the 1Password SCIM bridge using Docker. The Docker Compose and Docker Swarm managers are available and deployment using each manager is described below. + +## Docker Compose + +This is the simplest method of deploying the SCIM bridge. These instructions require a remote Docker host be set up and configured to be accessed by the Docker CLI. _Please refer to your cloud provider on how to setup a remote Docker host if you do not have one set up already or are experiencing difficulties doing so._ + +**Note that the Docker Compose strategy is very useful for testing, but it is not recommended for use in a production environment. The scimsession file is passed into the docker container via an environment variable, which is less secure than Docker Swarm secrets or Kubernetes secrets, both of which are supported, and recommended.** + +## Docker Swarm + +These instructions require a remote Docker Swarm cluster be set up and configured to be accessed by the Docker CLI. _Please refer to your cloud provider on how to setup a remote Docker Swarm Cluster if you do not have one set up already or are experiencing difficulties doing so._ + +## 1: Clone this repository + +To make this process easier, it is recommended to clone this repository to have easy access to scripts and configuration files. + +## 2: Install Docker locally + +Install [Docker for Desktop](https://www.docker.com/products/docker-desktop) on your local machine and _start Docker_ before continuing, as it will be needed to run the setup process + +## 3: Create your DNS record + +The 1Password SCIM bridge requires SSL/TLS in order to communicate with your IdP. In order to use TLS, you must create a DNS record that points to your Docker node. _Do not attempt to perform a provisioning sync before the DNS records have been propogated_. The DNS record must exist and the SCIM bridge server must be running if you wish to have LetsEncrypt automatically issue a TLS certificate for your SCIM bridge. _Please refer to your cloud provider on how to setup a DNS record if you do not have one set up already or are experiencing difficulties doing so._ + +## 4: Create your scimsession file and Deploy SCIM bridge + +1. Connect to your remote Docker host from your local machine + - Either connect using [docker-machine](https://docs.docker.com/machine/), OR use SSH to access your remote maching and clone this repo. + +2. In your terminal, use the bash script [./scim-setup.sh](../session/scim-setup.sh) to authenticate your account and generate a `scimsession` file : This script uses a Docker container to run the `op-scim setup` command and writes the scimsession file back to your local machine using a mounted volume. Your bearer token will be printed to the console. **Save your bearer token, as it will be needed to authenticate with your IdP**. + +_The scimsession file is equivalent to your Master Password and Secret Key when combined with the bearer token, therefore they should never be stored in the same place._ + +Example: +``` +> cd [location of cloned scim-examples folder] +> ./scim-setup.sh + +[interactive script] +Bearer token: jafewnqrrupcnoiqj0829fe209fnsoudbf02efsdo + +> ./docker/deploy.sh +``` + +3. Once your scimsession file has been created, use the bash script `./docker/deploy.sh` to deploy the SCIM bridge. _Have the domain name indicated by the DNS record created for the SCIM bridge ready_. This script will do the following : + + 1. Ask if you want to deploy with Docker Swarm or Compose + + 1. For `docker-compose`, it will generate a `scim.env` file that allows the scimsession file to be passed into the container without insecurely writing it to the container filesystem. For `docker-swarm`, it will create a secret called `scimsession`, which the op-scim container will then read from `/run/secrets`, as defined in docker-compose.yml. + + 1. You will be prompted for your SCIM bridge domain name which will configure LetsEncrypt to automatically issue a certificate for your bridge. + + 1. Lastly, it will deploy a container from the `1password/scim` image. A redis container will also be started automatically to be used by the SCIM bridge. + +The logs from the SCIM bridge and redis containers will be streamed to your machine. When you are done, press ctrl+c to stop the logs, and the containers will remain running on the remote machine. + +_After the DNS record has been propogated_, you can continue setting up your IdP with the SCIM bridge Administration Guide while monitoring the logs from the bridge on your local machine. + +### Systemd + +In order to automatically launch the 1Password SCIM bridge upon startup when using **docker-compose**, you will need to configure systemd to automatically start the Docker daemon and launch op-scim. + +1. Install the service file for op-scim. A [sample](op-scim.service) is provided and you'll need to change the path. +2. Reload systemd: `systemctl daemon-reload` +3. Enable the op-scim service: `systemctl enable op-scim` diff --git a/docker-compose/docker-compose.yml b/docker/compose/docker-compose.yml similarity index 100% rename from docker-compose/docker-compose.yml rename to docker/compose/docker-compose.yml diff --git a/docker-compose/generate-env.bat b/docker/compose/generate-env.bat similarity index 100% rename from docker-compose/generate-env.bat rename to docker/compose/generate-env.bat diff --git a/docker-compose/generate-env.sh b/docker/compose/generate-env.sh similarity index 88% rename from docker-compose/generate-env.sh rename to docker/compose/generate-env.sh index a6220aa..511f6b2 100755 --- a/docker-compose/generate-env.sh +++ b/docker/compose/generate-env.sh @@ -5,4 +5,4 @@ SESSION=$(cat scimsession | base64 | tr -d "\n") -echo "OPSCIM_SESSION=$SESSION" > scim.env \ No newline at end of file +echo "OP_SESSION=$SESSION" > scim.env \ No newline at end of file diff --git a/docker-compose/op-scim.service b/docker/compose/op-scim.service similarity index 100% rename from docker-compose/op-scim.service rename to docker/compose/op-scim.service diff --git a/docker/deploy.sh b/docker/deploy.sh new file mode 100755 index 0000000..f68e9df --- /dev/null +++ b/docker/deploy.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +echo "Initiating 1Password SCIM Bridge Deployment" + +run_docker_compose() { + mv ./scimsession ./docker/compose/scimsession + + set -e # if the scimsession is already in ^, don't fail + + cd docker/compose + ./generate-env.sh + mv ./scimsession ../../ + + read -p 'Please enter your domain name : ' domain_name + + sed -i '' s/{YOUR-DOMAIN-HERE}/$domain_name/g docker-compose.yml + + docker-compose up --build -d + sed -i '' s/$domain_name/{YOUR-DOMAIN-HERE}/g docker-compose.yml + + docker-compose logs -f +} + +run_docker_swarm(){ + mv ./scimsession ./docker/swarm/scimsession + cd docker/swarm + ./generate-secret.sh + + set -e # if the secret already exists, don't fail + + mv ./scimsession ../../ + + read -p 'Please enter your domain name : ' domain_name + + sed -i '' s/{YOUR-DOMAIN-HERE}/$domain_name/g docker-compose.yml + + docker stack deploy -c docker-compose.yml op-scim + sed -i '' s/$domain_name/{YOUR-DOMAIN-HERE}/g docker-compose.yml + + docker service logs --raw -f op-scim_scim +} + +read -p 'Please enter the configuration you are using [compose] or [swarm] : ' docker_path + +if [ "$docker_path" == "compose" ]; +then + run_docker_compose +elif [ "$docker_path" == "swarm" ] +then + run_docker_swarm +else + echo "Invalid docker manager. Please use docker-compose or docker-swarm" + exit +fi diff --git a/docker-swarm/docker-compose.yml b/docker/swarm/docker-compose.yml similarity index 97% rename from docker-swarm/docker-compose.yml rename to docker/swarm/docker-compose.yml index 002d81f..389efae 100644 --- a/docker-swarm/docker-compose.yml +++ b/docker/swarm/docker-compose.yml @@ -29,4 +29,4 @@ networks: secrets: scimsession: - external: true \ No newline at end of file + external: true diff --git a/docker-swarm/generate-secret.sh b/docker/swarm/generate-secret.sh similarity index 100% rename from docker-swarm/generate-secret.sh rename to docker/swarm/generate-secret.sh