zero-knowledgescripting, programming and administrating2011-11-22T19:31:29+01:00http://zero-knowledge.org/http://zero-knowledge.org/post/80find cycle detected2011-11-22T19:31:29+01:00Gibheer<p>If you encounter the following error with <code>make install</code></p>
<p>If you encounter the following error with <code>make install</code></p>
<pre><code>find: cycle detected for /lib/secure/32/
find: cycle detected for /lib/crypto/32/
find: cycle detected for /lib/32/
find: cycle detected for /usr/lib/elfedit/32/
find: cycle detected for /usr/lib/secure/32/
find: cycle detected for /usr/lib/link_audit/32/
find: cycle detected for /usr/lib/lwp/32/
find: cycle detected for /usr/lib/locale/en_US.UTF-8/32/
find: cycle detected for /usr/lib/locale/en_US.UTF-8/LO_LTYPE/32/
find: cycle detected for /usr/lib/locale/en_US.UTF-8/LC_CTYPE/32/
find: cycle detected for /usr/lib/32/
</code></pre>
<p>use <code>ginstall</code> in your Makefile instead of <code>install</code>. It seems just broken on solaris.</p>
http://zero-knowledge.org/post/78openindiana - curl CA failure2011-11-14T19:09:54+01:00Gibheer
<p>There is a bug in openindiana that does not let you get the content of a page with curl, when it's secured with ssl. The cause of this is an option set on compile time. This option is the the path to the certificate storage.
In the case of openindiana this is set to <code>/etc/curl/curlCA</code>, but all certificates reside in <code>/etc/certs/CA/</code>. This leads to the following error message, when you try it:</p>
<p>There is a bug in openindiana that does not let you get the content of a page with curl, when it's secured with ssl. The cause of this is an option set on compile time. This option is the the path to the certificate storage.
In the case of openindiana this is set to <code>/etc/curl/curlCA</code>, but all certificates reside in <code>/etc/certs/CA/</code>. This leads to the following error message, when you try it:</p>
<pre><code>curl: (77) error setting certificate verify locations
</code></pre>
<p>To fix this, run the following script.</p>
<pre><code>mkdir /etc/curl && cat /etc/certs/CA/*.pem > /etc/curl/curlCA
</code></pre>
<p>This writes all certificates of the default CA in the file curl is looking for and after that, it works.</p>
http://zero-knowledge.org/post/77openindiana - set up ssh with kerberos authentication2011-11-12T21:45:01+01:00Gibheer<p>This time, we will build a base kerberos setup. At the end, you will be able to login into another machine using kerberos only.</p>
<p>This time, we will build a base kerberos setup. At the end, you will be able to login into another machine using kerberos only.</p>
<p>You need the following things, to make kerberos work:</p>
<ul>
<li>a working dns server</li>
<li>2 servers</li>
</ul>
<p>I will explain this setup on an openindiana system with 2 zones. <code>kerberosp1</code> will be my kerberos machine and <code>sshp1</code> will be my ssh server with kerberos support.</p>
<h1>setup of kerberos</h1>
<p>The setup of kerberos was pretty easy, after reading 3 tutorials about it. The essential part here is to decide, how the realm and the admin account should be called.</p>
<p>To start the setup, call <code>kdcmgr</code>. At first, it asks your realm, which you should name like your domain.
After that, you have to generate an admin principal.A principal is like an account for a user or admin. But it's also used for services. I named mine <code>kerberosp1/admin</code>. Give it a safe password and you are done.</p>
<p>Now you should have an populated <code>/etc/krb5/</code> directory. Open the file <code>kdc.conf</code> in that directory and search for <code>max_life</code>. It was set to 8 hours for me, which was too long. Adjust the value to 4h or 16h, like you want. I did the same with <code>max_renewable_life</code>.</p>
<p>Edit: You should add the following option in the realms section to your realm.</p>
<pre><code>kpasswd_protocol = SET_CHANGE
</code></pre>
<p>Kerberos uses a separate protocol for changing the password of principals. A RPC like protocol is used in the solaris version and microsoft has another one too. So the only option compatible on all is <code>SET_CHANGE</code>. But to make things worse, the solaris default does not even work in an internal network. So just add this entry and save some stress from trying to find out, why this is not working.</p>
<h1>setting up some accounts</h1>
<p>To use the kerberos service, check first, if the kdc is running and start it, if it's not. For openindiana, the check is</p>
<p><code>svcs krb5kdc</code></p>
<p>which should return online.</p>
<p>After that, as root start the kerberos shell with <code>kadmin.local</code>. This is a management shell to create, delete and modify principals.
Here we are going to create some policies. With these, we can set some minimal standards, like the minimum password length.</p>
<p>I created three policies. An <code>admin</code>, <code>user</code> and a <code>service</code> policy. These got the following settings:</p>
<ul>
<li>admin
<ul>
<li>minlength 8</li>
<li>minclasses 3</li>
</ul></li>
<li>user
<ul>
<li>minlength 8</li>
<li>minclasses 2</li>
</ul></li>
<li>service
<ul>
<li>minlength 12</li>
<li>minclasses 4</li>
</ul></li>
</ul>
<p>This sets some password limitations for every principal group I have. <code>minclasses</code> is used for different types of characters. There are lower case, upper case, numbers, punctation and other characters.
The create a new policy use the command <code>addpol</code> or <code>add_policy</code> with <code>-minlength</code> and <code>-minclasses</code>. You can simply type the command to get some help or read the man page.</p>
<p>After creating the policies, we have to create some principals. First, we should create one for ourselves. You can do this with the command <code>addprinc</code> or <code>add_principal</code>. Give it a policy with the argument <code>-policy</code> and a name. You will have to input a password for this principal according to the policies.</p>
<p>You can use this scheme to create user accounts too. For that, you can generate a password for them with the program <code>pwgen</code>. It's pretty helpful and can generate pretty complex passwords, so that should be best.</p>
<p>Now we need a principal for our ssh server. The name of this principal should be <code>host/name_of_service.your.domain.name</code>, so in my case, it is <code>host/sshp1.prod.lan</code>. But I did not want to generate any password and added the argument <code>-randkey</code> which generates a password according to the policies we set.</p>
<p>Now we have to export the key of the last principal into a keytab file, that can be read by the service, which wants to use it. This is done with the command <code>ktadd</code> like this</p>
<p><code>ktadd -k /etc/krb5.keytab host/sshp1.prod.lan</code></p>
<p>This generates our file in /etc/krb5.keytab. Copy this file into the kerberos directory (on openindiana it's <code>/etc/krb5/</code>) and delete the one on the kerberos host. This is important, as another execution of ktadd will append the next key to that file.</p>
<h1>setting up ssh</h1>
<p>For making ssh work with kerberos, we need <code>/etc/krb5/krb5.conf</code> and <code>/etc/krb5/krb5.keytab</code>. In the step before, we already moved the <code>krb5.keytab</code>. We can copy the <code>krb5.conf</code> from the kerberos server to the ssh server.</p>
<p>Now you can start the ssh deamon.</p>
<h1>try to log in</h1>
<p>For the test, we will try to connect to the ssh host from the kerberos host. So start a shell on the kerberos server and type <code>kinit</code>. This should ask for your password. If it was correct, <code>klist</code> should show you, that you have been granted a ticket.</p>
<p>Now try to open a ssh session to the server, with <code>-v</code> set for more informations and it should work.</p>
<h1>problems that can occur</h1>
<h2>no default realm</h2>
<p>The is the message</p>
<pre><code>kinit(v5): Configuration file does not specify default realm when parsing name gibheer
</code></pre>
<p>which hints, that your <code>/etc/krb5/krb5.conf</code> is missing.</p>
<h2>client/principal not found</h2>
<p>The message</p>
<pre><code>kinit(v5): Client 'foo@PROD.LAN' not found in Kerberos database while getting initial credentials
</code></pre>
<p>is a hint, that you forgot to add the principal or that your username could not be found. Just add the principal with <code>kadmin</code> and it should work.</p>
<h2>ssh does not use kerberos</h2>
<p>If ssh does not want to use kerberos at all, check for the GSSAPI options. These should be enabled by default, but can be disabled. If that's the case, add the following line to your <code>sshd_config</code>.</p>
<pre><code>GSSAPIAuthentication yes
</code></pre>
<p>After a restart, ssh should use kerberos for authentication.</p>
<h1>links</h1>
<ul>
<li><a href="http://www.linuxtopia.org/online_books/opensolaris_2008/SYSADV6/html/setup-148.html">setup of kerberos on opensolaris</a></li>
<li><a href="http://web.mit.edu/kerberos/krb5-1.5/krb5-1.5.4/doc/krb5-admin/krb5_002econf.html">MIT kerberos page</a></li>
<li><a href="http://wiki.creatica.org/cgi-bin/wiki.pl/Kerberos_KDC_server_on_Solaris">KDC Setup on Solaris</a></li>
<li><a href="http://fnal.gov/docs/strongauth/princ_pw.html#46115">Kerberos password</a></li>
<li><a href="http://pig.made-it.com/kerberos-policy.html">Kerberos policies</a></li>
<li><a href="http://techpubs.spinlocksolutions.com/dklar/kerberos.html#err_server_not_found">Administrative Guide to Kerberos</a></li>
</ul>
<h1>one last word</h1>
<p>I have one last word for you: Kerberos does not do authorization!</p>
<p>That means, that kerberos can not say, if one principal is allowed to use a service or not. It just manages the authentication for you.
If you want to manage the access, there are some possibilities for that. One is to use ldap, often used in conjunction with kerberos. Or you manage the <code>passwd</code> files or any other file yourself or you use a service like <a href="http://wiki.opscode.com/display/chef/Home">chef</a> or <a href="http://puppetlabs.com/">puppet</a>.</p>
<h1>changelog</h1>
<ul>
<li>added some explanation to <code>kpasswd_protocol</code></li>
</ul>
http://zero-knowledge.org/post/76great resource to ipfilter2011-11-05T03:43:41+01:00Gibheer<p>In the need of a resource about <code>ipnat</code>/<code>ipfilter</code> I found <a href="http://www.obfuscation.org/ipf/ipf-howto.html">http://obfuscation.org/ipf/ipf-howto.html</a>. <code>ipfilter</code> is a packet filter running on Solaris and illumos distributions.</p><p>In the need of a resource about <code>ipnat</code>/<code>ipfilter</code> I found <a href="http://www.obfuscation.org/ipf/ipf-howto.html">http://obfuscation.org/ipf/ipf-howto.html</a>. <code>ipfilter</code> is a packet filter running on Solaris and illumos distributions.</p>http://zero-knowledge.org/post/73openindiana - how to get routing working2011-10-29T16:01:11+02:00Gibheer<p>This time, we are going to get routing working on the global zone for our other zones. You can replace the global zone with another zone too, as the setup is the same.</p>
<p>This time, we are going to get routing working on the global zone for our other zones. You can replace the global zone with another zone too, as the setup is the same.</p>
<h1>What's needed?</h1>
<p>First, we need to install ipfilter, if it isn't already installed. To do that, just invoke</p>
<pre><code># pkg install ipfilter
</code></pre>
<p>This will install the package filter and NAT engine. Latter is the part, we want to use now.</p>
<p>We will asume, that the global zone has to interfaces with the following setup</p>
<ul>
<li>bge0 -> 192.168.4.1/24</li>
<li>bge1 -> 192.168.5.1/24</li>
</ul>
<h1>configure ipnat</h1>
<p>With <code>ipnat</code> installed, we need to write a small configuration. For this example, we set up routing for every machine in the subnet.</p>
<p>For that, open the file <code>/etc/ipf/ipnat.conf</code> and write the following lines:</p>
<pre><code>map bge0 192.168.5.0/24 -> 0/32 portmap tcp/udp auto
map bge0 192.168.5.0/24 -> 0/32
</code></pre>
<p>These two lines say, that all packages from the subnet to the rest shall be relabeled and forwarded.</p>
<p>After that, all we need to do is enable the ipfilter and the routing deamons with the following commands.</p>
<pre><code># svcadm enable ipfilter
# routeadm -e ipv4-forwarding
# routeadm -e ipv4-routing
# routeadm -u
</code></pre>
<p>The last command checks if all deamons are running according to the settings. To see, which settings are set and what the deamons are doing, run the <code>routeadm</code> command without any arguments.</p>
<h1>configure the zone</h1>
<p>Now we fire up the zone to test, if we can get anywhere near routing. In our case, the zone only has one interface, so that it detects the router itself per icmp.</p>
<p>We can prove that very easy with</p>
<pre><code># netstat -rn
</code></pre>
<p>The default gateway should point to our global zone. To make a last test, you can ping an ip in another subnet. If the global zone says, this host is alive, the zone should do too.</p>
<p>A good IP to test is 8.8.8.8, as it is really easy to remember.</p>
<p>That was all. Have fun with your access</p>
<h1>links and hints</h1>
<p>You can get some more documentation to ipfilter and routing in the man pages of ipnat, ipf and routeadm. Some example rule sets for ipf can be found in <code>/usr/share/ipfilter/examples/nat.eg</code>.</p>
<ul>
<li><a href="http://blog.kevinvandervlist.nl/2011/06/openindiana-zone-with-nat/">a rough setup of routing</a></li>
<li><a href="http://www.rite-group.com/rich/solaris_nat.html">NAT on solaris</a></li>
</ul>
http://zero-knowledge.org/post/74openindiana - how to configure a zone2011-10-29T15:14:16+02:00Gibheer<p>In this short post, we will get a container running on a openindiana host. We will do some things in crossbow, but of the following stuff is just configuring the zone. At the end of this blog post, you will find some links to related pages.</p>
<p>In this short post, we will get a container running on a openindiana host. We will do some things in crossbow, but of the following stuff is just configuring the zone. At the end of this blog post, you will find some links to related pages.</p>
<h1>some preparations</h1>
<p>Make sure, that you have a free vnic created with dladm to use in the zone or else, we will have no network available. Further, we need a place on the filesystem, where our zone can be created. We need 500MB to 1.5GB of free space.</p>
<h1>writing a zone configuration</h1>
<p>In the first step, we have to write a zone configuration. You can use zonecfg directly, but it's better to write it into a textfile and let zonecfg read that file. That way, you can check the configuration into a vcs of your choice.</p>
<p>The config should look like this.</p>
<pre><code>create -b
set zonepath=/zones/zone1
set ip-type=exclusive
set autoboot=false
add net
set physical=zone1
end
commit
</code></pre>
<p>With this configuration, we build a zone, which get's saved in <code>/zones</code>. <code>/zones</code> has to be a zfs partition or else the zone can not be created.</p>
<p>The sixth line sets the network device for the zone to the vnic <code>zone1</code>.</p>
<p>Now we feed the file to zonecfg and let it create <em>zone1</em>.</p>
<pre><code># zonecfg -z zone1 -f zone1.conf
</code></pre>
<h1>installation of the zone</h1>
<p>The next step is to install the zone with the command:</p>
<pre><code># zoneadm -z zone1 install
</code></pre>
<p>or clone it from a template with</p>
<pre><code># zoneadm -z zone1 clone template_name
</code></pre>
<p>Now we have to wait a bit and can write the next configuration file.</p>
<h1>writing a sysidcfg</h1>
<p>I wrote a rough post about the <a href="http://zero-knowledge.org/post/72">sysidcfg</a> already, so take a look there, if you are interested in further details.</p>
<p>For this example, we use the following content.</p>
<pre><code>name_service=NONE
nfs4_domain=dynamic
terminal=xterms
# the password is foobar
root_password=0WMBUdFzAu6qU
security_policy=NONE
network_interface=zone1 {
primary
hostname=zone1
default_route=NONE
ip_address=192.168.5.3
netmask=255.255.255.0
protocol_ipv6=no
}
</code></pre>
<h1>booting the zone</h1>
<p>When the installation process has ended, copy the file to <code>/zones/zone1/root/etc/sysidcfg</code>. This way, the zone can read the file on the first boot and set most of the stuff.</p>
<pre><code># zoneadm -z zone1 boot
</code></pre>
<p>To check if everything gets configured, log into the zone and check the output.</p>
<pre><code># zlogin -e ! -C zone1
</code></pre>
<p>It will take some time until the zone is ready to use, but it should not ask for further details. When the prompt shows, the configuration completed.</p>
<p>Now you can login into the zone and make further adjustments. Some topics will get their own blog entries here, so take a look at the other entries for help too.</p>
<h1>links</h1>
<p>Here are some links for further details to this topic:</p>
<ul>
<li><a href="http://www.c0t0d0s0.org/archives/5355-Upcoming-Solaris-Features-Crossbow-Part-1-Virtualisation.html">crossbow example from c0t0d0s0</a></li>
<li><a href="http://zero-knowledge.org/post/72">howto sysidcfg</a></li>
</ul>
http://zero-knowledge.org/post/72How to use sysidcfg for zone deployment2011-10-28T13:41:53+02:00Gibheer<p>This is mostly for myself that I can remember how to use the least documented feature of Solaris and openindiana - the <code>sysidcfg</code> files.</p>
<p>This is mostly for myself that I can remember how to use the least documented feature of Solaris and openindiana - the <code>sysidcfg</code> files.</p>
<p>These files help deploying new zones faster, as you don't have to configure them by hand afterwards. But what is the syntax and how can you use them?</p>
<p>Here is an example file</p>
<pre><code>name_service=NONE
# name_service=DNS {domain_name=<your_domain> name_server=<your_dns_server>}
nfs4_domain=dynamic
timezone=Europe/Stockholm
terminal=xterms
root_password=<crypted_password>
security_policy=NONE
network_interface=<interface1> {primary hostname=<hostname> default_route=<route_ip> ip_address=<if_ip> netmask=<if_netmask> protocol_ipv6=yes}
network_interface=<interface2> {hostname=<hostname> ip_address=<if_ip> netmask=<if_netmask> protocol_ipv6=yes default_route=NONE}`
</code></pre>
<p>The most important thing first: you don't need system_locale after openindiana 151 anymore. If you have it in your config, even with C, delete it or else the setup will not work!</p>
<p>If you don't have a dns record for your zone yet, set the @name_service@ to NONE. If you have already a record set, use the commented syntax.</p>
<p>The next interesting setting is root_password. Here you don't input the password in cleartext but crypted. I wrote a little script to generate this string. You can find the code <a href="https://github.com/Gibheer/zero-pwcrypter">here</a>.</p>
<p>The network_interface part is pretty easy, if you take these lines as a dummy. If you have only one interface, you can name the first interface PRIMARY. That way, you have a bit less to write.</p>
<p>That's all so far. I will update this post, when I have figured out, what to fill into nfs4_domain and security_policy.</p>
http://zero-knowledge.org/post/71set environment variables in smf manifests2011-09-26T14:35:10+02:00Gibheer<p>If you are in the need to set an environment variable for an smf service, you are looking for envvar. It get's set in the <code>service</code> scope or in the <code>exec_method</code> scope. Here is a small example, how it's used.</p>
<p>If you are in the need to set an environment variable for an smf service, you are looking for envvar. It get's set in the <code>service</code> scope or in the <code>exec_method</code> scope. Here is a small example, how it's used.</p>
<p><code>
<exec_method type="method" name="start" exec="/bin/bash">
<method_context>
<method_environment>
<envvar name="FOO" value="bar" />
</method_environment>
</method_context>
</exec_method>
</code></p>
<p>This example sets the environment variable <code>FOO</code> to bar. This is espacially useful, when you have to modify <code>PATH</code> or <code>LD_LIBRARY_PATH</code>. Just don't forget, that you did it.</p>
http://zero-knowledge.org/post/70get pfexec back in Solaris2011-09-16T19:08:39+02:00Gibheer<p>If you tried Solaris 11 or OpenIndiana in a fresh installation, you may have noticed, that pfexec may not work the way you are used to. I asked in #openindiana on <code>irc.freenode.org</code> and I was told, that the behavior was changed. OpenSolaris was used to have an <code>Primary Administrator</code> profile which got assigned to the first account created on the installation. The problem with that is the same as on Windows - you are doing everything with the administrator or root account. To avoid that, sudo was introduced, which needs the password of your account with the default settings. What both tools are very different at what they do and at what they are good at. So it's up to the administrator to define secure roles where appropriate and use sudo rules for the parts, which have to be more secured.</p>
<p>If you tried Solaris 11 or OpenIndiana in a fresh installation, you may have noticed, that pfexec may not work the way you are used to. I asked in #openindiana on <code>irc.freenode.org</code> and I was told, that the behavior was changed. OpenSolaris was used to have an <code>Primary Administrator</code> profile which got assigned to the first account created on the installation. The problem with that is the same as on Windows - you are doing everything with the administrator or root account. To avoid that, sudo was introduced, which needs the password of your account with the default settings. What both tools are very different at what they do and at what they are good at. So it's up to the administrator to define secure roles where appropriate and use sudo rules for the parts, which have to be more secured.</p>
<p>If you want back the old behavior, these two steps should be enough. But keep in mind, that it is important that you secure your system, to avoid misuse.</p>
<ul>
<li>there should be line like the following in <code>/etc/security/prof_attr</code>
<code>Primary Administrator:::Can perform all administrative tasks:auths=solaris.*,solaris.grant;help=RtPriAdmin.html</code></li>
<li>if there is, then you can add that profile to your user with
<code>usermod -P'Primary Administrator</code> <username></li>
</ul>
<p>It is possible to combine these two mechanics too. You could build a zone to ssh into the box with a key and from there, ssh with sudo and a password into the internal systems.</p>
http://zero-knowledge.org/post/68OpenIndiana 151a released2011-09-14T08:15:00+02:00Gibheer<p>After the release of <a href="http://www.postgresql.org/about/news.1349">PostgreSQL 9.1</a>, today another great open source project released a new version - <a href="http://wiki.openindiana.org/oi/oi_151a+Release+Notes">OpenIndiana</a>.</p>
<p>After the release of <a href="http://www.postgresql.org/about/news.1349">PostgreSQL 9.1</a>, today another great open source project released a new version - <a href="http://wiki.openindiana.org/oi/oi_151a+Release+Notes">OpenIndiana</a>.</p>
<p>OpenIndiana is based on a fork of OpenSolaris, named <a href="http://illumos.org">Illumos</a>. It was announced in august 2010. OpenIndiana has evolved since that time and got a stable release 148 and today 151a. That release is very solid and got one thing, which Solaris 11 has and most likely will never have: <em>KVM</em>.</p>
<p>So from today you get a Solaris fork with crossbow, resource containers, zones and the kernel virtual machine, converted from linux to Illumos from the developers of <a href="http://joyent.com">Joyent</a>. They built there own distribution, <a href="http://smartos.org">SmartOS</a>, which is a bootable OS for managing a cloud like setup but without the zones.</p>
<p>So if you have a large Infrastructure and want to seperate some programs from each other or have some old infrastructure, try OpenIndiana and it's zones and kvm.</p>