How to specify a user id and password for Visual Studio Code with an authenticating proxy?

后端 未结 9 1926
谎友^
谎友^ 2020-12-08 01:38

How to specify a user id and password for Visual Studio Code with an authenticating proxy?

I\'ve seen the Proxy Server Support on the main VS Code site, but this onl

9条回答
  •  一生所求
    2020-12-08 01:54

    I really like the solution David Martin posted (further below) using Fiddler, however I wanted to figure out how to use http.proxyAuthorization and here is my solution considering you are OK to have credtials saved in base64 encoded format in the settings.json file.

    WARNING: Saving credentials in base64 encoded format is certainly better than plain text, however consider base64 encoding as obfuscation not an ecryption and the account can still be compromised - use at your own risk. Consider modifying the ACL of the settings file to reduce read acess to it.

    Step 1: Encode your credentials using the code below:

    var s = @"DOMAIN\user:pass";
    var bytes = System.Text.Encoding.UTF8.GetBytes(s);
    Console.WriteLine(Convert.ToBase64String(bytes));
    

    RE9NQUlOXHVzZXI6cGFzcw==

    Step 2: Update VS Code settings by adding http.proxyAuthorization using the base64 encoded value from above:

    {
        "https.proxy": "https://internal-proxy.corp.net:8080",
        "http.proxyAuthorization": "Authorization: Basic RE9NQUlOXHVzZXI6cGFzcw=="
    }
    

    Step 3: Secure the settings.json by updating it's ACL

    Since you have stored credentials in the file to increase the security you can modify the ACL of the settings file by removing the local administrators group - make sure only you can read this file. I used the following PowerShell script to remove the local admin group for example:

    $settings = "$env:appdata\Code\$env:username\settings.json"
    $acl = (Get-Item $settings).GetAccessControl('Access')
    $acl.SetAccessRuleProtection($true,$true) # removes the ACL inheritance
    $accesToRemove = $acl.Access | ?{ $_.IsInherited -eq $false -and $_.IdentityReference -eq 'BUILTIN\Administrators' }
    $acl.RemoveAccessRule($accesToRemove)
    Set-Acl -AclObject $acl $settings
    

提交回复
热议问题