How can I use the Bitbucket API to add an SSH key to a Workspace?

Drew Heasman
Contributor
October 15, 2021

I'm trying to work out how to add an SSH key to a Workspace.

There is this documentation for adding an SSH key to a User: https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Bselected_user%7D/ssh-keys#post

But I can't find anything for the Workspace, this call only adds an SSH key to my user.

When performing the action using the UI in a browser the users/%7Bselected_user%7D/ssh-keys call appears to happen, but I can't work out what is making it get added to the Workspace instead of the User.

Any help appreciated.

1 answer

0 votes
seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 15, 2021

What is your reason for adding an SSH to a workspace?

SSH keys are only meant to be added for users.

The closest thing to what I think you're looking for is called Access Keys. You can upload SSH keys for each individual repository to enable `git clone` and `git pull` (read only) access only. This is useful for running tests or for deploying.

At the moment this is repository by repository. However, hopefully we'll have a solution for group the same repository settings for a project (a collection of repositories).

Drew Heasman
Contributor
October 16, 2021

Hi @seanaty,

We use git submodules, so are generating a Pipeline SSH Key for a repository, then adding the generated public key to the Workspace SSH keys, so Bitbucket Pipelines can access other repositories during a build.

Creating the Pipeline SSH Key is possible via this endpoint: https://api.bitbucket.org/internal/repositories/<workspace>/<repo>/pipelines_config/ssh/key_pair/generate

When I create a Workspace SSH key via the UI it calls this endpoint: 

https://api.bitbucket.org/2.0/users/<user>/ssh-keys - but if I do that directly (e.g. with curl), the key is added to the User, not the Workspace and I can't work out why.
Any help, or update to the API docs, would be appreciated.
Drew Heasman
Contributor
November 1, 2021

@seanaty - any thoughts?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events