Skip to content

chore: replace git dependency for http - #2490

Open
pindo696 wants to merge 3 commits into
RedHatInsights:masterfrom
pindo696:replace-git-dependency
Open

chore: replace git dependency for http#2490
pindo696 wants to merge 3 commits into
RedHatInsights:masterfrom
pindo696:replace-git-dependency

Conversation

@pindo696

@pindo696 pindo696 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Replaced git dependency for playboooks and content import with http. This includes change from git clone to downloading an archive. Updated requirements, keeping git for dev only as tests requires them. RHINENG-30176 and RHINENG-30177

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Replace Git-based repository access with HTTP archive downloads for application content, playbooks, and static assets.

New Features:

  • Add HTTP archive downloading and extraction for content and playbooks repositories, including archive revision tracking.

Enhancements:

  • Replace runtime and image-build Git repository cloning with authenticated HTTP archive retrieval while retaining Git dependencies for tests only.
  • Support static asset archive configuration through deployment parameters and environment variables.

Build:

  • Update container dependencies to use tar and gzip instead of Git.

Deployment:

  • Update deployment configuration to provide content and playbooks archive URLs.

Tests:

  • Add coverage for archive extraction, revision handling, download failures, and missing static archives.

Chores:

  • Remove GitPython and related Git dependency packages from production requirements.

@sourcery-ai

sourcery-ai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR removes Git-based repository access from production workflows by introducing authenticated HTTP archive downloads and extraction, updates FedRAMP image construction and deployment configuration to use archive URLs, retains GitPython only for tests, and adds focused coverage for the new import and error-handling paths.

Sequence diagram for HTTP archive repository synchronization

sequenceDiagram
    participant Job as rules_git_sync
    participant Config
    participant Downloader as ArchiveDownloader
    participant GitHost as GitArchiveHost
    participant Filesystem
    participant Database

    Job->>Config: read content_archive_url and playbooks_archive_url
    Job->>Downloader: download_and_extract(extract_to)
    Downloader->>GitHost: GET archive URL with Authorization
    GitHost-->>Downloader: tar.gz or zip archive
    Downloader->>Downloader: extract_commit_sha_from_archive(archive_path)
    Downloader->>Filesystem: extract archive and locate directory
    Downloader-->>Job: extracted_dir_path and commit_sha
    Job->>Filesystem: move extracted repository to target_dir
    Job->>Database: store_versions(commit_sha, archive_url)
Loading

File-Level Changes

Change Details Files
Replace runtime Git cloning with authenticated HTTP archive download, extraction, and revision tracking.
  • Add a reusable downloader supporting tar.gz and ZIP archives, streaming downloads, safe tar extraction, archive cleanup, and commit SHA or content-hash detection.
  • Update rules synchronization to download content and playbooks, move extracted repositories into the expected locations, and handle failures without aborting the process.
  • Read archive URLs from configuration and persist those URLs alongside imported versions.
taskomatic/jobs/archive_downloader.py
taskomatic/jobs/rules_git_sync.py
common/config.py
conf/taskomatic.env
Update container builds and deployments for archive-based static assets.
  • Remove Git from the production image and install tar/gzip utilities.
  • Download and extract FedRAMP static assets during image construction while retaining playbooks and content archives for version computation.
  • Replace Git repository deployment parameters with content and playbook archive URL parameters.
Dockerfile
deploy/clowdapp.yaml
Restrict GitPython to development and refresh dependency artifacts.
  • Move GitPython from production dependencies to the development/test dependency group.
  • Regenerate lock and requirements files, including transitive dependency updates.
pyproject.toml
poetry.lock
requirements.txt
requirements-build.txt
requirements-dev.txt
requirements-extra.txt
Add coverage for archive import behavior and failure paths.
  • Test archive download, extraction, SHA extraction, cleanup, repository download results, download errors, and missing static archives.
tests/taskomatic_tests/test_rules_git_sync.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@pindo696
pindo696 force-pushed the replace-git-dependency branch from 8f6598b to 233fa36 Compare September 2, 2026 12:10
@pindo696

