How to manage signing keystore in Gitlab CI for android











up vote
1
down vote

favorite












Dear stackoverflow community, once more I turn to you :)



I've recently come across the wonder of Gitlab and their very nice bundled CI/CD solution. It works gallantly however, we all need to sign our binaries don't we and I've found no way to upload a key as I would to a Jenkins server for doing this.



So, how can I, without checking in my keys and secrets sign my android (actually flutter) application when building a release?



From what I see, most people define the build job with signing settings referring to a non-committed key.properties file specifying a local keystore.jks. This works fine when building APKs locally but if I would like to build and archive them as a part of the CI/CD job, how do I?



For secret keys, for example the passwords to the keystore itself, I've found that I can simply store them as protected variables but the actual keystore file itself. What can I do about that?



Any ideas, suggestions are dearly welcome.
Cheers










share|improve this question






















  • You should look into App Signing inside the google play console.
    – Oliver
    Aug 7 at 11:16










  • I've seen that one but I didn't catch you can build without key. I expected you'll need an upload key or so anyway. I'll reread it and see if I can get it. Thanks!
    – Almund
    Aug 7 at 12:00










  • Yes, you will still need a Keystore. But you can invalidate this keystore in the play console, if it gets leaked, because this one isn't your "real" keystore.
    – Oliver
    Aug 7 at 12:15















up vote
1
down vote

favorite












Dear stackoverflow community, once more I turn to you :)



I've recently come across the wonder of Gitlab and their very nice bundled CI/CD solution. It works gallantly however, we all need to sign our binaries don't we and I've found no way to upload a key as I would to a Jenkins server for doing this.



So, how can I, without checking in my keys and secrets sign my android (actually flutter) application when building a release?



From what I see, most people define the build job with signing settings referring to a non-committed key.properties file specifying a local keystore.jks. This works fine when building APKs locally but if I would like to build and archive them as a part of the CI/CD job, how do I?



For secret keys, for example the passwords to the keystore itself, I've found that I can simply store them as protected variables but the actual keystore file itself. What can I do about that?



Any ideas, suggestions are dearly welcome.
Cheers










share|improve this question






















  • You should look into App Signing inside the google play console.
    – Oliver
    Aug 7 at 11:16










  • I've seen that one but I didn't catch you can build without key. I expected you'll need an upload key or so anyway. I'll reread it and see if I can get it. Thanks!
    – Almund
    Aug 7 at 12:00










  • Yes, you will still need a Keystore. But you can invalidate this keystore in the play console, if it gets leaked, because this one isn't your "real" keystore.
    – Oliver
    Aug 7 at 12:15













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Dear stackoverflow community, once more I turn to you :)



I've recently come across the wonder of Gitlab and their very nice bundled CI/CD solution. It works gallantly however, we all need to sign our binaries don't we and I've found no way to upload a key as I would to a Jenkins server for doing this.



So, how can I, without checking in my keys and secrets sign my android (actually flutter) application when building a release?



From what I see, most people define the build job with signing settings referring to a non-committed key.properties file specifying a local keystore.jks. This works fine when building APKs locally but if I would like to build and archive them as a part of the CI/CD job, how do I?



For secret keys, for example the passwords to the keystore itself, I've found that I can simply store them as protected variables but the actual keystore file itself. What can I do about that?



Any ideas, suggestions are dearly welcome.
Cheers










share|improve this question













Dear stackoverflow community, once more I turn to you :)



I've recently come across the wonder of Gitlab and their very nice bundled CI/CD solution. It works gallantly however, we all need to sign our binaries don't we and I've found no way to upload a key as I would to a Jenkins server for doing this.



So, how can I, without checking in my keys and secrets sign my android (actually flutter) application when building a release?



From what I see, most people define the build job with signing settings referring to a non-committed key.properties file specifying a local keystore.jks. This works fine when building APKs locally but if I would like to build and archive them as a part of the CI/CD job, how do I?



For secret keys, for example the passwords to the keystore itself, I've found that I can simply store them as protected variables but the actual keystore file itself. What can I do about that?



Any ideas, suggestions are dearly welcome.
Cheers







android gitlab flutter code-signing continuous-deployment






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 7 at 11:10









Almund

2,6821726




