Documentation
¶
Overview ¶
Package userdb implements a simple user database.
Format ¶
The user database is a file containing a list of users and their passwords, encrypted with some scheme. We use a text-encoded protobuf, the structure can be found in userdb.proto.
We write text instead of binary to make it easier for administrators to troubleshoot, and since performance is not an issue for our expected usage.
Users must be UTF-8 and NOT contain whitespace; the library will enforce this.
Schemes ¶
The default scheme is SCRYPT, with hard-coded parameters. The API does not allow the user to change this, at least for now. A PLAIN scheme is also supported for debugging purposes.
Writing ¶
The functions that write a database file will not preserve ordering, invalid lines, empty lines, or any formatting.
It is also not safe for concurrent use from different processes.
Index ¶
- Variables
- type DB
- func (db *DB) AddDeniedUser(name string) error
- func (db *DB) AddUser(name, plainPassword string) error
- func (db *DB) Authenticate(name, plainPassword string) bool
- func (db *DB) Exists(name string) bool
- func (db *DB) Reload() error
- func (db *DB) RemoveUser(name string) bool
- func (db *DB) Write() error
- type Denied
- type Password
- func (*Password) Descriptor() ([]byte, []int)deprecated
- func (x *Password) GetDenied() *Denied
- func (x *Password) GetPlain() *Plain
- func (m *Password) GetScheme() isPassword_Scheme
- func (x *Password) GetScrypt() *Scrypt
- func (p *Password) PasswordMatches(plain string) bool
- func (*Password) ProtoMessage()
- func (x *Password) ProtoReflect() protoreflect.Message
- func (x *Password) Reset()
- func (x *Password) String() string
- type Password_Denied
- type Password_Plain
- type Password_Scrypt
- type Plain
- type ProtoDB
- type Scrypt
- func (*Scrypt) Descriptor() ([]byte, []int)deprecated
- func (x *Scrypt) GetEncrypted() []byte
- func (x *Scrypt) GetKeyLen() int32
- func (x *Scrypt) GetLogN() uint64
- func (x *Scrypt) GetP() int32
- func (x *Scrypt) GetR() int32
- func (x *Scrypt) GetSalt() []byte
- func (s *Scrypt) PasswordMatches(plain string) bool
- func (*Scrypt) ProtoMessage()
- func (x *Scrypt) ProtoReflect() protoreflect.Message
- func (x *Scrypt) Reset()
- func (x *Scrypt) String() string
Constants ¶
This section is empty.
Variables ¶
var File_userdb_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a single user database.
func Load ¶
Load the database from the given file. Return the database, and a fatal error if the database could not be loaded.
func (*DB) AddDeniedUser ¶ added in v1.13.0
AddDenied to the database. If the user is already present, override it. Note we enforce that the name has been normalized previously.
func (*DB) AddUser ¶
AddUser to the database. If the user is already present, override it. Note we enforce that the name has been normalized previously.
func (*DB) Authenticate ¶
Authenticate returns true if the password is valid for the user, false otherwise.
func (*DB) Reload ¶
Reload the database, refreshing its contents from the current file on disk. If there are errors reading from the file, they are returned and the database is not changed.
func (*DB) RemoveUser ¶
RemoveUser from the database. Returns True if the user was there, False otherwise.
type Denied ¶ added in v1.13.0
type Denied struct {
// contains filtered or unexported fields
}
func (*Denied) Descriptor
deprecated
added in
v1.13.0
func (*Denied) ProtoMessage ¶ added in v1.13.0
func (*Denied) ProtoMessage()
func (*Denied) ProtoReflect ¶ added in v1.13.0
func (x *Denied) ProtoReflect() protoreflect.Message
type Password ¶
type Password struct { // Types that are assignable to Scheme: // // *Password_Scrypt // *Password_Plain // *Password_Denied Scheme isPassword_Scheme `protobuf_oneof:"scheme"` // contains filtered or unexported fields }
func (*Password) Descriptor
deprecated
func (*Password) PasswordMatches ¶
PasswordMatches returns true if the given password is a match.
func (*Password) ProtoMessage ¶
func (*Password) ProtoMessage()
func (*Password) ProtoReflect ¶
func (x *Password) ProtoReflect() protoreflect.Message
type Password_Denied ¶ added in v1.13.0
type Password_Denied struct {
Denied *Denied `protobuf:"bytes,4,opt,name=denied,proto3,oneof"`
}
type Password_Plain ¶
type Password_Plain struct {
Plain *Plain `protobuf:"bytes,3,opt,name=plain,proto3,oneof"`
}
type Password_Scrypt ¶
type Password_Scrypt struct {
Scrypt *Scrypt `protobuf:"bytes,2,opt,name=scrypt,proto3,oneof"`
}
type Plain ¶
type Plain struct { Password []byte `protobuf:"bytes,1,opt,name=password,proto3" json:"password,omitempty"` // contains filtered or unexported fields }
func (*Plain) Descriptor
deprecated
func (*Plain) GetPassword ¶
func (*Plain) PasswordMatches ¶
PasswordMatches implementation for the plain text scheme. Useful mostly for testing and debugging. TODO: Do we really need this? Removing it would make accidents less likely to happen. Consider doing so when we add another scheme, so we a least have two and multi-scheme support does not bit-rot.
func (*Plain) ProtoMessage ¶
func (*Plain) ProtoMessage()
func (*Plain) ProtoReflect ¶
func (x *Plain) ProtoReflect() protoreflect.Message
type ProtoDB ¶
type ProtoDB struct { Users map[string]*Password `` /* 151-byte string literal not displayed */ // contains filtered or unexported fields }
func (*ProtoDB) Descriptor
deprecated
func (*ProtoDB) ProtoMessage ¶
func (*ProtoDB) ProtoMessage()
func (*ProtoDB) ProtoReflect ¶
func (x *ProtoDB) ProtoReflect() protoreflect.Message
type Scrypt ¶
type Scrypt struct { LogN uint64 `protobuf:"varint,1,opt,name=logN,proto3" json:"logN,omitempty"` R int32 `protobuf:"varint,2,opt,name=r,proto3" json:"r,omitempty"` P int32 `protobuf:"varint,3,opt,name=p,proto3" json:"p,omitempty"` KeyLen int32 `protobuf:"varint,4,opt,name=keyLen,proto3" json:"keyLen,omitempty"` Salt []byte `protobuf:"bytes,5,opt,name=salt,proto3" json:"salt,omitempty"` Encrypted []byte `protobuf:"bytes,6,opt,name=encrypted,proto3" json:"encrypted,omitempty"` // contains filtered or unexported fields }
func (*Scrypt) Descriptor
deprecated
func (*Scrypt) GetEncrypted ¶
func (*Scrypt) PasswordMatches ¶
PasswordMatches implementation for the scrypt scheme, which we use by default.
func (*Scrypt) ProtoMessage ¶
func (*Scrypt) ProtoMessage()
func (*Scrypt) ProtoReflect ¶
func (x *Scrypt) ProtoReflect() protoreflect.Message