pindo696 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 4 issues

Fixed security issues:

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="taskomatic/jobs/archive_downloader.py" line_range="71-72" />
<code_context>
+
+    try:
+        if archive_type == "zip":
+            with zipfile.ZipFile(archive_path, "r") as z:
+                if sha := z.comment.decode("utf-8").strip():
+                    LOGGER.debug("Extracted commit SHA from ZIP comment: %s", sha[:8])
</code_context>
<issue_to_address>
**🚨 issue (security):** ZIP archives are extracted without validating member paths, so a repository archive containing `../` entries writes files outside `extract_to` and can overwrite arbitrary files writable by the taskomatic process.

**Triggers:** When a downloaded ZIP archive contains path-traversal entries.

**Suggested fix:** Validate every ZIP member resolves beneath `extract_to` before extraction, or use a safe extraction routine equivalent to the tar `filter="data"` protection.

```suggestion
            with zipfile.ZipFile(archive_path, "r") as z:
                extract_root = os.path.realpath(extract_to)
                for member in z.infolist():
                    member_path = os.path.realpath(os.path.join(extract_root, member.filename))
                    if os.path.commonpath((extract_root, member_path)) != extract_root:
                        raise ValueError(f"Unsafe ZIP member path: {member.filename}")
                z.extractall(extract_root)
```
</issue_to_address>

### Comment 2
<location path="taskomatic/jobs/archive_downloader.py" line_range="78" />
<code_context>
-        python312 libpq shadow-utils git-core postgresql && \
+        python312 libpq shadow-utils postgresql && \
     microdnf clean all

 # Copy pg_repack 1.5.2 from builder stage
</code_context>
<issue_to_address>
**issue (bug_risk):** Unsupported archive extensions are logged but do not raise an error, so `download_and_extract` treats the empty extraction directory as a successful repository, returns a fallback hash, and `download_repos` can report success before `sync` runs against missing content.

**Triggers:** When an archive URL does not end in `.tar.gz` or `.zip`, including URLs whose download endpoint has no archive suffix.

**Suggested fix:** Raise an exception for unsupported archive types and verify that extraction produced the expected repository directory before returning success.
</issue_to_address>

### Comment 3
<location path="Dockerfile" line_range="78" />
<code_context>
+        # VMaaS assets
+        curl -L "${VMAAS_ARCHIVE_URL}" -o /tmp/vmaas.tar.gz && \
+        tar -xzf /tmp/vmaas.tar.gz -C /tmp && \
+        mv /tmp/vmaas-assets-master /engine/vmaas_assets_git && \
+        rm /tmp/vmaas.tar.gz && \
+        \
</code_context>
<issue_to_address>
**issue (bug_risk):** The static-assets build assumes every archive expands to a fixed `*-master` directory, so configuring an archive URL for another branch, tag, commit, or provider-generated root name makes `mv` fail and prevents the image from building.

**Triggers:** When any `*_ARCHIVE_URL` points to an archive generated from a ref other than the default `master` layout.

**Suggested fix:** Discover the single extracted top-level directory instead of hardcoding the archive root name, or derive the expected root from the configured URL/ref.

```suggestion
        mv "/tmp/$(tar -tzf /tmp/vmaas.tar.gz | sed 's#/.*##' | head -n 1)" /engine/vmaas_assets_git && \
```
</issue_to_address>

### Comment 4
<location path="Dockerfile" line_range="76-77" />
<code_context>
+        \
+        # VMaaS assets
+        curl -L "${VMAAS_ARCHIVE_URL}" -o /tmp/vmaas.tar.gz && \
+        tar -xzf /tmp/vmaas.tar.gz -C /tmp && \
+        mv /tmp/vmaas-assets-master /engine/vmaas_assets_git && \
+        rm /tmp/vmaas.tar.gz && \
</code_context>
<issue_to_address>
**issue (bug_risk):** The static-assets image build always invokes `tar -xzf`, so a configured ZIP archive—which `ArchiveDownloader` explicitly supports—fails extraction and aborts the build.

