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

Error: The remote server returned an error: (401) Unauthorized #2

Closed
Bouke opened this issue Apr 23, 2018 · 18 comments
Closed

Error: The remote server returned an error: (401) Unauthorized #2

Bouke opened this issue Apr 23, 2018 · 18 comments

Comments

@Bouke
Copy link

Bouke commented Apr 23, 2018

Hi Mario, thanks for the plugin. It used to work for us and was of great help. However our deployment showed the following error in the release log:

2018-04-23T18:18:46.0647509Z ##[section]Starting: Retain indefinitely current release
2018-04-23T18:18:46.0657494Z ==============================================================================
2018-04-23T18:18:46.0657494Z Task         : Retain indefinitely current release
2018-04-23T18:18:46.0657494Z Description  : This task will allow you to mark the current release to be retained indefinitely
2018-04-23T18:18:46.0657494Z Version      : 1.1.0
2018-04-23T18:18:46.0657494Z Author       : Mario Majcica
2018-04-23T18:18:46.0657494Z Help         : On a successful release to production, usually you will mark the release to be retained for certain amount of time. This task will automate the desired behaviour, by marking the current release to be retained indefinitely.
2018-04-23T18:18:46.0657494Z ==============================================================================
2018-04-23T18:18:47.5747743Z ##[error]The remote server returned an error: (401) Unauthorized.
2018-04-23T18:18:47.5907715Z ##[section]Finishing: Retain indefinitely current release

The "Manage releases" is set to "allow" for the build service. I'm not sure what to do about this, have you got any suggestions?

@mmajcica
Copy link
Owner

Hi @Bouke,

what is the identity on which your build agent is running?
Are you able to share a screenshot of Permission window of 'All release definitions'?

@mmajcica
Copy link
Owner

If you are using TFS there is a project level build service account, like in the following example:

rel-sec

In order for the task to work, the specific project level build service also needs the 'Manage Releases' permission set.

@Bouke
Copy link
Author

Bouke commented Apr 25, 2018

Sure! We're on VSTS. These are setup like this:

All release definitions:

screen_shot_2018-04-25_at_20_55_00

My Release Definition:

screen_shot_2018-04-25_at_20_54_30

@Bouke
Copy link
Author

Bouke commented Apr 25, 2018

Don't know if relevant: we're using a self-hosted agent.

@mmajcica
Copy link
Owner

mmajcica commented Apr 25, 2018 via email

@Bouke
Copy link
Author

Bouke commented Apr 25, 2018

It's a private agent. I think you're referring to these credentials? What should be added here? "Release (read, write, execute and manage)"?

pasted_image_25_04_2018__23_43

@mmajcica
Copy link
Owner

mmajcica commented Apr 26, 2018

Well, you answered yourself here.
Can you try flagging that Release (read, write, execute and manage) option, then use the newly created PAT key with your agent and then retry?

@mmajcica
Copy link
Owner

You can also try it via a script

$Pat = "fdxtop6poxvonnlndaz5xf4smah3uq6ja6rpxzg7rrtnponrtxta"
$collectionUrl = "https://mummy.vsrm.visualstudio.com"
$project = "TestProject"
$releaseId = "53"

$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$Pat"))

$uri = "$collectionUrl/$project/_apis/release/releases/$($releaseId)?api-version=3.0-preview.2"

Invoke-RestMethod -Uri $uri -Method Patch -ContentType "application/json" -Body "{keepforever:true}" -Headers @{ Authorization = "Basic $encodedCredentials"}

Just set the variables to match your case and fire it. If that account has sufficient permissions, your release should be marked as retained.

@mmajcica
Copy link
Owner

@Bouke any updates?

Thanks

@mmajcica mmajcica closed this as completed May 5, 2018
@Bouke
Copy link
Author

Bouke commented May 9, 2018

We don't deploy that often. I've updated the PAT -- will know in a week or so if it was successful. Thank you for your time!

@Bouke
Copy link
Author

Bouke commented May 14, 2018

So I've updated the PAT (from the VSTS web interface), but after deploying the same error appears:

2018-05-14T15:21:08.1077285Z ##[error]The remote server returned an error: (401) Unauthorized.

Do I need to restart/reconfigure my VSTS agent before the new permissions take effect?

@mmajcica
Copy link
Owner

Hi,

sure you do. Reconfigure the agent with the new PAT.

@mmajcica
Copy link
Owner

@Bouke Did reconfigure of the agent did the trick?

@Bouke
Copy link
Author

Bouke commented May 23, 2018

So I configured the agent with the new PAT, and as a test added the task to the Acceptance environment. All seemed well:

2018-05-22T09:45:15.1462495Z ##[section]Starting: Retain indefinitely current release (test)
2018-05-22T09:45:15.1462495Z ==============================================================================
2018-05-22T09:45:15.1462495Z Task         : Retain indefinitely current release
2018-05-22T09:45:15.1462495Z Description  : This task will allow you to mark the current release to be retained indefinitely
2018-05-22T09:45:15.1462495Z Version      : 2.1.0
2018-05-22T09:45:15.1462495Z Author       : Mario Majcica
2018-05-22T09:45:15.1462495Z Help         : On a successful release to production, usually you will mark the release to be retained for certain amount of time. This task will automate the desired behaviour, by marking the current release to be retained indefinitely.
2018-05-22T09:45:15.1462495Z ==============================================================================
2018-05-22T09:45:15.7392503Z Release '1.9.7.2399' is marked with Retain indefinitely flag.
2018-05-22T09:45:15.7462522Z ##[section]Finishing: Retain indefinitely current release (test)

However, when deploying to production yesterday it failed:

2018-05-22T21:03:13.2815591Z ##[section]Starting: Retain indefinitely current release
2018-05-22T21:03:13.2815591Z ==============================================================================
2018-05-22T21:03:13.2815591Z Task         : Retain indefinitely current release
2018-05-22T21:03:13.2815591Z Description  : This task will allow you to mark the current release to be retained indefinitely
2018-05-22T21:03:13.2815591Z Version      : 1.1.0
2018-05-22T21:03:13.2815591Z Author       : Mario Majcica
2018-05-22T21:03:13.2815591Z Help         : On a successful release to production, usually you will mark the release to be retained for certain amount of time. This task will automate the desired behaviour, by marking the current release to be retained indefinitely.
2018-05-22T21:03:13.2815591Z ==============================================================================
2018-05-22T21:03:14.8075062Z ##[error]The remote server returned an error: (401) Unauthorized.
2018-05-22T21:03:14.8234985Z ##[section]Finishing: Retain indefinitely current release

Comparing these logs, it appears that the versions are different? But how's that possible, given that both deployments were performed by the same VSTS agent?

@mmajcica
Copy link
Owner

mmajcica commented May 23, 2018

As the version 1.1.0 shipped with the first version of the task, it was based on PS3 handler. Later, in the 2.x version, I implemented the logic of the task with the Node handler.
Considering that the task may be used, after the upgrade, both versions should be on your TFS instance. Looks like that you updated the task you used for the PAT meanwhile in PROD still the old version is used. Can you verify in the list of tasks for the PROD if the latest version is used?

image

@Bouke
Copy link
Author

Bouke commented May 23, 2018

The configuration is as follows:

image

@mmajcica
Copy link
Owner

Can you remove the extension, then verify with tfx-cli that task is not on your system? Can we get on chat somewhere, I would like you to get this solved.

@Bouke
Copy link
Author

Bouke commented May 25, 2018

All of a sudden it switched over to version 2, without me doing anything. I'll keep monitoring, but so far so good. Thanks a lot for your time!

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

2 participants