guard

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 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.

Documentation

Overview

Package guard is what a service that other machines may reach shares with the others: the one bearer token it accepts (RFC 6750), where a token is read from, and the rule that a listener off loopback is served only with one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsB64Token

func IsB64Token(s string) bool

IsB64Token reports whether s is a b64token of RFC 6750 § 2.1.

func IsLoopbackAddr

func IsLoopbackAddr(addr net.Addr) bool

IsLoopbackAddr reports whether a bound address can be reached from this machine only.

func IsLoopbackHost

func IsLoopbackHost(host string) bool

IsLoopbackHost reports whether a host name or address is this machine's loopback interface.

func ListenAddress

func ListenAddress(spec string) (string, error)

ListenAddress reads a listening address as every service spells one: a port alone, or host:port whose host is empty, binds loopback (localhost).

func NoToken

func NoToken(env string) error

NoToken is why a listener other machines reach is refused with no token; env is the variable the command reads one from.

Types

type Refusal

type Refusal int

Refusal is why an Authorization header was not accepted, or Accepted.

const (
	// Accepted is a header carrying the token.
	Accepted Refusal = iota
	// NothingPresented is a request with no Authorization header.
	NothingPresented
	// NotBearer is an Authorization header of another scheme.
	NotBearer
	// Malformed is a Bearer header whose credentials are not a b64token.
	Malformed
	// Mismatch is a well-formed bearer token that is not this server's.
	Mismatch
)

func (Refusal) Challenge

func (r Refusal) Challenge(realm string) string

Challenge is the WWW-Authenticate value for a refusal under a realm.

func (Refusal) ChallengeParams

func (r Refusal) ChallengeParams() []string

ChallengeParams are the error parameters of a WWW-Authenticate challenge, none when nothing was presented.

func (Refusal) Code

func (r Refusal) Code() string

Code is the RFC 6750 § 3.1 error code, empty when nothing was presented.

func (Refusal) Description

func (r Refusal) Description() string

Description says what was wrong, empty when nothing was presented.

func (Refusal) HTTPStatus

func (r Refusal) HTTPStatus() int

HTTPStatus is the status a refusal is answered with: 400 for a header the server cannot read, 401 otherwise (RFC 6750 § 3.1).

func (Refusal) Message

func (r Refusal) Message() string

Message is the refusal's text for the client.

func (Refusal) String

func (r Refusal) String() string

String names the refusal for a log line; it never carries what was presented.

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token is the one access token a service accepts (RFC 6750), issued out of band by whoever runs it; the zero value is no token.

func New

func New(s string) (Token, error)

New reads a token as RFC 6750 § 2.1 spells one (b64token), so a client can send what the server was given; anything else is refused.

func Read

func Read(tokenFile, token, env string) (Token, string, error)

Read reads the token -token-file (one trailing line break dropped), -token or the environment variable env names, in that precedence; both flags set is refused, none and an empty variable is no token. The text is returned beside the token for a command that prints its configuration.

func (Token) Check

func (t Token) Check(authorization string) Refusal

Check classifies the Authorization header of a request (RFC 6750 § 2.1).

func (Token) Matches

func (t Token) Matches(presented string) bool

Matches compares a presented token in constant time.

func (Token) Set

func (t Token) Set() bool

Set reports whether a token is configured.

Jump to

Keyboard shortcuts

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