**Triggers:** When a static asset archive URL is configured with a `.zip` archive.

**Suggested fix:** Select the extraction command from the archive extension, or restrict and validate the build arguments to tar.gz URLs.

```suggestion
        case "${VMAAS_ARCHIVE_URL}" in \
            *.tar.gz) : ;; \
            *) echo "VMAAS_ARCHIVE_URL must reference a .tar.gz archive" >&2; exit 1 ;; \
        esac && \
        curl -L "${VMAAS_ARCHIVE_URL}" -o /tmp/vmaas.tar.gz && \
        tar -xzf /tmp/vmaas.tar.gz -C /tmp && \
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +71 to +72
with zipfile.ZipFile(archive_path, "r") as z:
z.extractall(extract_to)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚨 issue (security): ZIP archives are extracted without validating member paths, so a repository archive containing ../ entries writes files outside extract_to and can overwrite arbitrary files writable by the taskomatic process.

Triggers: When a downloaded ZIP archive contains path-traversal entries.

Suggested fix: Validate every ZIP member resolves beneath extract_to before extraction, or use a safe extraction routine equivalent to the tar filter="data" protection.

Suggested change
with zipfile.ZipFile(archive_path, "r") as z:
z.extractall(extract_to)
with zipfile.ZipFile(archive_path, "r") as z:
extract_root = os.path.realpath(extract_to)
for member in z.infolist():
member_path = os.path.realpath(os.path.join(extract_root, member.filename))
if os.path.commonpath((extract_root, member_path)) != extract_root:
raise ValueError(f"Unsafe ZIP member path: {member.filename}")
z.extractall(extract_root)

Comment thread taskomatic/jobs/archive_downloader.py
Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Comment on lines +76 to +77
curl -L "${VMAAS_ARCHIVE_URL}" -o /tmp/vmaas.tar.gz && \
tar -xzf /tmp/vmaas.tar.gz -C /tmp && \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): The static-assets image build always invokes tar -xzf, so a configured ZIP archive—which ArchiveDownloader explicitly supports—fails extraction and aborts the build.

Triggers: When a static asset archive URL is configured with a .zip archive.

Suggested fix: Select the extraction command from the archive extension, or restrict and validate the build arguments to tar.gz URLs.

Suggested change
curl -L "${VMAAS_ARCHIVE_URL}" -o /tmp/vmaas.tar.gz && \
tar -xzf /tmp/vmaas.tar.gz -C /tmp && \
case "${VMAAS_ARCHIVE_URL}" in \
*.tar.gz) : ;; \
*) echo "VMAAS_ARCHIVE_URL must reference a .tar.gz archive" >&2; exit 1 ;; \
esac && \
curl -L "${VMAAS_ARCHIVE_URL}" -o /tmp/vmaas.tar.gz && \
tar -xzf /tmp/vmaas.tar.gz -C /tmp && \

@pindo696
pindo696 force-pushed the replace-git-dependency branch from 233fa36 to d4e36f7 Compare September 2, 2026 15:25
@pindo696
pindo696 force-pushed the replace-git-dependency branch from d4e36f7 to 88b8d26 Compare September 10, 2026 07:39
@pindo696
pindo696 marked this pull request as ready for review September 10, 2026 08:59

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 3 issues

Fixed security issues:

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="taskomatic/jobs/archive_downloader.py" line_range="55-57" />
<code_context>
+        LOGGER.warning("Could not extract commit SHA: %s", err)
+
+    # Fallback: SHA256 hash of archive
+    LOGGER.warning("No metadata SHA, using SHA256 hash of archive")
+    with open(archive_path, "rb") as f:
+        return hashlib.sha256(f.read()).hexdigest()[:40]
+
+
</code_context>
<issue_to_address>
**issue:** When an archive has no PAX or ZIP comment, `extract_commit_sha_from_archive` returns the first 40 characters of the archive's SHA256 digest rather than the repository commit SHA promised by the function and used as the imported content version.

**Triggers:** When GitHub or another archive provider does not include commit metadata in the generated archive.

**Suggested fix:** Derive the commit from the archive URL or provider metadata, or explicitly store and document an archive digest instead of treating it as a commit SHA.
</issue_to_address>

### Comment 2
<location path="Dockerfile" line_range="69" />
<code_context>
+        \
+        # VMaaS assets
+        curl -L -H "Authorization: Bearer ${GIT_TOKEN}" "${VMAAS_ARCHIVE_URL}" -o /tmp/vmaas${ARCHIVE_EXT} && \
+        tar -xzf /tmp/vmaas${ARCHIVE_EXT} -C /tmp && \
+        mv /tmp/vmaas-assets-* /engine/vmaas_assets_git && \
+        rm /tmp/vmaas${ARCHIVE_EXT} && \
</code_context>
<issue_to_address>
**issue (bug_risk):** The image build declares `ARCHIVE_EXT` and the downloader supports both `.tar.gz` and `.zip`, but the static-asset build always invokes `tar -xzf`; setting `ARCHIVE_EXT` to `.zip` downloads a ZIP file and then fails extraction.

**Triggers:** When a deployment overrides `ARCHIVE_EXT` to use the advertised ZIP format.

**Suggested fix:** Select the extraction command based on `ARCHIVE_EXT`, or remove ZIP from the supported formats/configuration for the image build.

```suggestion
ENV ARCHIVE_EXT=".tar.gz"
```
</issue_to_address>

### Comment 3
<location path="taskomatic/jobs/archive_downloader.py" line_range="22-23" />
<code_context>
+SUPPORTED_ARCHIVE_FORMATS = {".tar.gz": "tarball", ".zip": "zip"}
+
+
+def _get_archive_type(archive_path: str) -> str:
+    """Detect archive type from path. Returns 'tarball', 'zip', or None"""
+    for ext, archive_type in SUPPORTED_ARCHIVE_FORMATS.items():
+        if archive_path.endswith(ext):
+            return archive_type
+    return None
+
+
</code_context>
<issue_to_address>
**nitpick (bug_risk):** `_get_archive_type` is annotated as returning `str` but returns `None` for every unsupported extension, so its declared return contract is false and strict type checking reports an incompatible return value.

**Triggers:** When static type checking is enabled or a caller relies on the declared non-null return type.

**Suggested fix:** Change the annotation to `str | None` and update the docstring to match.

```suggestion
def _get_archive_type(archive_path: str) -> str | None:
    """Detect archive type from path. Returns 'tarball', 'zip', or None."""
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread taskomatic/jobs/archive_downloader.py
Comment thread Dockerfile Outdated
Comment thread taskomatic/jobs/archive_downloader.py Outdated
Replaced git dependency for playboooks and content import with http. This includes change from git clone to downloading an archive. Updated requirements, keeping git for dev only as tests requires them. RHINENG-30176 and RHINENG-30177
@pindo696
pindo696 force-pushed the replace-git-dependency branch from b5c567d to 2a7aea7 Compare September 10, 2026 15:33
return commit_sha
except Exception as err:
LOGGER.exception("Error downloading repo: %s", err)
from common.utils import EXCEPTION_COUNT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

duplicated import?

return None

try:
# Use tmp dir for download and extract

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is already in tmp dir, no need to create another one

# Try all supported archive formats
for ext in SUPPORTED_ARCHIVE_FORMATS.keys():
archive_path = os.path.join(STATIC_GITS_PATH, f"{repo_name}{ext}")
if os.path.exists(archive_path):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will never succeed, in static repo dir is unpacked repository archive (see static assets in dockerfile)

# Fallback: SHA256 hash of archive
LOGGER.warning("No metadata SHA, using SHA256 hash of archive")
with open(archive_path, "rb") as f:
return hashlib.sha256(f.read()).hexdigest()[:40]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why truncating remaining 24 chars?

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