Documentation
¶
Overview ¶
Package ipa is a Go client for the FreeIPA JSON-RPC API. It is a maintained continuation of github.com/ubccr/goipa.
A Client logs in with a password (Login for Kerberos, RemoteLogin for the web API), a keytab (LoginWithKeytab), a credentials cache (LoginFromCCache), or an existing session (NewDefaultClientWithSession, SetSessionID). A *Client is safe for concurrent use.
A FreeIPA error is returned as a bare *IpaError: match it with errors.Is against ErrNotFound and the other sentinels, or with a type assertion.
Every method that talks to the server has a ...Context twin that bounds the request with a context, except Login, LoginWithKeytab and LoginFromCCache (gokrb5 is not cancellable). RPC calls any command goipa does not wrap.
Example (Login) ¶
The Kerberos logins need a KDC, so this example is compiled but not run.
package main
import (
"fmt"
"log"
ipa "github.com/neverlless/goipa"
)
func main() {
c := ipa.NewClient("ipa.example.com", "EXAMPLE.COM")
if err := c.LoginWithKeytab("/etc/app/app.keytab", "svc-app"); err != nil {
log.Fatal(err)
}
u, err := c.UserShow("jesse")
if err != nil {
log.Fatal(err)
}
fmt.Println(u.Username, u.Email)
}
Output:
Index ¶
- Constants
- Variables
- func ParseDateTime(str string) time.Time
- type Client
- func (c *Client) AddOTPToken(token *OTPToken) (*OTPToken, error)
- func (c *Client) AddOTPTokenContext(ctx context.Context, token *OTPToken) (*OTPToken, error)
- func (c *Client) ChangePassword(username, oldPasswd, newPasswd, otpcode string) error
- func (c *Client) ChangePasswordContext(ctx context.Context, username, oldPasswd, newPasswd, otpcode string) error
- func (c *Client) ClearSession()
- func (c *Client) DisableOTPToken(tokenUUID string) error
- func (c *Client) DisableOTPTokenContext(ctx context.Context, tokenUUID string) error
- func (c *Client) EnableOTPToken(tokenUUID string) error
- func (c *Client) EnableOTPTokenContext(ctx context.Context, tokenUUID string) error
- func (c *Client) FetchOTPTokens(owner string) ([]*OTPToken, error)
- func (c *Client) FetchOTPTokensContext(ctx context.Context, owner string) ([]*OTPToken, error)
- func (c *Client) GroupAdd(group *Group) (*Group, error)
- func (c *Client) GroupAddContext(ctx context.Context, group *Group) (*Group, error)
- func (c *Client) GroupAddMember(group string, users, groups []string) (*Group, error)
- func (c *Client) GroupAddMemberContext(ctx context.Context, group string, users, groups []string) (*Group, error)
- func (c *Client) GroupAddMemberManager(group string, users, groups []string) (*Group, error)
- func (c *Client) GroupAddMemberManagerContext(ctx context.Context, group string, users, groups []string) (*Group, error)
- func (c *Client) GroupDelete(names ...string) error
- func (c *Client) GroupDeleteContext(ctx context.Context, names ...string) error
- func (c *Client) GroupFind(options Options) ([]*Group, error)
- func (c *Client) GroupFindContext(ctx context.Context, options Options) ([]*Group, error)
- func (c *Client) GroupMod(group *Group) (*Group, error)
- func (c *Client) GroupModContext(ctx context.Context, group *Group) (*Group, error)
- func (c *Client) GroupRemoveMember(group string, users, groups []string) (*Group, error)
- func (c *Client) GroupRemoveMemberContext(ctx context.Context, group string, users, groups []string) (*Group, error)
- func (c *Client) GroupRemoveMemberManager(group string, users, groups []string) (*Group, error)
- func (c *Client) GroupRemoveMemberManagerContext(ctx context.Context, group string, users, groups []string) (*Group, error)
- func (c *Client) GroupShow(name string) (*Group, error)
- func (c *Client) GroupShowContext(ctx context.Context, name string) (*Group, error)
- func (c *Client) Host() string
- func (c *Client) HostFind(options Options) ([]*Host, error)
- func (c *Client) HostFindContext(ctx context.Context, options Options) ([]*Host, error)
- func (c *Client) HostShow(fqdn string) (*Host, error)
- func (c *Client) HostShowContext(ctx context.Context, fqdn string) (*Host, error)
- func (c *Client) Login(username, password string) error
- func (c *Client) LoginFromCCache(cpath string) error
- func (c *Client) LoginWithKeytab(ktab, username string) error
- func (c *Client) Ping() (*Response, error)
- func (c *Client) PingContext(ctx context.Context) (*Response, error)
- func (c *Client) RPC(method string, args []string, options Options) (*Response, error)
- func (c *Client) RPCContext(ctx context.Context, method string, args []string, options Options) (*Response, error)
- func (c *Client) Realm() string
- func (c *Client) RemoteLogin(uid, passwd string) error
- func (c *Client) RemoteLoginContext(ctx context.Context, uid, passwd string) error
- func (c *Client) RemoveOTPToken(tokenUUID string) error
- func (c *Client) RemoveOTPTokenContext(ctx context.Context, tokenUUID string) error
- func (c *Client) ResetPassword(username string) (string, error)
- func (c *Client) ResetPasswordContext(ctx context.Context, username string) (string, error)
- func (c *Client) SessionID() string
- func (c *Client) SetAuthTypes(username string, types []string) error
- func (c *Client) SetAuthTypesContext(ctx context.Context, username string, types []string) error
- func (c *Client) SetPassword(username, oldPasswd, newPasswd, otpcode string) error
- func (c *Client) SetPasswordContext(ctx context.Context, username, oldPasswd, newPasswd, otpcode string) error
- func (c *Client) SetSessionID(sessionID string)
- func (c *Client) StickySession(enable bool)
- func (c *Client) UserAdd(user *User, random bool) (*User, error)
- func (c *Client) UserAddContext(ctx context.Context, user *User, random bool) (*User, error)
- func (c *Client) UserAddWithPassword(user *User, password string) (*User, error)
- func (c *Client) UserAddWithPasswordContext(ctx context.Context, user *User, password string) (*User, error)
- func (c *Client) UserDelete(preserve, stopOnError bool, usernames ...string) error
- func (c *Client) UserDeleteContext(ctx context.Context, preserve, stopOnError bool, usernames ...string) error
- func (c *Client) UserDisable(username string) error
- func (c *Client) UserDisableContext(ctx context.Context, username string) error
- func (c *Client) UserEnable(username string) error
- func (c *Client) UserEnableContext(ctx context.Context, username string) error
- func (c *Client) UserFind(options Options) ([]*User, error)
- func (c *Client) UserFindContext(ctx context.Context, options Options) ([]*User, error)
- func (c *Client) UserMod(user *User) (*User, error)
- func (c *Client) UserModContext(ctx context.Context, user *User) (*User, error)
- func (c *Client) UserShow(username string) (*User, error)
- func (c *Client) UserShowContext(ctx context.Context, username string) (*User, error)
- type Group
- type HTTPError
- type Host
- type IpaError
- type MemberError
- type MemberFailure
- type Message
- type OTPToken
- type Options
- type Response
- type Result
- type SSHAuthorizedKey
- type User
Examples ¶
Constants ¶
const ( CodeVersion = 901 CodeCommand = 905 CodeReferer = 911 CodeACI = 2100 CodeRequirement = 3007 CodeValidation = 3009 CodeNotFound = 4001 CodeDuplicateEntry = 4002 CodeAlreadyActive = 4009 CodeAlreadyInactive = 4010 CodeNotGroupMember = 4012 CodeAlreadyGroupMember = 4014 CodeAttrValueNotFound = 4026 CodeAlreadyContainsValue = 4038 CodeEmptyModlist = 4202 CodeDatabase = 4203 )
FreeIPA error codes (ipalib.errors).
const ( DefaultKerbConf = "/etc/krb5.conf" IpaClientVersion = "2.237" IpaDatetimeFormat = "20060102150405Z" )
const ( AlgorithmSHA1 = "sha1" AlgorithmSHA256 = "sha256" AlgorithmSHA384 = "sha384" AlgorithmSHA512 = "sha512" )
OTP Token hash Algorithms supported by FreeIPA
const ( TokenTypeTOTP = "totp" TokenTypeHOTP = "hotp" )
OTP Token types supported by FreeIPA
Variables ¶
var ( ErrNotFound = &IpaError{Code: CodeNotFound, Name: "NotFound", Message: "not found"} ErrDuplicateEntry = &IpaError{Code: CodeDuplicateEntry, Name: "DuplicateEntry", Message: "entry already exists"} ErrACI = &IpaError{Code: CodeACI, Name: "ACIError", Message: "insufficient access"} ErrEmptyModlist = &IpaError{Code: CodeEmptyModlist, Name: "EmptyModlist", Message: "no modifications to be performed"} )
Sentinels for common FreeIPA errors. They are matched with errors.Is by code only; any other code is available through errors.As and IpaError.Code.
var ( // ErrPasswordPolicy is returned when a password does not conform to the password policy ErrPasswordPolicy = errors.New("password does not conform to policy") // ErrInvalidPassword is returned when a password is invalid ErrInvalidPassword = errors.New("invalid current password") // ErrExpiredPassword is returned when a password is expired ErrExpiredPassword = errors.New("password expired") ErrUnauthorized = errors.New("unauthorized") // ErrUserExists is returned when user account already exists. UserAdd // returns it for FreeIPA's DuplicateEntry (4002). ErrUserExists = errors.New("user exists") )
Functions ¶
func ParseDateTime ¶
Parse a FreeIPA datetime. Datetimes in FreeIPA are returned using a class-hint system. Values are stored as an array with a single element indicating the type and value, for example, '[{"__datetime__": "YYYY-MM-DDTHH:MM:SSZ"]}'
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
FreeIPA Client
Methods with a Context suffix bound the HTTP request with the given context. Kerberos login and SPNEGO header generation are not cancellable (gokrb5 has no context support), so Login, LoginWithKeytab and LoginFromCCache have no Context twins.
func NewClientCustomHttp ¶
New IPA Client with host, realm and custom http client
func NewDefaultClient ¶
func NewDefaultClient() *Client
New default IPA Client using host and realm from /etc/ipa/default.conf
func NewDefaultClientWithSession ¶
New default IPA Client with existing sessionID using host and realm from /etc/ipa/default.conf
func (*Client) AddOTPToken ¶
Add OTP token. Returns new OTPToken
func (*Client) AddOTPTokenContext ¶ added in v0.2.0
AddOTPTokenContext is like AddOTPToken but bounds the request with ctx.
func (*Client) ChangePassword ¶
Change user password. This will run the passwd ipa command. Optionally provide an OTP if required
func (*Client) ChangePasswordContext ¶ added in v0.2.0
func (c *Client) ChangePasswordContext(ctx context.Context, username, oldPasswd, newPasswd, otpcode string) error
ChangePasswordContext is like ChangePassword but bounds the request with ctx.
func (*Client) DisableOTPToken ¶
Disable OTP token.
func (*Client) DisableOTPTokenContext ¶ added in v0.2.0
DisableOTPTokenContext is like DisableOTPToken but bounds the request with ctx.
func (*Client) EnableOTPToken ¶
Enable OTP token.
func (*Client) EnableOTPTokenContext ¶ added in v0.2.0
EnableOTPTokenContext is like EnableOTPToken but bounds the request with ctx.
func (*Client) FetchOTPTokens ¶
Fetch OTP tokens by owner.
func (*Client) FetchOTPTokensContext ¶ added in v0.2.0
FetchOTPTokensContext is like FetchOTPTokens but bounds the request with ctx.
func (*Client) GroupAdd ¶ added in v0.4.0
GroupAdd creates a group with `group_add` and returns it; it requires the Group Administrators privilege (System: Add Groups). A zero Group creates a POSIX group, as `ipa group-add` does; set NonPOSIX for a group without a GID.
func (*Client) GroupAddContext ¶ added in v0.4.0
GroupAddContext is like GroupAdd but bounds the request with ctx.
func (*Client) GroupAddMember ¶ added in v0.4.0
GroupAddMember adds users and groups to a group with `group_add_member`. It needs the Group Administrators or Modify Group membership privilege, or the caller is a member manager of the group; per-member problems, including insufficient access, are returned as *MemberError, together with the group as it stands. This is the context-aware API from ubccr/goipa#17, generalised to users and groups.
func (*Client) GroupAddMemberContext ¶ added in v0.4.0
func (c *Client) GroupAddMemberContext(ctx context.Context, group string, users, groups []string) (*Group, error)
GroupAddMemberContext is like GroupAddMember but bounds the request with ctx.
func (*Client) GroupAddMemberManager ¶ added in v0.4.0
GroupAddMemberManager makes users and groups member managers of a group with `group_add_member_manager`; it requires the Group Administrators privilege (System: Modify Groups). Per-member problems are returned as *MemberError, together with the group as it stands.
func (*Client) GroupAddMemberManagerContext ¶ added in v0.4.0
func (c *Client) GroupAddMemberManagerContext(ctx context.Context, group string, users, groups []string) (*Group, error)
GroupAddMemberManagerContext is like GroupAddMemberManager but bounds the request with ctx.
func (*Client) GroupDelete ¶ added in v0.4.0
GroupDelete deletes groups with `group_del`; it requires the Group Administrators privilege (System: Remove Groups).
func (*Client) GroupDeleteContext ¶ added in v0.4.0
GroupDeleteContext is like GroupDelete but bounds the request with ctx.
func (*Client) GroupFind ¶ added in v0.4.0
GroupFind finds groups with `group_find`; options are passed through (e.g. `cn`, `user`, `in_group`, `sizelimit`). Any authenticated user may read groups (System: Read Groups).
func (*Client) GroupFindContext ¶ added in v0.4.0
GroupFindContext is like GroupFind but bounds the request with ctx.
func (*Client) GroupMod ¶ added in v0.4.0
GroupMod changes a group's description (an empty one clears it) and, for a POSIX group, its GID with `group_mod`; it requires the Group Administrators privilege (System: Modify Groups). It returns group itself when nothing changed. Conversion between group types and renames go through RPC.
func (*Client) GroupModContext ¶ added in v0.4.0
GroupModContext is like GroupMod but bounds the request with ctx.
func (*Client) GroupRemoveMember ¶ added in v0.4.0
GroupRemoveMember removes users and groups from a group with `group_remove_member`. It needs the Group Administrators or Modify Group membership privilege, or the caller is a member manager of the group; per-member problems, including insufficient access, are returned as *MemberError, together with the group as it stands.
func (*Client) GroupRemoveMemberContext ¶ added in v0.4.0
func (c *Client) GroupRemoveMemberContext(ctx context.Context, group string, users, groups []string) (*Group, error)
GroupRemoveMemberContext is like GroupRemoveMember but bounds the request with ctx.
func (*Client) GroupRemoveMemberManager ¶ added in v0.4.0
GroupRemoveMemberManager removes member managers from a group with `group_remove_member_manager`; it requires the Group Administrators privilege (System: Modify Groups). Per-member problems are returned as *MemberError, together with the group as it stands.
func (*Client) GroupRemoveMemberManagerContext ¶ added in v0.4.0
func (c *Client) GroupRemoveMemberManagerContext(ctx context.Context, group string, users, groups []string) (*Group, error)
GroupRemoveMemberManagerContext is like GroupRemoveMemberManager but bounds the request with ctx.
func (*Client) GroupShow ¶ added in v0.4.0
GroupShow fetches a group with `group_show`. Any authenticated user may read groups (System: Read Groups).
func (*Client) GroupShowContext ¶ added in v0.4.0
GroupShowContext is like GroupShow but bounds the request with ctx.
func (*Client) HostFind ¶ added in v0.4.0
HostFind finds hosts with `host_find`; options are passed through (e.g. `fqdn`, `in_hostgroup`, `sizelimit`). Any authenticated user may read hosts (System: Read Hosts). ubccr/goipa#11.
func (*Client) HostFindContext ¶ added in v0.4.0
HostFindContext is like HostFind but bounds the request with ctx.
func (*Client) HostShow ¶ added in v0.4.0
HostShow fetches a host with `host_show`. Any authenticated user may read hosts (System: Read Hosts). ubccr/goipa#11.
func (*Client) HostShowContext ¶ added in v0.4.0
HostShowContext is like HostShow but bounds the request with ctx.
func (*Client) Login ¶
Login to FreeIPA using local kerberos login username and password
Example ¶
Login gets a Kerberos ticket for the password, which later calls authenticate with; it needs /etc/krb5.conf and a KDC, so it is compiled but not run.
package main
import (
"log"
ipa "github.com/neverlless/goipa"
)
func main() {
c := ipa.NewClient("ipa.example.com", "EXAMPLE.COM")
if err := c.Login("jesse", "secret"); err != nil {
log.Fatal(err)
}
}
Output:
func (*Client) LoginFromCCache ¶
Login to FreeIPA using credentials cache
Example ¶
LoginFromCCache reuses a ticket obtained with kinit; compiled but not run.
package main
import (
"log"
ipa "github.com/neverlless/goipa"
)
func main() {
c := ipa.NewDefaultClient()
if err := c.LoginFromCCache("/tmp/krb5cc_1000"); err != nil {
log.Fatal(err)
}
}
Output:
func (*Client) LoginWithKeytab ¶
Login to FreeIPA using local kerberos login with keytab and username
func (*Client) PingContext ¶ added in v0.2.0
PingContext is like Ping but bounds the request with ctx.
func (*Client) RPC ¶ added in v0.2.0
RPC calls any FreeIPA command, an escape hatch for commands goipa does not wrap. It uses the client's HTTP client, session or Kerberos credentials and API version. A FreeIPA failure is returned as a bare *IpaError. options is not modified; a "version" in options wins over IpaClientVersion.
Example ¶
package main
import (
"fmt"
"log"
"github.com/neverlless/goipa/ipatest"
)
func main() {
s := ipatest.New()
defer s.Close()
res, err := s.ClientAs("admin").RPC("ping", nil, nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(res.Principal, res.Version)
}
Output: admin@TEST.LOCAL 4.13.4
func (*Client) RPCContext ¶ added in v0.2.0
func (c *Client) RPCContext(ctx context.Context, method string, args []string, options Options) (*Response, error)
RPCContext is like RPC but ends the request when ctx is done.
func (*Client) RemoteLogin ¶
Login to FreeIPA using web API with uid/passwd and set the FreeIPA session id on the client for subsequent requests.
Example ¶
RemoteLogin posts the password to /ipa/session/login_password. Its session ID can be stored, for example in a web session, and reused later without logging in again; compiled but not run.
package main
import (
"fmt"
"log"
ipa "github.com/neverlless/goipa"
)
func main() {
c := ipa.NewDefaultClient()
if err := c.RemoteLogin("jesse", "secret"); err != nil {
log.Fatal(err)
}
sid := c.SessionID()
later := ipa.NewDefaultClientWithSession(sid)
u, err := later.UserShow("jesse")
if err != nil {
log.Fatal(err)
}
fmt.Println(u.Username)
}
Output:
func (*Client) RemoteLoginContext ¶ added in v0.2.0
RemoteLoginContext is like RemoteLogin but bounds the request with ctx.
func (*Client) RemoveOTPToken ¶
Remove OTP token
func (*Client) RemoveOTPTokenContext ¶ added in v0.2.0
RemoveOTPTokenContext is like RemoveOTPToken but bounds the request with ctx.
func (*Client) ResetPassword ¶
Reset user password and return new random password
func (*Client) ResetPasswordContext ¶ added in v0.2.0
ResetPasswordContext is like ResetPassword but bounds the request with ctx.
func (*Client) SetAuthTypes ¶
Update user authentication types.
func (*Client) SetAuthTypesContext ¶ added in v0.2.0
SetAuthTypesContext is like SetAuthTypes but bounds the request with ctx.
func (*Client) SetPassword ¶
Set user password. In FreeIPA when a password is first set or when a password is later reset it is marked as immediately expired and requires the owner to perform a password change. See here https://www.freeipa.org/page/New_Passwords_Expired for more details. This function exists to circumvent the "new passwords expired" feature of FreeIPA and allow an administrator to set a new password for a user without it being expired. This is acheived, for example, by first calling ResetPassword() then immediately calling this function. *WARNING* See https://www.freeipa.org/page/Self-Service_Password_Reset for security issues and possible weaknesses of this approach.
func (*Client) SetPasswordContext ¶ added in v0.2.0
func (c *Client) SetPasswordContext(ctx context.Context, username, oldPasswd, newPasswd, otpcode string) error
SetPasswordContext is like SetPassword but bounds the request with ctx.
func (*Client) SetSessionID ¶ added in v0.2.0
SetSessionID restores a session saved from SessionID (for example in a web session store) on any client. An empty string clears it.
func (*Client) UserAdd ¶
Add new user. If random is true a random password will be created for the user. Note this requires "User Administrators" Privilege in FreeIPA.
func (*Client) UserAddContext ¶ added in v0.2.0
UserAddContext is like UserAdd but bounds the request with ctx.
func (*Client) UserAddWithPassword ¶
Add new user and set password. Note this requires "User Administrators" Privilege in FreeIPA.
func (*Client) UserAddWithPasswordContext ¶ added in v0.2.0
func (c *Client) UserAddWithPasswordContext(ctx context.Context, user *User, password string) (*User, error)
UserAddWithPasswordContext is like UserAddWithPassword but bounds the request with ctx.
func (*Client) UserDelete ¶
Delete user. If preserve is false the user will be permanetly deleted, if true the users is moved to the Delete container. If stopOnError is false the operation will be in continuous mode otherwise it will stop on errors
func (*Client) UserDeleteContext ¶ added in v0.2.0
func (c *Client) UserDeleteContext(ctx context.Context, preserve, stopOnError bool, usernames ...string) error
UserDeleteContext is like UserDelete but bounds the request with ctx.
func (*Client) UserDisable ¶
Disable User Account
func (*Client) UserDisableContext ¶ added in v0.2.0
UserDisableContext is like UserDisable but bounds the request with ctx.
func (*Client) UserEnableContext ¶ added in v0.2.0
UserEnableContext is like UserEnable but bounds the request with ctx.
func (*Client) UserFindContext ¶ added in v0.2.0
UserFindContext is like UserFind but bounds the request with ctx.
func (*Client) UserMod ¶
Modify user. Currently only modifies a subset of user attributes: mail (all values, see Emails), givenname, sn, homedirectory, loginshell, displayname, ipasshpubkey, telephonenumber, and mobile
func (*Client) UserModContext ¶ added in v0.2.0
UserModContext is like UserMod but bounds the request with ctx.
type Group ¶ added in v0.4.0
type Group struct {
Name, Description, GID string
// member_user, member_group, memberindirect_user, memberindirect_group
Users, Groups, IndirectUsers, IndirectGroups []string
// memberof_group
MemberOf []string
// membermanager_user, membermanager_group
ManagerUsers, ManagerGroups []string
// External: objectclass has ipaexternalgroup. NonPOSIX: objectclass lacks
// posixgroup. The zero value is a POSIX group.
External, NonPOSIX bool
}
Group is a FreeIPA user group.
type HTTPError ¶ added in v0.2.0
HTTPError is returned when the server answers a JSON-RPC call with a status other than 200. HTTP 401 (for example an expired session) also matches ErrUnauthorized with errors.Is.
type Host ¶ added in v0.4.0
type Host struct {
// fqdn, description, l, nshostlocation, nshardwareplatform, nsosversion,
// krbprincipalname (first value of each)
FQDN, Description, Locality, Location, Platform, OSVersion, Principal string
// macaddress, userclass
MACAddresses, UserClass []string
// memberof_hostgroup, memberofindirect_hostgroup
HostGroups, IndirectHostGroups []string
// managedby_host
ManagedBy []string
// has_keytab, has_password
HasKeytab, HasPassword bool
}
Host is a FreeIPA host.
type IpaError ¶
type IpaError struct {
Message string
Code int
Name string `json:"name"`
// Data is the raw JSON of the exception's keyword arguments, e.g.
// {"reason":"..."}. A string so IpaError stays comparable.
Data string `json:"data"`
}
FreeIPA error
func (*IpaError) MarshalJSON ¶ added in v0.3.0
MarshalJSON writes FreeIPA's error shape; an empty or non-JSON Data becomes {}.
func (*IpaError) UnmarshalJSON ¶ added in v0.2.0
UnmarshalJSON keeps Data as raw JSON text; Message and Code still match the "message" and "code" keys case-insensitively.
type MemberError ¶ added in v0.4.0
type MemberError struct {
Failures []MemberFailure
}
MemberError reports the members a group member call could not change. FreeIPA lists them in the result, with no error, even when the caller lacks the right to change members at all.
func (*MemberError) Error ¶ added in v0.4.0
func (e *MemberError) Error() string
type MemberFailure ¶ added in v0.4.0
type MemberFailure struct {
Kind string // "member" or "membermanager"
Type string // "user" or "group"
Name string
Message string
}
MemberFailure is one member FreeIPA refused to add or remove.
type Message ¶ added in v0.2.0
type Message struct {
Type string `json:"type"`
Name string `json:"name"`
Message string `json:"message"`
Code int `json:"code"`
Data json.RawMessage `json:"data"`
}
Message is a server warning attached to a FreeIPA result.
type OTPToken ¶
type OTPToken struct {
DN string `json:"dn"`
UUID string `json:"ipatokenuniqueid"`
Algorithm string `json:"ipatokenotpalgorithm"`
Digits int `json:"ipatokenotpdigits"`
Owner string `json:"ipatokenowner"`
TimeStep int `json:"ipatokentotptimestep"`
ClockOffest int `json:"ipatokentotpclockoffset"`
ManagedBy string `json:"managedby_user"`
Enabled bool `json:"-"`
Type string `json:"type"`
URI string `json:"uri"`
Description string `json:"description"`
Vendor string `json:"ipatokenvendor"`
Model string `json:"ipatokenmodel"`
Serial string `json:"ipatokenserial"`
NotBefore time.Time `json:"ipatokennotbefore"`
NotAfter time.Time `json:"ipatokennotafter"`
}
OTPToken encapsulates FreeIPA otptokens
var DefaultTOTPToken *OTPToken = &OTPToken{ Type: TokenTypeTOTP, Algorithm: AlgorithmSHA1, Digits: 6, TimeStep: 30, }
func (*OTPToken) DisplayName ¶
type Response ¶
type Response struct {
Error *IpaError `json:"error"`
ID int `json:"id"`
Principal string `json:"principal"`
Version string `json:"version"`
Result *Result `json:"result"`
}
Response returned from a FreeIPA JSON rpc call
type Result ¶
type Result struct {
Summary string `json:"summary"`
Value interface{} `json:"value"`
Data json.RawMessage `json:"result"`
Count int `json:"count"`
Truncated bool `json:"truncated"`
Messages []Message `json:"messages"`
Completed int `json:"completed"`
Failed json.RawMessage `json:"failed"`
// Raw is the whole FreeIPA result object, for shapes without a "result"
// key such as hbactest.
Raw json.RawMessage `json:"-"`
}
Result returned from a FreeIPA JSON rpc call
func (*Result) UnmarshalJSON ¶ added in v0.2.0
UnmarshalJSON decodes the result and keeps a copy of the raw object in Raw.
type SSHAuthorizedKey ¶
type SSHAuthorizedKey struct {
Comment string
Options []string
PublicKey ssh.PublicKey
Fingerprint string
}
SSH Public Key
func NewSSHAuthorizedKey ¶
func NewSSHAuthorizedKey(in string) (*SSHAuthorizedKey, error)
func (*SSHAuthorizedKey) MarshalJSON ¶
func (k *SSHAuthorizedKey) MarshalJSON() ([]byte, error)
func (*SSHAuthorizedKey) String ¶
func (k *SSHAuthorizedKey) String() string
type User ¶
type User struct {
UUID string `json:"ipauniqueid"`
DN string `json:"dn"`
First string `json:"givenname"`
Last string `json:"sn"`
DisplayName string `json:"displayname"`
Principal string `json:"krbprincipalname"`
Username string `json:"uid"`
Uid string `json:"uidnumber"`
Gid string `json:"gidnumber"`
Groups []string `json:"memberof_group"`
SSHAuthKeys []*SSHAuthorizedKey `json:"ipasshpubkey"`
AuthTypes []string `json:"ipauserauthtype"`
HasKeytab bool `json:"has_keytab"`
HasPassword bool `json:"has_password"`
Locked bool `json:"nsaccountlock"`
Preserved bool `json:"preserved"`
HomeDir string `json:"homedirectory"`
Email string `json:"mail"`
TelephoneNumber string `json:"telephonenumber"`
Mobile string `json:"mobile"`
Shell string `json:"loginshell"`
Category string `json:"userclass"`
SudoRules []string `json:"memberofindirect_sudorule"`
HbacRules []string `json:"memberofindirect_hbacrule"`
LastPasswdChange time.Time `json:"krblastpwdchange"`
PasswdExpire time.Time `json:"krbpasswordexpiration"`
PrincipalExpire time.Time `json:"krbprincipalexpiration"`
LastLoginSuccess time.Time `json:"krblastsuccessfulauth"`
LastLoginFail time.Time `json:"krblastfailedauth"`
RandomPassword string `json:"randompassword"`
// Emails holds every mail value; Email is the first. UserMod and UserAdd
// send Email first, then Emails[1:] (see ToOptions), so Emails[0] is
// ignored on write. To set the whole list, set Email = list[0] and
// Emails = list.
Emails []string `json:"emails"`
// IndirectGroups: nested groups; filled by UserShow only, UserFind puts
// nested groups in Groups (FreeIPA).
IndirectGroups []string `json:"memberofindirect_group"`
// Street, City, State, PostalCode and PreferredLanguage are returned only
// with all, which UserShow and UserFind send.
Street string `json:"street"`
City string `json:"l"`
State string `json:"st"`
PostalCode string `json:"postalcode"`
PreferredLanguage string `json:"preferredlanguage"`
Title string `json:"title"`
OrgUnit string `json:"ou"`
// Passkeys: FreeIPA 4.11+, format passkey:<id>,<key>[,<userid>].
Passkeys []string `json:"ipapasskey"`
}
User encapsulates user data returned from ipa user commands
func (*User) AddSSHAuthorizedKey ¶
func (u *User) AddSSHAuthorizedKey(key *SSHAuthorizedKey)
Add ssh authorized key
func (*User) FormatSSHAuthorizedKeys ¶
Format ssh authorized keys
func (*User) RemoveSSHAuthorizedKey ¶
Removes ssh authorized key