Skip to content

feat: add "runas_host_user" param to get_source() #614

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

Closed
wants to merge 2 commits into from

Conversation

nicob3y
Copy link

@nicob3y nicob3y commented Feb 14, 2025

Docker in Docker context.

I need to execute a containerized source with same UID as the containerized host executing script in order to simplify file permissions management.
"config" and "catalog" files generated thanks to "tempfile" library have 600 POSIX perms and the "runas_host_user" approach helped me to allow source container to read this ones.

It works like the use_host_network param, simply set runas_host_user to True while calling get_source() method.

Summary by CodeRabbit

  • New Features

    • Connectors now offer an option to execute with host user privileges, improving file permission handling and resource access.
  • Deprecations

    • An older connector method has been deprecated in favor of the updated implementation.

Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new boolean parameter runas_host_user to key utility functions across the project. When set to True, these functions modify the Docker command to include the host user's UID and GID by appending the --user flag. This update is applied in the executor, destination, and source modules, with the sources module also deprecating the old get_connector function. Additionally, an import for the os module has been added to support user permission handling.

Changes

Files Change Summary
airbyte/_executors/util.py Added runas_host_user: bool = False to get_connector_executor; modified Docker command construction to append the --user flag when true; added import os at the top.
airbyte/destinations/util.py
airbyte/sources/util.py
Added runas_host_user: bool = False to get_destination and get_source functions; updated method signatures and documentation accordingly; in sources, marked get_connector as deprecated with a warning to use get_source instead.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Function
    participant DockerExecutor

    Caller->>Function: Call with runas_host_user flag set (True/False)
    alt runas_host_user True
        Function->>DockerExecutor: Execute Docker command with "--user UID:GID"
    else runas_host_user False
        Function->>DockerExecutor: Execute standard Docker command
    end
Loading

Possibly related PRs

Suggested labels

enable-ai-review

Suggested reviewers

  • aaronsteers

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
airbyte/_executors/util.py (2)

241-243: Consider adding platform compatibility check?

The os.getuid() and os.getgid() functions are not available on Windows. Should we add a platform check and provide a helpful error message for Windows users, wdyt?

 if runas_host_user is True:
+    if os.name == 'nt':  # Windows
+        raise exc.PyAirbyteInputError(
+            message="The 'runas_host_user' parameter is not supported on Windows.",
+            guidance="This feature is only available on POSIX systems (Linux, macOS)."
+        )
     docker_cmd.extend(["--user", f"{os.getuid()}:{os.getgid()}"])

127-127: Consider documenting platform limitations?

The runas_host_user parameter is only supported on POSIX systems. Should we add this information to the docstring, wdyt?

     use_host_network: bool = False,
-    runas_host_user: bool = False,
+    runas_host_user: bool = False,  # Only supported on POSIX systems (Linux, macOS)
     source_manifest: bool | dict | Path | str | None = None,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d064d42 and c660095.

📒 Files selected for processing (3)
  • airbyte/_executors/util.py (3 hunks)
  • airbyte/destinations/util.py (3 hunks)
  • airbyte/sources/util.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Pytest (No Creds)
  • GitHub Check: Pytest (Fast)
🔇 Additional comments (2)
airbyte/destinations/util.py (1)

31-31: LGTM!

The parameter is well-documented and correctly propagated to the executor.

Also applies to: 60-62, 77-77

airbyte/sources/util.py (1)

58-58: LGTM!

The parameter is well-documented and correctly propagated to the executor.

Also applies to: 99-101, 123-123

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
airbyte/_executors/util.py (4)

2-9: Import block needs reordering per pipeline warning.

The CI pipeline reported that the import block is un-sorted. Would you consider reordering the imports alphabetically and grouping them properly (standard library, third-party, local imports)? This will resolve the warning and improve code organization, wdyt?

from __future__ import annotations

import logging
import os
import tempfile
from pathlib import Path
from typing import TYPE_CHECKING, Literal, cast


import requests
import yaml
from rich import print  # noqa: A004  # Allow shadowing the built-in
🧰 Tools
🪛 GitHub Actions: Run Linters

