Git Product home page Git Product logo

apt-golang-s3's Introduction

apt-golang-s3

An s3 transport method for the apt package management system

Build Status Go Report Card GoDoc

The apt-golang-s3 project provides support for hosting private apt repositories in Amazon S3. This is useful if you have private packages, vendored public packages, or forks of public packages that your software or business depend on. There are several opensource projects that solve this problem, but they come with some limitations.

  1. They are unmaintained.
  2. They don't support the S3v4 request signature method.
  3. They are written in a language that requires a runtime or other dependencies.

This project is an attempt to address those limitations.

TL;DR

  1. Build the binary $ go build -o apt-golang-s3 main.go
  2. Install the binary $ sudo cp apt-golang-s3 /usr/lib/apt/methods/s3
  3. Add your s3 based source to a package list $ echo "deb s3://access-key:[email protected]/private-repo-bucket stable main" > /etc/apt/sources.list.d/private-repo.list
  4. Update and install packages $ sudo apt-get update && sudo apt-get install your-private-package

Building the go program

There is an included Dockerfile to setup an environment for building the binary in a sandboxed environment:

$ ls
Dockerfile  main.go  method  README.md

$ docker build -t apt-golang-s3 .
...

$ docker run -it --rm -v $(pwd):/app apt-golang-s3 bash

root@83823fffd369:/app# ls
Dockerfile  README.md  build-deb.sh  go.mod  go.sum  main.go  method

root@83823fffd369:/app# go build -o apt-golang-s3 main.go
...

root@83823fffd369:/app# ls
Dockerfile  README.md  apt-golang-s3  build-deb.sh  go.mod  go.sum  main.go  method

root@83823fffd369:/app# exit
exit

$ ls
apt-golang-s3  build-deb.sh  Dockerfile  go.mod  go.sum  main.go  method  README.md

Building a debian package

For convenience, there is a small bash script in the repository that can build the binary and package it as a .deb.

$ ls
build-deb.sh  Dockerfile  go.mod  go.sum  main.go  method  README.md

$ docker build -t apt-golang-s3 .

$ docker run -it --rm -v $(pwd):/app apt-golang-s3 /app/build-deb.sh
...
Created package {:path=>"apt-golang-s3_1_amd64.deb"}

$ ls
apt-golang-s3  apt-golang-s3_1_amd64.deb  build-deb.sh  Dockerfile  go.mod  go.sum  main.go  method  README.md

Installing in production

The apt-golang-s3 binary is an executable. To install it copy it to /usr/lib/apt/methods/s3 on your computer. The .deb file produced by build-deb.sh will install the method in the correct place.

Configuration

APT Repository Source Configuration

We recommend issuing a separate set of API keys, with read-only access, to the S3 bucket that hosts your repository. The keys are specified in the apt sources list configuration as follows:

$ cat /etc/apt/sources.list.d/my-private-repo.list
deb s3://aws-access-key-id:[email protected]/my-private-repo-bucket stable main

APT Method Configuration

The current default AWS region is set to us-east-1, but can be overridden by adding an option in your apt configuration, e.g.

echo "Acquire::s3::region us-east-1;" > /etc/apt/apt.conf.d/s3

Alternatively, you may specify an IAM role to assume before connecting to S3. The role will be assumed using the default credential chain; this option is mutually exclusive with static credentials in the S3 URL.

echo "Acquire::s3::role arn:aws:iam::123456789012:role/s3-apt-reader;" > /etc/apt/apt.conf.d/s3

Additional configuration options may be added in the future.

How it works

Apt creates a child process using the /usr/lib/apt/methods/s3 binary and writes to that processes standard input using a specific protocol. The method interprets the input, downloads the requested files, and communicates back to apt by writing to its standard output. The protocol spec is available here http://www.fifi.org/doc/libapt-pkg-doc/method.html/ch2.html.

Similar Projects

Disclaimer

This is not an officially supported Google product.

apt-golang-s3's People

Contributors

adamrothman avatar adamvduke avatar dedalusj avatar nouse avatar patcable avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

apt-golang-s3's Issues

Releases with CI-built binaries

It'd be really nice if this repo included releases with usable binaries.

Would there be any interest in a PR to set up a Github Actions workflow that uses goreleaser to build and publish release artifacts when a semver tag is pushed?

I would propose configuring it to publish a "plain" binary as well as a deb, targeting at least amd64 to start. (The configuration to add other targets is trivial.)

Secret access key with `/`: invalid port ... after host

If there is a / character in the secret access key, the url parsing fails with an error like this:

General failure: parse "s3://AKIA...:B.../[email protected]/my-bucket/.../InRelease": invalid port ":B.../...A" after host

This can be worked around by double-urlencoding the secret access key in the sources file (apt seems to remove one layer of urlencoding).

However, the string does make it through to the transport binary (that error is coming from url.Parse) cleanly, so this could be handled entirely within the transport, such as by pre-processing the url before it is passed to url.Parse.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.