5/18/2015

Syncplicity, How to use with Shibboleth


EMC Syncplicity is a a cloud based "Software as a Service" offering. The Syncplicity brand is owned by EMC Corporation. For companies that purchased substantial hosting services they create a custom branded EMC website for managing the cloud hosted accounts.

A cloud hosted account is a signed in user who has the ability to initiate and maintain a file storage session for the purpose of conducting file sharing services over the EMC Syncplicity cloud based file sharing system. Participants who maintain a cloud account are not individually licensed but receive web browser delivered software agents that enable their internet connected workstation or mobile device to use EMC cloud storage to share files.

Customers of EMC often already have an authentication system such as Active Directory, and often use ADFS or an OASIS style SAML2 compatible Single Sign On service in order to avoid proliferation of account management issues and to allow members of their domain to remember only one set of logon credentials.

Shibboleth is a commonly used SAML complaint SSO.

This is an example with Shibboleth 2.4.2 on RHEL6 connected to a Windows 2008r2 Domain.

Images: within this document are Expandable by "clicking" on them to enhance readability.

On the EMC provided Management page for the Customer service site

  •  NOTE:  When setting up SSO  "the Management page"  may log you out automatically after 30 minutes (before you are finished) . You can log back in regardless of whether SSO is enabled by going to the my.syncplicity.com website and "clicking" the triangle for  Sign-in Help   it will take you back to the Admin page for your subdomain account.

After signing into the EMC Management site you begin by choosing from the

Menu bar > Admin > Settings

Manage Settings
>Account Configuration
>>Custom Domain and single sign-on.




STEP 1

> Configuration Authentication Settings
>> Domain Settings (should already be filled out for you)

> Single Sign-On (SSO)
>> Single Sign-On Status*

"select" the radio button [Enabled] to un-grey the fields that follow


STEP 2

upload a PEM format X.509 copy of your Shibboleth Idp "internal" signing certificate:

[NOTE: This is the Idp "internal" cert used for signing SAML assertions. It is NOT the SSO Website certificate a users browser receives when they are directed to a logon page]

For example:

The SAML signing cert for Shibboleth is commonly placed here:

/opt/shibboleth-idp/credentials/idp.crt



 Master Tip! 

be sure to take a look at the [Current Certificate: ] information after it uploads

it is common for an Idp cert to reveal very little information

"too much" information could signal the  wrong  cert was uploaded


"the right" amount of information signals the  right  cert was uploaded 


STEP 3

complete the rest of the fields that refer to the Shibboleth server hosted at your site



Provide the Identity provider (Entity Id) for the Shibboleth Idp website:  < on your server > 

Provide the Customer facing "Sign-in page" (SSO) url:  < on your server > 

Provide the Customer facing "Logout page" (SSO) url:  < on your server > 

The press  [ Save Changes ]  to save the settings.


note: these are "paths" to web services on your shibboleth server, they have to be setup on your shibboleth server to receive requests and provide answers; they can be mapped to different paths, you have to be sure to use the correct paths; these are provided as common examples


On the Shibboleth server


STEP 1

The EMC website needs to be added as a Service Provider to the relying-party file.

The EMC website will be "relying" on your Shibboleth server to provide "authentication".

For example:

The shibboleth relying-party file is commonly found here:

/opt/shibboleth-idp/conf/relying-party.xml



The file is in xml format and has a series of "chunks" or "sections" of information


Syncplicity needs a new section like this
 rp:RelyingParty

Where id = "Service provider (SP id) for the EMC hosted website /sp"
Where provider = "Identity provider (Entity ID) for your shibboleth svr"
to save time and typing errors you can copy an existing section and modify it

Syncplicity needs to be added to this section
metadata:MetadataProvider

the Metadata that goes into the file
/opt/shibboleth-idp/metadata/emcshib.xml
has to come from EMC and is specific to your hosted service
here is what it looks like

the Metadata is a "contract" for how the Service Provider will communicate
it includes the SP id, the SAML protocol type, the SP x509 signing cert, what it expects to see used in the Subject line for communications (the "NameID") and how to contact the Service Provider when the Shibboleth server is done fullfilling the User login request
you can obtain it in one of three ways; 

1. https://custdomain.syncplicity.com/Auth/ServiceProviderMetadata.aspx
wget https://customain.syncplicity.com/Auth/ServiceProviderMetadata.aspx -O emcshib.xml
curl https://custdomain.syncplicity.com/Auth/ServiceProviderMetadata.aspx > emcshib.xml
 NOTE:  this method currently retrieves metadata with a known problem

