Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging - capture more information about a user (user name, domain, remote?, system?) #615

Closed
DarwinJS opened this issue Feb 6, 2016 · 9 comments
Assignees
Milestone

Comments

@DarwinJS
Copy link
Contributor

DarwinJS commented Feb 6, 2016

_Let Me Know If You Want This Broken Up and if so, How Many Issues to Break It Into_

It would be helpful if for each of these choco
[a] Set a Variable
[b] reported all of these near each other in the log
[c] if each log entry included unique text that could be searched and/or configured in a log highlighter.

Username
Variable: $env:username
Log example: Chocolatey is running under account username:

SYSTEM Account Context
Also would be nice if Choco reported explicitly whether it thinks it is running under SYSTEM.

  1. From experience, checking the user name is not a good idea because: it is reported slightly differently depending on context. Sometimes it is $ and sometimes "SYSTEM".
  2. Some accounts, like "LocalSystem" may also be considered "SYSTEM" accounts.
    I think this API call is the best way - but I have not researched whether it catches alternative SYSTEM accounts:
If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).IsSystem)
{$IsSystem = $True} Else {$IsSystem = $True}

Log example: Chocolatey is running in SYSTEM account context. (Also exposed in variable $IsSystem)

PLEASE DO NOT REPOST CONTENT WITHOUT PERMISSION. Training and Tools to Make Apps Run on Win7 and Virtualization => http://CSI-Windows.com

ELEVATED Administrator Rights
Reporting System Admin rights or not would also be helpful.
Most reliable way I know is the following - this SID only appears if the current session IS ELEVATED. So you don't need to goof around with methods that tell you the user is in the admins group - but still not elevated:

If ([bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544"))
{$IsElevated = $True} Else {$IsElevated = $False}

Log example: Chocolatey is running in an ELEVATED ADMIN context. (Also exposed in variable $IsElevated)

REMOTING Context
Get-host could be helpful here. I know of one stumbling block. (Get-Host).Name can contain the string "remote" for some scheduled jobs. (Get-host).runspace may be more reliable, but I have not tested it in scheduled jobs

[bool]((get-host).name -ilike "*remot*")
[bool]((get-host).runspaces -ilike "*remot*")
{$IsRemoting = $True} Else {$IsRemoting = $False}

Log example: Chocolatey is running in a REMOTE SESSION. (Also exposed in variable $IsRemoting)

@ferventcoder
Copy link
Member

ELEVATED

We already capture this.

@DarwinJS
Copy link
Contributor Author

DarwinJS commented Feb 6, 2016

We already capture this.

Ok - is it both a variable and logging?

@ferventcoder
Copy link
Member

@DarwinJS
Copy link
Contributor Author

DarwinJS commented Feb 6, 2016

Cool - looking for the same pattern with the others if possible and a bit of choco unique logging text.

@DarwinJS
Copy link
Contributor Author

DarwinJS commented Feb 6, 2016

Would also be cool to show all the indicator variables choco takes pains to set - in the default template produced by "choco new". May prevent a lot of packagers taking time to find their own methods - methods which may not cover all use cases their package will end up in.

@ferventcoder ferventcoder added this to the 0.9.10 milestone Feb 12, 2016
@ferventcoder ferventcoder self-assigned this Feb 12, 2016
@ferventcoder ferventcoder modified the milestones: 0.9.10.1, 0.9.10 Apr 29, 2016
@ferventcoder ferventcoder modified the milestones: 0.9.10.1, 0.9.10.2, 0.9.10.3, 0.9.10.4, 0.9.10.5 Jun 17, 2016
@ferventcoder ferventcoder modified the milestones: 0.10.1, 0.10.2 Aug 15, 2016
@ferventcoder ferventcoder modified the milestones: 0.10.4, 0.10.3 Oct 3, 2016
@ferventcoder ferventcoder modified the milestones: 0.10.4, 0.10.5 Feb 27, 2017
@ferventcoder ferventcoder modified the milestones: 0.10.5, 0.10.6, 0.10.7 Mar 30, 2017
@ferventcoder ferventcoder modified the milestones: 0.10.6, 0.10.7 Apr 26, 2017
@ferventcoder
Copy link
Member

This will be in 0.10.6

@ferventcoder
Copy link
Member

There is a way to know if choco is running inside of a terminal services (remote desktop context). However it doesn't appear there is a way for anything to know it is being run over PowerShell Remoting (outside of the entered PowerShell session, which will know that it is running something like ServerRemoteHost). That information doesn't flow into any environment variables and is not passed down to choco (or any tool) when it runs so there is likely no way to know it is coming over remoting. HTH

@ferventcoder
Copy link
Member

ferventcoder commented Apr 27, 2017

The one thing we may be able to do is see $env:SESSIONNAME is completely empty and not "Console" and guess it may have something to do with not being a local session... it's not very deterministic though.

@ferventcoder
Copy link
Member

ferventcoder commented Apr 27, 2017

@DarwinJS probably more deterministic from PowerShell - https://twitter.com/anthonymastrean/status/857399759895744512

From @AnthonyMastrean

ferventcoder added a commit that referenced this issue May 1, 2017
Capture the following additional information about a user:

* Username
* User domain
* User is System?
* User is Remote?
ferventcoder added a commit that referenced this issue May 1, 2017
* stable: (35 commits)
  (GH-1238) Save extra info about installed packages
  (maint) allow overrides
  (GH-1253)(GH-1263) List/Search returns Summary and Release Notes
  (GH-1101) Search results by relevance by default
  (GH-1004) Ensure choco info returns results
  (maint) Note on install if auto-uninstall possible
  (maint) look for licensed assembly based build-type
  (GH-615) capture more user information
  (GH-1145) show inner exception message
  (GH-1267) API - get configuration
  (maint) Resources proj does not produce pdb file
  (doc) update nuspec authors
  (doc) update licensed release notes
  (build) ILMerge pdb files
  (GH-1247) ensure xml documentation
  (maint) note force install is for same version
  (GH-1243) Update Chocolatey shims
  (GH-1243)(shimgen) upgrade to 0.8.x
  (maint) fix copyright double period
  (log) show exit code when running -v
  ...
@ferventcoder ferventcoder changed the title Enhance Logging: Explicit Reporting of User Name, System Account Context, Admin Rights and Remoting Context Logging - capture more information about a user May 24, 2017
@ferventcoder ferventcoder changed the title Logging - capture more information about a user Logging - capture more information about a user (user name, domain, remote?, system?) May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants