Skip to content

Instantly share code, notes, and snippets.

@anubhavg-icpl
Last active September 15, 2024 06:20
Show Gist options
  • Save anubhavg-icpl/71ad7dd20332a051f9f4f3a524691cee to your computer and use it in GitHub Desktop.
Save anubhavg-icpl/71ad7dd20332a051f9f4f3a524691cee to your computer and use it in GitHub Desktop.

Aptly Setup on Arch Linux for APT Repository Management

This README provides instructions for setting up Aptly on Arch Linux and configuring it to create and manage APT repositories for Debian-based systems, with integration to AWS S3 for hosting.

Table of Contents

  1. Prerequisites
  2. Installation on Arch Linux
  3. Aptly Configuration
  4. GPG Key Setup
  5. Creating and Managing APT Repositories
  6. Publishing to S3
  7. Client-side Configuration (for Debian-based systems)
  8. Troubleshooting

Prerequisites

  • Arch Linux system
  • sudo privileges
  • AWS account with S3 access

Installation on Arch Linux

  1. Update your system:

    sudo pacman -Syu
    
  2. Install necessary dependencies:

    sudo pacman -S base-devel git go
    
  3. Clone the Aptly repository:

    git clone https://github.com/aptly-dev/aptly.git
    
  4. Build and install Aptly:

    cd aptly
    make install
    
  5. Verify the installation:

    aptly version
    

Aptly Configuration

  1. Create the Aptly configuration directory:

    sudo mkdir -p /etc/aptly
    
  2. Create and edit the Aptly configuration file:

    sudo nano /etc/aptly/aptly.conf
    
  3. Add the following configuration, adjusting as necessary:

    {
      "rootDir": "/var/lib/aptly",
      "downloadConcurrency": 4,
      "downloadSpeedLimit": 0,
      "architectures": ["amd64"],
      "dependencyFollowSuggests": false,
      "dependencyFollowRecommends": false,
      "dependencyFollowAllVariants": false,
      "dependencyFollowSource": false,
      "dependencyVerboseResolve": false,
      "gpgDisableSign": false,
      "gpgDisableVerify": false,
      "downloadSourcePackages": false,
      "skipContentsPublishing": false,
      "S3PublishEndpoints": {
        "invinsense": {
          "region": "us-east-2",
          "bucket": "invinsense",
          "prefix": "4.x/apt/",
          "storageClass": "STANDARD",
          "encryptionMethod": "AES256"
        }
      }
    }

    Note: Ensure you have configured AWS credentials securely using AWS CLI configuration, IAM roles, or environment variables. Do not include AWS access keys in this file.

GPG Key Setup

  1. Generate a GPG key:

    gpg --full-generate-key
    
  2. List your keys and note the ID of the newly created key:

    gpg --list-keys
    
  3. Export the public key:

    gpg --armor --export 'Your Key ID' > public-key.gpg
    
  4. Upload the public key to S3:

    aws s3 cp public-key.gpg s3://invinsense/4.x/apt/public-key.gpg
    

Creating and Managing APT Repositories

  1. Create a new repository:

    aptly repo create -distribution=stable -component=main invinsense-repo
    
  2. Add Debian packages to the repository:

    aptly repo add invinsense-repo /path/to/your/package.deb
    

    Note: Ensure you're adding .deb packages for Debian-based systems.

  3. Create a snapshot of the repository:

    aptly snapshot create invinsense-snap from repo invinsense-repo
    

Publishing to S3

  1. Publish the snapshot to S3:

    aptly publish snapshot -architectures="amd64" -distribution="stable" -gpg-key="Your Key ID" invinsense-snap s3:invinsense:
    
  2. To update the repository later:

    aptly publish update stable s3:invinsense:
    

Client-side Configuration (for Debian-based systems)

For Debian-based clients to use your repository: Based on the error messages you're encountering, it seems there are a few issues we need to address to get the repository working correctly. Let's go through this step-by-step:

  1. The GPG key issue: The system is unable to verify the repository because it doesn't have the correct public key. The error message shows the key ID: F89036D491DD8FC5

  2. The attempt to add the key using apt-key failed: This is because apt-key is deprecated, and the keyserver didn't have the key we're looking for.

