Skip to content

Commit 72786be

Browse files
committed
Remove Auth0
1 parent 391b0e3 commit 72786be

File tree

6 files changed

+339
-389
lines changed

6 files changed

+339
-389
lines changed

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM quay.io/keycloak/keycloak:latest
2+
3+
ENV KC_DB=postgres
4+
5+
RUN /opt/keycloak/bin/kc.sh build

docker-compose.sample.yml

+42-53
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,31 @@ services:
55
image: ghcr.io/lighthousenotes/server:latest
66
container_name: lighthousenotes-server
77
links:
8-
- database
8+
- postgresql
99
- meilisearch
1010
- redis
11-
volumes:
12-
- ./BlinkBinaries:/app/BlinkBinaries
1311
environment:
1412
- AllowedHosts=*
15-
- Auth0__DOMAIN=example.auth0.com
16-
- Auth0__Audience=https://api.example.com
17-
- ConnectionStrings__Database=Host=database;Database=lighthousenotes;Username=lighthousenotes;Password=CHANGEME
13+
- Authentication__Authority=https://idp.example.com/realms/master
14+
- Authentication__Audience=account
15+
- ConnectionStrings__Database=Host=postgresql;Database=lighthousenotes;Username=lighthousenotes;Password=CHANGEME
1816
- ConnectionStrings__Redis=redis
1917
- Logging__LogLevel__Default=Warning
2018
- Logging__LogLevel__Microsoft.AspNetCore=Warning
2119
- Logging__LogLevel__Microsoft.Hosting.Lifetime=Warning
2220
- Sqids__MinLength=10
2321
- Sqids__Alphabet=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
24-
- Syncfusion__LicenseKey=CHANGEME
22+
- Minio__Endpoint=s3.example.com
23+
- Minio__BucketName=lighthousenotes
24+
- Minio__NetworkEncryption=true
25+
- Minio__AccessKey=CHAGEME
26+
- Minio__SecretKey=CHAGEME
27+
- Meilisearch__Url=http://meilisearch:7700
28+
- Meilisearch__Key=CHAGEME
2529
- Urls=http://server:6000
2630
- WebApp=https://app.example.com
2731
restart: unless-stopped
2832

29-
# Lighthouse Notes Web - Blazor web app for Lighthouse Notes
30-
web:
31-
image: ghcr.io/lighthousenotes/web:latest
32-
container_name: lighthousenotes-web
33-
links:
34-
- redis
35-
volumes:
36-
- ./lighthousenotes.pfx:/lighthousenotes.pfx
37-
environment:
38-
- AllowedHosts=*
39-
- ASPNETCORE_Kestrel__Certificates__Default__Path=/lighthousenotes.pfx
40-
- ASPNETCORE_Kestrel__Certificates__Default__Password=CHANGEME
41-
- Auth0__DOMAIN=example.auth0.com
42-
- Auth0__Auth__Audience=https://api.example.com
43-
- Auth0__Auth__ClientId=CHANGEME
44-
- Auth0__Auth__ClientSecret=CHANGEME
45-
- Auth0__Management__Audience=https://api.example.com
46-
- Auth0__Management__ClientId=CHANGEME
47-
- Auth0__Management__ClientSecret=CHANGEME
48-
- Auth0__Roles__user=CHANGEME
49-
- Auth0__Roles__sio=CHANGEME
50-
- Auth0__Roles__organization-administrator=CHANGEME
51-
- Auth0__ConnectionId=CHANGEME
52-
- ConnectionStrings__Redis=redis
53-
- Syncfusion__LicenseKey=CHANGEME
54-
- Logging__LogLevel__Default=Warning
55-
- Logging__LogLevel__Microsoft.AspNetCore=Warning
56-
- Urls=https://web:5000
57-
- LighthouseNotesApiUrl=https://api.example.com
58-
restart: unless-stopped
59-
6033
# Secure Web Application Gateway - Nginx & Let's Encrypt
6134
swag:
6235
image: lscr.io/linuxserver/swag:latest
@@ -72,26 +45,42 @@ services:
7245
- TZ=Europe/London
7346
- URL=example.com
7447
- VALIDATION=http
75-
- SUBDOMAINS=app,api,s3
48+
- SUBDOMAINS=api,idp,s3
7649
- ONLY_SUBDOMAINS=true
7750
volumes:
78-
- ./swag:/config
51+
- ./data/swag:/config
7952
ports:
8053
- 443:443
8154
- 80:80
8255
restart: unless-stopped
8356

