Skip to content

Conversation

@8ohamed
Copy link
Contributor

@8ohamed 8ohamed commented Nov 28, 2025

Automating platform service setup

Type of Change

  • New feature

Description

Solving issue #1366, by making methods to adjust permissions (rabbitMQ, MongoDB, InfluxDB), more commits to be made.
Making the methods cross-platform.
Moving the script to Cli.

the PR is not finished yet.

@prasadtalasila
Copy link
Contributor

@8ohamed please rebase the pull request. Thanks.

Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@8ohamed Thanks for the pull request. Please see the comments. It seems that the script is only copying the certificates. The goal is to actually run the compose file and run all the certificates.

@prasadtalasila
Copy link
Contributor

@8ohamed The services in compose.services.yml come with their own licenses and it is better to separate the services installation CLI from DTaaS CLI.
How about converting this script into a standalone poetry project placed in deploy/services/cli directory?

@prasadtalasila
Copy link
Contributor

@8ohamed The services in compose.services.yml come with their own licenses and it is better to separate the services installation CLI from DTaaS CLI. How about converting this script into a standalone poetry project placed in deploy/services/cli directory?

Let us take this up in the next PR.

@prasadtalasila
Copy link
Contributor

prasadtalasila commented Nov 29, 2025

@8ohamed Please consider:

  1. Reusing information from services.env as much as possible. The script does not need to take any arguments from user. It can perform all the operations in sequence and exit.
  2. Placing the script in deploy/services/script.
  3. Updating the deploy/services/README.md.

@8ohamed
Copy link
Contributor Author

8ohamed commented Nov 30, 2025

@prasadtalasila I have resolved the issues.
I am loading the values from .env using dotenv, please let me know if you want me to use something else.
And for the user running this script, if the script is supposed to only have one option to run it (where all methods runs in a sequence) then I can make the code cleaner/shorter, by not handling possibilities of users running only one of the methods.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces automation for setting up platform services (RabbitMQ, MongoDB, InfluxDB) by creating a new Python script that handles certificate copying and permission configuration in a cross-platform manner. The work is part of addressing issue #1366 and is still in progress, as noted in the PR description.

Key Changes:

  • New service_setup.py script with ServicesConfig class to automate TLS certificate management and permission settings
  • Addition of UID/GID environment variables for services in the configuration template

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 19 comments.

File Description
deploy/services/script/service_setup.py New script implementing automated service setup with methods for certificate copying and permission management for MongoDB, InfluxDB, and RabbitMQ
deploy/services/config/services.env.template Added UID/GID configuration variables for RabbitMQ, InfluxDB, and MongoDB services

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines 1 to 11
import platform
import os
from pathlib import Path
import os
import platform
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Tuple
from dotenv import load_dotenv
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing module-level docstring. The file lacks a module-level docstring explaining the purpose of this script, its usage, and requirements (e.g., need for root privileges, expected environment variables). Add a comprehensive docstring at the top of the file following the existing Python documentation standards in the project.

Copilot uses AI. Check for mistakes.
certs_target = self.certs_dir / self.host_name

if self.os_type in ("linux", "darwin"):
source_dir = Path(f"/etc/letsencrypt/archive/{self.host_name}")
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded certificate path may be a security concern. The path /etc/letsencrypt/archive/{self.host_name} on line 62 is hardcoded and requires root access. This assumes a specific Let's Encrypt installation. Consider making this configurable via an environment variable or configuration file to improve flexibility and allow testing without root privileges.

Copilot uses AI. Check for mistakes.
@prasadtalasila
Copy link
Contributor

@prasadtalasila I have resolved the issues. I am loading the values from .env using dotenv, please let me know if you want me to use something else. And for the user running this script, if the script is supposed to only have one option to run it (where all methods runs in a sequence) then I can make the code cleaner/shorter, by not handling possibilities of users running only one of the methods.

@8ohamed The script does not need any arguments. For now, please make the script all methods. Please consider the issues raised by sonarcube and copilot. Also do update the README. Thanks.

@8ohamed
Copy link
Contributor Author

8ohamed commented Nov 30, 2025

@prasadtalasila I have applied the suggestions and updated readme, if it looks good then I can start implementing for windows.

Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@8ohamed thanks for fixing the previous issues. Please see few more suggestions. The copilot points out few bugs in the code. Please check them as well. Thanks.

Copilot AI review requested due to automatic review settings December 1, 2025 12:32
@8ohamed
Copy link
Contributor Author

8ohamed commented Dec 1, 2025

@prasadtalasila I have applied the suggestions, and the code also handles windows OS now.

Copilot finished reviewing on behalf of 8ohamed December 1, 2025 12:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 21 comments.

Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@8ohamed Please see the minor comments.

@prasadtalasila
Copy link
Contributor

@8ohamed some improvements to text in the README.md. Please copy the raw version of the markdown copy from here onwards.


Installation steps

Please follow the steps outlined here for installation.
script/service_setup.py, is provided to streamline the setup of TLS certificates
and permissions for MongoDB, InfluxDB, and RabbitMQ services.

The script has the following features:

  • Automation: Automates all manual certificate and permission steps for
    MongoDB, InfluxDB, and RabbitMQ as described above.
  • Cross-platform: Works on Linux, macOS, and Windows.
  • Configuration-driven: Reads all required user IDs, group IDs, and hostnames
    from config/services.env.

Create Config

  1. Copy config/services.env.template into config/services.env
  2. Update config/services.env with the correct values for your environment.
  3. Run the script from with root privilege:

Install

Install Python dependencies before running the script:

pip install -r script/requirements.txt

Run the installation script

cd deploy/services
sudo python3 script/service_setup.py

The script will:

  • Combine and set permissions for MongoDB certificates.
  • Copy and set permissions for InfluxDB and RabbitMQ certificates.
  • Use the correct UID/GID values from config/services.env.

If any required variable is missing, the script will exit with an error message.

This automation reduces manual errors and ensures your service containers have
the correct certificate files and permissions for secure operation.

Copilot AI review requested due to automatic review settings December 1, 2025 22:06
Copilot finished reviewing on behalf of 8ohamed December 1, 2025 22:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 18 comments.

Comment on lines 123 to 124
for p in candidates:
if p != target:
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _normalize_cert_candidates method has a potential logic issue. After renaming latest to target (line 122), the subsequent loop (lines 123-125) iterates over the original candidates list and attempts to unlink files where p != target. This will attempt to unlink latest (which no longer exists at its original path after the rename), potentially causing a FileNotFoundError despite the missing_ok=True flag in unlink() at line 124.

The logic should track which file was renamed to avoid attempting to remove it:

def _normalize_cert_candidates(self, prefix: str) -> None:
    """Keep only the latest cert file for a given prefix, rename it, and remove others."""
    candidates = list(self.certs["dir"].glob(f"{prefix}*.pem"))
    if not candidates:
        return
    latest = max(candidates, key=lambda p: p.stat().st_mtime)
    target = self.certs["dir"] / f"{prefix}.pem"
    target.unlink(missing_ok=True)
    latest.rename(target)
    # Remove all candidates except the one we just renamed
    for p in candidates:
        if p != latest and p != target:
            p.unlink(missing_ok=True)
Suggested change
for p in candidates:
if p != target:
# Remove all candidates except the canonical target (new path)
for p in candidates:
if p.resolve() != target.resolve():

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants