QA:Testcase freeipav2 cli

{{QA/Test_Case
 * description=CLI testing.
 * setup=
 * 1) Make sure you have a working FreeIPA server (see QA:Testcase_freeipav2_installation)
 * actions=

Creating Users
To make things interesting create several users. Some of these will be used in later tests.

Make sure you have a valid ticket:


 * 1) kinit admin

Fully Interactive User Creation:


 * 1) ipa user-add

You should be prompted for just First name, Last name and login name.

A example would be:

First name: Patty Last name: Smith User login [psmith]:
 * 1) ipa user-add

Create and provide some optional data:


 * 1) ipa user-add mmouse --first=Mickey --last=Mouse --street='123 Disney Way' --city=Anaheim --state=CA --postalcode=92801
 * 2) ipa user-add mightym --first=Mighty --last=Mouse --uid=500 --shell=/bin/tcsh

Specify an illegal UID number:


 * 1) ipa user-add --first=Bad --last=Guy bguy --uid=0

This should fail, you can't add new root users.

Try some bad login names:


 * 1) ipa user-add --first=Bad --last=User +user
 * 2) ipa user-add --first=Bad --last=User ^buser
 * 3) ipa user-add --first=Bad --last=User aloginnamethatislongerthanthedefaultloginallowed

Searching for Users
At this point we should have 4 users.

First find them all:


 * 1) ipa user-find

Now search for the Mouse family (should return 2 users):


 * 1) ipa user-find mouse

Look for a user based on uid (should return 1 user):


 * 1) ipa user-find --uid=500

Updating Users
Mighty Mouse is moving in with Mickey, add an address:


 * 1) ipa user-mod mightym --street='123 Disney Way' --city=Anaheim --state=CA --postalcode=92801

Make sure the data was actually saved:


 * 1) ipa user-show mightym --all

The output should include the address we added.

Setting Passwords
Note that there is no password set on any of the accounts we created in this section. You could have added  to any of the user-add commands to create one, lets do one now.


 * 1) ipa passwd mmouse

A password set by an administrator is marked as expired. This way only the end user will know their final password.

Become mmouse to show that password resetting works:


 * 1) kinit mmouse

Now we are the user mmouse,  will confirm this.

Locking accounts
Do a kinit 4 times and enter a bad password for each one. The last one should return:

kinit: Clients credentials have been revoked while getting initial credentials

Unlocking Locked Accounts
kinit to admin so we can unlock this user:


 * 1) kinit admin
 * 2) ipa user-unlock mmouse

Test that the unlock worked (use correct password this time):


 * 1) kinit mmouse

Testing the Account
Lets see if the mmouse account actually works as a unix account. We should still have a TGT for the mmouse user from the previous step, if not run:.

su: warning: cannot change directory to /home/mmouse: No such file or directory
 * 1) su - mmouse

This is expected, IPA doesn't create user directories automatically.

Return to root:

$ exit

Removing Users
Entries can be removed one at a time or you can specify multiple on a single command-line. Let us try both:


 * 1) ipa user-del mightym

Oops, that failed because we are still the user mmouse who isn't allowed to delete users.


 * 1) kinit admin

Now try again:


 * 1) ipa user-del mightym

And let us remove the rest at once:


 * 1) ipa user-del mmouse psmith

That should be it, you can to a user-find to see if everyone is gone, except for admin and perhaps the user created during the Installation test.

Creating Groups
Start by being admin:


 * 1) kinit admin

Create a Group Interactively:

Group name: testgroup1 Description: test group 1
 * 1) ipa group-add

Create a Group Specifying required options:


 * 1) ipa group-add --desc='test group 2' testgroup2

Create a group with a specific GID:


 * 1) ipa group-add --desc='test group 3' --gid=500 testgroup3

Create a non-POSIX group:


 * 1) ipa group-add --nonposix --desc='test group 4' testgroup4

Searching for Groups
We should have 4 test groups now, find them:


 * 1) ipa group-find test

Four entries should be returned, the groups we just added.

Adding Members to Groups
Lets add a group as a member of a group:


 * 1) ipa group-add-member --groups=testgroup2 testgroup1

It should have 1 group member (testgroup2)

Now add a user to a group:


 * 1) ipa group-add-member --users=admin testgroup2

Now look at the user admin and it is a member of 3 groups: admins, testgroup2 and testgroup1.

Member of groups: admins, testgroup2, testgroup1
 * 1) ipa user-show admin | grep Member

It is a member of testgroup1 because it is a member of testgroup2 which is a member of testgroup 1. Group membership is nested, in other words.

Removing Members from Groups
admin isn't a direct member of testgroup1 so we can't remove it:

Group name: testgroup1 Description: test group 1 GID: 618600026 Member groups: testgroup2 Indirect Member users: admin Failed members: user: admin: This entry is not a member --- Number of members removed 0 ---
 * 1) ipa group-remove-member --users=admin testgroup1

If we remove testgroup2 as a member of testgroup1 we'll also see a change in the admin user:

Member of groups: admins, testgroup2
 * 1) ipa group-remove-member --groups=testgroup2 testgroup1
 * 2) ipa user-show admin | grep Member

Promote a non-POSIX group to POSIX
A non-POSIX group doesn't have a GID number:


 * 1) ipa group-show testgroup4

Let's make this a POSIX group:


 * 1) ipa group-mod --posix  testgroup4

It should have a GID number now.

Deleting Groups
We can remove them one at a time:


 * 1) ipa group-del testgroup4

Or a bunch at a time:


 * 1) ipa group-del testgroup1 testgroup2 testgroup3

And the user is updated accordingly:

Member of groups: admins
 * 1) ipa user-show admin | grep Member

All the test groups should be gone now, confirm with:

0 groups matched Number of entries returned 0
 * 1) ipa group-find test

Managed Groups
When a user is created a group with the same name is created with the GID set to the user's UID.


 * 1) ipa user-add --first=Patty --last=Smith psmith


 * 1) ipa group-show psmith

Note that the UID number of the user matches the GID number of the group.

These groups are hidden by default, they aren't generally interesting as you can't add users to them:

0 groups matched Number of entries returned 0
 * 1) ipa group-find psmith

Group name: psmith Description: User private group for psmith GID: 618600030 Failed members: user: admin: attribute "member" not allowed - Number of members added 0 -
 * 1) ipa group-add-member --users=admin psmith

It is possible to find them though:

--- 1 group matched ---  Group name: psmith Description: User private group for psmith GID: 618600029 Number of entries returned 1
 * 1) ipa group-find --private psmith

You can detach the group from the user and make it into a regular old users group where you can add members. This process is irreversible.


 * 1) ipa group-detach psmith

Now you can find it on a normal search:

--- 1 group matched --- Group name: psmith Description: User private group for psmith GID: 618600029 Number of entries returned 1
 * 1) ipa group-find psmith

And add members:


 * 1) ipa group-add-member --users=admin psmith

Note that admin is a Member now.

The group is now also independent of the user, lets delete Patty:


 * 1) ipa user-del psmith

And the group is still available:


 * 1) ipa group-show psmith

Create another user to show how managed entries are tied together:


 * 1) ipa user-add --first=Ron --last=Jones rjones
 * 2) ipa group-find --private rjones
 * 3) ipa user-del rjones
 * 4) ipa group-find --private rjones

The group is deleted with the user if they are still attached.

We'll finish by deleting the psmith group:


 * 1) ipa group-del psmith

Hosts
Hosts are separate from DNS entries (e.g. the data is not stored together) but it is required that a host have a valid DNS entry. Without DNS Kerberos doesn't really work..

Start as admin:

 * 1) kinit admin

Creating Hosts
For the sake of testing the assumption is going to be that none of these hostnames exist in your DNS. If you have valid hostnames you can use then you can drop the  flag. We are going to touch briefly on enrollment but aren't actually going to enroll any client machines.

Create a host:

The domain name must be fully-qualified.


 * 1) ipa host-add --force panther.freeipa.org

This host is ready to be enrolled as a client machine using an authorized principal. Let us create one that can be registered using a simple password:


 * 1) ipa host-add --random --force lion.freeipa.org

Note in the output there is a random password. Using this password you could enroll the host.

Or if you want to set a specific password on a new host entry:


 * 1) ipa host-add --password=secret123 --force puma.freeipa.org

Searching for Hosts
We can search on either the FQDN or just the server name:


 * 1) ipa host-find puma

Returns the same as:


 * 1) ipa host-find puma.freeipa.org

Updating Hosts
We can also store information specific to the host such as operating system, etc:


 * 1) ipa host-mod --os='Fedora 12' --platform='White Box' --locality=Baltimore puma.freeipa.org

Or change if we upgrade:


 * 1) ipa host-mod --os='Fedora 14' puma.freeipa.org

Managing other Hosts
You may have noticed the managedby field with the same value as the FQDN of the host. This is the list of hosts are allowed to bind and manage this entry, lets try that:


 * 1) ipa host-add-managedby --hosts=`hostname` puma.freeipa.org

Now your current host is allowed to manage the certificates and keytab of puma.freeipa.org. Lets try to update something else. First let us get a TGT for the current host:


 * 1) kinit -kt /etc/krb5.keytab host/`hostname`

And try to modify puma:


 * 1) ipa host-mod --os='Ubuntu 10.14' puma.freeipa.org

It fails due to lack of permissions. Remember, we can only modify certificates and its keytab.

