Skip to content
Closed
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
6 changes: 4 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lowercase owner
run: echo "OWNER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
push: true
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
tags: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.image_suffix }}:latest
ghcr.io/${{ github.repository_owner }}/${{ matrix.image_suffix }}:${{ steps.package_version.outputs.VERSION }}
ghcr.io/${{ env.OWNER }}/${{ matrix.image_suffix }}:latest
ghcr.io/${{ env.OWNER }}/${{ matrix.image_suffix }}:${{ steps.package_version.outputs.VERSION }}
2 changes: 2 additions & 0 deletions dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
package-lock.json

# Output
.output
Expand All @@ -7,6 +8,7 @@ node_modules
.wrangler
/.svelte-kit
/build
/dist

# OS
.DS_Store
Expand Down
12 changes: 9 additions & 3 deletions dashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ FROM base AS build
RUN pnpm install --frozen-lockfile

COPY ./src ./src
COPY ./server.ts ./server.ts
COPY ./ws-proxy.ts ./ws-proxy.ts
COPY ./auth-check.ts ./auth-check.ts
COPY ./tsconfig.server.json ./tsconfig.server.json

RUN pnpm build
RUN pnpm build && pnpm tsc -p tsconfig.server.json

FROM base AS prod-deps

Expand All @@ -28,7 +32,9 @@ FROM node:25-alpine

WORKDIR /app

COPY --from=build /app/package.json ./package.json
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/build ./build
COPY --from=build /app/build ./build
COPY --from=build /app/dist ./dist

CMD ["node", "build/index.js"]
CMD ["node", "dist/server.js"]
38 changes: 38 additions & 0 deletions dashboard/auth-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import crypto from 'node:crypto';

export const SESSION_COOKIE_NAME = 'SESSION_ID';

export function hashAuthKey(value: string): string {
return crypto.createHash('sha256').update(value).digest('hex');
}

export function isAuthRequired(): boolean {
return !!process.env.AUTH_KEY;
}

export function expectedHashedAuthKey(): string {
return hashAuthKey(process.env.AUTH_KEY!);
}

export function parseCookies(cookieStr: string): Record<string, string> {
const cookies: Record<string, string> = {};
cookieStr.split(';').forEach(cookie => {
const [name, ...rest] = cookie.trim().split('=');
if (name) cookies[name] = rest.join('=');
});
return cookies;
}

export function isSessionValid(cookieValue: string | undefined): boolean {
if (!isAuthRequired()) return true;
return cookieValue === expectedHashedAuthKey();
}

/**
* Check if a raw HTTP cookie header represents an authenticated session.
* Returns true if AUTH_KEY is not set (no auth required).
*/
export function isAuthenticatedByCookie(cookieHeader: string | undefined): boolean {
const cookies = parseCookies(cookieHeader || '');
return isSessionValid(cookies[SESSION_COOKIE_NAME]);
}
1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@sveltejs/vite-plugin-svelte": "^6.2.4",
"@tailwindcss/vite": "^4.1.18",
"@types/luxon": "^3.7.1",
"@types/node": "^25.3.3",
"bits-ui": "^2.14.4",
"clsx": "^2.1.1",
"svelte": "^5.48.2",
Expand Down
Loading