2,6821726












  • You should look into App Signing inside the google play console.
    – Oliver
    Aug 7 at 11:16










  • I've seen that one but I didn't catch you can build without key. I expected you'll need an upload key or so anyway. I'll reread it and see if I can get it. Thanks!
    – Almund
    Aug 7 at 12:00










  • Yes, you will still need a Keystore. But you can invalidate this keystore in the play console, if it gets leaked, because this one isn't your "real" keystore.
    – Oliver
    Aug 7 at 12:15


















  • You should look into App Signing inside the google play console.
    – Oliver
    Aug 7 at 11:16










  • I've seen that one but I didn't catch you can build without key. I expected you'll need an upload key or so anyway. I'll reread it and see if I can get it. Thanks!
    – Almund
    Aug 7 at 12:00










  • Yes, you will still need a Keystore. But you can invalidate this keystore in the play console, if it gets leaked, because this one isn't your "real" keystore.
    – Oliver
    Aug 7 at 12:15
















You should look into App Signing inside the google play console.
– Oliver
Aug 7 at 11:16




You should look into App Signing inside the google play console.
– Oliver
Aug 7 at 11:16












I've seen that one but I didn't catch you can build without key. I expected you'll need an upload key or so anyway. I'll reread it and see if I can get it. Thanks!
– Almund
Aug 7 at 12:00




I've seen that one but I didn't catch you can build without key. I expected you'll need an upload key or so anyway. I'll reread it and see if I can get it. Thanks!
– Almund
Aug 7 at 12:00












Yes, you will still need a Keystore. But you can invalidate this keystore in the play console, if it gets leaked, because this one isn't your "real" keystore.
– Oliver
Aug 7 at 12:15




Yes, you will still need a Keystore. But you can invalidate this keystore in the play console, if it gets leaked, because this one isn't your "real" keystore.
– Oliver
Aug 7 at 12:15












2 Answers
2






active

oldest

votes

















up vote
1
down vote













I've used git-secret in the past to check-in password protected secret files. Then pass the password via a secret/protected environmental variable (as you already know) and modify the .gitlab-ci.yml to use the password to open the files and use them.