[warning] 2-2: Ruff: Import block is un-sorted or un-formatted. Organize imports.


129-129: New parameter looks good, but should be documented.

The runas_host_user parameter matches the PR objectives and follows the existing parameter pattern. However, I noticed the docstring only references another function for parameter documentation. Would you consider updating the docstring to include this new parameter directly?


121-121: Function complexity exceeds threshold per pipeline error.

The get_connector_executor function now exceeds the complexity threshold (25 > 24) according to the pipeline error. This is likely due to the new runas_host_user implementation.

Would you consider refactoring some of the logic into smaller helper functions to reduce the complexity? Perhaps extracting the Docker command construction into a separate function would help here.

🧰 Tools
🪛 Ruff (0.8.2)

121-121: get_connector_executor is too complex (25 > 24)

(C901)

🪛 GitHub Actions: Run Linters

[error] 121-121: Ruff: get_connector_executor is too complex (25 > 24).


243-248: Consider handling Windows systems more explicitly.

The current implementation tries to use os.getuid() and os.getgid(), which aren't available on Windows. While the exception handling works, it might be clearer to detect the OS type explicitly.

What do you think about this approach?

if runas_host_user is True:
+    import platform
+    if platform.system() != "Windows":
        try:
            docker_cmd.extend(["--user", f"{os.getuid()}:{os.getgid()}"])
-        except:
+        except AttributeError:
            logger.info("The 'runas_host_user' parameter is only supported on POSIX systems.")
+    else:
+        logger.info("The 'runas_host_user' parameter is not supported on Windows.")
🧰 Tools
🪛 Ruff (0.8.2)

246-246: Do not use bare except

(E722)

🪛 GitHub Actions: Run Linters

[error] 246-246: Ruff: Do not use bare except.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c660095 and 414ec3d.

📒 Files selected for processing (1)
  • airbyte/_executors/util.py (4 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
airbyte/_executors/util.py

246-246: Do not use bare except

(E722)

🪛 GitHub Actions: Run Linters
airbyte/_executors/util.py

[warning] 2-2: Ruff: Import block is un-sorted or un-formatted. Organize imports.


[error] 121-121: Ruff: get_connector_executor is too complex (25 > 24).


[error] 246-246: Ruff: Do not use bare except.

Comment on lines +243 to +248
if runas_host_user is True:
try:
docker_cmd.extend(["--user", f"{os.getuid()}:{os.getgid()}"])
except:
logger.info("The 'runas_host_user' parameter is only supported on POSIX systems.")

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid bare except and consider reporting non-POSIX limitation more visibly.

The implementation of the runas_host_user parameter makes sense, but there are a couple of issues:

  1. The bare except clause is flagged by linters and should be replaced with specific exception types.
  2. The behavior silently falls back without the --user flag on non-POSIX systems.

What do you think about this implementation?

if runas_host_user is True:
    try:
        docker_cmd.extend(["--user", f"{os.getuid()}:{os.getgid()}"])
-    except:
+    except AttributeError:
        logger.info("The 'runas_host_user' parameter is only supported on POSIX systems.")
+        logger.warning("Continuing without host user permissions. File operations may fail.")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if runas_host_user is True:
try:
docker_cmd.extend(["--user", f"{os.getuid()}:{os.getgid()}"])
except:
logger.info("The 'runas_host_user' parameter is only supported on POSIX systems.")
if runas_host_user is True:
try:
docker_cmd.extend(["--user", f"{os.getuid()}:{os.getgid()}"])
except AttributeError:
logger.info("The 'runas_host_user' parameter is only supported on POSIX systems.")
logger.warning("Continuing without host user permissions. File operations may fail.")
🧰 Tools
🪛 Ruff (0.8.2)

246-246: Do not use bare except

(E722)

🪛 GitHub Actions: Run Linters

[error] 246-246: Ruff: Do not use bare except.

@nicob3y
Copy link
Author

nicob3y commented Mar 29, 2025

resolved by #637

@nicob3y nicob3y closed this Mar 29, 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.

1 participant