Skip to content

feat: Support Debian-based distros #62

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cmam
Copy link
Contributor

@cmam cmam commented May 28, 2025

what

  • This PR adds support for Debian-based (more like apt-get-based) distros for the Tailscale installation.

why

  • Currently, the "user-data" script assumes that "dnf" is used as the package manager.
  • This is not "compatible" with the AMI variable that allows to customize the instance image to be used, as there are plenty of default package managers.
  • The PR changes the "user-data" script to work with "apt-get" (it does not add support for every package manager out there). The way this was added in the script is to possibly allow for other package managers.
  • The PR also changes the Tailscale setup script, to use the one provided by Tailscale, as it has a wide coverage for many OS. The reason for this is that it removes the responsibility of handling many distros in this script (module).

references

Summary by CodeRabbit

  • New Features
    • The script now automatically detects and uses the appropriate package manager (apt-get or dnf) for installing required packages.
  • Refactor
    • Simplified and unified installation steps for CloudWatch Agent and Tailscale across different Linux distributions.
    • Reduced complexity in Tailscale installation by using the official install script.

@cmam cmam requested a review from a team as a code owner May 28, 2025 14:05
Copy link

coderabbitai bot commented May 28, 2025

Walkthrough

This change updates the userdata.sh.tmpl script to dynamically detect the system's package manager (apt-get or dnf) at runtime. It introduces an install_packages function, which installs required utilities and the CloudWatch Agent using package-manager-specific commands. For apt-get systems, the script downloads and installs the CloudWatch Agent .deb package; for dnf systems, installation is performed directly via dnf. The Tailscale installation is streamlined by using the official install script via curl with retry logic, and explicit systemctl commands for enabling and starting the Tailscale service are removed. Other configurations remain unchanged.

Possibly related PRs

  • fix: avoid RPM lock issue #44: Both PRs refactor the userdata.sh.tmpl script, focusing on improving package installation logic and Tailscale setup, with this PR adding dynamic package manager detection and conditional CloudWatch Agent installation.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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 anywhere in the PR title to generate the title automatically.

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

@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: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a822e2 and 6e8e7b6.

📒 Files selected for processing (1)
  • userdata.sh.tmpl (2 hunks)
🔇 Additional comments (2)
userdata.sh.tmpl (2)

6-18: LGTM: Clean package manager detection logic.

The implementation correctly detects apt-get availability and falls back to dnf, which aligns well with the PR objective of supporting Debian-based distributions.


118-118:

✅ Verification successful

Verify the official Tailscale install script handles service management.

The change simplifies Tailscale installation by using the official script, but the previous implementation explicitly enabled and started the service via systemctl. Ensure the official script handles this properly.

Please verify that the official Tailscale install script properly enables and starts the tailscaled service:


🏁 Script executed:

#!/bin/bash
# Check what the official Tailscale install script does regarding service management
curl -fsSL https://tailscale.com/install.sh | grep -A 5 -B 5 "systemctl\|service"

Length of output: 2240


Service management confirmed in the official Tailscale installer

I’ve verified that the upstream install script handles enabling and starting the tailscaled service across all supported platforms:

  • Debian/Ubuntu (APT):
    Installs tailscale and, if APT_SYSTEMCTL_START=true, runs
    systemctl enable --now tailscaled
    systemctl start tailscaled
    
  • RHEL/CentOS/Fedora (yum, dnf, tdnf):
    Always runs
    systemctl enable --now tailscaled
    
  • SUSE (zypper), Arch (pacman):
    Likewise uses systemctl enable --now tailscaled
  • FreeBSD (pkg):
    Uses
    service tailscaled enable
    service tailscaled start
    
  • Alpine (apk):
    Uses
    rc-update add tailscale
    rc-service tailscale start
    

Since the official script already manages service enablement and startup, replacing the manual systemctl calls with the curl-and-sh approach is safe.

Comment on lines +99 to +100
echo "Installing utilities..."
retry_command "$INSTALL_CMD dnf-utils" 5
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Inconsistent utility installation between package managers.

For apt-get systems, the script installs curl and wget, but for dnf systems it only installs dnf-utils. This inconsistency could cause issues if later parts of the script expect these utilities to be available.

Ensure consistent utility installation:

       # Install utilities.
       echo "Installing utilities..."
-      retry_command "$INSTALL_CMD dnf-utils" 5
+      retry_command "$INSTALL_CMD curl wget dnf-utils" 5
📝 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
echo "Installing utilities..."
retry_command "$INSTALL_CMD dnf-utils" 5
# Install utilities.
echo "Installing utilities..."
retry_command "$INSTALL_CMD curl wget dnf-utils" 5
🤖 Prompt for AI Agents
In userdata.sh.tmpl around lines 99 to 100, the script installs curl and wget
for apt-get systems but only installs dnf-utils for dnf systems, causing
inconsistency. Modify the dnf installation command to also include curl and wget
along with dnf-utils to ensure these utilities are consistently installed across
package managers.

arch=arm64
;;
esac
retry_command "wget https://amazoncloudwatch-agent.s3.amazonaws.com/$distro/$arch/latest/amazon-cloudwatch-agent.deb" 5
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Validate distro ID before using in URL construction.

The script extracts the distro ID directly from /etc/os-release without validation, which could lead to malformed URLs or security issues if the distro ID contains unexpected characters.

Add validation for the distro ID:

       distro=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
+      # Remove quotes and validate distro ID
+      distro=$(echo "$distro" | tr -d '"' | grep -E '^[a-z0-9]+$')
+      if [ -z "$distro" ]; then
+        echo "Could not determine valid distro ID"
+        exit 1
+      fi
       arch=$(uname -m)
