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.
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
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.