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
- Variables
- func Carries(h http.Header) bool
- func CheckRedirect(req *http.Request, via []*http.Request) error
- func Client(c *http.Client) *http.Client
- func Guard(req *http.Request) error
- func List(envVar string) []string
- func Loopback(host string) bool
- func Origin(raw string) (string, error)
- func RequireTLS(raw string) error
- func Token(named, def string) (name, value string, err error)
- func Variable(named, def string) (string, error)
- type InsecureError
- type RefusedVariableError
Constants ¶
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 ¶
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 CheckRedirect ¶
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 ¶
Client returns a copy of c that refuses to take a credential to another origin on a redirect.
func Guard ¶
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 ¶
List reads a comma-separated environment variable, dropping blanks and surrounding space.
func Origin ¶
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 ¶
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 ¶
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 ¶
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