Service account API key not working

Hi, I am trying to setup service account for TeamCity, but it says that API key is invalid.

This error tested on 2.4.4 and 2.4.5 releases. Here is detailed log

@@@
An exception was thrown while trying to establish a principal for the current request
Octopus.Platform.Web.Security.OctopusSecurityException: The API key that you provided was not valid. Please double-check your API key and try again. For instructions on finding your API key, please visit: https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki/Authentication
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.EnsureApiKeyValid(String attemptedKey, IOctopusPrincipal principal) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 118
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.GetPresentedUserIdentity(NancyContext context) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 89
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.EstablishPrincipalForRequest(NancyContext context) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 43
Warning 2014-05-19 17:04:10
You do not have permission to perform this action. Please contact your Octopus administrator. (http://deploy.directcrm.ru/api/projects)
Warning 2014-05-19 17:14:09
An exception was thrown while trying to establish a principal for the current request
Octopus.Platform.Web.Security.OctopusSecurityException: The API key that you provided was not valid. Please double-check your API key and try again. For instructions on finding your API key, please visit: https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki/Authentication
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.EnsureApiKeyValid(String attemptedKey, IOctopusPrincipal principal) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 118
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.GetPresentedUserIdentity(NancyContext context) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 89
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.EstablishPrincipalForRequest(NancyContext context) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 43
@@@
And from Octo.exe:
@@@
Step 37/37: OctopusDeploy: Create release
[17:04:10][Step 37/37] Octopus Deploy
[17:04:10]Running command: octo.exe create-release --server http://deploy.directcrm.ru/ --apikey SECRET --project Demo --enableservicemessages --version 1.0.34 --deployto Staging --waitfordeployment
[17:04:10]Creating Octopus Deploy release
[17:04:10]Octopus Deploy Command Line Tool, version 2.4.2.54
[17:04:10]
[17:04:10]Handshaking with Octopus server: http://deploy.directcrm.ru/
[17:04:10]Handshake successful. Octopus version: 2.4.5.46; API version: 3.0.0
[17:04:10]Finding project: Demo
[17:04:10]Error from Octopus server (HTTP 403): You do not have permission to perform this action. Please contact your Octopus administrator.
[17:04:10]Exit code: -7
[17:04:10]Octo.exe exit code: -7
[17:04:10][Step 37/37] Unable to create or deploy release. Please check the build log for details on the error.
[17:04:10][Step 37/37] Step OctopusDeploy: Create release failed
@@@
Here is configuration http://screencast.com/t/QX0i7FHS

When I use API key from my account, it works fine http://screencast.com/t/DkfHX7r6vA8
@@@
Step 37/37: OctopusDeploy: Create release (24s)
[17:14:10]Octopus Deploy (23s)
[17:14:10]Running command: octo.exe create-release --server http://deploy.directcrm.ru/ --apikey SECRET --project Demo --enableservicemessages --version 1.0.35 --deployto Staging --waitfordeployment
[17:14:10]Creating Octopus Deploy release
[17:14:10]Octopus Deploy Command Line Tool, version 2.4.2.54
[17:14:10]
[17:14:11]Handshaking with Octopus server: http://deploy.directcrm.ru/
[17:14:11]Handshake successful. Octopus version: 2.4.5.46; API version: 3.0.0
[17:14:11]Finding project: Demo
[17:14:11]Finding deployment process for project: Demo
[17:14:11]Finding release template…
[17:14:12]Resolving NuGet package versions…
[17:14:12]Finding latest NuGet package for step: Deploy Package
[17:14:12]Using version number provided on command-line.
[17:14:12]Release plan for release: 1.0.35
[17:14:12]Steps:
[17:14:12] # Name Version Source
[17:14:12] — ---------------- --------------- ------------------------------------
[17:14:12] 1 Deploy Package 1.0.30 Latest available in NuGet repository
[17:14:12]
[17:14:12]Creating release…
[17:14:13]Release 1.0.35 created successfully!
[17:14:13]##teamcity[setParameter name=‘octo.releaseNumber’ value=‘1.0.35’]
[17:14:14]Deploying Demo 1.0.35 to: Staging (Guided Failure: Not Enabled)
[17:14:14]Waiting for 1 deployment(s) to complete…
[17:14:34]Deploy Demo release 1.0.35 to Staging: Success
[17:14:34]Done!
[17:14:34]Octo.exe exit code: 0
@@@

Hi Igor,

Thanks for getting in touch! Can you let me know whether there are any errors in the Windows event viewer on the Octopus server?

Paul

Hi Paul,
Thanks for response.

There is couple errors in eventlog but nothing new as I see

@@@
2014-05-19 17:04:09.1412 WARN An exception was thrown while trying to establish a principal for the current request
Octopus.Platform.Web.Security.OctopusSecurityException: The API key that you provided was not valid. Please double-check your API key and try again. For instructions on finding your API key, please visit: https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki/Authentication
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.EnsureApiKeyValid(String attemptedKey, IOctopusPrincipal principal) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 118
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.GetPresentedUserIdentity(NancyContext context) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 89
at Octopus.Server.Web.Infrastructure.Authentication.OctopusPrincipalEstablisher.EstablishPrincipalForRequest(NancyContext context) in y:\work\db516cd4dfb6f424\source\Octopus.Server\Web\Infrastructure\Authentication\OctopusPrincipalEstablisher.cs:line 43
@@@

@@@
2014-05-19 17:04:10.2095 WARN You do not have permission to perform this action. Please contact your Octopus administrator. (http://deploy.directcrm.ru/api/projects)
@@@

Hi Igor,

Thanks for the update. I’d like to get to the bottom of this but going back and forth here might take a while - would you be free to do a Skype or GoToMeeting call? You can pick a time that works for you here:

https://octopusdeploy.acuityscheduling.com/schedule.php

Paul

Paul, unfortunately I am in UTC+4 zone, so is shows available times from 1am till 4am. If you can shift for a couple hours earlier, like 22:00-23:00, I’ll be glad to help.

My skype is clain23.

Best Regards
Igor Kudrin, CTO
Mindboxhttp://mindbox.ru/

Hi Igor,

I’ve added you to Skype - I’ll try to catch you throughout the day, but when you are online feel free to ping me too.

Paul

Thahks for the call, Paul!

Adding Service account to Administrators group solved the problem.

Hey - what was the outcome of this chat? I’m seeing similar problems trying to create-release from command line

Try adding Service account to Administrators group

Hmm. That;s a little high privilege for a service account… TBH, after posting, I found this thread which has the minimum perms needed, so I created a group for my service account users with these perms

http://help.octopusdeploy.com/discussions/questions/2464-minimum-permissions-for-a-service-account-role