From c4d10f0ef8ad98e60a1d436ccf1e258cc148f3b2 Mon Sep 17 00:00:00 2001 From: Christopher <1289128+dragonfire1119@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:16:45 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(big-bear-casaos-user-managemen?= =?UTF-8?q?t):=20Add=20user=20management=20system=20(#27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ feat(big-bear-casaos-user-management): Add user management system This commit introduces a new user management system for the BigBearCasaOS project. The key changes include: - Added a Dockerfile to build a Docker image for the user management system - Created a Docker Compose file to easily deploy the user management service - Implemented a Flask-based web application to manage user accounts - Added an HTML template for the user management interface - Configured environment variables for the admin username and password - Granted the container extended privileges and capabilities for system integration These changes enable the CasaOS platform to manage user accounts and roles, improving the overall security and usability of the system. * 🔧 feat(user-management): Enhance user management service configuration Modify the Docker Compose configuration for the CasaOS user management service: - Expose port 5000 on the host and map it to the container - Mount the cgroup filesystem in read-only mode for system resource monitoring - Persist the CasaOS database files to retain data across container restarts - Mount systemd's runtime directory for integration with the host system - Provide access to the D-Bus system bus for communication with host services - Set the Flask application entry point and production environment - Specify the admin username and password for the service - Grant the container extended privileges and the SYS_ADMIN capability - Disable the default seccomp security profile to allow unrestricted system calls - Rename the service from "big-bear-casaos-user-manager" to "big-bear-casaos-user-management" for consistency --- ...e_for_big_bear_casaos_user_management.yaml | 47 +++++ .gitignore | 4 + big-bear-casaos-user-management/Dockerfile | 27 +++ big-bear-casaos-user-management/VERSION | 1 + big-bear-casaos-user-management/app/app.py | 71 ++++++++ .../app/templates/base.html | 15 ++ .../app/templates/index.html | 128 +++++++++++++ .../app/user_management.py | 170 ++++++++++++++++++ .../docker-compose.yml | 45 +++++ 9 files changed, 508 insertions(+) create mode 100644 .github/workflows/build_and_release_for_big_bear_casaos_user_management.yaml create mode 100644 big-bear-casaos-user-management/Dockerfile create mode 100644 big-bear-casaos-user-management/VERSION create mode 100644 big-bear-casaos-user-management/app/app.py create mode 100644 big-bear-casaos-user-management/app/templates/base.html create mode 100644 big-bear-casaos-user-management/app/templates/index.html create mode 100644 big-bear-casaos-user-management/app/user_management.py create mode 100644 big-bear-casaos-user-management/docker-compose.yml diff --git a/.github/workflows/build_and_release_for_big_bear_casaos_user_management.yaml b/.github/workflows/build_and_release_for_big_bear_casaos_user_management.yaml new file mode 100644 index 0000000..6d37acb --- /dev/null +++ b/.github/workflows/build_and_release_for_big_bear_casaos_user_management.yaml @@ -0,0 +1,47 @@ +name: "Build and release for big-bear-casaos-user-management" + +on: + push: + branches: + - main + paths: + - "big-bear-casaos-user-management/**" + +jobs: + create: + name: "Creates the newest release by version" + runs-on: "ubuntu-latest" + + steps: + - name: Checkout project + uses: actions/checkout@v2.3.4 + + # New step to read the VERSION file and set the version as an output + - name: Get the version + id: get_version + run: echo "big_bear_casaos_user_management_version=$(cat big-bear-casaos-user-management/VERSION)" >> $GITHUB_ENV + + - name: Set up QEMU + uses: docker/setup-qemu-action@master + with: + platforms: all + + - name: Set up Docker Build + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + push: true + platforms: linux/amd64,linux/arm64 + context: ./big-bear-casaos-user-management + file: ./big-bear-casaos-user-management/Dockerfile + tags: | + bigbeartechworld/big-bear-casaos-user-management:latest + bigbeartechworld/big-bear-casaos-user-management:${{ env.big_bear_casaos_user_management_version }} diff --git a/.gitignore b/.gitignore index 9804a16..ed1ad03 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ pihole-unbound/build.log pihole-unbound/build.sh genmon/build.log genmon/build.sh +genmon/build.log +genmon/build.sh +big-bear-casaos-user-management/build.log +big-bear-casaos-user-management/build.sh \ No newline at end of file diff --git a/big-bear-casaos-user-management/Dockerfile b/big-bear-casaos-user-management/Dockerfile new file mode 100644 index 0000000..18dcf4f --- /dev/null +++ b/big-bear-casaos-user-management/Dockerfile @@ -0,0 +1,27 @@ +FROM python:3.9-slim + +# Install system dependencies (systemd includes systemctl) +RUN apt-get update && \ + apt-get install -y systemd sudo && \ + rm -rf /var/lib/apt/lists/* + +# Create necessary directories +RUN mkdir -p /var/lib/casaos/db + +# Set working directory +WORKDIR /app + +# Copy all application files +COPY app/ . + +# Install Python dependencies +RUN pip install flask flask-wtf + +# Create a volume for persistent storage +VOLUME /var/lib/casaos/db + +# Expose port for Flask +EXPOSE 5000 + +# Run Flask app +CMD ["python", "app.py"] diff --git a/big-bear-casaos-user-management/VERSION b/big-bear-casaos-user-management/VERSION new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/big-bear-casaos-user-management/VERSION @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/big-bear-casaos-user-management/app/app.py b/big-bear-casaos-user-management/app/app.py new file mode 100644 index 0000000..9c20912 --- /dev/null +++ b/big-bear-casaos-user-management/app/app.py @@ -0,0 +1,71 @@ +from flask import Flask, render_template, redirect, url_for, flash, request +from user_management import (list_users, add_user, edit_password, + remove_user, reset_database, hash_password) +from functools import wraps +from flask import request, Response +import os + +app = Flask(__name__) +app.config['SECRET_KEY'] = 'your-secret-key' + +ADMIN_USERNAME = os.environ.get('ADMIN_USERNAME', 'admin') +ADMIN_PASSWORD = os.environ.get('ADMIN_PASSWORD', 'YOUR_SECURE_PASSWORD') + +def check_auth(username, password): + """Verify admin credentials""" + return username == ADMIN_USERNAME and password == ADMIN_PASSWORD + +def authenticate(): + return Response( + 'Could not verify your access level for that URL.\n' + 'You have to login with proper credentials', 401, + {'WWW-Authenticate': 'Basic realm="Login Required"'} + ) + +def requires_auth(f): + @wraps(f) + def decorated(*args, **kwargs): + auth = request.authorization + if not auth or not check_auth(auth.username, auth.password): + return authenticate() + return f(*args, **kwargs) + return decorated + +@app.route('/') +@requires_auth +def index(): + users = list_users(return_data=True) + return render_template('index.html', users=users) + +@app.route('/add_user', methods=['POST']) +def add_user_route(): + username = request.form.get('username') + password = request.form.get('password') + if add_user(username, password): + flash('User added successfully', 'success') + return redirect(url_for('index')) + +@app.route('/edit_password', methods=['POST']) +def edit_password_route(): + user_id = request.form.get('user_id') + new_password = request.form.get('new_password') + if edit_password(user_id, new_password): + flash('Password updated successfully', 'success') + return redirect(url_for('index')) + +@app.route('/remove_user', methods=['POST']) +def remove_user_route(): + user_id = request.form.get('user_id') + if remove_user(user_id): + flash('User removed successfully', 'success') + return redirect(url_for('index')) + +@app.route('/reset_database', methods=['POST']) +@requires_auth +def reset_database_route(): + if reset_database(): + flash('Database reset successfully', 'success') + return redirect(url_for('index')) + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000, debug=True) diff --git a/big-bear-casaos-user-management/app/templates/base.html b/big-bear-casaos-user-management/app/templates/base.html new file mode 100644 index 0000000..5733ef6 --- /dev/null +++ b/big-bear-casaos-user-management/app/templates/base.html @@ -0,0 +1,15 @@ + + +
+ID | +Username | +Role | +Actions | +
---|---|---|---|
{{ user[0] }} | +{{ user[1] }} | +{{ user[2] }} | ++ + + | +