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

Add-AccountToDockerAccess fails in pwsh 7.0 #4

Open
epvanhouten opened this issue Apr 22, 2020 · 5 comments
Open

Add-AccountToDockerAccess fails in pwsh 7.0 #4

epvanhouten opened this issue Apr 22, 2020 · 5 comments

Comments

@epvanhouten
Copy link

When running in pwsh 7.0 the following errors are generated:

InvalidOperation: C:\Users\CpUser\Documents\PowerShell\Modules\dockeraccesshelper\0.0.3\Add-AccountToDockerAccess.psm1:65
Line |
  65 |      $dSec = $dInfo.GetAccessControl()
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [System.IO.DirectoryInfo] does not contain a method named
     | 'GetAccessControl'.

InvalidOperation: C:\Users\CpUser\Documents\PowerShell\Modules\dockeraccesshelper\0.0.3\Add-AccountToDockerAccess.psm1:67
Line |
  67 |      $dSec.AddAccessRule($rule)
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.

InvalidOperation: C:\Users\CpUser\Documents\PowerShell\Modules\dockeraccesshelper\0.0.3\Add-AccountToDockerAccess.psm1:68
Line |
  68 |      $dInfo.SetAccessControl($dSec)
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [System.IO.DirectoryInfo] does not contain a method named
     | 'SetAccessControl'.

My $PSVersionTable:

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Running Add-AccountToDockerAccess in a powershell session with version 5.1.17763.1007 runs to completion successfully.

@tfenster
Copy link
Owner

Thanks for opening the issue. As PS 7 is using .net Core, I probably need to use different classes and / or methods. Unfortunately, I won't have time for that in the foreseeable future but would keep this issue open as a reminder

@robquinn
Copy link

I got this same error while using Powershell (Preview) 7.1.3.

The Solution

Open up the standard Powershell (5.1 or something), and try again. For me, it worked using the regular Powershell.

@franzeal
Copy link

franzeal commented Sep 7, 2022

You should also be able to do this from pwsh:

powershell Install-Module -Name dockeraccesshelper
powershell Add-AccountToDockerAccess $UserName

@mcarbonneaux
Copy link

mcarbonneaux commented Nov 7, 2022

My Power shell version Table :

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

as Admin user in powershell 7 i've done it with this command:

> $acl = Get-Acl "\\.\pipe\docker_engine"
> $acl.access

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : AUTORITE NT\Système
IsInherited       : False
InheritanceFlags  : None
PropagationFlags  : None

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrateurs
IsInherited       : False
InheritanceFlags  : None
PropagationFlags  : None
> $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("<Domain>\<user>","FullControl","Allow")
> $acl.SetAccessRule($rule)
> $acl.Access

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : AUTORITE NT\Système
IsInherited       : False
InheritanceFlags  : None
PropagationFlags  : None

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : BUILTIN\Administrateurs
IsInherited       : False
InheritanceFlags  : None
PropagationFlags  : None

FileSystemRights  : FullControl
AccessControlType : Allow
IdentityReference : <Domain>\<user>
IsInherited       : False
InheritanceFlags  : None
PropagationFlags  : None
> Set-Acl "\\.\pipe\docker_engine" -AclObject $acl

From <user> powershell i can now use docker command:

PS C:\Users\<user>> docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 1
 Server Version: 20.10.13
 Storage Driver: windowsfilter
  Windows:
 Logging Driver: json-file
 Plugins:
  Volume: local
  Network: ics internal l2bridge l2tunnel nat null overlay private transparent
  Log: awslogs etwlogs fluentd gcplogs gelf json-file local logentries splunk syslog
 Swarm: inactive
 Default Isolation: hyperv
 Kernel Version: 10.0 19044 (19041.1.amd64fre.vb_release.191206-1406)
 Operating System: Windows 10 Enterprise Version 2009 (OS Build 19044.2130)
 OSType: windows
 Architecture: x86_64
 CPUs: 4
 Total Memory: 8GiB
 Name: <hostname>
 ID: <id>
 Docker Root Dir: C:\ProgramData\docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

@rkl110
Copy link

rkl110 commented Oct 25, 2024

You can run this code on PowerShell 7

$account="$env:USERDOMAIN\$env:USERNAME"
$npipe = "\\.\pipe\docker_engine"
$dInfo = New-Object "System.IO.DirectoryInfo" -ArgumentList $npipe
#$dSec = $dInfo.GetAccessControl()
$dSec = Get-Acl -Path $dInfo
$fullControl =[System.Security.AccessControl.FileSystemRights]::FullControl
$allow =[System.Security.AccessControl.AccessControlType]::Allow
$rule = New-Object "System.Security.AccessControl.FileSystemAccessRule" -ArgumentList $account,$fullControl,$allow
$dSec.AddAccessRule($rule)
#$dInfo.SetAccessControl($dSec)
Set-Acl -Path $dInfo -AclObject $dSec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants