Articles and Ideas

Start and Stop Service from a non-Administrator user account

Posted by:

Start and Stop Service from a non-Administrator user account

Many times as System Engineer I have been challenged with potential security issue to allow non-administrators to control system services states (including custom ones). Because of many “solutions” I’ve encountered on field, I feel the urge to state that giving non-admin administrative credentials is never a right solution, not even remotely! If you are presented with similar request, please spend more time designing rather than repairing solution which will never pass any audit.

To make this solution a bit more challenging I will use this article to describe process of allowing non-administrators custom service (not built-in windows service) service control rights. To make it even more challenging I have chosen service which doesn’t have same Service and Display name.

Scenario:

You wish to allow operators in your company right to start/stop several services also giving them rights to query for their state. Furthermore, they don’t necessarily have to possess knowledge to operate services on remote systems (servers) from their workstations and you want to automate process (create script) to minimize human errors, giving them current service state and allowing them to start/restart it.

We have a BGDIT01SQL01 SQL server running CentralizedAafService service which Operators need to maintain in their daily routine.

Prerequisites:

Operators OU BeforeYou need to have appropriate objects organized in your domain environment nested using AGDLP strategy, which is always my recommendation. In my Test Environment I have already created Operators OU with user accounts of all operators all nested in Global group G_Operators.

Service Manipulation OU

SG_BGDIT01SQL01_CentralizedAafService PropertiesI always like creating dedicated OU as container for objects used for service manipulation. So if you wish, go ahead and create Service Manipulation OU. Inside that OU create logically named Global group (e.g. SG_servername_servicename) for every service you need to delegate and always use narrative description (I speak from personal experience) because sooner or later you will be asked to change configuration. I’ve created SG_BGDIT01SQL01_CentralizedAafService group, nesting G_Operators group inside it. Since you’re gonna be testing this include your domain user account for the Testing period inside it too.

Solution Approach:

It is pretty straightforward solution, once you break it down into these steps:

  1. Create group of users. We will be giving service control rights to that group.

Now, if you want to control standard Windows (built-in) service:

    1. On domain controller, start Group Policy Management Console (GPMC) and set needed right(s) to that service(s) via Group Policy Object (GPO).
    2. Continue to solution approach step 4.

Note: This solution will not be presented in this post.

If you want to control custom Windows service:

    1. Log in to the server hosting service and install GPMC appropriate to that specific server and your domain forest functional level. For example, if you wish to control service hosted on Windows Server 2003 and your domain forest function level and domain controller operating system is Windows Server 2008 R2 you will need to download this GPMC and install it on server hosting service (Windows Server 2003 in this example). Google for GPMC you need in your environment (i.e. you just need to enable GPMC in Windows Server 2008, no need for download).
    2. Start GPMC on server hosting service you wish to manage and set needed rights to that specific service via Group Policy Object (GPO).
  1. Create a script for users who need service control.
  2. Test it from users’ workstation.
Implementation Procedure:
  1. Download the appropriate GPMC and install it on server hosting service you wish to configure access to.
  2. Run GPMC on that server and find container where server (Computer Object) that hosts that service reside in (since we will use GPO Computer Configuration) or some top level OU, depending on your OU structure (I mainly use Group Policy Type-Based Model design in my environments). See note below.

Note: In my Production Environment in have several sub OU’s (treelike structure) designed to host just server accounts. I always apply this GPO on top level OU hosting server accounts and then use Security Filtering to apply GPO only to Computer Object(s) I need to (e.g. BGDIT01SQL01 server).

  1. Right click on that OU and choose Create a GPO in this domain, and Link it here… option.
  2. Give it descriptive name, like BGDIT01SQL01 Service Management.
  3. Navigate to Computer ConfigurationPoliciesWindows SettingsSecurity SettingsSystem Services section and double click service you wish to setup access to:

GPMC

  1. Click Define this policy setting and select Service startup mode equal to that services’ default startup type setting (i.e. you can find out services’ default startup type setting by running services.msc console and inspecting Startup Type column).
  2. Click the Edit Security… button:

CentralizedAafService Properties

  1. Add created SG_BGDIT01SQL01_CentralizedAafService group containing users that need access to the following service and
  2. give them the needed rights (e.g. Full Control):

 Security for CentralizedAafService

  1. Confirm and close all windows by pressing OK buttons.

Now it’s time to write script for our Operators to minimize human errors. We will use simple batch file to control installed services through Service Control Manager (SCM) via Service Controller (SC) program.

Before we proceed, I would like to state few very important facts:

  1. SC control services via their Service Name (if you use services’ Display Name in SC syntax it will result in error). To find out service name use services.msc console and look under Properties of specified service (i.e. in this example we have service with CentralizedAafService Display Name and CentralizedWorkflowService Service Name).
  2. If you have spaces in Service Name parameter you are required to use quotation marks in your SC syntax (e.g. “service name with spaces“).
  3. Also, SC command is case sensitive and it is important to mind letter capitalization in Service Name parameter (e.g. “service name with spaces” is not same service as “Service Name with spaces“, those are two different services).

For example, to query for service state run following command and look under STATE output:

Same syntax is for start or stop service commands.

Now we will write the following code in notepad and save it as “QUERY BGDIT01SQL01 CentralizedAafService.BAT” file:

We will use same syntax for start and stop batch files and give them to Operators. Now they can control specified service running on remote server by double clicking batch file as tested:

QUERY BGDIT01SQL01 CentralizedAafService Test

Further Reading:

There are a lot of guides on internet to achieve the same goal by using the Security Descriptor Definition Language but – as a con – I like centralized and easily managed solutions and SDDL does not meet such requirements but – as a pro – it has much more granulated service management.

References:

  1. MSDN: Security Descriptor String Format
  2. University of Washington: Understanding SDDL Syntax
  3. NetworkAdminKB: How to Read a SDDL String
  4. NetworkAdminKB: Understanding the SDDL permissions in the ACE_String

0


Predrag Mirjanić

About the Author:

I am capable of working as an engineer on complicated projects or as a "one-man band" bringing the project from scratch to successful fruition. Regarding my technical skills I have quite a lot to offer. Primarily I am a Systems Administrator (Engineer). I have acquired experience in the field by installing, implementing and administering many different Microsoft based network setups in large ICT environments, in diverse industry and government companies. I am familiar with older operating systems including Linux/UNIX based systems. I have designed, installed and implemented different technologies like: Exchange, IP CCTV, BES, SCCM (specifically ZTI), network QoS optimization, and much more. I have good experience with virtualized environments (Microsoft based). I can apply my skills to help automate processes in order to reduce administrative overheads and/or human errors. I am in process of developing WAMP based (Windows, Apache, MySQL and PHP) intranet (company-wide) social networking site for document and project management purposes. Engineering hardware based cloud (powered by Linux OS) for purposes of rendering video material. Also programming several different RouterOS based MikroTik routers to deliver ultimate network management solution (QoS, bandwidth control, L7 protocol traffic control etc.).

Add a Comment