2. https://syncplicity.zendesk.com
sign up for a Syncplicity Support account and "open" a Support Ticket
 NOTE:  support will review the ticket and may take up to 1 day to respond 

3. write it yourself
obtaining the Service Provider x509 cert is the only really hard part
you can fetch that from the URL for your hosted site in method # 1

STEP 2

The attributes to be returned to the service provider after a successful login need to be defined.

The required attributes need to be added to 

/opt/shibboleth-idp/conf/attributes-resolver.xml 


Syncplicity needs a new section like this

 resolver:AttributeDefinition

 

a particular attribute is not required, but at least one must be capable of being turned into the "Name ID" for the conversation; and it must be tagged as being formatted as a

nameid-format:emailAddress 


For example

we invent an attribute "EmcID" and fill it with the users mail address from an LDAP query to Active Directory for the authenticated user and tag it as being formatted as a  

nameid-format:emailAddress  

and SAML encode it with the SAML2StringNameID routine


the result will be when it comes time to pare down the attributes to be sent back to the EMC Syncplicity service provider, this attribute will be available


STEP 3

The attributes to be released need to be defined in the attribute-filter policy file.

The attributes to be released need to be added to 

/opt/shibboleth-idp/conf/attributes-filter.xml 


Syncplicity needs a new section like this

 afp:AttributeFilterPolicy


an AttributeFilterPolicy applies to a particular Service Provider ID and declares what attributes are Permitted or Denied release, usually you will have more Deny rules than Permit rules


in a SAML2 based server its also important to filter out the "Transient ID" explicitly since it is by default Permitted and often unintentionally takes the place of the NameID

after all rules are applied to pare down the available attributes for a user, one is selected for the NameID and based on the Metadata from the Service Provider it uses an attribute that is in the format

nameid-format:emailAddress  

Syncplicity will use this attribute to find the User Account on the hosted Service Provider site and log them in


STEP 4


Services need to be stopped and started to pick up the changes.

# service tomcat stop
# service tomcat start

And a Shibboleth / Active Directory user should attempt to login to the EMC provided Service site

It will take them to their familar Shibboleth SSO logon page for authentication.

After authentication it will return them to the same EMC Service Site and if their

 NameID = nameid-format:emailAddress 

matches a User Account created in the EMC management page for this site.

They will be allowed to initiate a Syncplicity file sharing session.

To be completely clear

Syncplicity "uses" an Email address as the UID or Unique Identifier for a Syncplicity user account in their system. Shibboleth must return a NameID in an email address format that Syncplicity can use to "find" a Syncplicity user account in the EMC system. If it fails to find a match the user may indeed succeed in logging in with their SSO credentials but Syncplicity will present an error screen indicating it could not match up their login with a Syncplicity user account.

It is also not enough to return or "assert" an attribute for a successfully logged in user, it must be mapped or used as the NameID for the SAML conversation. Syncplicity does not scan the attributes returned for "any" email address, it only looks at the NameID of the SAML conversation.

This is "why" it is so critical to make sure a Transient ID doesn't get accidentally mapped into the NameID. It is in the wrong format and will not in general be sourced from the mail attribute for a user.

You can tell from the log messages in the idp-process.log when detail is turned up, which released attribute is being "used" for the NameID. This is a terrific troubleshooting step.

Its even easier if you use a SAML tracer plugin on Firefox to "watch" what is used as the NameID in the conversation between the browser and Syncplicity when it returns from a successful SSO sign in.

Which released attribute will be picked for the NameID can seem a bit random in nature depending on the attributes available after all the attribute filters for that service provider have been applied.


 TroubleShooting Tips! 


 TIP #1 

The logging for Idp, OpenSAML, LDAP and Protocol messages can be increased in this file

/opt/shibboleth-idp/conf/logging.xml

After restart the tomcat Shibboleth process will record additional detail in

/opt/shibboleth-idp/logs/idp-access.log
/opt/shibboleth-idp/logs/idp-audit.log
/opt/shibboleth-idp/logs/idp-process.log
  
the ipd-process.log file will contain the most useful information.

these log files typically roll over at midnight local time.

Be sure to reduce the logging detail after troubleshooting.


 TIP #2  

The Firefox web browser has a SAML transaction decoder and monitoring tool [ Add-on ]

 NOTE:  works with Firefox version 29.0 and later "only"  


After it is installed