57+
# Keycloak - Open Source Identity and Access Management For Modern Applications and Services
58+
keycloak:
59+
build:
60+
dockerfile: ./Dockerfile
61+
container_name: keycloak
62+
depends_on:
63+
- postgresql
64+
environment:
65+
- KC_DB=postgres
66+
- KC_DB_URL=jdbc:postgresql://postgresql/keycloak
67+
- KC_DB_USER=keycloak
68+
- KC_DB_PASSWORD=CHANGEME
69+
- KEYCLOAK_ADMIN=admin
70+
- KEYCLOAK_ADMIN_PASSWORD=CHANGEME
71+
- KC_HOSTNAME=example.com
72+
- KC_PROXY_HEADERS=xforwarded
73+
command: start --optimized
74+
restart: unless-stopped
75+
8476
# PostgreSQL Database - Open-source relational database
85-
database:
86-
image: postgres:14
87-
container_name: database
77+
postgresql:
78+
image: postgres
79+
container_name: postgresql
8880
volumes:
8981
- ./postgres:/var/lib/postgresql/data
9082
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
9183
environment:
92-
- POSTGRES_DB=lighthousenotes
93-
- POSTGRES_USER=lighthousenotes
94-
- POSTGRES_PASSWORD=CHANGEME
9584
- POSTGRES_ROOT_PASSWORD=CHANGEME
9685
restart: unless-stopped
9786

@@ -103,11 +92,11 @@ services:
10392
- 9000:9000
10493
- 9001:9001
10594
volumes:
106-
- ./minio:/data
107-
- ./swag/etc/letsencrypt/live/app.example.com/fullchain.pem:/root/.minio/certs/public.crt
108-
- ./swag/etc/letsencrypt/live/app.example.com/privkey.pem:/root/.minio/certs/private.key
109-
- ./swag/etc/letsencrypt/live/app.example.com/fullchain.pem:/root/.minio/certs/CAs/public.crt
110-
- ./swag/etc/letsencrypt/live/app.example.com/privkey.pem:/root/.minio/certs/CAs/private.key
95+
- ./data/minio:/data
96+
- ./data/swag/etc/letsencrypt/live/idp.example.com/fullchain.pem:/root/.minio/certs/public.crt
97+
- ./data/swag/etc/letsencrypt/live/idp.example.com/privkey.pem:/root/.minio/certs/private.key
98+
- ./data/swag/etc/letsencrypt/live/idp.example.com/fullchain.pem:/root/.minio/certs/CAs/public.crt
99+
- ./data/swag/etc/letsencrypt/live/idp.example.com/privkey.pem:/root/.minio/certs/CAs/private.key
111100
environment:
112101
- MINIO_SERVER_URL=https://s3.example.com:9000
113102
- MINIO_ROOT_USER=minio
@@ -120,7 +109,7 @@ services:
120109
image: redis
121110
container_name: redis
122111
volumes:
123-
- ./redis:/data
112+
- ./data/redis:/data
124113
command: ["redis-server"]
125114
healthcheck:
126115
test: ["CMD", "redis-cli", "ping"]
@@ -136,5 +125,5 @@ services:
136125
environment:
137126
- MEILI_MASTER_KEY=CHANGEME
138127
volumes:
139-
- ./data.ms:/data.ms
128+
- ./data/meilisearch:/data.ms
140129
restart: unless-stopped

gen.py

+52-98
Original file line numberDiff line numberDiff line change
@@ -52,70 +52,36 @@ def shuffled_alphabet():
5252
###############
5353
# User inputs #
5454
###############
55-
print("\nPlease enter the requested data at each prompt and press enter.\n")
55+
print("Please enter the requested data at each prompt and press enter.\n")
5656

5757
root_domain = input(f"Root domain (e.g., {COLOR_BLUE}example.com{COLOR_END}): ")
5858

59-
auth0_domain = input(f"Auth0 Domain (e.g., {COLOR_BLUE}example.auth0.com{COLOR_END}): ")
60-
auth0_audience = input(f"Auth0 Audience (e.g., {COLOR_BLUE}https://api.example.com{COLOR_END}): ")
59+
#############
60+
# Generated #
61+
#############
62+
# Database
63+
api_database_password = secrets.token_urlsafe(14)
64+
keycloak_database_password = secrets.token_urlsafe(14)
6165

62-
syncfusion_license_key = input (f"Syncfusion License Key {COLOR_YELLOW}(Get from: https://www.syncfusion.com/account/downloads){COLOR_END}: ")
63-
64-
certificate_password = getpass(f"Certificate Password {COLOR_GREEN}(input will not show){COLOR_END}: ")
65-
66-
database_password = secrets.token_urlsafe(14)
66+
# Meilisearch
67+
meilisearch_master_key = secrets.token_urlsafe(42)
6768