Getting a keytab for a managed host:


 * 1) ipa-getkeytab -s `hostname` -p host/puma.freeipa.org -k /tmp/test.keytab
 * 2) klist -kt /tmp/test.keytab

We successfully retrieved a keytab for a different host. Let's try again for a host we do not manage, panther:

Operation failed! Insufficient access rights
 * 1) ipa-getkeytab -s `hostname` -p host/panther.freeipa.org -k /tmp/test.keytab

As expected, we aren't allowed.

Removing Hosts
Now back to admin and we'll remove the hosts we added:


 * 1) kinit admin
 * 2) ipa host-del puma panther lion

Note that we're using the shortname for all.

Service
A service must be connected to a host. A service consists of a service name, a hostname and a realm. The service name is case sensitive.

Creating Services
Start by creating a host to attach our test services to:


 * 1) ipa host-add --force puma.freeipa.org

Now we can start adding services:


 * 1) ipa service-add HTTP/puma.freeipa.org

The service name isn't checked but the formatting is:

ipa: ERROR: Service principal is not of the form: service/fully-qualified host name: missing service
 * 1) ipa service-add puma.freeipa.org

The realm is optional but must match the current realm: ipa: ERROR: The realm for the principal does not match the realm for this IPA server
 * 1) ipa service-add HTTP/puma.freeipa.org@FOO.ORG

Searching for Services
Now find out service, there should just be one, HTTP:


 * 1) ipa service-find puma
 * 2) ipa service-find HTTP/puma.freeipa.org@FOO.ORG

Searching for a service with  option, should display the services which are managed by this host.


 * 1) ipa service-find HTTP/puma.freeipa.org@FOO.ORG --hosts=

Searching for a service with  option, should display the services which are not managed by this host.


 * 1) ipa service-find HTTP/puma.freeipa.org@FOO.ORG --no-hosts=

Searching for services with  option, should display only the number of services specified.


 * 1) ipa service-find HTTP/puma.freeipa.org@FOO.ORG --sizelimit=1

Searching for services with  option, should display the services searched in that timelimit. (0 = show all)


 * 1) ipa service-find HTTP/puma.freeipa.org@FOO.ORG --timelimit=5

Modifying Services
Make sure your service does not have any certificate.

To add an attribute to any existing service
 * 1) ipa service-mod HTTP/puma.freeipa.org@FOO.ORG --addattr=certificate=

To replace an existing attribute
 * 1) ipa service-mod HTTP/puma.freeipa.org@FOO.ORG --setattr=certificate=

Disabling Services

 * 1) ipa service-disable HTTP/puma.freeipa.org@FOO.ORG

Deleting Services
Deleting a service
 * 1) ipa service-del HTTP/puma.freeipa.org@FOO.ORG

Deleting a service with  option

The deleting process is continued even though there exists an INVALID service in between. This should fail deleting SSH/puma.freeipa.org@FOO.ORG if --continue option is not specified.
 * 1) ipa service-del HTTP/puma.freeipa.org@FOO.ORG INVALID/puma.freeipa.org@FOO.ORG SSH/puma.freeipa.org@FOO.ORG

Managing a Host's services
By default a host can manage its own services. This is controlled by the managedby option.

Management is defined as retrieving a keytab and requesting certificates on behalf of a service or host.

So we can create a service for a host and get a keytab for it using the host's credentials:

Keytab successfully retrieved and stored in: /tmp/test.keytab
 * 1) kinit admin
 * 2) ipa service-add test/puma.freeipa.org
 * 3) kinit host/slinky.freeipa.org
 * 4) ipa-getkeytab -s slinky -k /tmp/test.keytab -p test/puma.freeipa.org

Managing Services on other Hosts
It is possible to allow a host to manage other hosts or services on other hosts.

If a host is added to the Managed By of another host this does not mean management of all services on that host. Each delegation has to be done independently. In other words to manage a host and all of its services you need to add the host to each host and service you want to delegate management for.

Create a new host:


 * 1) kinit admin
 * 2) ipa host-add panther.freeipa.org

And create a service on the host:


 * 1) ipa service-add test/panther.freeipa.org

Delegate managing the service:


 * 1) ipa service-add-host --hosts=slinky panther

Now we can use the host service principal on slinky to manage panther:

Keytab successfully retrieved and stored in: /tmp/test.keytab
 * 1) kinit -kt /etc/krb5.keytab host/slinky.freeipa.org
 * 2) ipa-getkeytab -s slinky -k /tmp/test.keytab -p test/panther.freeipa.org

To create a certificate for this service first generate a CSR (Certificate Signing Request).

The subject you use is not particularly important because our backend CA will only use the value of CN. The CN value must be your hosts fully-qualified domain name.

You can generate the CSR using either OpenSSL:

Generating a 2048 bit RSA private key .........................................................+++ .............................+++ writing new private key to 'private.key' - You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. - Country Name (2 letter code) [XX]:AU State or Province Name (full name) []:QLD Locality Name (eg, city) [Default City]:BNE Organization Name (eg, company) [Default Company Ltd]:MYDOMAIN.NET Organizational Unit Name (eg, section) []:ECS Common Name (eg, your name or your server's hostname) []:myserver.mydomain.net Email Address []:authors@mydomain.net Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
 * 1) openssl req -out example.csr -new -newkey rsa:2048 -nodes -keyout private.key

...or using NSS:

If you need to create an NSS database in which to store your key, use the certutil command as follows: $ certutil -N -d /path/to/database/dir $ certutil -R -s "CN=myserver.mydomain.net, O=MYDOMAIN.NET" -d /path/to/database/dir -a > example.csr

Once you have the CSR, do:

Certificate: MIICETCCAXqgA...[snip] Subject: CN=panther.freeipa.org,O=FREEIPA.ORG Issuer: CN=EXAMPLE.COM Certificate Authority Not Before: Tue Feb 08 18:51:51 2011 UTC Not After: Mon Feb 08 18:51:51 2016 UTC Fingerprint (MD5): c1:46:8b:29:51:a6:4c:11:cd:81:cb:9d:7c:5e:84:d5 Fingerprint (SHA1): 01:43:bc:fa:b9:d8:30:35:ee:b6:54:dd:a4:e7:d2:11:b1:9d:bc:38 Serial number: 1005
 * 1) ipa cert-request --add --principal=test/panther.freeipa.org panther.csr

The same can be done for hosts:


 * 1) kinit admin
 * 2) ipa host-add-managedby --hosts=slinky panther

Become slinky and get a keytab for panther:

Keytab successfully retrieved and stored in: /tmp/panther.keytab
 * 1) kinit -kt /etc/krb5.keytab host/slinky.freeipa.org
 * 2) ipa-getkeytab -s slinky -k /tmp/panther.keytab -p host/panther.freeipa.org

Removing hosts from managed by list of a service:
 * 1) ipa service-remove-host test/panther.freeipa.org --hosts=slinky,panther

Getting a keytab
Get a keytab quietly with no output on the terminal.


 * 1) ipa-getkeytab -q -s `hostname` -p HTTP/puma.freeipa.org -k /tmp/service.keytab

Display the supported encryption types for this keytab:


 * 1) klist -ekt /tmp/service.keytab

Get a keytab with specific encryption type
 * 1) ipa-getkeytab -s `hostname` -p HTTP/puma.freeipa.org -k /tmp/service.keytab -e aes256-cts.

Verify that just the requested encryption type is available in keytab:
 * 1) klist -ekt /tmp/service.keytab

Setting a password while getting keytab: New Principal Password: Verify Principal Password: Keytab successfully retrieved and stored in: /tmp/service.keytab Check the validity by: Password for HTTP/puma.freeipa.org:
 * 1) ipa-getkeytab -s `hostname` -p HTTP/puma.freeipa.org -k /tmp/service.keytab -P
 * 1) kinit HTTP/puma.freeipa.org
 * 1) klist

Get a keytab using binddn and its credentials: Keytab successfully retrieved and stored in: /tmp/service.keytab
 * 1) ipa-getkeytab -s `hostname` -p HTTP/puma.freeipa.org -k /tmp/service.keytab -D "binddn" -w "bindpw"

Get a keytab for this service:


 * 1) ipa-getkeytab -s `hostname` -p HTTP/puma.freeipa.org -k /tmp/service.keytab

Check the validity of the keytab:


 * 1) kinit -kt /tmp/service.keytab  HTTP/puma.freeipa.org

The kinit should have succeeded, return to admin:


 * 1) kinit admin

Removing a keytab
Removing a specific principal from a keytab: Removing principal HTTP/puma.freeipa.org
 * 1) ipa-rmkeytab -p HTTP/puma.freeipa.org -k /tmp/service.keytab

Validate by listing the principals in the keytab:
 * 1) klist -ekt /tmp/service.keytab

Removing all principal in this realm: Removing principal HTTP/puma.freeipa.org@FOO.ORG
 * 1) ipa-rmkeytab -r FOO.ORG -k /tmp/service.keytab

Disable a keytab
A service can be disabled without having to do anything on the remote server.


 * 1) ipa-service-disable HTTP/puma.freeipa.org

Double-check that the keytab is invalidated:

kinit: Preauthentication failed while getting initial credentials
 * 1) kinit -kt /tmp/service.keytab  HTTP/puma.freeipa.org

All the test steps should end with the specified results. }}
 * results=