生產環境項目問題記錄系列(二):Docker打包鏡像Nuget包因權限問題還原失敗


docker打包鏡像遇到一個因為nuget權限驗證問題導致鏡像打包失敗的問題,公司Nuget包用的是tfs管理的,tfs有權限驗證,結果導致nuget還原失敗,原有的NuGet.config文件如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="CompanyNuGet" value="*****" />
  </packageSources>
</configuration>

使用這個nuget配置在docker中還原遇到的第一個報錯如下: ”Unable to load the service index for source ...”,OK很明顯是說無法訪問nuget地址,突然想到可能是權限問題,所以修改配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="CompanyNuGet" value="..." />
  </packageSources>
  <packageSourceCredentials>
    <CompanyNuGet>
      <add key="Username" value="NugetReader" />
      <add key="ClearTextPassword" value="i'm a secret!" />
    </CompanyNuGet>
  </packageSourceCredentials>
</configuration>

然后又報了第二個錯:"/home/pi/dotnet/sdk/2.2.300/NuGet.targets(121,5): error :   GSSAPI operation failed with error - An invalid status code was supplied (SPNEGO cannot find mechanisms to negotiate)."

看樣子好像是驗證失敗,無奈網上找辦法,找了半天找到了解決方案,首先我們需要在tfs中創建一個私人的Token來當做密碼:

 

 

然后將創建的Token當做密碼在NuGet中配置,還要再加一個重要的配置,表示使用基礎驗證:

<add key="ValidAuthenticationTypes" value="basic" />

最終的NuGet配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="private-nuget" value="nuget url" />
  </packageSources>
  <packageSourceCredentials>
    <private-nuget>
      <add key="Username" value="NugetReader" />
      <add key="ClearTextPassword" value="Token" />
      <add key="ValidAuthenticationTypes" value="basic" />
    </private-nuget>
  </packageSourceCredentials>
</configuration>

然后鏡像打包成功!

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM