Skip to content

Commit 5b73d7d

Browse files
authored
Merge pull request #152 from browserstack/testing_manually
Adding docs for local setup
2 parents b52f7e3 + 308fdaf commit 5b73d7d

File tree

10 files changed

+159
-34
lines changed

10 files changed

+159
-34
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ RUN DEBIAN_FRONTEND=noninteractive \
1616
# Set env variables used in this Dockerfile (add a unique prefix, such as DEV)
1717
RUN apt update && apt install -y netcat dnsutils libmariadbclient-dev
1818

19+
RUN mkdir -p /ebs/logs && touch /ebs/logs/engima.log && chmod 777 /ebs/logs/engima.log
20+
1921
ARG APPUID=1001
2022
RUN useradd -rm -d /home/app -s /bin/bash -g root -G sudo -u "$APPUID" app
2123
WORKDIR /srv/code/dev
2224
RUN mkdir -p logs
23-
RUN chown -R app /srv/code/dev
25+
RUN chown -R app /srv/code/dev /ebs
2426
USER app
2527

2628

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ dev: setup_mounts
2424

2525
## make build : Build and start docker containers - (web and db)
2626
.PHONY: build
27+
build: export APPUID = $(APP_UID)
2728
build:
2829
@docker-compose up --build -d web
2930

31+
## make build_only : Only build the web container
32+
.PHONY: build_only
33+
build_only: export APPUID = $(APP_UID)
34+
build_only:
35+
@docker-compose build web
36+
3037
.PHONY: down
3138
down: export APPUID = $(APP_UID)
3239
down:
@@ -73,4 +80,4 @@ schema_validate:
7380
@echo $(shell python3 scripts/clone_access_modules.py && python3 scripts/validator.py)
7481

7582
run_semgrep:
76-
$(shell semgrep --error --config "p/cwe-top-25" --config "p/owasp-top-ten" --config "p/r2c-security-audit")
83+
$(shell semgrep --error --config "p/cwe-top-25" --config "p/r2c-security-audit")

README.md

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
1-
# enigma-public-central
2-
Central Codebase for access management tool
1+
## Enigma Access Management
32