share|improve this answer





















  • Sounds reasonable, I've read in other places about using different repos and such to store the secret files. I'll give it a try and come back once it's done. Thank you!
    – Almund
    Aug 8 at 13:47










  • Sure.. there is also a fastlane plugin that encrypts keystores github.com/hjanuschka/fastlane-plugin-cryptex (haven't tried). Plus here is a (dated) article about how NOT to manage certificates in Google Play Store researchcenter.paloaltonetworks.com/2014/08/…
    – mmccabe
    Aug 8 at 14:45


















up vote
0
down vote













Usually I store keystore file (as base64 string), alias and passwords to Gitlab's secrets variables.



In the .gitlab-ci.yml do something like:



create_property_files:
stage: prepare
only:
- master
script:
- echo $KEYSTORE | base64 -d > my.keystore
- echo "keystorePath=my.keystore" > signing.properties
- echo "keystorePassword=$KEYSTORE_PASSWORD" >> signing.properties
- echo "keyAlias=$ALIAS" >> signing.properties
- echo "keyPassword=$KEY_PASSWORD" >> signing.properties
artifacts:
paths:
- my.keystore
- signing.properties
expire_in: 10 mins


And, finally, in your build gradle:



signingConfigs {
release {
file("../signing.properties").with { propFile ->
if (propFile.canRead()) {
def properties = new Properties()
properties.load(new FileInputStream(propFile))

storeFile file(properties['keystorePath'])
storePassword properties['keystorePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
} else {
println 'Unable to read signing.properties'
}
}
}
}





share|improve this answer





















  • In this case you have all your sensitive data lying about in artifacts though, don't you ?
    – zlandorf
    Nov 27 at 14:52










  • Yes, for 10 minutes. To prevent this, you can write signing.properties directly in build stage
    – IvanP
    Nov 28 at 8:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51725339%2fhow-to-manage-signing-keystore-in-gitlab-ci-for-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













I've used git-secret in the past to check-in password protected secret files. Then pass the password via a secret/protected environmental variable (as you already know) and modify the .gitlab-ci.yml to use the password to open the files and use them.






share|improve this answer





















  • Sounds reasonable, I've read in other places about using different repos and such to store the secret files. I'll give it a try and come back once it's done. Thank you!
    – Almund
    Aug 8 at 13:47










  • Sure.. there is also a fastlane plugin that encrypts keystores github.com/hjanuschka/fastlane-plugin-cryptex (haven't tried). Plus here is a (dated) article about how NOT to manage certificates in Google Play Store researchcenter.paloaltonetworks.com/2014/08/…
    – mmccabe
    Aug 8 at 14:45















up vote
1
down vote













I've used git-secret in the past to check-in password protected secret files. Then pass the password via a secret/protected environmental variable (as you already know) and modify the .gitlab-ci.yml to use the password to open the files and use them.






share|improve this answer





















  • Sounds reasonable, I've read in other places about using different repos and such to store the secret files. I'll give it a try and come back once it's done. Thank you!
    – Almund
    Aug 8 at 13:47










  • Sure.. there is also a fastlane plugin that encrypts keystores github.com/hjanuschka/fastlane-plugin-cryptex (haven't tried). Plus here is a (dated) article about how NOT to manage certificates in Google Play Store researchcenter.paloaltonetworks.com/2014/08/…
    – mmccabe
    Aug 8 at 14:45













up vote
1
down vote










up vote
1
down vote









I've used git-secret in the past to check-in password protected secret files. Then pass the password via a secret/protected environmental variable (as you already know) and modify the .gitlab-ci.yml to use the password to open the files and use them.






share|improve this answer












I've used git-secret in the past to check-in password protected secret files. Then pass the password via a secret/protected environmental variable (as you already know) and modify the .gitlab-ci.yml to use the password to open the files and use them.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 8 at 3:08









mmccabe

976915




976915












  • Sounds reasonable, I've read in other places about using different repos and such to store the secret files. I'll give it a try and come back once it's done. Thank you!
    – Almund
    Aug 8 at 13:47










  • Sure.. there is also a fastlane plugin that encrypts keystores github.com/hjanuschka/fastlane-plugin-cryptex (haven't tried). Plus here is a (dated) article about how NOT to manage certificates in Google Play Store researchcenter.paloaltonetworks.com/2014/08/…
    – mmccabe
    Aug 8 at 14:45


















  • Sounds reasonable, I've read in other places about using different repos and such to store the secret files. I'll give it a try and come back once it's done. Thank you!
    – Almund
    Aug 8 at 13:47










  • Sure.. there is also a fastlane plugin that encrypts keystores github.com/hjanuschka/fastlane-plugin-cryptex (haven't tried). Plus here is a (dated) article about how NOT to manage certificates in Google Play Store researchcenter.paloaltonetworks.com/2014/08/…
    – mmccabe
    Aug 8 at 14:45
















Sounds reasonable, I've read in other places about using different repos and such to store the secret files. I'll give it a try and come back once it's done. Thank you!
– Almund
Aug 8 at 13:47




Sounds reasonable, I've read in other places about using different repos and such to store the secret files. I'll give it a try and come back once it's done. Thank you!
– Almund
Aug 8 at 13:47












Sure.. there is also a fastlane plugin that encrypts keystores github.com/hjanuschka/fastlane-plugin-cryptex (haven't tried). Plus here is a (dated) article about how NOT to manage certificates in Google Play Store researchcenter.paloaltonetworks.com/2014/08/…
– mmccabe
Aug 8 at 14:45




Sure.. there is also a fastlane plugin that encrypts keystores github.com/hjanuschka/fastlane-plugin-cryptex (haven't tried). Plus here is a (dated) article about how NOT to manage certificates in Google Play Store researchcenter.paloaltonetworks.com/2014/08/…
– mmccabe
Aug 8 at 14:45












up vote
0
down vote













Usually I store keystore file (as base64 string), alias and passwords to Gitlab's secrets variables.



In the .gitlab-ci.yml do something like:



create_property_files:
stage: prepare
only:
- master
script:
- echo $KEYSTORE | base64 -d > my.keystore
- echo "keystorePath=my.keystore" > signing.properties
- echo "keystorePassword=$KEYSTORE_PASSWORD" >> signing.properties
- echo "keyAlias=$ALIAS" >> signing.properties
- echo "keyPassword=$KEY_PASSWORD" >> signing.properties
artifacts:
paths:
- my.keystore
- signing.properties
expire_in: 10 mins


And, finally, in your build gradle:



signingConfigs {
release {
file("../signing.properties").with { propFile ->
if (propFile.canRead()) {
def properties = new Properties()
properties.load(new FileInputStream(propFile))

storeFile file(properties['keystorePath'])
storePassword properties['keystorePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
} else {
println 'Unable to read signing.properties'
}
}
}
}





share|improve this answer





















  • In this case you have all your sensitive data lying about in artifacts though, don't you ?
    – zlandorf
    Nov 27 at 14:52










  • Yes, for 10 minutes. To prevent this, you can write signing.properties directly in build stage
    – IvanP
    Nov 28 at 8:46















up vote
0
down vote













Usually I store keystore file (as base64 string), alias and passwords to Gitlab's secrets variables.



In the .gitlab-ci.yml do something like:



create_property_files:
stage: prepare
only:
- master
script:
- echo $KEYSTORE | base64 -d > my.keystore
- echo "keystorePath=my.keystore" > signing.properties
- echo "keystorePassword=$KEYSTORE_PASSWORD" >> signing.properties
- echo "keyAlias=$ALIAS" >> signing.properties
- echo "keyPassword=$KEY_PASSWORD" >> signing.properties
artifacts:
paths:
- my.keystore
- signing.properties
expire_in: 10 mins


And, finally, in your build gradle:



signingConfigs {
release {
file("../signing.properties").with { propFile ->
if (propFile.canRead()) {
def properties = new Properties()
properties.load(new FileInputStream(propFile))

storeFile file(properties['keystorePath'])
storePassword properties['keystorePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
} else {
println 'Unable to read signing.properties'
}
}
}
}





share|improve this answer





















  • In this case you have all your sensitive data lying about in artifacts though, don't you ?
    – zlandorf
    Nov 27 at 14:52










  • Yes, for 10 minutes. To prevent this, you can write signing.properties directly in build stage
    – IvanP
    Nov 28 at 8:46













up vote
0
down vote










up vote
0
down vote









Usually I store keystore file (as base64 string), alias and passwords to Gitlab's secrets variables.



In the .gitlab-ci.yml do something like:



create_property_files:
stage: prepare
only:
- master
script:
- echo $KEYSTORE | base64 -d > my.keystore
- echo "keystorePath=my.keystore" > signing.properties
- echo "keystorePassword=$KEYSTORE_PASSWORD" >> signing.properties
- echo "keyAlias=$ALIAS" >> signing.properties
- echo "keyPassword=$KEY_PASSWORD" >> signing.properties
artifacts:
paths:
- my.keystore
- signing.properties
expire_in: 10 mins


And, finally, in your build gradle:



signingConfigs {
release {
file("../signing.properties").with { propFile ->
if (propFile.canRead()) {
def properties = new Properties()
properties.load(new FileInputStream(propFile))

storeFile file(properties['keystorePath'])
storePassword properties['keystorePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
} else {
println 'Unable to read signing.properties'
}
}
}
}





share|improve this answer












Usually I store keystore file (as base64 string), alias and passwords to Gitlab's secrets variables.



In the .gitlab-ci.yml do something like:



create_property_files:
stage: prepare
only:
- master
script:
- echo $KEYSTORE | base64 -d > my.keystore
- echo "keystorePath=my.keystore" > signing.properties
- echo "keystorePassword=$KEYSTORE_PASSWORD" >> signing.properties
- echo "keyAlias=$ALIAS" >> signing.properties
- echo "keyPassword=$KEY_PASSWORD" >> signing.properties
artifacts:
paths:
- my.keystore
- signing.properties
expire_in: 10 mins


And, finally, in your build gradle:



signingConfigs {
release {
file("../signing.properties").with { propFile ->
if (propFile.canRead()) {
def properties = new Properties()
properties.load(new FileInputStream(propFile))

storeFile file(properties['keystorePath'])
storePassword properties['keystorePassword']
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
} else {
println 'Unable to read signing.properties'
}
}
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 15:37









IvanP

439711




439711












  • In this case you have all your sensitive data lying about in artifacts though, don't you ?
    – zlandorf
    Nov 27 at 14:52










  • Yes, for 10 minutes. To prevent this, you can write signing.properties directly in build stage
    – IvanP
    Nov 28 at 8:46


















  • In this case you have all your sensitive data lying about in artifacts though, don't you ?
    – zlandorf
    Nov 27 at 14:52










  • Yes, for 10 minutes. To prevent this, you can write signing.properties directly in build stage
    – IvanP
    Nov 28 at 8:46
















In this case you have all your sensitive data lying about in artifacts though, don't you ?
– zlandorf
Nov 27 at 14:52




In this case you have all your sensitive data lying about in artifacts though, don't you ?
– zlandorf
Nov 27 at 14:52












Yes, for 10 minutes. To prevent this, you can write signing.properties directly in build stage
– IvanP
Nov 28 at 8:46




Yes, for 10 minutes. To prevent this, you can write signing.properties directly in build stage
– IvanP
Nov 28 at 8:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51725339%2fhow-to-manage-signing-keystore-in-gitlab-ci-for-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo