-
Notifications
You must be signed in to change notification settings - Fork 1
Docker Web improvements & better security #64
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
Changes from 4 commits
69d2e02
6fa10f2
0402b02
acd9460
45166c1
7eea6f0
9320695
d63dc7b
f0e0dca
a935098
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| services: | ||
| switchcraft-web: | ||
| build: . | ||
| image: switchcraft-web:latest | ||
| container_name: switchcraft-web | ||
| ports: | ||
| - "8080:8080" | ||
| volumes: | ||
| - switchcraft_data:/root/.switchcraft | ||
| environment: | ||
| - SC_CLIENT_ID=${SC_CLIENT_ID} | ||
| - SC_CLIENT_SECRET=${SC_CLIENT_SECRET} | ||
| - SC_AUTH_PROVIDER=${SC_AUTH_PROVIDER:-entra} | ||
| - SC_ENTRA_CLIENT_ID=${SC_ENTRA_CLIENT_ID} | ||
| - SC_ENTRA_CLIENT_SECRET=${SC_ENTRA_CLIENT_SECRET} | ||
| - SC_ENTRA_TENANT_ID=${SC_ENTRA_TENANT_ID} | ||
| - SC_GITHUB_CLIENT_ID=${SC_GITHUB_CLIENT_ID} | ||
| - SC_GITHUB_CLIENT_SECRET=${SC_GITHUB_CLIENT_SECRET} | ||
| - SC_BASE_URL=${SC_BASE_URL} | ||
| - SC_DISABLE_WINGET_INSTALL=1 | ||
| restart: unless-stopped | ||
|
|
||
| volumes: | ||
| switchcraft_data: |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,42 +1,107 @@ | ||||||||||||||||
| # SwitchCraft Web App (Docker) Guide | ||||||||||||||||
|
|
||||||||||||||||
| ## Overview | ||||||||||||||||
| SwitchCraft can be deployed as a Dockerized Web Application using Flet. This provides a web-accessible version of the packaging tool. | ||||||||||||||||
|
|
||||||||||||||||
| ## Deployment | ||||||||||||||||
|
|
||||||||||||||||
| ### Prerequisites | ||||||||||||||||
| - Docker Engine | ||||||||||||||||
| - Git | ||||||||||||||||
|
|
||||||||||||||||
| ### Build & Run | ||||||||||||||||
| 1. **Build the Image** | ||||||||||||||||
| ```bash | ||||||||||||||||
| docker build -t switchcraft-web . | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| 2. **Run the Container** | ||||||||||||||||
| ```bash | ||||||||||||||||
| docker run -d -p 8080:8080 --name switchcraft switchcraft-web | ||||||||||||||||
| ``` | ||||||||||||||||
| Access the app at `http://localhost:8080`. | ||||||||||||||||
|
|
||||||||||||||||
| ## Configuration | ||||||||||||||||
| The application uses environment variables for configuration in Docker. | ||||||||||||||||
|
|
||||||||||||||||
| | Variable | Description | Default | | ||||||||||||||||
| | :--- | :--- | :--- | | ||||||||||||||||
| | `SC_AUTH_PROVIDER` | Auth provider (`github`, `entra`, `none`) | `none` | | ||||||||||||||||
| | `SC_GITHUB_CLIENT_ID` | GitHub App Client ID | - | | ||||||||||||||||
| | `SC_GITHUB_CLIENT_SECRET` | GitHub App Client Secret | - | | ||||||||||||||||
| | `SC_SESSION_SECRET` | Secret key for session encryption | (Random) | | ||||||||||||||||
| | `SC_DISABLE_WINGET_INSTALL` | Set `1` to skip Winget check (Use static fallback) | `0` | | ||||||||||||||||
|
|
||||||||||||||||
| ## Limitations vs Desktop | ||||||||||||||||
| - **Winget Search**: Relies on a static dataset of ~50 popular apps or external APIs. Results may differ from Desktop Winget CLI. | ||||||||||||||||
| - **Intune Upload**: Requires Azure authentication which may need device code flow. | ||||||||||||||||
| - **Local Files**: Browser sandbox applies; file upload/download is used instead of direct file system access. | ||||||||||||||||
|
|
||||||||||||||||
| ## Troubleshooting | ||||||||||||||||
| - **No Search Results?** The app uses a fallback static dataset if public APIs are unreachable. | ||||||||||||||||
| - **Login Fails?** Ensure `SC_GITHUB_CLIENT_ID` and `SECRET` are set correctly if using GitHub auth. | ||||||||||||||||
| # SwitchCraft Server (Docker) Guide | ||||||||||||||||
|
|
||||||||||||||||
| SwitchCraft enables you to host your own instance of the application using **Docker**. The containerized version allows you to access SwitchCraft from any browser in your network, complete with a built-in authentication system, Single Sign-On (SSO), and administrative controls. | ||||||||||||||||
|
|
||||||||||||||||
| ## 🚀 Quick Start | ||||||||||||||||
|
|
||||||||||||||||
| ### 1. Build & Run | ||||||||||||||||
| You can build the image directly from the source: | ||||||||||||||||
|
|
||||||||||||||||
| ```bash | ||||||||||||||||
| # Build the image | ||||||||||||||||
| docker build -t switchcraft-web . | ||||||||||||||||
|
|
||||||||||||||||
| # Run the container (Mapping port 8080) | ||||||||||||||||
| # We map a volume to persist configuration AND user database | ||||||||||||||||
| docker run -d \ | ||||||||||||||||
| -p 8080:8080 \ | ||||||||||||||||
| -v switchcraft_data:/root/.switchcraft \ | ||||||||||||||||
| --name switchcraft \ | ||||||||||||||||
| switchcraft-web | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| Access the application at: `http://localhost:8080` | ||||||||||||||||
|
|
||||||||||||||||
| ## 🔐 Authentication & User Management | ||||||||||||||||
|
|
||||||||||||||||
| The Docker container includes a full **User Management System**. | ||||||||||||||||
|
|
||||||||||||||||
| ### Default Login | ||||||||||||||||
| - **Username:** `admin` | ||||||||||||||||
| - **Password:** `admin` (You should change this immediately in the Admin Panel) | ||||||||||||||||
|
Comment on lines
+30
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strengthen security warning for default credentials. The note to change the default password should be more emphatic for production deployments. Consider using stronger language and making this a prominent warning block rather than a casual parenthetical note. 🔒 Suggested improvement ### Default Login
- **Username:** `admin`
-- **Password:** `admin` (You should change this immediately in the Admin Panel)
+- **Password:** `admin`
+
+> **🔴 SECURITY WARNING:** The default password `admin` is publicly known. You **must** change it immediately after first login via the Admin Panel (`/admin` → Security → Change Password). Failure to do so leaves your instance vulnerable to unauthorized access.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| ### Multi-User Support | ||||||||||||||||
| The server supports multiple users with distinct roles (`admin` or `user`). | ||||||||||||||||
| - **Admins** have access to the `/admin` dashboard to manage users and server settings. | ||||||||||||||||
| - **Users** can access the application tools but cannot modify server settings or other users. | ||||||||||||||||
|
|
||||||||||||||||
| ### Single Sign-On (SSO) Setup | ||||||||||||||||
| SwitchCraft supports OAuth2 login via **GitHub** and **Microsoft Entra ID (Office 365)**. | ||||||||||||||||
| To enable SSO, you must provide the following environment variables when running the Docker container. | ||||||||||||||||
|
|
||||||||||||||||
| #### 1. Microsoft Entra ID (O365) | ||||||||||||||||
| Register an App in Azure AD -> App Registrations. | ||||||||||||||||
| * **Redirect URI:** `http://<your-domain>:8080/oauth_callback/entra` | ||||||||||||||||
| * **API Permissions:** `User.Read` (Delegated) | ||||||||||||||||
|
|
||||||||||||||||
| ```bash | ||||||||||||||||
| docker run -d ... \ | ||||||||||||||||
| -e SC_ENTRA_CLIENT_ID="<your-client-id>" \ | ||||||||||||||||
| -e SC_ENTRA_TENANT_ID="<your-tenant-id>" \ | ||||||||||||||||
| -e SC_ENTRA_CLIENT_SECRET="<your-client-secret>" \ | ||||||||||||||||
| -e SC_BASE_URL="http://myserver.com:8080" \ | ||||||||||||||||
| switchcraft-web | ||||||||||||||||
| ``` | ||||||||||||||||
|
|
||||||||||||||||
| *Users logging in via Entra for the first time will be **automatically created** as normal users.* | ||||||||||||||||
|
|
||||||||||||||||
| #### 2. GitHub | ||||||||||||||||
| Register an OAuth App in GitHub Developer Settings. | ||||||||||||||||
| * **Callback URL:** `http://<your-domain>:8080/oauth_callback/github` | ||||||||||||||||
|
|
||||||||||||||||
| ```bash | ||||||||||||||||
| docker run -d ... \ | ||||||||||||||||
| -e SC_GITHUB_CLIENT_ID="<your-client-id>" \ | ||||||||||||||||
| -e SC_GITHUB_CLIENT_SECRET="<your-client-secret>" \ | ||||||||||||||||
| switchcraft-web | ||||||||||||||||
| ``` | ||||||||||||||||
|
Comment on lines
+38
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add guidance on secure secret management for production. The examples show secrets passed as environment variables directly in Consider adding a note recommending:
📝 Suggested additionAdd after line 67: > **🔒 Production Secret Management:**
> For production deployments, avoid passing secrets via command-line arguments.
> Use:
> - Docker Compose with `.env` files (set permissions to `600`)
> - Docker Secrets for Swarm mode
> - External secret management systems (HashiCorp Vault, AWS Secrets Manager, etc.)🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| ## ⚙️ Administration Dashboard | ||||||||||||||||
|
|
||||||||||||||||
| Access the dashboard at `http://localhost:8080/admin` (Link in Footer). | ||||||||||||||||
|
|
||||||||||||||||
| ### Features | ||||||||||||||||
| 1. **User Management**: | ||||||||||||||||
| * **List Users:** See all registered accounts (Local and SSO). | ||||||||||||||||
| * **Add User:** Manually create accounts with passwords. | ||||||||||||||||
| * **Delete User:** Remove accounts (except the root admin). | ||||||||||||||||
| 2. **Server Settings**: | ||||||||||||||||
| * **Demo Mode:** Switch app to Read-Only mode. | ||||||||||||||||
| * **Disable Auth:** Allow public access without login (Auto-Login as Guest/Admin). | ||||||||||||||||
|
Comment on lines
+78
to
+80
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add security warning for "Disable Auth" feature. The "Disable Auth" feature that allows auto-login as Admin is extremely dangerous and should have a prominent security warning. This effectively disables all security protections and should only be used in completely isolated, non-production environments.
|
||||||||||||||||
| 3. **Security**: | ||||||||||||||||
| * **Change Password:** Update your own password. | ||||||||||||||||
| * **MFA / 2FA:** Setup Time-based OTP (Google Authenticator) enforcement. | ||||||||||||||||
|
|
||||||||||||||||
| ## 💾 Persistence | ||||||||||||||||
|
|
||||||||||||||||
| To keep your users and settings safe, mount the `/root/.switchcraft` volume. | ||||||||||||||||
|
|
||||||||||||||||
| | Path | Purpose | | ||||||||||||||||
| | :--- | :--- | | ||||||||||||||||
| | `server/auth_config.json` | Stores Global Server Config (Secret Keys, Demo Mode). | | ||||||||||||||||
| | `server/users.json` | **User Database** (Usernames, Password Hashes, Roles). | | ||||||||||||||||
| | `users/<username>/config.json` | (Future) Server-side user profiles. | | ||||||||||||||||
|
|
||||||||||||||||
| ## 🌐 Web Architecture Notes | ||||||||||||||||
|
|
||||||||||||||||
| * **Session Storage:** Login sessions use secure, encrypted cookies valid for 24 hours. | ||||||||||||||||
| * **Client Settings:** Currently, app preferences (Theme, etc.) are stored in the **Browser** (LocalStorage) to ensure fast load times. We are working on server-side roaming profiles for the next release. | ||||||||||||||||
| * **File Access:** The web version runs in a sandbox. You cannot access the host filesystem directly. Use the Upload/Download features. | ||||||||||||||||
|
|
||||||||||||||||
| ## 🛠 Troubleshooting | ||||||||||||||||
|
|
||||||||||||||||
| * **SSO Redirect Error?** Ensure `SC_BASE_URL` matches exactly the URL you access in the browser (including http/https and port). | ||||||||||||||||
| * **Locked Out?** | ||||||||||||||||
| * `docker exec -it switchcraft sh` | ||||||||||||||||
| * Delete `server/users.json` to reset the database (recreating default admin). | ||||||||||||||||
| * Or manually edit `server/users.json` if you know JSON syntax. | ||||||||||||||||
|
Comment on lines
+104
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix list indentation and add safety warning. The nested list items under "Locked Out?" have inconsistent indentation. Additionally, the instruction to delete ✍️ Proposed fix * **Locked Out?**
- * `docker exec -it switchcraft sh`
- * Delete `server/users.json` to reset the database (recreating default admin).
- * Or manually edit `server/users.json` if you know JSON syntax.
+ * `docker exec -it switchcraft sh`
+ * Stop the container (`docker stop switchcraft`) then delete `server/users.json` to reset the database (recreating default admin).
+ * Or manually edit `server/users.json` if you know JSON syntax (while container is stopped).Note: Changed indentation to 4 spaces for nested items and added safety guidance about stopping the container before modifying the database. 🧰 Tools🪛 markdownlint-cli2 (0.18.1)105-105: Inconsistent indentation for list items at the same level (MD005, list-indent) 105-105: Unordered list indentation (MD007, ul-indent) 106-106: Inconsistent indentation for list items at the same level (MD005, list-indent) 106-106: Unordered list indentation (MD007, ul-indent) 107-107: Inconsistent indentation for list items at the same level (MD005, list-indent) 107-107: Unordered list indentation (MD007, ul-indent) 🤖 Prompt for AI Agents |
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: FaserF/SwitchCraft
Length of output: 44
🏁 Script executed:
Repository: FaserF/SwitchCraft
Length of output: 737
🏁 Script executed:
Repository: FaserF/SwitchCraft
Length of output: 1248
🏁 Script executed:
Repository: FaserF/SwitchCraft
Length of output: 479
Fix heredoc indentation in web_entry.py generation — will cause IndentationError at runtime.
The heredoc content has 10 leading spaces on each line. When the file is generated, these spaces become part of the Python file, causing an IndentationError on line 1. Use
<<-instead of<<to strip leading tabs, or remove the indentation from the heredoc content:🤖 Prompt for AI Agents