auth

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-auth

go-auth is a hosted authentication, authorization, TLS certificate, and LDAP management application. It combines three subsystems in one server process:

  • Auth management for local users, sessions, identity providers, and bearer tokens.
  • Certificate management for storing and working with TLS certificate material.
  • LDAP management for projecting users and groups into an LDAP directory.

It requires a PostgreSQL database for storage and can be configured with environment variables and CLI flags.

Quick Start

Run the container, in order to add users, groups, and scopes to the system:

export PG_URL='postgres://user@host.docker.internal/database?sslmode=prefer'
docker run --rm  --name go-auth \
  -e PG_URL -e PG_PASSWORD \
  -p 80:80 \
  ghcr.io/mutablelogic/go-auth run --no-auth.enabled --local.enabled

Then you can login with the local provider at http://localhost:80 (to which you only need to add an email address) and start managing users, groups, and scopes. The local provider supports browser-based login flows but does not have a password-based API, so you must create users with the CLI or UI before you can authenticate.

After you've added the scopes, users and groups, you can enable authentication on the management endpoints and add more providers as needed. See the sections below for details on all available configuration options.

Notes:

  • PG_URL is required. The service will not start without a PostgreSQL connection.

Auth Parameters

These parameters configure the authentication manager and identity provider integration.

Parameter Type Description
AUTH_SCHEMA env Database schema used for auth tables.
AUTH_SESSION_TTL env Session lifetime. Defaults to 15 minutes when unset.
AUTH_REFRESH_TTL env Refresh token lifetime. Defaults to 7 days when unset.
GOOGLE_CLIENT_ID env Enables the Google provider when set.
GOOGLE_CLIENT_SECRET env Google OAuth client secret.
--auth.enabled / --no-auth cli Enable or disable authentication on management endpoints. Default is enabled.
--auth.signer=file:///path/to/key.pem?kid=main cli Add a private key PEM file used to sign issued tokens. Repeat to add multiple signers.
--local.enabled / --no-local.enabled cli Enable or disable the built-in local browser-flow identity provider. Default is disabled.

Examples:

docker run --rm \
  -p 8084:80 \
  -e AUTHMANAGER_ADDR=:80 \
  -e PG_URL='postgres://user:password@host.docker.internal/authdb?sslmode=disable' \
  -e AUTH_SCHEMA='auth' \
  -e AUTH_SESSION_TTL='30m' \
  -e AUTH_REFRESH_TTL='168h' \
  -e GOOGLE_CLIENT_ID='your-google-client-id' \
  -e GOOGLE_CLIENT_SECRET='your-google-client-secret' \
  "$IMAGE"

Cert Parameters

These parameters configure the certificate manager.

Parameter Type Description
CERT_ENABLED env Enable or disable the certificate manager. Default is true.
CERT_PASSPHRASE env Passphrase used for encrypting private keys. Can be supplied multiple times in CLI usage; in Docker this is typically provided once per environment variable name supported by your runtime.
CERT_SCHEMA env Database schema used for certificate tables.

Example:

docker run --rm \
  -p 8084:80 \
  -e AUTHMANAGER_ADDR=:80 \
  -e PG_URL='postgres://user:password@host.docker.internal/authdb?sslmode=disable' \
  -e CERT_ENABLED='true' \
  -e CERT_SCHEMA='cert' \
  -e CERT_PASSPHRASE='change-me' \
  "$IMAGE"

LDAP Parameters

These parameters configure the LDAP manager. The LDAP manager is only started when LDAP_URL is set.

Parameter Type Description
LDAP_URL env LDAP server URL to connect to or manage. When unset, the LDAP manager is disabled.
LDAP_BASEDN env Base DN for LDAP entries. Default is dc=example,dc=org.
LDAP_USER env Bind user DN used by the LDAP manager. Default is cn=admin,dc=example,dc=org.
LDAP_PASS env Bind password for the LDAP manager.
LDAP_USER_DN env Relative DN for the user subtree, for example ou=users.
LDAP_GROUP_DN env Relative DN for the group subtree, for example ou=groups.

Example:

docker run --rm \
  -p 8084:80 \
  -e AUTHMANAGER_ADDR=:80 \
  -e PG_URL='postgres://user:password@host.docker.internal/authdb?sslmode=disable' \
  -e LDAP_URL='ldap://ldap.example.org:389' \
  -e LDAP_BASEDN='dc=example,dc=org' \
  -e LDAP_USER='cn=admin,dc=example,dc=org' \
  -e LDAP_PASS='change-me' \
  -e LDAP_USER_DN='ou=users' \
  -e LDAP_GROUP_DN='ou=groups' \
  "$IMAGE"

