Thursday, March 18, 2010

Running pkg server as regular user

I wanted to run the pkg server a regular user, to be able to publish into the repository via the file protocol without giving the user any extra privileges. It turned to be quite easy to achieve:

Export the current configuration to a file:

svccfg export pkg/server > pkg.xml 

Modify the file so that it looks like the below example. I added the <method_context> and modified the inst_root property. Also the port has to be > 1024 to be usable by ordinary user.


<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
  <service name='application/pkg/server' type='service' version='0'>
    <create_default_instance enabled='true'/>
    <dependency name='fs' grouping='require_all' restart_on='none' type='service'>
      <service_fmri value='svc:/system/filesystem/local'/>
    </dependency>
    <dependency name='autofs' grouping='optional_all' restart_on='none' type='service'>
      <service_fmri value='svc:/system/filesystem/autofs'/>
    </dependency>
    <dependency name='ntp' grouping='optional_all' restart_on='none' type='service'>
      <service_fmri value='svc:/network/ntp'/>
    </dependency>
    <dependency name='network' grouping='require_all' restart_on='none' type='service'>
      <service_fmri value='svc:/milestone/network'/>
    </dependency>
    <exec_method name='start' type='method' exec='%{pkg/pkg_root}/lib/svc/method/svc-pkg-depot %m' timeout_seconds='0'>
    <method_context>
        <method_credential
        user='test'
        group='staff' />
    </method_context>
    </exec_method>
    <exec_method name='stop' type='method' exec='%{pkg/pkg_root}/lib/svc/method/svc-pkg-depot %m %{restarter/contract}' timeout_seconds='30'/>
    <property_group name='pkg' type='application'>
      <propval name='cfg_file' type='astring' value=''/>
      <propval name='content_root' type='astring' value='usr/share/lib/pkg'/>
      <propval name='debug' type='astring' value=''/>
      <propval name='log_access' type='astring' value='none'/>
      <propval name='log_errors' type='astring' value='stderr'/>
      <propval name='mirror' type='boolean' value='false'/>
      <propval name='pkg_root' type='astring' value='/'/>
      <propval name='proxy_base' type='astring' value=''/>
      <propval name='readonly' type='boolean' value='false'/>
      <propval name='socket_timeout' type='count' value='60'/>
      <propval name='sort_file_max_size' type='astring' value=''/>
      <propval name='ssl_cert_file' type='astring' value='none'/>
      <propval name='ssl_dialog' type='astring' value='smf'/>
      <propval name='ssl_key_file' type='astring' value='none'/>
      <propval name='threads' type='count' value='10'/>
      <propval name='writable_root' type='astring' value=''/>
      <propval name='port' type='count' value='10000'/>
      <propval name='inst_root' type='astring' value='/export/home/test/repo'/>
    </property_group>
    <property_group name='pkg_secure' type='application'>
      <property name='read_authorization' type='astring'/>
      <property name='ssl_key_passphrase' type='astring'/>
    </property_group>
    <property_group name='startd' type='framework'>
      <propval name='duration' type='astring' value='child'/>
    </property_group>
    <stability value='Unstable'/>
    <template>
      <common_name>
        <loctext xml:lang='C'>image packaging repository</loctext>
      </common_name>
    </template>
  </service>
</service_bundle>

And import the settings back:

svccfg import pkg.xml

Do not forget to make the service log file writable for the user, otherwise the pkg server will not start:

pfexec chown test /var/svc/log/application-pkg-server:default.log

No comments:

Post a Comment