📝 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
retry_command "wget https://amazoncloudwatch-agent.s3.amazonaws.com/$distro/$arch/latest/amazon-cloudwatch-agent.deb" 5
distro=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
# Remove quotes and validate distro ID
distro=$(echo "$distro" | tr -d '"' | grep -E '^[a-z0-9]+$')
if [ -z "$distro" ]; then
echo "Could not determine valid distro ID"
exit 1
fi
arch=$(uname -m)
retry_command "wget https://amazoncloudwatch-agent.s3.amazonaws.com/$distro/$arch/latest/amazon-cloudwatch-agent.deb" 5
🤖 Prompt for AI Agents
In userdata.sh.tmpl at line 94, the distro ID used in the wget URL is extracted
without validation, risking malformed URLs or security issues. Add validation
logic to ensure the distro ID contains only expected characters (e.g.,
alphanumeric, dashes) before using it in the URL. If the validation fails,
handle the error appropriately or set a default safe value to prevent unsafe URL
construction.

Comment on lines +84 to +93
distro=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
arch=$(uname -m)
case "$arch" in
x86_64)
arch=amd64
;;
*)
arch=arm64
;;
esac
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve architecture detection for better compatibility.

The current architecture mapping is overly simplistic and may cause issues with other architectures like i386, s390x, or ppc64le.

Consider using a more comprehensive architecture mapping:

-      case "$arch" in
-        x86_64)
-          arch=amd64
-          ;;
-        *)
-          arch=arm64
-          ;;
-      esac
+      case "$arch" in
+        x86_64)
+          arch=amd64
+          ;;
+        aarch64|arm64)
+          arch=arm64
+          ;;
+        *)
+          echo "Unsupported architecture: $arch"
+          exit 1
+          ;;
+      esac
📝 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
distro=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
arch=$(uname -m)
case "$arch" in
x86_64)
arch=amd64
;;
*)
arch=arm64
;;
esac
distro=$(grep '^ID=' /etc/os-release | cut -d'=' -f2)
arch=$(uname -m)
case "$arch" in
x86_64)
arch=amd64
;;
aarch64|arm64)
arch=arm64
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
🤖 Prompt for AI Agents
In userdata.sh.tmpl around lines 84 to 93, the architecture detection is too
simplistic, only mapping x86_64 to amd64 and everything else to arm64, which can
cause issues with other architectures like i386, s390x, or ppc64le. Update the
case statement to include explicit mappings for common architectures such as
i386 to 386, s390x to s390x, ppc64le to ppc64le, and keep amd64 for x86_64,
while defaulting to arm64 only if no other match is found. This will improve
compatibility across different systems.

Copy link
Member

@Gowiem Gowiem left a comment

Choose a reason for hiding this comment

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

@cmam appreciate you opening a PR and trying to upstream these changes. We haven't had the need to run this module on any other distros so this hasn't come up before.

I'm hesitant to accept these changes. It substantially increases the footprint of what we would need to test to verify that this module is working correctly. Also, bash that runs on the host machine is also hard to test -- we definitely don't have a setup for testing this today. Those two pieces make me feel like we're boiling the ocean with this type of change, because someone using Arch linux could come by next week and want to support their OS / package manager.

I think what I'd rather see is that we have an examples/debian/ that shows how to use this module with a different user_data.sh.tmpl script and then a callout in our README that directs debian users there. Then it's less likely that we're taking on potentially hard-to-test changes like this and we're still providing a path for folks like yourself who might have OS requirements in their org.

Make sense? Do you mind updating this PR to be an example rather than trying to handle non-Amazon Linux distros?

Comment on lines -73 to -76
# Setup Tailscale
echo "Enabling and starting tailscaled service..."
systemctl enable --now tailscaled

Copy link
Member

Choose a reason for hiding this comment

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

Why remove these lines @cmam?

Copy link
Member

Choose a reason for hiding this comment

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

Ah from your comment in PR description, it sounds like the new install script that you're invoking does this step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed @Gowiem, if you check the install script provided by Tailscale, they cover the service registration (https://tailscale.com/install.sh).

@cmam
Copy link
Contributor Author

cmam commented May 28, 2025

@cmam appreciate you opening a PR and trying to upstream these changes. We haven't had the need to run this module on any other distros so this hasn't come up before.

@Gowiem Thank you for taking the time to look at the PR and provide comments.

I'm hesitant to accept these changes. It substantially increases the footprint of what we would need to test to verify that this module is working correctly. Also, bash that runs on the host machine is also hard to test -- we definitely don't have a setup for testing this today. Those two pieces make me feel like we're boiling the ocean with this type of change, because someone using Arch linux could come by next week and want to support their OS / package manager.

Fair enough, I thought that you might want to extend the "out-of-the-box" image coverage, but since the module exposes the "user_data" variable, it makes sense to just provide more examples of this as you say.

I think what I'd rather see is that we have an examples/debian/ that shows how to use this module with a different user_data.sh.tmpl script and then a callout in our README that directs debian users there. Then it's less likely that we're taking on potentially hard-to-test changes like this and we're still providing a path for folks like yourself who might have OS requirements in their org.

Make sense? Do you mind updating this PR to be an example rather than trying to handle non-Amazon Linux distros?

Sure, I will make some changes and come back.

@cmam
Copy link
Contributor Author

cmam commented Jun 4, 2025

@Gowiem Hello again, as I tried to make the example, I realized that we can't have a user-data "drop-in" exactly, because the module uses templatefile and passes values from resources it creates (e.g. tailscale_tailnet_key.default.key etc). I don't think the use case can be supported with an example as is TBH.

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