Here's what we can do to resolve these issues:

  1. First, let's try to download the public key directly from the S3 bucket and add it to the apt trusted keys:
wget -qO- https://invinsense.s3.us-east-2.amazonaws.com/4.x/apt/public-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/invinsense-archive-keyring.gpg
  1. Now, let's modify the sources list entry to use the new keyring file:
echo "deb [signed-by=/usr/share/keyrings/invinsense-archive-keyring.gpg] https://invinsense.s3.us-east-2.amazonaws.com/4.x/apt/ stable main" | sudo tee /etc/apt/sources.list.d/invinsense-repo.list
  1. After these changes, try updating again:
sudo apt-get update

If you still encounter issues, we might need to verify a few things:

  1. Check if the public key was correctly downloaded and added:
ls -l /usr/share/keyrings/invinsense-archive-keyring.gpg
  1. If the file exists but you're still getting errors, we might need to check the contents of the public key. Let's view its contents:
gpg --no-default-keyring --keyring /usr/share/keyrings/invinsense-archive-keyring.gpg --list-keys

This should show you the key ID. Make sure it matches the one in the error message (F89036D491DD8FC5).

  1. If all else fails, you might need to contact the repository maintainer to ensure that the public key available in the S3 bucket is correct and up-to-date.

Let me know the results of these steps, and we can troubleshoot further if needed.

Troubleshooting

  • If clients encounter GPG key errors, verify the key was correctly imported:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 'Your Key ID'
    
  • For S3 access issues, verify your AWS credentials and S3 bucket permissions.

  • If packages are not found, ensure the S3 paths in your Aptly configuration and sources.list are correct.

  • For detailed logs on Debian-based clients, check /var/log/apt/term.log.

Remember to keep your AWS credentials and GPG keys secure. Never share them publicly or include them in configuration files. If you suspect your credentials have been compromised, rotate them immediately through the AWS IAM console.

@anubhavg-icpl
Copy link
Author

Adding xdr-manager Package to Existing Aptly-managed APT Repository

  1. Prepare the Debian package

    • Ensure you have the xdr-manager.deb package ready.
  2. Add the package to the Aptly repository

    aptly repo add invinsense-repo path/to/xdr-manager.deb
    
  3. Create a new snapshot

    aptly snapshot create xdr-manager-snap from repo invinsense-repo
    
  4. Publish the new snapshot

    aptly publish switch stable s3:invinsense: xdr-manager-snap
    
  5. Verify the upload

    aws s3 ls s3://invinsense/4.x/apt/ --recursive
    
  6. Update client machines
    On Debian-based machines using this repository:

    sudo apt update
    
  7. Test the new package

    sudo apt install xdr-manager
    

Remember to replace path/to/xdr-manager.deb with the actual path to your Debian package file.

@anubhavg-icpl
Copy link
Author

It appears you're trying to publish an Aptly snapshot to an S3 bucket, but you've encountered an error. The error message indicates that the distribution "stable" is already being used by another published repository in the same S3 bucket.

To resolve this issue, you have a few options:

  1. Use a different distribution name:
    Instead of "stable", you could use a different name like "testing" or "dev":

    aptly publish snapshot -architectures="amd64" -distribution="testing" -gpg-key="BEBF58B9A6DA5F5DBE770AC4F89036D491DD8FC5" xdr s3:invinsense:
    
  2. Update the existing publication:
    If you want to update the existing "stable" publication, you can use the -update flag:

    aptly publish switch -gpg-key="BEBF58B9A6DA5F5DBE770AC4F89036D491DD8FC5" stable s3:invinsense: xdr
    
  3. Remove the existing publication:
    If you want to replace the existing publication entirely, you can drop it first:

    aptly publish drop stable s3:invinsense:
    

    Then run your original publish command.

  4. Use a different prefix:
    You could publish to a different prefix within the S3 bucket:

    aptly publish snapshot -architectures="amd64" -distribution="stable" -gpg-key="BEBF58B9A6DA5F5DBE770AC4F89036D491DD8FC5" xdr s3:invinsense:newprefix/
    

Which option you choose depends on your specific needs and workflow. Would you like me to explain any of these options in more detail?

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