6869
##########
6970
# Server #
7071
##########
71-
# Auth0
72-
compose["services"]["server"]["environment"]["Auth0__DOMAIN"] = auth0_domain
73-
compose["services"]["server"]["environment"]["Auth0__Audience"] = auth0_audience
72+
# Authentication
73+
compose["services"]["server"]["environment"]["Authentication__Authority"] = f"https://idp.{root_domain}"
7474

7575
# Connection string
76-
compose["services"]["server"]["environment"]["ConnectionStrings__Database"] = f"Host=database;Database=lighthousenotes;Username=lighthousenotes;Password={database_password}"
76+
compose["services"]["server"]["environment"]["ConnectionStrings__Database"] = f"Host=postgresql;Database=lighthousenotes;Username=lighthousenotes;Password={api_database_password}"
7777

7878
# Sqids
7979
compose["services"]["server"]["environment"]["Sqids__Alphabet"] = shuffled_alphabet()
8080

81-
# Syncfusion
82-
compose["services"]["server"]["environment"]["Syncfusion__LicenseKey"] = syncfusion_license_key
83-
84-
# Web app
85-
compose["services"]["server"]["environment"]["WebApp"] = f"https://app.{root_domain}"
86-
87-
#######
88-
# Web #
89-
#######
90-
# Certificate
91-
compose["services"]["web"]["environment"]["ASPNETCORE_Kestrel__Certificates__Default__Password"] = certificate_password
92-
93-
# Auth0
94-
compose["services"]["web"]["environment"]["Auth0__DOMAIN"] = auth0_domain
95-
96-
# Auth0 Authentication
97-
compose["services"]["web"]["environment"]["Auth0__Auth__Audience"] = auth0_audience
98-
compose["services"]["web"]["environment"]["Auth0__Auth__ClientId"] = input(f"Authentication client ID {COLOR_YELLOW}(Dashboard > Applications > Applications > Lighthouse Notes){COLOR_END}: ")
99-
compose["services"]["web"]["environment"]["Auth0__Auth__ClientSecret"] = input(f"Authentication client secret {COLOR_YELLOW}(Dashboard > Applications > Applications > Lighthouse Notes){COLOR_END}: ")
100-
101-
# Auth0 Management
102-
compose["services"]["web"]["environment"]["Auth0__Management__Audience"] = auth0_audience
103-
compose["services"]["web"]["environment"]["Auth0__Management__ClientId"] = input(f"Management client ID {COLOR_YELLOW}(Dashboard > Applications > Applications > Lighthouse Notes M2M){COLOR_END}: ")
104-
compose["services"]["web"]["environment"]["Auth0__Management__ClientSecret"] = input(f"Management client secret {COLOR_YELLOW}(Dashboard > Applications > Applications > Lighthouse Notes M2M){COLOR_END}: ")
105-
106-
# Auth0 Role IDs
107-
compose["services"]["web"]["environment"]["Auth0__Roles__user"] = input(f"User role ID {COLOR_YELLOW}(Dashboard > User Management > Roles > user){COLOR_END}: ")
108-
compose["services"]["web"]["environment"]["Auth0__Roles__sio"] = input(f"SIO role ID {COLOR_YELLOW}(Dashboard > User Management > Roles > sio){COLOR_END}: ")
109-
compose["services"]["web"]["environment"]["Auth0__Roles__organization-administrator"] = input(f"Organization-administrator role ID {COLOR_YELLOW}(Dashboard > User Management > Roles > organization-administrator){COLOR_END}: ")
110-
111-
# Auth0 Connection ID
112-
compose["services"]["web"]["environment"]["Auth0__ConnectionId"] = input(f"Connection ID {COLOR_YELLOW}(Dashboard > Authentication > Database > Username-Password-Authentication){COLOR_END}: ")
113-
114-
# Syncfusion
115-
compose["services"]["web"]["environment"]["Syncfusion__LicenseKey"] = syncfusion_license_key
81+
# Minio
82+
compose["services"]["server"]["environment"]["Minio__Endpoint"] = f"https://s3.{root_domain}"
83+
compose["services"]["server"]["environment"]["Meilisearch__Key"] = meilisearch_master_key
11684

117-
# API Url
118-
compose["services"]["web"]["environment"]["LighthouseNotesApiUrl"] = f"https://api.{root_domain}"
11985

12086
########
12187
# SWAG #
@@ -125,17 +91,23 @@ def shuffled_alphabet():
12591
############
12692
# Postgres #
12793
############
128-
compose["services"]["database"]["environment"]["POSTGRES_PASSWORD"] = database_password
12994
compose["services"]["database"]["environment"]["POSTGRES_ROOT_PASSWORD"] = secrets.token_urlsafe(14)
13095

96+
############
97+
# Keycloak #
98+
############
99+
compose["services"]["keycloak"]["environment"]["KC_DB_PASSWORD"] = keycloak_database_password
100+
compose["services"]["keyclaok"]["environment"]["KC_HOSTNAME"] = f"https://idp.{root_domain}"
101+
compose["services"]["keyclaok"]["environment"]["KEYCLOAK_ADMIN"] = getpass(f"Keycloak admin password {COLOR_GREEN}(input will not show){COLOR_END}: ")
102+
131103
#########
132104
# Minio #
133105
#########
134106
# Certificate volumes
135-
compose["services"]["minio"]["volumes"][1] = f"./swag/etc/letsencrypt/live/app.{root_domain}/fullchain.pem:/root/.minio/certs/public.crt"
136-
compose["services"]["minio"]["volumes"][2] = f"./swag/etc/letsencrypt/live/app.{root_domain}/privkey.pem:/root/.minio/certs/private.key"
137-
compose["services"]["minio"]["volumes"][3] = f"./swag/etc/letsencrypt/live/app.{root_domain}/fullchain.pem:/root/.minio/certs/CAs/public.crt"
138-
compose["services"]["minio"]["volumes"][4] = f"./swag/etc/letsencrypt/live/app.{root_domain}/privkey.pem:/root/.minio/certs/CAs/private.key"
107+
compose["services"]["minio"]["volumes"][1] = f"./data/swag/etc/letsencrypt/live/api.{root_domain}/fullchain.pem:/root/.minio/certs/public.crt"
108+
compose["services"]["minio"]["volumes"][2] = f"./data/swag/etc/letsencrypt/live/api.{root_domain}/privkey.pem:/root/.minio/certs/private.key"
109+
compose["services"]["minio"]["volumes"][3] = f"./data/swag/etc/letsencrypt/live/api.{root_domain}/fullchain.pem:/root/.minio/certs/CAs/public.crt"
110+
compose["services"]["minio"]["volumes"][4] = f"./data/swag/etc/letsencrypt/live/api.{root_domain}/privkey.pem:/root/.minio/certs/CAs/private.key"
139111

140112

141113
compose["services"]["minio"]["environment"]["MINIO_SERVER_URL"] = f"https://s3.{root_domain}"
@@ -144,7 +116,6 @@ def shuffled_alphabet():
144116
###############
145117
# Meilisearch #
146118
###############
147-
meilisearch_master_key = secrets.token_urlsafe(42)
148119
compose["services"]["meilisearch"]["environment"]["MEILI_MASTER_KEY"] = meilisearch_master_key
149120

150121
###############################
@@ -181,58 +152,41 @@ def shuffled_alphabet():
181152
api_site_config.write(data)
182153
api_site_config.truncate()
183154

184-
185-
shutil.move(f'site-confs/app.example.com.conf', f'site-confs/app.{root_domain}.conf')
186-
with open(f'site-confs/app.{root_domain}.conf', 'r+') as app_site_config:
187-
data = app_site_config.read()
188-
app_site_config.seek(0)
155+
shutil.move(f'site-confs/idp.example.com.conf', f'site-confs/idp.{root_domain}.conf')
156+
with open(f'site-confs/idp.{root_domain}.conf', 'r+') as api_site_config:
157+
data = api_site_config.read()
158+
api_site_config.seek(0)
189159
data = data.replace('example.com', root_domain)
190-
app_site_config.write(data)
191-
app_site_config.truncate()
192-
160+
api_site_config.write(data)
161+
api_site_config.truncate()
193162

