Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Where to store API Key on bitbucket?

nikolay_kolev
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 17, 2019

I am trying to set up a CI/CD process for Salesforce using Docker and SFDX. 

I got everything working except that I am not sure how to safely store the private key that SFDX uses to authenticate into salesforce.

 

Here's the command that I am using to authenticate:
sfdx force:auth:jwt:grant --clientid $CONSUMER_KEY --jwtkeyfile keys/server.key --username $SFDC_QA_USER --setdefaultdevhubusername --setalias testPipelines --instanceurl $SFDC_QA_URL

 

Where "CONSUMER_KEY" is a repository variable. 

However server.key is inside a "keys" folder in the branch itself.

I was wondering if there's something like "repository secret files" maybe? If not can I store an encrypted version of the server.key and have docker decrypt it and pass it to SFDX? I am really not sure how to approach this.

1 answer

0 votes
mwatson
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 18, 2019

Don't check the key into the repository - it will be in the history forever!

Instead, use the same approach we recommend for additional ssh keys.

See the section entitled Use multiple SSH keys in your pipeline in https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html

nikolay_kolev
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 18, 2019

@mwatson if you look at the command I posted the property --jwtkeyfile is mandatory and it requires that I specify a file afterwards for it to work. I don't see how adding a SSH key would overcome this. 

Is there really no way to store api key files in bitbucket?

mwatson
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 18, 2019

The docs section I linked shows how to store a key in a secure repository variable and then use a code fragment in your step to save it to a file and use it in your scripts. You can use the same approach for other keys, not just ssh keys.

e.g. if you take your key and run (on linux)

base64 -w 0 < keys/server.key

 then store the output in a secure repository variable called SERVER_KEY you can then do this in your step to get it onto your filesystem in your build:

- (umask  077 ; echo $SERVER_KEY | base64 --decode > keys/server.key)
 
Tom Gagne August 31, 2024

What about creating a custom Docker image and saving the key there?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events