Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(registry): fix auth in docker with http #630

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 88 additions & 87 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,92 @@
version: "2.4"
version: '2.4'
services:
registry:
image: namecheap/ilc_registry:latest
ports:
- "4001:4001"
environment:
NODE_ENV: production
DB_CLIENT: mysql
# DB_CLIENT: pg
DB_HOST: mysql
# DB_HOST: postgres
DB_USER: root
DB_PASSWORD: pwd
DB_NAME: ilc
depends_on:
mysql:
condition: service_healthy
# postgres:
# condition: service_healthy
registry_worker:
image: namecheap/ilc_registry:latest
command: ["npm", "run", "assetsdiscovery"]
environment:
NODE_ENV: production
DB_CLIENT: mysql
# DB_CLIENT: pg
DB_HOST: mysql
# DB_HOST: postgres
DB_USER: root
DB_PASSWORD: pwd
DB_NAME: ilc
network_mode: "service:ilc" # We need this to make apps accessible at 127.0.0.1
depends_on:
mysql:
condition: service_healthy
ilc:
image: namecheap/ilc:latest
restart: always
ports:
- "80:8233"
- "8233:8233"
- "8234-8240:8234-8240" # Ports from "demo-apps" container
environment:
NODE_ENV: production
REGISTRY_ADDR: "http://host.docker.internal:4001"
OVERRIDE_CONFIG_TRUSTED_ORIGINS: all
demo-apps:
image: namecheap/ilc-demo-apps:latest
network_mode: "service:ilc" # We need this to make apps accessible at 127.0.0.1 inside "ilc" container
# ports:
# - "8234-8240:8234-8240" # Uncomment to run with ilc via node
env_file:
- ./demo-apps.env # Used by the demo site to override PUBLIC_HOST var
mysql:
container_name: mysql
platform: linux/x86_64
image: mysql:5.7
volumes:
- .:/usr/src/ilc
- "./dbfiles:/var/lib/mysql"
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: pwd
MYSQL_DATABASE: ilc
healthcheck:
test: ["CMD", "mysqladmin", "-uroot", "-ppwd", "processlist", "-h", "localhost"]
interval: 3s
timeout: 3s
retries: 50
postgres:
container_name: postgres
image: postgres:15.6-alpine
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: pwd
POSTGRES_DB: ilc
ports:
- '5432:5432'
volumes:
- postgres:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "sh -c 'pg_isready -U root -d ilc'"]
interval: 3s
timeout: 3s
retries: 50
registry:
image: namecheap/ilc_registry:latest
ports:
- '4001:4001'
environment:
NODE_ENV: production
DB_CLIENT: mysql
# DB_CLIENT: pg
DB_HOST: mysql
# DB_HOST: postgres
DB_USER: root
DB_PASSWORD: pwd
DB_NAME: ilc
DB_SEED: true
depends_on:
mysql:
condition: service_healthy
# postgres:
# condition: service_healthy
registry_worker:
image: namecheap/ilc_registry:latest
command: ['npm', 'run', 'assetsdiscovery']
environment:
NODE_ENV: production
DB_CLIENT: mysql
# DB_CLIENT: pg
DB_HOST: mysql
# DB_HOST: postgres
DB_USER: root
DB_PASSWORD: pwd
DB_NAME: ilc
network_mode: 'service:ilc' # We need this to make apps accessible at 127.0.0.1
depends_on:
mysql:
condition: service_healthy
ilc:
image: namecheap/ilc:latest
restart: always
ports:
- '80:8233'
- '8233:8233'
- '8234-8240:8234-8240' # Ports from "demo-apps" container
environment:
NODE_ENV: production
REGISTRY_ADDR: 'http://host.docker.internal:4001'
OVERRIDE_CONFIG_TRUSTED_ORIGINS: all
demo-apps:
image: namecheap/ilc-demo-apps:latest
network_mode: 'service:ilc' # We need this to make apps accessible at 127.0.0.1 inside "ilc" container
# ports:
# - "8234-8240:8234-8240" # Uncomment to run with ilc via node
env_file:
- ./demo-apps.env # Used by the demo site to override PUBLIC_HOST var
mysql:
container_name: mysql
platform: linux/x86_64
image: mysql:5.7
volumes:
- .:/usr/src/ilc
- './dbfiles:/var/lib/mysql'
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: pwd
MYSQL_DATABASE: ilc
healthcheck:
test: ['CMD', 'mysqladmin', '-uroot', '-ppwd', 'processlist', '-h', 'localhost']
interval: 3s
timeout: 3s
retries: 50
postgres:
container_name: postgres
image: postgres:15.6-alpine
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: pwd
POSTGRES_DB: ilc
ports:
- '5432:5432'
volumes:
- postgres:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', "sh -c 'pg_isready -U root -d ilc'"]
interval: 3s
timeout: 3s
retries: 50
volumes:
postgres:
driver: local
2 changes: 2 additions & 0 deletions registry/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ ADD ./ /codebase

RUN npm run build

ENTRYPOINT ["sh", "./scripts/docker-entrypoint.sh"]

CMD ["npm", "run", "start-docker"]
4 changes: 4 additions & 0 deletions registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ This command ignores `.env` file
```bash
$ npm run test:postgres
```

## Secure session on production

To set the session cookie as secure, set the environment variable AUTH_COOKIE_SECURE=true. Note that you will need to use an HTTPS forward proxy to access the registry admin panel.
1 change: 1 addition & 0 deletions registry/config/custom-environment-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
},
auth: {
sessionSecret: 'AUTH_SESSION_SECRET',
cookieSecure: 'AUTH_COOKIE_SECURE',
},
healthCheck: {
url: 'ILC_REGISTRY_HEALTH_CHECK_URL',
Expand Down
1 change: 1 addition & 0 deletions registry/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
},
auth: {
sessionSecret: 'zaM7%#BjyZZ3A5zV@Mpt',
cookieSecure: false,
},
http: {
requestLimit: '1mb',
Expand Down
9 changes: 9 additions & 0 deletions registry/scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e

if [ "$DB_SEED" = 'true' ] && [ ! -f .seed ]; then
npm run seed
touch .seed
fi

exec "$@"
2 changes: 1 addition & 1 deletion registry/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default async (withAuth: boolean = true): Promise<Application> => {
{
session: {
secret: config.get('auth.sessionSecret'),
cookie: { httpOnly: true, secure: process.env.NODE_ENV === 'production' },
cookie: { httpOnly: true, secure: config.get('auth.cookieSecure') },
},
},
getLogger(),
Expand Down
Loading