194163
#######
195164
# SQL #
196165
#######
197-
print("\nPlease enter the requested data at each prompt and press enter.")
198-
print("This information will be used to generate the SQL file which seeds the database.\n")
199-
# Organization
200-
organization_id = input(f"Organization ID {COLOR_YELLOW}(Dashboard > Organizations){COLOR_END}: ")
201-
organization_name = input(f"Organization Name {COLOR_YELLOW}(Dashboard > Organizations){COLOR_END}: ")
202-
organization_display_name = input(f"Organization Display Name {COLOR_YELLOW}(Dashboard > Organizations){COLOR_END}: ")
203-
204-
organization_sql = f"INSERT INTO \"Organization\" (\"Id\", \"Name\", \"DisplayName\", \"Created\", \"Modified\") VALUES ('{organization_id}', '{organization_name}', '{organization_display_name}', NOW(), NOW());"
205-
206-
# User
207-
user_id = input(f"User ID {COLOR_YELLOW}(Dashboard > User Management > Your Name){COLOR_END}: " )
208-
job_title = input(f"Job Title {COLOR_GREEN}(Can be changed later){COLOR_END}: ")
209-
given_name = input(f"Given Name {COLOR_GREEN}(Can be changed later){COLOR_END}: ")
210-
last_name = input(f"Last Name {COLOR_GREEN}(Can be changed later){COLOR_END}: ")
211-
email_address = input(f"Email Address {COLOR_GREEN}(Can be changed later){COLOR_END}: ") # Double check this
212-
profile_picture = input(f"Profile Picture URL: {COLOR_YELLOW}(Dashboard > User Management > Your Name > Identity Provider Attributes){COLOR_END}: ")
213-
214-
user_sql = f"INSERT INTO \"User\" (\"Auth0Id\", \"JobTitle\", \"DisplayName\", \"GivenName\", \"LastName\", \"EmailAddress\", \"ProfilePicture\", \"OrganizationId\", \"Created\", \"Modified\") VALUES ('{user_id}', '{job_title}', '{given_name} {last_name}', '{given_name}', '{last_name}', '{email_address}', '{profile_picture}', '{organization_id}', NOW(), NOW());\n"
215-
216-
# User roles
217-
user_roles_sql = """
218-
INSERT INTO "Role" ("Name", "UserId", "Created", "Modified") VALUES ('organization administrator', 1, NOW(), NOW());
219-
INSERT INTO "Role" ("Name", "UserId", "Created", "Modified") VALUES ('sio', 1, NOW(), NOW());
220-
INSERT INTO "Role" ("Name", "UserId", "Created", "Modified") VALUES ('user', 1, NOW(), NOW());
166+
keycloak_create_sql = f"""
167+
create database keycloak;
168+
create user keycloak with encrypted password '{keycloak_database_password}';
169+
grant all privileges on database keycloak to keycloak;
170+
ALTER DATABASE keycloak OWNER TO keycloak;
221171
"""
222172

223-
# User settings
224-
user_settings_sql = "INSERT INTO \"UserSettings\" (\"UserId\", \"TimeZone\", \"DateFormat\", \"TimeFormat\", \"Locale\", \"Created\", \"Modified\") VALUES (1, 'GMT Standard Time', 'dddd dd MMMM yyyy', 'HH:mm:ss', 'en-GB', NOW(), NOW());\n"
225173

226-
# Organization settings
227-
organization_settings_sql = f"INSERT INTO \"OrganizationSettings\" (\"OrganizationId\", \"S3Endpoint\", \"S3BucketName\", \"S3NetworkEncryption\", \"S3AccessKey\", \"S3SecretKey\", \"MeilisearchUrl\", \"MeilisearchApiKey\", \"Created\", \"Modified\") VALUES ('{organization_id}', 's3.{root_domain}:9000', 'lighthouse-notes', true, 'CHANGME', 'CHANGEME', 'http://meilisearch:7700', 'CHANGME', NOW(), NOW());\n"
174+
lighthousenotes_create_sql = f"""
175+
create database lighthousenotes;
176+
create user lighthousenotes with encrypted password '{api_database_password}';
177+
grant all privileges on database lighthousenotes to lighthousenotes;
178+
ALTER DATABASE lighthousenotes OWNER TO lighthousenotes;
179+
"""
180+
181+
with open('sample.init.sql', 'r') as sql_file:
182+
existing_content = sql_file.read()
228183

229-
with open(f'init.sql', 'a') as sql_file:
230-
sql_file.write(organization_sql)
231-
sql_file.write(user_sql)
232-
sql_file.write(user_roles_sql)
233-
sql_file.write(user_settings_sql)
234-
sql_file.write(organization_settings_sql)
184+
# Write new content followed by the existing content
185+
with open('init.sql', 'w') as sql_file:
186+
sql_file.write(keycloak_create_sql)
187+
sql_file.write(lighthousenotes_create_sql)
188+
sql_file.write(existing_content)
235189

236190
# Final
237191
print (f"Meilisearch API key is: {meilisearch_master_key}")
238-
print (f"\n{COLOR_GREEN}docker-compose.yml file, nginx configurations and initialization database script successfully created!{COLOR_END}\n")
192+
print (f"\n{COLOR_GREEN}docker-compose.yml file and NGINX configurations created!\n")

0 commit comments

Comments
 (0)