> Tools
>> SAML tracer

will open a separate box and track all of the traffic within open browser windows

traffic identitied as encrypted and SAML encoded will be decrypted and decoded into human readable content (can you 'Spot' the <saml2:NameID > line?)




 Be Careful  when sharing screenshots of decrypted SAML sessions as there is often "sensitive" user information exchanged within the SAML transactions 


 TIP #3  

Once SSO is enabled, only Users with accounts already set up in Syncplicity will be able to log into their Syncplicity accounts.

To be clear

If "End-users" merely visit the hosted portal site at <custom-domain>.syncplicity.com and try to login with their SSO credentials. They may indeed succeed in authenticating, but upon return from their SSO login page Syncplicity "will not" proceed with the "Self-signup" process. They will be denied access.

   Setting up "End-user self-signup" is a completely separate Administrative task.    

Once it is configured and enabled End-users will need a specially crafted "invitation URL" created for the Syncplicity hosted domain in order to begin the self-signup process.

The "invitation URL" is unique to the hosted site, but not to the End-user, so once it is created the same URL can be shared with everyone who is entitled within an organization to participate.



3/26/2015

Win MMC, adding tasks to the ADUC menu


Its not a common thing to do, customizing the MMC console Apps so they are less annoying when they first startup, or adding third party tools that take arguments from an MMC context menu.. as in perform this task on this machine or collection of machines. Here's how to do that.

... to be continued

Win Task, email the results


There are a couple of ways of sending email from Windows 2008r2 or Windows 2012r2.

Both depend on whats inherently available with the operating system.

Windows 2008r2 included an email function built-into WinTask, but it also imposed a limitation on email "From:" to be only from the username that executed the task, hence that account had to have a mailbox or it would generically error out befuddling the hapless administrator.

Windows 2012r2 removed the email function citing security concerns and the availablility of a email function in the powershell toolbox as the preferred method for emailing.

This demonstration will show how to use both, when triggered by the ending of another WinTask script.. which can be monitored by process "WinTask name" using a custom XML trigger for its criteria.

... to be continued

Windows, reg value interpretation and publishing


Sometimes you want to monitor a registry value and publish it without installing a heavy remote management infrastructure, heres how to do that.

For this demo the Teamviewer client/server is installed and the ID for connecting to it is made available to any machine that can retrieve a list of the local groups on that windows system.

Teamviewer is like RDP but works over port 80 and 443, its encrypted and allows a remote console without complex setup. It works across OSX, Windows and Linux so its rather unbiquitous.

The key piece of information to have is the ID or TVID.. which is a three digit triplet of numbers that act like an address or phone number to connect with a system that has already started and connected with the Internet connection directory service. Where possible Teamviewer uses local peer to peer connections, and fallsback to a remote proxy service to ensure connections are made.

The Teamviewer "Host" package is a Microsoft Software Installer package, a kind of atomic database installation package which makes distributing and installing signed packages easy. This [.msi] also accepts command line arguments to control the level of detail exposed to the end User upon installation.

Often you may want to have an end user install it or install it using a GPO, and then either automatically, or on-demand summon the current TeamViewer ID so that you can open a concurrent console with a system to debug or help out an end user.

@echo off

taskkill /IM TeamViewer.exe

FOR /F "skip=2 tokens=2*" %%i IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\TeamViewer\Version6" /V "ClientID"') do set /a "LAD=%%j"

net localgroup | find /i "%LAD%" > nul && goto exists

net localgroup %LAD% /ADD /COMMENT:"TeamViewer ID"

taskkill /IM TeamViewer.exe

:exists
exit /B 0

When Teamviewer installs it creates a unique TVID and stores it in the systems registery.

This can be fetched using the SQL "like" command line tool [ reg query ] but the value is in [ hex ].

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\TeamViewer\Version6" /V "ClientID"
>    ClientID    REG_DWORD    0x1a3c3d6b

This then needs to be parsed and converted into decimal so a user can type it into a remote Teamviewer client to connect to the system with the TVID which is acting as the console server.
FOR /F "skip=2 tokens=2*" %%i IN ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\TeamViewer\Version6" /V "ClientID"') do ...

Which means
FOR /F

skip=2 - number of lines to skip at the beginning of the file

tokens=2* - tokens to be passed to FOR body, skipping the first token and only passing the second token and all others assigned to i,j,k ect.. then "do" something
Which converts the token 0x1a3c3d6b  into a decimal number
set /a "LAD=%%
>  440124987
Basically the "set /a" command [evaluates] the expression which is prefixed with a 0x string that indicates it is in [ hex ]  and the result is displayed in decimal form.
 
