As part of my Bitbucket pipeline task i am invoking a web call which needs password. If I store the password as secret variable in bitbucket pipeline is it safe? If not what are other options available?
I would use a repository variable and reference it in your pipeline.
You can store the value as secured, such that no-one can view the value once saved.
Read more here: https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
Related
I have a pretty standard application written in Java which also runs queries against a DB. The application resides on GCP and the DB on Atlas.
For understandable reasons, I don't want to keep the username and password for the DB in the code.
So option number 1 that I had in mind, is to pass the username and password as environment variables to the application container in GCP.
Option number 2 is using Secret Manager in GCP and store my username and password there, and pass the GCP Credentials as an environment variable to the application container in GCP.
My question is, what is the added value of option number 2 if it has any? It seems that option 2 is even worse from a security aspect since if some hacker gets the google credentials, it has access to all of the secrets stored in the Secret Manager.
I don't know what are the best practices and what is advised to do in such cases. Thank you for your help.
Having credentials in GCP secret manager will help you to keep track of all the secrets and changes in a centralized location and access globally from any of your app.
For a standard application where one JAVA is connecting to a DB, may not add much values.
You may look into kubernetes secret for that reason.
If your application resides in GCP, you don't need a service account key file (which is your security concern, and you are right. I wrote an article on this)
TL;DR use ADC (Application Default Credential) to automatically get the service account credential provided automatically on Google Cloud Component (look at metadata server for more details).
Then grant this component identity (by default or user defined, when supported), i.e. the service account email, to access to your secrets.
And that's all! You haven't secrets in your code and your environment variable, neither the login/password, nor the service account key file.
If you have difficulties to use ADC in Java, don't hesitate to share your code. I will be able to help your to achieve this.
To use Secret Manager on Google Cloud you need to install the Secret Manager Java SDK Libraries. This documentation shows how to get started with the Cloud Client Libraries for the Secret Manager API, you only need to go to the Java section.
This Libraries helps you to access your keys in order that it can be used by your app.
The following link shows how to get details about a secret by viewing its metadata. Keep in mind that viewing a secret's metadata requires the Secret Viewer role (roles/secretmanager.viewer) on the secret, project, folder, or organization.
I recommend you to create a special Service Account to handle the proper permissions for your app, because if you don’t have a SA defined, the default SA is what is going to generate the request, and it is not secure. you can learn more about how to create a service account in this link
On the other hand, you can find an example on how you can use the following guide that contains a good example of finding your credentials automatically, that's more convenient and secure than manually passing credentials.
I would like to create ARM Template
create a resource group that contains KeyVault;
generate new secret with predefined name, e.g AdminPassword.
Use the password in other resources, e.g Master password when creating a SQL Database.
When redeploying the template and KeyVault and the AdminPassword secret already exist, existing secret should be used.
I have found samples where KeyVault secret is used as a parameter, however this is different, because KeyVault does not exist at the time parameters are resolved.
Can you write sample ARM teplate that creates KeyVault and then uses sectets from it?
if you generate a secret in an arm template - it makes no sense to retrieve it from the key vault, if you pass the secret to the template - again it makes no sense to retrieve it, just use it. either way, if you are really keen on making your life harder you can probably hack something in the arm template using conditions and nested templates
It depends on how secure you want the password to be...
If you want a subsequent deployment to use the same password value, then it has to be deterministic. If it's deterministic then anyone with access to the deployment can determine the password.
If you want the password to be random, then the template will generate a random one each time so a subsequent deployment would create a new password.
You could use a user provided seed for the password generation as a parameter (and use uniqueString() which is idempotent) and then only someone who knows the seed and has access to the deployment could determine the password. Note that your seed would have to be a secureString parameter type. But at this point a better practice would be to separate the steps of password generation and resource deployment.
You can generate the password in the ARM Template using uniqueString.
Then create your KeyVault and the Secret. On the outputs of the KeyVault template you can then get the URI of the Secret which can be injected into the App Configuration of another resource such as a Web App. https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references
"outputs": {
"dbSecretUri": {
"value": "[reference(resourceId('Microsoft.KeyVault/vaults/secrets', parameters('keyVaultName'), 'yourSecretName')).secretUriWithVersion]"
}
}
Your web app will need Managed Identity enabled and the KeyVault will need to have an Access Policy that allows that app to connect to the vault.
I have to provide docker image that will be used in CI, and it should has git ssh authorization built-in.
To achieve this I would need to put a private key of git service user inside, but I am out of ideas how to do it without exposing key content itself.
I understand that if end-user is able to authorize with this key from within the container it is basically the same as giving him the key itself, but I am alright that user can perform any ssh auth required operations from withing the image, but do not want key to be extracted and used somewhere else.
So far I thought about copying encrypted key and providing the password to key manager during the build with ssh-add, but of course it won't work because it will save password only for current shell session. Are there any best practices to do such a thing?
I wonder what is the best practice way to store password parameters in Jenkins?
The best way is to store them as Jenkins Credentials and inject them into your build via CredentialsBinding Plugin, whereby you can define how to make them available via the environment (Username:Password, Separated Username and Password,...). Jenkins supports different types of credentials such as
Username and Password
SSH Keys
Docker Credentials
...
This way the credentials are only visible to the build execution and cannot be accessed by other developers, just used. Jenkins will hide exact matches of the username and password in the logs.
Links
https://jenkins.io/doc/book/using/using-credentials/
https://wiki.jenkins.io/display/JENKINS/Credentials+Binding+Plugin
My corp Jenkins instance uses the corp LDAP for user authentication. We have a requirement to automate one on the internal portals which also takes corp LDAP for authentication.
Since there is a restriction of using "dummy" LDAP for automation purpose, i am thinking of passing my (or Jenkins users) corp credential to automation script securely.
How do I pass the Jenkins logged in user credential as parameters to a job.
How do I securely pass the parameters to job that executes remote script.I dont want to store / pass corp LDAP anywhere between Jenkins and remote.
Advanced thanks. appreciate inputs and any suggestions on alternate solution to meets this requirement.
This is an old question I stumbled on while searching answers for a similar issue. But I believe you can use the apitoken in place for the password. To find out apitoken, go to http(s)://yourJenkinsURL/user/yourID/configure, you will find it there.