4-
### For contributing code
3+
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
4+
5+
This tool consists of 2 different components: a central webserver and pluggable access modules.
6+
7+
This repo is the code-base for the central webserver.
8+
Refer to [this](https://github.com/browserstack/enigma-public-access-modules) for published access modules with this tool.
9+
10+
Refer to [this doc](/docs/%E2%80%9CHow-to%E2%80%9D%20guides/Adding%20Modules.md) on how to create custom access modules
11+
12+
## Usage
13+
14+
The following steps are for hosting Enigma locally from published docker container images.
15+
16+
For development setup, follow this [doc](/docs/one-click-dev.md)
17+
18+
### Pre-requisistes
19+
20+
You will need to have docker daemon running locally to run the published containers.
21+
If you don't have docker setup, follow the guidelines [here](https://docs.docker.com/get-docker/)
22+
23+
### Steps
24+
25+
1. Ensure you have a valid `config.json` present locally.
26+
27+
The default [config.json.sample](https://github.com/browserstack/enigma-public-central/blob/main/config.json.sample) should be sufficient to start.
28+
29+
You can then add module-specific configuration for the modules you want integrated with Enigma.
30+
For detailed instructions on configuration, follow [this doc](/docs/Configuration%20Guide.md)
31+
32+
2. Run the enigma docker container by mounting the downloaded config to the container
33+
34+
```bash
35+
docker run --rm --name enigma -p 8000:8000 -v "$(pwd)/config.json":/srv/code/dev/config.json browserstack/enigma:v1
36+
```
37+
38+
Ensure that you 8000 port is free to use, and ensure that path to config.json is correct.
39+
40+
That's it! Enigma should be running locally on port 8000
41+
42+
43+
For first time user sign-in, follow [this doc](/docs/%E2%80%9CHow-to%E2%80%9D%20guides/User%20Guides/First%20User%20Setup.md)
44+
45+
46+
## Contributing code
547

648
- Python 3.11.0
749
- pre-commit (see rules [below](#rules-enforced-by-the-pre-commit-hooks))
@@ -11,7 +53,7 @@ Central Codebase for access management tool
1153
- run: `pre-commit autoupdate`
1254
- run: `pre-commit run --all-files --show-diff-on-failure --color always`
1355

14-
## Commit Message Guideline
56+
### Commit Message Guideline
1557

1658
Format: `<type>(<scope>): <subject>`
1759

@@ -32,7 +74,7 @@ Format: `<type>(<scope>): <subject>`
3274
- `perf`: a code change that improves performance
3375
- `revert`: revert to a commit
3476

35-
## Example
77+
### Example
3678

3779
```
3880
feat: add hat wobble

config.json.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"django_setup": {
3-
"SECRET_KEY": "",
3+
"SECRET_KEY": "random_secret_that_you_should_change_on_production",
44
"DEBUG": false,
55
"ALLOWED_HOSTS": [
66
"localhost"

docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: '3'
22
services:
33
web:
44
container_name: dev
5+
image: browserstack/enigma:v1
56
build:
67
context: .
78
dockerfile: Dockerfile
@@ -19,9 +20,6 @@ services:
1920
- 8000:8000
2021
depends_on:
2122
- db
22-
command: >
23-
bash -c "echo Starting Django runserver;
24-
python manage.py runserver --insecure 0.0.0.0:8000"
2523
db:
2624
container_name: db
2725
image: mysql/mysql-server:8.0.31

docker-entrypoint.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
LOG_FILE=/ebs/logs/enigma.log
44
CONTAINER_HASH=$(echo $RANDOM | md5sum | head -c 20)
55

6+
trap ctrl_c INT
7+
8+
pid_to_kill=1
9+
should_continue=0
10+
11+
function ctrl_c() {
12+
echo "===== Stopping Service with pid $pid_to_kill ====="
13+
kill $pid_to_kill
14+
should_continue=1
15+
}
16+
617
function log() {
718
echo "$(date): $CONTAINER_HASH $@" 2>&1 | tee -a $LOG_FILE
819
}
@@ -34,4 +45,18 @@ log "===== Ensure Logs ====="
3445
touch /ebs/logs/enigma.log
3546

3647
log "===== Running Service ====="
37-
eval "$@" 2>&1 | prepend
48+
if [ "$#" -ne 0 ]; then
49+
eval "$@" 2>&1 | prepend
50+
else
51+
echo "===== Starting Webserver ====="
52+
python manage.py runserver --insecure 0.0.0.0:8000 2>&1 &
53+
pid_to_kill=$!
54+
echo "Server PID $pid_to_kill"
55+
56+
while true; do
57+
if [ "$should_continue" -ne 0 ]; then
58+
break
59+
fi
60+
sleep 5
61+
done
62+
fi

docs/“How-to” guides/Adding Modules.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This document describes how to add modules on Enigma.
1+
# How to add modules on Enigma.
22

33
Enigma’s access management is built on modules, which refer to the resources/applications the user requires.
44
Each module needs to be added and integrated with Enigma's central code in order to provide access for the user.
@@ -12,7 +12,10 @@ Enigma provides the following modules as part of its default settings, these can
1212
6. Slack
1313
7. Zoom
1414

15-
When a new resource is required, it's corresponding module has to be added in [Engima's modules repository](https://github.com/browserstack/enigma-public-access-modules.git) or it's own (as per the usecase):
15+
## Creating custom access modules
16+
17+
When a new resource is required, it's corresponding module has to be added in [Engima's modules repository](https://github.com/browserstack/enigma-public-access-modules.git) or a new dedicated repo (as per the usecase):
18+
1619
- Add `__init__.py`:
1720

1821
```bash
Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
This document describes how to add users on Enigma.
1+
# How to add users on Enigma
22

3-
## Create users on Enigma:
4-
1. Manual Creation:
3+
## Manual Creation
54

6-
To manually create a user, login as superuser into the admin portal:
5+
To manually create a user, login as superuser into the admin portal:
76

8-
(i) Add user in "Authentication and Authorization administration".
7+
- Add user in "Authentication and Authorization administration" section.
98

10-
``` Set email to user email id and password to anything you want. Save user details. ```
9+
Set email to user email id and password to anything you want. Save user details.
1110

12-
(ii) Add new user in "Access" and save.
11+
- Add new user in "Access" and save.
1312

14-
(iii) The user can now log on to Enigma using the credentials set in Step (i)
15-
2. Google SSO:
16-
### Add the config of googleapi in `config.json`
17-
```bash
18-
....
19-
"sso": {
20-
"googleapi": {
21-
"SOCIAL_AUTH_GOOGLE_OAUTH2_KEY": "<your_google_auth_key>",
22-
"SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET": "<your_google_auth_secret>"
23-
}
13+
- The user can now log on to Enigma using the credentials.
14+
15+
## Allow all users to sign-in with Google SSO
16+
17+
### Obtain google OAuth key and secret
18+
19+
Follow the steps [here](https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred) to generate `client_secret.json` file.
20+
21+
22+
The content of the file will have `client_id` key in `web` section. This is `SOCIAL_AUTH_GOOGLE_OAUTH2_KEY` in the below config.
23+
24+
25+
The value for `client_secret` in `web` section is for `SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET`.
26+
27+
### Add the config of googleapi in `config.json`
28+
29+
```bash
30+
....
31+
"sso": {
32+
"googleapi": {
33+
"SOCIAL_AUTH_GOOGLE_OAUTH2_KEY": "<your_google_auth_key>",
34+
"SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET": "<your_google_auth_secret>"
2435
}
25-
....
26-
```
36+
}
37+
....
38+
```
39+
2740
Sign in to enigma using your Google Mail to create a user on Enigma.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# First User Setup
2+
3+
To setup admin user on enigma, follow these steps:
4+
5+
1. Setup django superuser
6+
7+
- Exec into the Enigma container
8+
9+
```bash
10+
docker exec -it enigma bash
11+
```
12+
13+
- Run the following command in the container to create a superuser
14+
15+
```bash
16+
python manage.py createsuperuser
17+
```
18+
19+
- Fill in the `username`, `email` and `password` for admin user
20+
21+
Detailed instructions are available [here](https://docs.djangoproject.com/en/1.8/intro/tutorial02/#creating-an-admin-user)
22+
23+
2. Sign-in into the admin site
24+
25+
- Login to the admin site with the credentials created above.
26+
27+
The admin site should be available at `/admin` with the base url on which enigma is hosted.
28+
29+
This will be `http://localhost:8000/admin` if you are running this locally
30+
31+
3. Now you can view the Enigma app dashboard, by navigating to enigma url.
32+
33+
This will be `http://localhost:8000/` if you are running this locally
34+
35+
36+
To create additional users, follow the doc [here](/docs/%E2%80%9CHow-to%E2%80%9D%20guides/Managing%20Groups/Adding%20Users.md)

scripts/clone_access_modules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
if not os.path.exists(requirements_file):
3131
open(requirements_file, 'w').close()
3232

33-
print("All urls: %s" % (",".join(urls)))
3433
for url in urls:
3534
specified_branch = None
3635
if "#" in url:

0 commit comments

Comments
 (0)