Common Container Parameters

These are not subsystem-specific, but they are usually required in Docker deployments:

Parameter Type Description
PG_URL env PostgreSQL connection URL. Required for startup.
PG_PASSWORD env PostgreSQL password override.
AUTHMANAGER_ADDR env HTTP listen address. Set this to :80 or :443 in containers.
ADDR env Alternate generic listen-address environment variable.
--http.prefix cli HTTP API path prefix. Default is /api.
--http.timeout cli HTTP server read/write timeout. Default is 15m.
--http.origin cli Cross-origin protection origin configuration.
--tls.name cli TLS server name.
--tls.cert cli TLS certificate file inside the container.
--tls.key cli TLS private key file inside the container.
--ui / --no-ui cli Enable or disable the embedded UI. Default is enabled.
--openapi / --no-openapi cli Enable or disable the OpenAPI endpoints. Default is enabled.

If you mount certificate files into the container, a TLS-enabled run looks like this:

docker run --rm \
  -p 8443:443 \
  -e AUTHMANAGER_ADDR=:443 \
  -e PG_URL='postgres://user:password@host.docker.internal/authdb?sslmode=disable' \
  -v "$PWD/certs:/certs:ro" \
  "$IMAGE" \
  run --tls.cert=/certs/tls.crt --tls.key=/certs/tls.key

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientError added in v0.0.15

func ClientError(err error) error

ClientError converts an error response from an API to the auth error for its status, which wraps it, so a client's callers can check it with errors.Is, as they would the errors of the server's store

func HTTPError

func HTTPError(err error) error

HTTPError converts an auth.Err to an appropriate httpresponse error, preserving the reason message.

Types

type Err

type Err int

Err represents a typed application error.

const (
	ErrSuccess Err = iota
	ErrNotFound
	ErrBadParameter
	ErrNotImplemented
	ErrConflict
	ErrServiceUnavailable
	ErrInternalServerError
	ErrInvalidProvider
	ErrForbidden
	ErrNotModified
)

func (Err) Error

func (e Err) Error() string

func (Err) With

func (e Err) With(args ...any) error

func (Err) Withf

func (e Err) Withf(format string, args ...any) error

Withf returns the error with a formatted reason. Errors in the arguments formatted with %w are wrapped, so errors.Is and errors.As match them as well as the Err.

Directories

Path Synopsis
auth
cmd
Package cmd has the commands which sign in to a server, in a browser, with OAuth, and keep the token, which the other commands send, with ClientEndpoint, and sign out.
Package cmd has the commands which sign in to a server, in a browser, with OAuth, and keep the token, which the other commands send, with ClientEndpoint, and sign out.
httpclient
Package httpclient is a general OAuth client, with go-client, which signs in to a resource which needs to be authorized, such as an MCP server's, or go-auth's own APIs:
Package httpclient is a general OAuth client, with go-client, which signs in to a resource which needs to be authorized, such as an MCP server's, or go-auth's own APIs:
httphandler
Package httphandler registers the HTTP handlers which sign people in with providers, such as Google, GitHub and LDAP, and exchange who they are for what the server makes of it
Package httphandler registers the HTTP handlers which sign people in with providers, such as Google, GitHub and LDAP, and exchange who they are for what the server makes of it
provider
Package provider has the interfaces of the providers people sign in with, such as Google, GitHub and LDAP, which exchange what proves who someone is for an identity.
Package provider has the interfaces of the providers people sign in with, such as Google, GitHub and LDAP, which exchange what proves who someone is for an identity.
provider/file
Package file keeps sessions in files, in a directory, one for each, named by the SHA-256 of its token, which isn't kept, so they last when the server restarts, without a database.
Package file keeps sessions in files, in a directory, one for each, named by the SHA-256 of its token, which isn't kept, so they last when the server restarts, without a database.
provider/github
Package github is a provider of GitHub, or GitHub Enterprise, which is signed in with at GitHub, as an OAuth app, which isn't OpenID Connect, so the identity is the user GitHub's API says the token is for.
Package github is a provider of GitHub, or GitHub Enterprise, which is signed in with at GitHub, as an OAuth app, which isn't OpenID Connect, so the identity is the user GitHub's API says the token is for.
provider/ldap
Package ldap is a provider of an LDAP directory, which is signed in with a username and password, which is checked with a bind as the user, whose groups are the identity's.
Package ldap is a provider of an LDAP directory, which is signed in with a username and password, which is checked with a bind as the user, whose groups are the identity's.
provider/oidc
Package oidc is a provider which is an OpenID Connect issuer, such as Google, Microsoft or Keycloak, which is signed in with at its own pages, and whose ID tokens are checked against its keys.
Package oidc is a provider which is an OpenID Connect issuer, such as Google, Microsoft or Keycloak, which is signed in with at its own pages, and whose ID tokens are checked against its keys.
security
Package security is the security scheme which the server's operations need, with their scopes: a session's token, as a bearer token, or the session's cookie, which a sign-in sets.
Package security is the security scheme which the server's operations need, with their scopes: a session's token, as a bearer token, or the session's cookie, which a sign-in sets.
store
Package store has the interfaces of what an identity is exchanged with: a hook, which allows it, or refuses it, the users, which say who it is, and the scopes they have, and the sessions, which they're signed in with, and the exchanger, which exchanges an identity for a session.
Package store has the interfaces of what an identity is exchanged with: a hook, which allows it, or refuses it, the users, which say who it is, and the scopes they have, and the sessions, which they're signed in with, and the exchanger, which exchanges an identity for a session.
test
Package test has fake providers, which tests sign in with: an OpenID Connect issuer, and GitHub, each an HTTP server, which gives the identity it's told to, for a code, once, when it's exchanged with the verifier of its PKCE challenge.
Package test has fake providers, which tests sign in with: an OpenID Connect issuer, and GitHub, each an HTTP server, which gives the identity it's told to, for a code, once, when it's exchanged with the verifier of its PKCE challenge.
cmd
schema
Package schema has the PostgreSQL store's tables and queries, and binds the certificate types in cert/cert to them.
Package schema has the PostgreSQL store's tables and queries, and binds the certificate types in cert/cert to them.
test
Package test runs certificate manager tests against PostgreSQL in a container: the manager's own tests, and the tests of what's built on it.
Package test runs certificate manager tests against PostgreSQL in a container: the manager's own tests, and the tests of what's built on it.
cmd
auth command
aws
cmd
env
pg
Package frontend is go-auth's web UI: its modules, such as Credentials, which the package @mutablelogic/go-auth exports, and the auth server's app, which make builds into app/dist, and which a command built with the "frontend" tag embeds, as EmbedFS.
Package frontend is go-auth's web UI: its modules, such as Credentials, which the package @mutablelogic/go-auth exports, and the auth server's app, which make builds into app/dist, and which a command built with the "frontend" tag embeds, as EmbedFS.
cmd
Package cmd serves the web UI, and the server's configuration, which it reads, beside the API, when the server is built with the "frontend" tag, which embeds the UI, once it's built, with npm, into frontend/dist, which make does.
Package cmd serves the web UI, and the server's configuration, which it reads, beside the API, when the server is built with the "frontend" tag, which embeds the UI, once it's built, with npm, into frontend/dist, which make does.
ldap
cmd
Package ldap has the LDAP manager's command-line flags, for a server
Package ldap has the LDAP manager's command-line flags, for a server
httpclient
Package httpclient calls the LDAP API, which ldap/httphandler serves
Package httpclient calls the LDAP API, which ldap/httphandler serves
httphandler
Package httphandler registers the HTTP handlers of the LDAP manager: the directory's schema, users, groups and their members, and objects by DN
Package httphandler registers the HTTP handlers of the LDAP manager: the directory's schema, users, groups and their members, and objects by DN
manager
Package manager connects to an LDAP directory, and keeps the connection, binding as the manager's user, and reconnecting when it's lost
Package manager connects to an LDAP directory, and keeps the connection, binding as the manager's user, and reconnecting when it's lost
parser
Package ldapparser reads the RFC 4512 descriptions of LDAP object classes and attribute types, such as a directory's subschema publishes
Package ldapparser reads the RFC 4512 descriptions of LDAP object classes and attribute types, such as a directory's subschema publishes
parser/schema
Package schema has the definitions of LDAP object classes and attribute types, which the parser reads from their RFC 4512 descriptions
Package schema has the definitions of LDAP object classes and attribute types, which the parser reads from their RFC 4512 descriptions
schema
Package schema has the LDAP manager's types: objects, with their LDIF, distinguished names, and the directory's object classes and attribute types, with the requests which list them, and its defaults
Package schema has the LDAP manager's types: objects, with their LDIF, distinguished names, and the directory's object classes and attribute types, with the requests which list them, and its defaults
test
Package test runs tests against LDAP directories, OpenLDAP, 389 DS and SMB LDS, with a manager connected to each.
Package test runs tests against LDAP directories, OpenLDAP, 389 DS and SMB LDS, with a manager connected to each.

Jump to

Keyboard shortcuts

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