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
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)
...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events