password

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 10 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 password is the password behavior: the password of a user, under the user. It sets the password on the Debian family. The controller hashes the password, so the job data and NATS have only its hash.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"password", "The password of a user",
	behavior.Title("User password"),
	behavior.Node,
	behavior.API,
	behavior.Area(area.Security),
	behavior.CLI,
	behavior.Of(user.Behavior),
	behavior.Requires(user.Behavior),
	behavior.Platform(behavior.PlatformDebian, newDebian),
	behavior.Write("update", Update).
		ReadsNothing("no read shows a password or its hash: the host keeps them, and osapi never reads them back").
		AdminOnly().
		Sudo("chpasswd").
		Always().
		Before(hashPassword).
		Describe("Set the password of a user").
		Explain("Sets the password with chpasswd -e, from its hash on standard input. "+
			"The controller hashes the password, so the job and NATS have only the "+
			"hash. Each call makes a new hash, so it always reports changed: true. A "+
			"user that the host does not have is not found. It runs on the Debian "+
			"family only, and elsewhere reports skipped.").
		Example("Set a password",
			UpdateInput{
				Name:         "osapitest",
				Password:     "osapi-test-password",
				PasswordHash: testHash,
			},
			Result{Name: "osapitest", Changed: true},
			withHost(newUser,
				behavior.After(user.CreateInput{Name: "osapitest"}),
				behavior.Ran("chpasswd", "-e"),
			)...,
		).
		Fails("No password", UpdateInput{Name: "alice"}, "give the password", withHost()...).
		Fails("A user that the host does not have",
			UpdateInput{Name: "nobody", PasswordHash: testHash}, "not found", withHost()...).
		Fails("A hash that is not a crypt hash",
			UpdateInput{Name: "alice", PasswordHash: "plain"}, "crypt hash", withHost()...).
		Fails("A name that is an option", UpdateInput{Name: "-r"}, "account_name").
		Fails("A name longer than 32 characters",
			UpdateInput{Name: strings.Repeat("a", 33)}, "max").
		Fails("A password with a line break",
			UpdateInput{Name: "alice", Password: "a\nb"}, "no_linebreak"),
))

Behavior is the password of a user, under the user: /api/node/{hostname}/user/{name}/password. Its permission is the user's user:write, which only the admin role gets, because an account gets to root.

Functions

This section is empty.

Types

type Provider

type Provider interface {
	// Set sets the password of the user from its sha512-crypt hash.
	Set(ctx context.Context, name string, hash string) error
}

Provider sets the password of a user. debian.go sets it on the Debian family; on each other platform the method reports skipped.

type Result

type Result struct {
	Name    string `json:"name"    doc:"The user"`
	Changed bool   `json:"changed" doc:"Whether the host changed"`
}

Result is what update reports for the user.

func Update

func Update(
	ctx context.Context,
	p Provider,
	in UpdateInput,
) (Result, error)

Update sets the password of a user. A new hash differs each time, so it always changes the host.

type UpdateInput

type UpdateInput struct {
	Name         string       `json:"name"                    validate:"required,max=32,account_name" doc:"The user, such as alice"`
	Password     secret.Value `` /* 131-byte string literal not displayed */
	PasswordHash string       `` /* 154-byte string literal not displayed */
}

UpdateInput sets the password of a user. The caller sends password; the controller's step hashes it into password_hash.

Directories

Path Synopsis
Package mocks holds the generated double of the password provider, for the methods' tests.
Package mocks holds the generated double of the password provider, for the methods' tests.

Jump to

Keyboard shortcuts

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