Once its in decimal form, its possible to create a [net local group] on the local windows system and annotate the local group with a description.

 net localgroup | find /i "%LAD%" > nul && goto exists
Searches the local group list from the result of "net localgroup" for an existing group by the name of the decimal TVID number, if it finds one it doesn't bother to create one (avoiding a collision error that would raise a script error) and exits the routine.

net localgroup %LAD% /ADD /COMMENT:"TeamViewer ID"

But if such a local group does not exist, it creates a localgroup with the TVID as its name and changes the description for the local group to indicate what this group is for.. in a way it creates a [value] = [key] pair which can be indexed and searched for using a remote tool or simple command line script.


Listing local groups are then accessible using common command line tools, gui tools, or even remote mangement tools and powershell commands.

There are pros and cons to using [value]=[key] or [key]=[value] order when repurposing the local groups list as a generically accessible string array.

There are name space collison possibilities, ease of search string matching depending on the method used, eye ease of finding, or security issues (minor obscuring by obfuscating what its for.. the description isn't always displayed by default).. even organizational procedures regarding local group naming conventions.. but none of that distracts from the cool factor of "intepreting and publishing" an arbitrary reg value which could be accessed using generic tools, or logged in an event log or emailed.



3/24/2015

Crontabs, Quick test for SSL websites

Sometimes you need to check the status or result of an SSL protected website after performing maintenance in an automated fashion, here's how to do that.

The typical crontab routine

MAILTO="john.willis@johnwillis.com, jwillis@johnwillis.com"
9 3 * * * /usr/bin/wget -O /dev/null https://www.johnwillis.com/index.cfm

Wget is a pretty flexible tool and if it is directed to [output] > [-O] the results of retrieving a website the details can be directed to devnull, while the alternate pipe results can be automatically emailed to the crontabs nominated recipient list.
--2015-03-24 03:09:01--  https://www.johnwillis.com/index.cfm 

Resolving www.johnwillis.com... 192.168.2.36 

Connecting to www.johnwillis.com|192.168.2.36|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: unspecified [text/html]
Saving to: `/dev/null'

     0K .......                                                59.1M=0s

2015-03-24 03:10:05 (59.1 MB/s) - `/dev/null' saved [8121]

 The really nice thing is the test is simple and quick to setup, not overly verbose, and does provide some measure of assurance that the connection was over an SSL protected connection (the certificate works) and was able to download the content to a file.

It could be refactored to perform additional testing or levels of detail, but essentially this would be sufficient for most quick glances at a mobile phone or early in the morning to be assured that a routine performed at night had not left a service in a nonfunctional state.


Crontabs, Nifty Notifications

When creating crontabs to exec a routine, its sometimes helpful to send the results as an wbem indication, snmptrap or email message often these are received on mobile device and a quick glance should indicate status, here's how to do that.

First a typical crontab routine


# crontab -e


58 7 * * * ( /wpa/test-auth-eduroam/wpa_supplicant/eapol_test -c /wpa/test-auth-eduroam/wpa_supplicant/peap-mschapv2.conf -a 192.168.2.180 -s "inwhowetrust" | grep ^SUCCESS > /dev/null ) && { echo "<p style='font-family:arial;color:green;font-size:20px;'> SUCCESS </p>" > test-auth-eduroam1.txt; } || { echo "<p style='font-family:arial;color:red;font-size:20px;' > FAILED </p>" > test-auth-eduroam1.txt; } ; mail -s "$(echo -e "eduroam - testing\nContent-Type: text/html")" john.willis@johnwillis.com < test-auth-eduroam1.txt
It follows the regular pattern of

[when/howoften]

[what/todo]

followed by a logical clause that creates a custom msg file based on the results of a grep for a condition in the results of the output of a command

[ 58 7 * * * ]
<<<<<<<< is the usual "when/howoften"


( /wpa/test-auth-eduroam/wpa_supplicant/eapol_test -c /wpa/test-auth-eduroam/wpa_supplicant/peap-mschapv2.conf -a 192.168.2.180 -s "inwhowetrust" | grep ^SUCCESS  > /dev/null )
<<<<<<<< is the usual "what/todo"

it "includes" a follow up task by piping the output of the command through a grep statement to search for a condition and consigns the rest to the bit bucket devnull

but the result of the grep statement sets a conditional status

which is used by the next piece

&& { echo "<p style='font-family:arial;color:green;font-size:20px;'>  SUCCESS  </p>" > test-auth-eduroam1.txt; } || { echo "<p style='font-family:arial;color:red;font-size:20px;' >  FAILED  </p>" > test-auth-eduroam1.txt; }

to "explicitly" echo an html formatted  msg based on the value of that "conditional status" from the grep statement

it is "either" going to be

>>>>>> "green formatted SUCCESS"

or

>>>>>> "red formatted FAILED"

the last piece merely "compounds" the number of things to do before this crontab is complete with a semicolon in normal bash shell fashion

mail -s "$(echo -e "eduroam - testing\nContent-Type: text/html")" john.willis@johnwillis.com < test-auth-eduroam1.txt

it sets a mail msg subject line and content header

directs the msg to a recipient

and inports the custom msg body from the content file filled with the desired formatted result of the grep test

the nice thing about this method is it demonstrates the level of sophistication achieveable using basic tools and the original crontab method in concert with what I like to call "horizontal programming" or "horizontal procedureal thinking"

there is no reason this could not be extended indefinately in the orthogonal dimension except possible command shell buffer limits.. and unfortunately that does seem to be the case with certain malware





3/12/2015

WSUS, How to Email Reports



 
Report.sql > contents follow <

/* note- javascript ignores whitespace, transact sql does not.
This allows the following raiserror trick to work. It inserts a custom CSS header.
Transact will try to interpret the message according to pseudo-printf substitution,
%% is required rather than % to print a % character, $_(name) is required rather than $(name)
where the underscore is an ordinary space.
*/

RAISERROR ('
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<style type="text/css" media="screen">table { width: 100%%; border: 1px solid #cef; text-align: left; } th { font-weight: bold; background-color: #acf; border-bottom: 1px solid #cef;} td,th {padding: 4px 5px;}.odd {background-color: #def;} .odd td{border-bottom:1px solid#cef;}></style>
<script language="JavaScript" type="text/javascript">$ (document).ready(function(){$ ("tr:odd").addClass("odd");});</script>
</script>
', 0, 1) WITH NOWAIT


/*
Approved security updates compliance report
Find computers within a specific target group that need security updates
that have been approved to this group (or a parent group) for at least N days
Optionally, only consider updates of a given MSRC severity rating
*/


SET NOCOUNT ON
DECLARE @TargetGroup nvarchar(30)
DECLARE @Days int

-- Configure these values as needed
-- Example: SELECT @TargetGroup = 'Unassigned Computers'
-- Example: Microsoft update is older than 1 days
SELECT @TargetGroup = 'SUS Reporting Group'
SELECT @Days = 1

-- Find the target group and all it's parent groups
DECLARE @groups AS TABLE (Id uniqueidentifier NOT NULL)
DECLARE @groupId uniqueidentifier
-- retrieve the singular @groupID that corresponds to the TargetGroup
SET @groupId = (
    SELECT ComputerTargetGroupId
    FROM PUBLIC_VIEWS.vComputerTargetGroup
    WHERE vComputerTargetGroup.Name = @TargetGroup
)
IF @groupId is NULL
    RAISERROR ('Invalid Target Group Name', 16, 1)
-- create a table @groups loaded with all the groupId's where the TargetGroup is a member
WHILE @groupId IS NOT NULL
BEGIN
    INSERT INTO @groups SELECT @groupId
    SET @groupId = (
        SELECT ParentTargetGroupId
        FROM PUBLIC_VIEWS.vComputerTargetGroup
        WHERE vComputerTargetGroup.ComputerTargetGroupId = @groupId
    )
END

-- Find all security updates which have been approved for install for at least
-- @Days to the specified target group (or one of it's parent groups)
--
-- create a table @updates loaded with UpdateId's where the TargetGroupId belongs to the @groups table
-- and the Action is 'Install'
-- and the MsrcSeverity is 'Not Null'
-- and the difference between the Microsoft creation data and Today is greater than @Days
--
DECLARE @updates AS TABLE (Id uniqueidentifier NOT NULL)
INSERT INTO @updates
SELECT vUpdate.UpdateId
FROM
    PUBLIC_VIEWS.vUpdate
    INNER JOIN PUBLIC_VIEWS.vUpdateApproval on vUpdateApproval.UpdateId = vUpdate.UpdateId
WHERE
    DATEDIFF (day, vUpdateApproval.CreationDate, GETUTCDATE()) > @Days
    AND vUpdate.MsrcSeverity is NOT NULL
    AND vUpdateApproval.Action = 'Install'
    AND vUpdateApproval.ComputerTargetGroupId IN (SELECT * FROM @groups)
    -- Can retrieve updates with important/critical MSRC ratings by replacing MsrcSeverity clause with this instead:
    -- AND vUpdate.MsrcSeverity in (’Critical’, ’Important’)
    -- values for MsrcSeverity include Unspecified, Moderate, Low, Critical and Important




IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp
SET NOCOUNT ON
SET ANSI_WARNINGS OFF


-- List of computers not in compliance for at least one updates
--
-- retrieve the computer name, kb article, and description
-- from several inner joins where
-- the ComputerTarget is an inner set of
-- a ComputerGroup which is an inner set of
-- an UpdateState which is an inner set of
-- an Update which is an inner set of
-- an Updates Group (from the previous query)
-- where the ComputerTarget has a State
-- and is in the 'definition' of 'Failed or Needed'
-- and ComputerTargetGroup Name is the original TargetGroup
--
--
SELECT

vComputerTargetGroup.Name AS Target_Group,
vComputerTarget.Name AS 'Computer_Name',
vComputerTarget.LastReportedStatusTime AS 'LastContactTime',
--CreationDate AS 'Microsoft_Released',
KnowledgebaseArticle AS 'KB_Article',
StateMap.Name AS 'Status',
SecurityBulletin AS 'Security_Bulletin',
MsrcSeverity AS 'Severity_Rating',
DefaultTitle AS Description


INTO #tmp

-- vComputerTarget.Name as 'Computer Name', vUpdate.KnowledgebaseArticle as 'KB Article', vUpdate.DefaultDescription as 'Update Title'
FROM PUBLIC_VIEWS.vComputerGroupMembership
    INNER JOIN PUBLIC_VIEWS.vComputerTarget on vComputerGroupMembership.ComputerTargetId = vComputerTarget.ComputerTargetId
    INNER JOIN PUBLIC_VIEWS.vComputerTargetGroup on vComputerGroupMembership.ComputerTargetGroupId = vComputerTargetGroup.ComputerTargetGroupId
    INNER JOIN PUBLIC_VIEWS.vUpdateInstallationInfoBasic on vUpdateInstallationInfoBasic.ComputerTargetId = vComputerTarget.ComputerTargetId
    INNER JOIN PUBLIC_VIEWS.fnUpdateInstallationStateMap() AS StateMap ON vUpdateInstallationInfoBasic.State = StateMap.Id
    INNER JOIN PUBLIC_VIEWS.vUpdate on vUpdate.UpdateId = vUpdateInstallationInfoBasic.UpdateId
    INNER JOIN @updates GROUPS on vUpdateInstallationInfoBasic.UpdateId = GROUPS.Id
WHERE vComputerTarget.ComputerTargetId = vUpdateInstallationInfoBasic.ComputerTargetId
    AND vUpdateInstallationInfoBasic.State in (2, 3, 5, 6)
    -- 0=Unknown, 1=NotApplicable, 2=NotInstalled, 3=Downloaded, 4=Installed, 5=Failed, 6=Installed Pending Reboot
    -- 2=NotInstalled, 3=Downloaded, 5=Failed, 6=Installed Pending Reboot (Definition of "Failed or Needed")
    AND vComputerTargetGroup.Name = @TargetGroup
-- would normally consolidate duplicate column values (but multiple Updates can have the same information)    
-- GROUP BY vComputerTarget.Name, vUpdate.KnowledgebaseArticle, vUpdate.DefaultDescription
-- ORDER BY 'Computer_Name' ASC, 'Microsoft_Released'
ORDER BY 'Computer_Name' ASC, 'Security_Bulletin'


EXECUTE SaveTableAsHTML @DBFetch = #tmp, @Header = 1, @CSS =
'table{font-family:"Lucida Sans Unicode", "Lucida Grande", Sans-Serif;font-size:12px;width:480px;text-align:left;border-collapse:collapse;margin:20px;}
 th{font-size:13px;font-weight:bold;background:#b9c9fe;border-top:4px solid #aabcfe;border-bottom:1px solid #fff;color:black;padding:8px;}
 td{background:#e8edff;border-bottom:1px solid #fff;color:#669;border-top:1px solid transparent;padding:8px;}
 tr:hover td{background:#d0dafd;color:#339;}'