akhttpd

package module
v0.0.0-...-0166261 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: Unlicense Imports: 12 Imported by: 0

README

akhttpd - Authorized Keys HTTP Daemon

CI Status

This repository contains a small go daemon that serves authorized_keys files for every GitHub user.

This Daemon has two GET-only endpoints:

  • /<user> - when called from a browser, same as /<user>.html, else /<user>/authorized_keys
  • /<user>/authorized_keys - gets the keys of the user user in a format ready for authorized_keys
  • /<user>.html - gets the keys of the user user and shows them in niceish html
  • /<user>.sh - gets a shell script the writes the file $HOME/.ssh/authorized_keys with the content above.

This is intended to be used inside of Docker, and can be found as a GitHub Package. To start it up run:

docker run -p 8080:8080 ghcr.io/tkw1536/akhttpd:latest

You can also use GitHub OAuth Token like so:

docker run -p 8080:8080 -e GITHUB_TOKEN=my-super-secret-token ghcr.io/tkw1536/akhttpd:latest

You can additionally add authorized key files to override whatever is stored on GitHub by adding:

-v /path/to/additional/keys:/keys:ro

For a more detailed documentation, see the godoc page.

License

The code is licensed under the CC0 License, hence in the public domain.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CountWriter

type CountWriter struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

CountWriter is an io.Writer that wraps an underlying writer. It is not safe for concurrent writing.

It counts the the total number of bytes written. Furthermore, once a single write fails, all future writes are silently suppressed.

func (CountWriter) State

func (w CountWriter) State() (int, error)

State returns the first error that occurred within the writer and the total number of bytes written up to that point.

func (CountWriter) StateWith

func (w CountWriter) StateWith(err error) (int, error)

StateWith returns the first error that occurred within the writer and the total number of bytes written up to that point. When err is not nil, returns the provided error instead of the internal error.

func (*CountWriter) Write

func (w *CountWriter) Write(b []byte) (int, error)

Write writes b into Writer.

type Handler

type Handler struct {
	repo.KeyRepository
	Formatters map[string]format.Formatter

	SuffixHTMLPath string // if non-empty, path to append to every html response
	IndexHTMLPath  string // if non-empty, path to serve index.html from
	RobotsTXTPath  string // if non-empty, path to serve robots.txt from
}

Handler is the main akhttpd Server Handler. It implements http.Handler, see the ServerHTTP method.

func (*Handler) RegisterFormatter

func (h *Handler) RegisterFormatter(extension string, formatter format.Formatter)

RegisterFormatter registers formatter as the formatter for the provided extension. When extension is empty, registers it for the path without an extension.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServerHTTP serves the main akhttpd server. It only answers to GET requests, all other requests are answered with Method Not Allowed. Whenever something goes wrong, responds with "Internal Server Error" and logs the error.

This method only responds successfully to a few URLS. All other URLs result in a HTTP 404 Response.

GET /
GET /index.html

When IndexHTMLPath is not the empty string, sends back the file with Status HTTP 200. When IndexHTMLPath is empty, it sends back a default index.html file.

GET /${username}
GET /${username}.${formatter}, GET /${username}/${formatter}

Fetches SSH Keys for the provided user and formats them with formatter. When formatter is omitted, uses the default formatter. If the formatter or user do not exist, returns HTTP 404.

GET /robots.txt

When RobotsTXTPath is not the empty string, sends back the file with Status HTTP 200. When RobotsTXTPath is empty, it sends back a default robots.txt file.

func (Handler) ServeUnderscore

func (Handler) ServeUnderscore(path string) http.Handler

ServeUnderscore returns an http.Handler that serves the provided filesystem path under the prefix '_'.

func (Handler) WriteSuffix

func (h Handler) WriteSuffix(w io.Writer) error

WriteSuffix writes the html suffix to w

Directories

Path Synopsis
cmd
akhttpd
Command akhttpd is the authorized_keys http daemon.
Command akhttpd is the authorized_keys http daemon.
Package legal contains legal notices of packages used by akhttpd.
Package legal contains legal notices of packages used by akhttpd.
pkg
count
Package count provides Writer
Package count provides Writer
repo
Package repo provides KeyRepository
Package repo provides KeyRepository

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL