Unable to authenticate on TeamCity feed

I’m targeting Octopus to local TeamCity NuGet feed. Both Octopus and TeamCity have Windows enabled. Proper credentials set.

Testing feed from returns an error:

There was a problem processing your request: 400 The remote server returned an error: (401) Unauthorized.

Event log:

2013-06-26 00:28:22,369 [8] ERROR Octopus [(null)] - System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at NuGet.RequestHelper.GetResponse(Func`1 createRequest, Action`1 prepareRequest, IProxyCache proxyCache, ICredentialCache credentialCache, ICredentialProvider credentialProvider)
at NuGet.HttpClient.GetResponse()
at NuGet.RedirectedHttpClient.GetResponseUri(HttpClient client)
at NuGet.RedirectedHttpClient.EnsureClient()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at NuGet.RedirectedHttpClient.get_CachedClient()
at NuGet.RedirectedHttpClient.get_Uri()
at NuGet.DataServicePackageRepository.GetPackages()
at Octopus.Portal.Areas.Api.Controllers.PackagesController.SearchForPackagesNamedLike(IPackageRepository repository, String packageId, Int32 take)
at Octopus.Portal.Areas.Api.Controllers.PackagesController.Index(String feedId, String packageId, Boolean partialMatch, Boolean includeMultipleVersions, Int32 take)
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()

But in the same time equally configured Red Gate Deployment Manager works fine. What can be wrong here?

Hi Alexander,

TeamCity appears to be rejecting the credentials you used. Can you check that the credentials are correct? Octopus also caches the credentials so if they are still being rejected you can try restarting the Octopus Portal app domain and Windows service to reset the cache.

Paul

Looks like Octopus Server rejects the credentials.
I tried to run octo.exe directly from TeamCiry server:

octo.exe deploy-release
    --server="http://server:8083/"
    --apikey=<KEY>
    --project="MyPackage"
    --enableservicemessages
    --version="0.1" 
    --deployto="Dev"
    --waitfordeployment
    --user="<domain\user>"
    --pass="<pass=word>"

Getting the same Unauthorized error:

Octopus Command Line Tool, version 1.1.17.62
Finding project: MyPackage
Handshaking with Octopus server: http://server.8083/
Octopus server responded with: The remote server returned an error: (401) Unauthorized.
Please ensure your API key is valid. If Basic authentication is being used by IIS, you will also need to pass your username and password.
System.Net.WebException: The remote server returned an error: (401) Unauthorized
at System.Net.HttpWebRequest.GetResponse()
at OctopusTools.Client.OctopusSession.Get[TResource](String path, QueryStringqueryString)
at OctopusTools.Client.OctopusSession.EstablishSession()
at System.Lazy`1.CreateValue() 
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at OctopusTools.Client.OctopusSession.get_RootDocument()
at ProjectExtensions.GetProject(IOctopusSession session, String projectName)
at OctopusTools.Commands.DeployReleaseCommand.Execute()
at OctopusTools.Infrastructure.CommandProcessor.Process(String[] args)

Windows & Basic Auth are turned on, Anonymous is turned off.
Both servers are running Windows Server 2008 R2 with Active Directory.
Please suggest. Thanks!

Hi,

Can you check the event log on the Octopus server? Are the --user and --pass values correct (perhaps try removing any quotes)?

What happens if you open a web browser on the TeamCity server, and browse to http://server:8083/api?

Paul

Hi Paul,
One important note: the proper problem’s title is “Unable to authenticate on Octopus Portal”.

I just disabled Anonymous Auth, left Basic and Windows for Octopus Portal using IIS snap-in, opened http://server:8083/api/, entered user/pass in Basic Auth dialog, and response was:

{
  "Application": "Octopus",
  "Version": "1.6.1.1718",
  "ApiVersion": "2.0.0",
  "OperatingSystem": "Microsoft Windows NT 6.1.7601 Service Pack 1",
  "Links": {
    "Self": "/api",
    "Environments": "/api/environments",
    "Machines": "/api/machines",
    "Projects": "/api/projects",
    "Feeds": "/api/feeds",
    "Tasks": "/api/tasks"
  }

}

But running octo.exe --user=<user> --pass=<pass> (with or without quotes) results the same error:

Finding project: MyProject
Handshaking with Octopus server: http://server:8083/api
Octopus server responded with: The remote server returned an error: (401) Unauthorized.
Please ensure your API key is valid. If Basic authentication is being used by IIS, you will also need to pass your username and password.
System.Net.WebException: The remote server returned an error: (401) Unauthorized.

EventLog is empty, and IIS log contains lines:

10.0.1.6 - DOMAIN\username [15/Jul/2013:07:03:53 +0400] "GET /api HTTP/1.1" 401 366
10.0.1.6 - - [15/Jul/2013:07:03:53 +0400] "GET /api HTTP/1.1" 401 0

Okay, when using --password=<> instead of just --pass=<> I’m getting another error:

Octopus Command Line Tool, version 1.1.17.62

Finding project: MyProject
Handshaking with Octopus server: http://server:8083/api
Octopus server responded with: The remote server returned an error: (401) Unauthorized.
Please ensure your API key is valid. If Basic authentication is being used by IIS, you will also need to pass your username and password.
System.Net.WebException: The remote server returned an error: (401) Unauthorized. --->
System.ComponentModel.Win32Exception: The logon attempt failed
   at System.Net.NTAuthentication.GetOutgoingBlob(Byte[] incomingBlob, Boolean throwOnError, SecurityStatus& statusCode)
   at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob)
   at System.Net.NegotiateClient.DoAuthenticate(String challenge, WebRequest webRequest, ICredentials credentials, Boolean preAuthenticate)
   at System.Net.NegotiateClient.Authenticate(String challenge, WebRequest webRequest, ICredentials credentials)
   at System.Net.AuthenticationManager.Authenticate(String challenge, WebRequest request, ICredentials credentials)
   at System.Net.AuthenticationState.AttemptAuthenticate(HttpWebRequest httpWebRequest, ICredentials authInfo)
   at System.Net.HttpWebRequest.CheckResubmitForAuth()
   at System.Net.HttpWebRequest.CheckResubmit(Exception& e, Boolean& disableUpload)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at OctopusTools.Client.OctopusSession.Get[TResource](String path, QueryString queryString)
   at OctopusTools.Client.OctopusSession.EstablishSession()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Lazy`1.get_Value()
   at OctopusTools.Client.OctopusSession.get_RootDocument()
   at ProjectExtensions.GetProject(IOctopusSession session, String projectName)
   at OctopusTools.Commands.DeployReleaseCommand.Execute()
   at OctopusTools.Infrastructure.CommandProcessor.Process(String[] args)

But --apikey=<> is exact to Configuration -> Certificates -> Octopus → Tentacle!

Lesson learned:

  • --pass= is the proper command line parameter
  • API Key mean user key (from profile) not server key (from portal configuration)

Thanks for the update Alexander and glad you got this sorted.

Paul