credential

package
v0.173.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 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 credential decides which credential a descriptor may name and where it may be sent.

A descriptor is a file that changes by pull request, and a pipeline running it holds secrets the descriptor's author does not. Every field that names an environment variable holding a credential, and every request that carries one, goes through here, so the answer to "can a change to the descriptor send this job's secrets somewhere" is given once and given the same way for every integration.

Three rules:

  • A descriptor may name only the integration's own variable, or one the pipeline lists in DRAUGR_TOKEN_ENVS. Any other name is refused before anything is read or sent.
  • A credential travels only over https, or over plain http to a loopback address.
  • A request carrying a credential does not follow a redirect to another origin.

Index

Constants

View Source
const TokenEnvsVar = "DRAUGR_TOKEN_ENVS"

TokenEnvsVar lists the further variables a descriptor may name as a credential, comma-separated.

Set by the pipeline, which is the party that knows which of its secrets is meant for which integration. A descriptor cannot set it.

#nosec G101 -- the name of an environment variable that lists variable names, not a credential.

Variables

View Source
var ErrInsecure = errors.New("a credential is sent only over https, or http to localhost, 127.0.0.0/8 or ::1")

ErrInsecure is a credential about to travel without TLS. An *InsecureError matches it.

Functions

func Carries

func Carries(h http.Header) bool

Carries reports whether a request's headers hold a credential.

func CheckRedirect

func CheckRedirect(req *http.Request, via []*http.Request) error

CheckRedirect is an http.Client CheckRedirect that refuses to take a credential to another origin.

A request that carries none follows redirects as net/http would, because some do so by design: an upload to a presigned storage URL carries its authority in the URL and may be redirected between a store's own hosts.

func Client

func Client(c *http.Client) *http.Client

Client returns a copy of c that refuses to take a credential to another origin on a redirect.

func Guard

func Guard(req *http.Request) error

Guard refuses a request that carries a credential over an address RequireTLS refuses. A transport calls it before every request it sends, redirects included.

func List

func List(envVar string) []string

List reads a comma-separated environment variable, dropping blanks and surrounding space.

func Loopback

func Loopback(host string) bool

Loopback reports whether host is this machine: localhost, 127.0.0.0/8 or ::1.

func Origin

func Origin(raw string) (string, error)

Origin is the scheme, host and port of an http or https address, lowercased, with the scheme's default port left out. Two addresses with the same origin reach the same server.

func RequireTLS

func RequireTLS(raw string) error

RequireTLS refuses an address a credential would cross the network to in clear text.

Plain http to localhost, 127.0.0.0/8 or ::1 is accepted, because the bytes never leave the machine and a local server under test is the ordinary reason to use it.

func Token

func Token(named, def string) (name, value string, err error)

Token resolves the variable as Variable does and reads its value.

The name is returned with the error too, so a caller can say which variable was refused, and with an empty value, so a caller can say which variable to set.

func Variable

func Variable(named, def string) (string, error)

Variable is the variable an integration reads its credential from: named, when the descriptor names one, and def otherwise.

A name other than def is refused unless DRAUGR_TOKEN_ENVS lists it. def may be empty, for an integration with no variable of its own, and then every name has to be listed.

Types

type InsecureError

type InsecureError struct {
	// URL is the address, with any password in it redacted.
	URL string
}

InsecureError is an address a credential would reach in clear text.

func (*InsecureError) Error

func (e *InsecureError) Error() string

func (*InsecureError) Is

func (e *InsecureError) Is(target error) bool

Is makes the error match ErrInsecure.

type RefusedVariableError

type RefusedVariableError struct {
	// Name is the variable the descriptor named.
	Name string
	// Default is the integration's own variable, empty for one that has none.
	Default string
}

RefusedVariableError is a descriptor naming a variable it may not read.

func (*RefusedVariableError) Error

func (e *RefusedVariableError) Error() string

Jump to

Keyboard shortcuts

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