Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

deployment variable in a (secure) environment variable#349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
peterjc wants to merge6 commits intodrdoctr:master
base:master
Choose a base branch
Loading
frompeterjc:dk_env_var

Conversation

@peterjc
Copy link

Unfinished attempt to implement#348, adds a new command line option--dkenv short for deploy key in environment variable.

As far as I can tell,doctr configure --dbenv DOC_KEY ... works nicely. Building on the existing code this generates a key, sends the public key to the destination GitHub repository, and prints the private key to the terminal with instructions to add it to the source repository's TravisCI config.

However, something is breaking on thedoctr deploy --dbenv DOC_KEY ... side, possibly in how I have been attempting to test is locally, and I don't understand enough of the design to immediately see where.

e.g. Something like this with--force and setting the$TRAVIS_REPO_SLUG variable to attempt to run locally:

$ TRAVIS_REPO_SLUG=owner/source doctr deploy ${TRAVIS_TAG:-dev} --dkenv DOC_KEY --build-tags --built-docs Doc/api/_build/html/ --deploy-repo owner/dest --force

The argument name --dkenv is short for deployment key environmentvariable, still considering better names for this.
Still need to fine tune how best to print the private key to screen (newlines etc).Next need to use the environment key in deploy.
Getting the indentation to look nice (while deliberately notindenting the private key to make life simple for copy-and-paste).
@asmeurer
Copy link
Member

I wouldn't try to test locally. I can give you push access to push this up directly and you can test it on Travis. I'm not clear if that gives you access to upload deploy keys so if it doesn't just let me know and I'll upload it.

@peterjc
Copy link
Author

Looks like some useful error from TravisCI as is.

Trying the deploy stuff as a shell script (locally), turned up another issue. The branch is here in the short term:

https://github.com/peterjc/biopython/tree/deploy

Called this file.github/ssh_via_deploy_key.sh:

#!/bin/bash# Call ssh using our GitHub repository deploy key (set via -i)# using -F to make sure this ignores ~/.ssh/configssh -i"$HOME/.biopython_doc_deploy.key" -F /dev/null -p 22$*

Called by:

#!/bin/bashset -euo pipefail# Assumes being called from the Biopython repository's root folder,# (i.e. a clone of https://github.com/biopython/biopython) as part# of our continuous integration testing to save the compiled docs# to https://github.com/biopython/docs## In order to have write permissions, we put a private key into the# TravisCI settings as a secure environment variable, and put the# matching public key into the GitHub documentation repository's# settings as a deploy key with write permissions.DEST_SLUG=biopython/docsDEST_DIR=${TRAVIS_TAG:-dev}SOURCE_DIR=${TRAVIS_BUILD_DIR:-.}/Doc/api/_build/htmlWORKING_DIR=/tmp/deploy_biopython_docs# This will make git use our deployment key,# using sed to restore line breaksecho$DOC_KEY| sed -E -e's/ RSA PRIVATE /private/g'| sed -E -e's/[[:space:]]+/\n/g'| sed -E -e's/private/ RSA PRIVATE /g'>$HOME/.biopython_doc_deploy.keychmod 600$HOME/.biopython_doc_deploy.keyexport GIT_SSH=${TRAVIS_BUILD_DIR:-$PWD}/.github/ssh_via_deploy_key.sh# Clone the destination under /tmp (public URL, no key needed)rm -rf$WORKING_DIRgit clone https://github.com/$DEST_SLUG.git$WORKING_DIR# Update the files (assumes nothing removed)mkdir -p$WORKING_DIR/$DEST_DIRcp -R$SOURCE_DIR/*$WORKING_DIR/$DEST_DIR/pushd$WORKING_DIRgit checkout gh-pages# Switch the git protocol to SSH based so we can use our keygit remote set-url origin --push git@github.com:$DEST_SLUG.gitgit add$DEST_DIR/git commit -m"Automated update" --author"TravisCI <travisci@example.org>"git push origin gh-pagespopdecho"Documentation deployed!"

The key finding from these experiments is a little massaging of the public key is needed to restore the line lines - done in the above with sed, but would be clearer in Python as part ofdoctr.

@peterjc
Copy link
Author

Another important lesson from trying this on TravisCI,

Setting environment variables from repository settings$ export DOC_KEY=[secure]We were unable to parse one of your secure environment variables.Please make sure to escape special characters such as ' ' (white space) and $ (dollar symbol) with \ (backslash) .For example, thi$isanexample would be typed as thi\$isanexample. See https://docs.travis-ci.com/user/encryption-keys.

Most likely we need to print the private key to screen escaped suitably for TravisCI to accept it (spaces and new lines), and unescape in the script.

@asmeurer
Copy link
Member

Can we base64 encode it?

@asmeurer
Copy link
Member

Actually the private key should already be base64 encoded. There's probably an issue with the header part of the file. This is what a private key that I just generated withssh-keygen looks like

-----BEGIN OPENSSH PRIVATE KEY-----b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcnNhAAAAAwEAAQAAAQEA8Qa2XbDCFwyJQ0bJTdckPnn20DoPQYntJ5AgE3WDpdZu3SczEQLl/fsY7b9XTB1hoRnNRtO7G+c+5HSEsKOJyO+wiTgEwVGHayDWrLvX+BS68EmzuEFnJ56puV5vcsamkBIGklxPjjJVzVI4r87pnC9o3wMHFrwd4190wfJ9QCUyj99J5aRkVKWAlXFkZWNJqnjq4okoGOohCKnIs99cX5uFfPGm+3xLNFEL0mq/XQMtXtPO+Y7EzRGgEzOgPGuy6tumKSsOjdg3qvd9k+Kme8wPJAkZ3UFxoHOtffvB6xoGVphIVh9nXGrGeQlEMVwYwlTmVSWOsDk4w098GwC/MwAAA8gZ9wEzGfcBMwAAAAdzc2gtcnNhAAABAQDxBrZdsMIXDIlDRslN1yQ+efbQOg9Bie0nkCATdYOl1m7dJzMRAuX9+xjtv1dMHWGhGc1G07sb5z7kdISwo4nI77CJOATBUYdrINasu9f4FLrwSbO4QWcnnqm5Xm9yxqaQEgaSXE+OMlXNUjivzumcL2jfAwcWvB3jX3TB8n1AJTKP30nlpGRUpYCVcWRlY0mqeOriiSgY6iEIqciz31xfm4V88ab7fEs0UQvSar9dAy1e0875jsTNEaATM6A8a7Lq26YpKw6N2Deq932T4qZ7zA8kCRndQXGgc619+8HrGgZWmEhWH2dcasZ5CUQxXBjCVOZVJY6wOTjDT3wbAL8zAAAAAwEAAQAAAQA0Kie+D0tygZwTm3ZmCnIls2/fkTFMFfXl4iOPEpfzhH1qD9nVjLMKTRYQHqFeL925aEQtWBXe7CWIfE9bi4l+m6GxkRY2YNbWML1FlUIgxxvOdaUX88/Hm2dQX0fvp17VP5F8i84MEIjRb0Ilirq0uu4PljAqk3xEgZxbfYfuIbNMyiEvBzU50YvFFnblFtyH8n7XbmAGqZIzS7Gbk4rsSGOldsNuDGtpcAPCRHHxJkiD8STxv85RERbL/qcBSejqWpNMwpB/9X+I7eeWuErByIz/8oppPUzCbrjTQEQA5cRdXSUYVf6At+Lc3dZIY/Hb1OyWlLnkvE/HyKau/zuBAAAAgFxRpd8v6I5XiSpXlw0sfErN7Jll82p9fBv9z0EpXguvyuG5PxXUfTDhrB9qdhr1HfyZL2ElrdXTlPanJvmhc92EcW5XqOzquqOfM025RiG3bKSA1iZePUIvwH5GQFlVcPkanKDUWP3Vt3c+FBfLXXn+YV7lIQGnoqBnY0WofUD8AAAAgQD9OqpLFHtN2t6rch84RgVFiATOGOc7S7SaKPUtu9dAhQBMZKjJLjxHB9V8zYp4wMouSuc0QAdjuplSjPNdJj5GyXFk70gGemeSRB2EOilemMyTTw3L3rKxLgEcGcEE08hz2KPSDjHHlerd1AD8w8QgKyULAE2U6wR20ep4HP4duQAAAIEA86ndY29CInD9vlltGd2RGat+0avLX8m3BwCp+f1H9JVietSF7SoYI4ttmodmMSPMh+rjWPnXFIfePkWceMzP0bPn6iwQazmYN7H6vaJ/WsObJ+761DT/RCI/1DUjpmazOlvaI5eTHSCgedAxFYB34FZg8O0mObU2HrXmIExzWksAAAATYWFyb25tZXVyZXJAdW5idW50dQ==-----END OPENSSH PRIVATE KEY-----

So we should remove the-----BEGIN OPENSSH PRIVATE KEY----- parts and any newlines, then when writing it back to a file in Travis, add those back in. I don't know how picky it is about having it in that exact format.

@asmeurer
Copy link
Member

I forgot that we usecryptography now to generate the ssh key instead ofssh-keygen. This is what it looks like

>>>doctr.local.generate_ssh_key()(b'-----BEGIN PRIVATE KEY-----\nMIIJRAIBADANBgkqhkiG9w0BAQEFAASCCS4wggkqAgEAAoICAQC6rPXZjhn82O3+\nvWBF0mZocRTKAd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VATE KEY-----\n',b'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC6rPXZjhn82O3+vWBF0mZocRTKAdOxRvdl8ezF+P2B7+tjr0uoMveTFDSLny6dIf9j+NLGAmCywtT63+/KOBZXiMFIfACcepQt9CEUWJfPZSo6/u8cjGneuZHNiT9z9Jo/PbZDAeKPGbdqZgTtJxb01Lo51zae5Z+rqiW5HqAwK2wpV/uz8FGvcsRN4luTjrgagG8o8Eu4AMzPZo0NiwSn+jY9SyrJ4ynMUXdA4AyvulYPMzDZtayNyws+31M5PQYMWmuVbdJ2wSnzfyvqchUay0jAnXytJ87c4wKbjrMeaAuy1QfOkpw/vMXQn8xvAepIrXvbwA+6tGneldXnXTQgPNtaYZC5vc0PRZAAbsAHf/5qQjk1mut9v6meYUnRZgKE8qWp0Jwo6JFiXWQ+9+Ba/WcqqVwtAho7vydvxKM72oMVLRhg3psYWJduQfa+p6vs6DJUBBf4cTIAzXg+ZJ0jZJ+UX5gmitI4p2gdstzQX95SbvLCPwxElAAOnmH5rKPR32JK08RmtwBcPDabQs/u+DY1EC97nb2VjM4QOH6xfc7pyYI1d0x+rPqRh8TZrZCTnLa5i8F9lMVnLColU0KzUdRzuBHaTFeUOuVnpPJ7j/VEmA8hFP03dCLHRt36tI++xW89Gd+I7seXfl1u1k0KxBuI8EVyTF8sPTz/vjS3XQ==')

@asmeurer
Copy link
Member

Or alternately we can change the encoding argument ingenerate_ssh_keyhttps://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/#serialization-encodings. Then likely use anothercryptography function to go from that to a valid id_rsa file.

if we do not appear to be on Travis.""")
deploy_parser_add_argument('deploy_directory',type=str,nargs='?',
help="""Directory to deploy the html documentation to on gh-pages.""")
deploy_parser_add_argument('--dkenv',type=str,metavar="ENVVAR",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should be able to detect this automatically.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe, personally I think the interface is much simpler and more flexible if the user picks the environment variable name(s) themselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can make a flag if the user wants to change it, but there should be a default. It should be possible to just use the variable names we already use, and detect based on the content if it is pointing to a file or if it is a private key. Most users don't really care how doctr works. They just do whatever it says to do and if it pushes their stuff up to gh-pages they are happy.

configure_parser.set_defaults(func=configure)
configure_parser.add_argument('--force',action='store_true',help="""Run the configure command even
if we appear to be on Travis.""")
configure_parser.add_argument('--dkenv',type=str,metavar="ENVVAR",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should use the existing environment variable names. If this works we should use it by default and have the old way behind a flag (or just remove it).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If you would be happy making the deploy key in an environment variable the default, then maybe you are right - re-using the old environment variable names would make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Assuming there are no issues with it we should. We will have to continue to support the old way at least for deploy for existing repos. It will need a lot of testing to make sure, once we get it working.

@peterjc
Copy link
Author

Right now I have been using this in bash to recover the key file:

# This will make git use our deployment key, using sed to restore line breaks.# On TravisCI, seems must create the variable using '\ ' and '\n'# The sed commands unescape these (but the new line one fails on macOS):echo$DOC_KEY| sed"s/\\\ / /g"| sed's/\\n/\n/g'>$HOME/.biopython_doc_deploy.keychmod 600$HOME/.biopython_doc_deploy.keyexport GIT_SSH=${TRAVIS_BUILD_DIR:-$PWD}/.github/ssh_via_deploy_key.sh

Note it won't necessarily be-----BEGIN PRIVATE KEY-----, depending how the key-pair is made it could be something like-----BEGIN RSA PRIVATE KEY----- instead (with a key I generated locally). This seems to cover the details:

https://stackoverflow.com/questions/20065304/differences-between-begin-rsa-private-key-and-begin-private-key

@asmeurer
Copy link
Member

asmeurer commentedJul 2, 2019
edited
Loading

The SO answer says PKCS#8 uses "BEGIN PRIVATE KEY", which is what we use:

serialization.PrivateFormat.PKCS8,

@peterjc
Copy link
Author

Yes,dotrc configure may use PKCS#8, but there is nothing to stop the user making their own keys - if it is trivial to support I would like to (it looks like just a minor header/footer change at the level we need to worry about).

@asmeurer
Copy link
Member

I don't know if we really need to support that, unless it is trivial to do so.

@peterjc
Copy link
Author

peterjc commentedJul 10, 2019
edited
Loading

Took a bit of poking to work this out, but while\ for a space is fine,\n in an environment variable breaks on TravisCI, eventually had to test with a non-secure environment variable in the TravisCI settings to see how it was failing. The key is recorded correctly, but this fails:

Setting environment variables from repository settings$ export DOC_KEY=-----BEGIN\ OPENSSH\ PRIVATE\ KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn\nNhAAAAAwEAAQAAAgEAtlM01FoYLahecnD0Rs7A63A5YVIEmE4WWToML6/DE3QWm+gRBC2x\ncIdcOKd0y0imx3ROVi7GQLvmcADexfj8iuUbfvQwSFRAfJ3Ejs1+Us41FeBi08IEG+eURO\nsRS+mQgjWbjErc/vq5JciQiY1mDOcUOkPD9deQZRdFMdgkoVo2LYwPyBDN8Q0/eOGbby62\na2Tz2KcCW67/41vTUuMciyXStbZBq6xQCCgZhPjP0lR61m7HjslNzlR/Dr2iM9CAGRuEvC\n18h5Nv2jcluri8Q5O+IJlPd+slmt0cEMXzsRIVPjIXz1WvSaNYRdcSZQu8O+jJHMJSC7Oj\n2ZYdEDW3z8I06h+90l/F3HejBI7AE+xXtf1m2c0EHvFPckm+6HVJvCWe0a6BwukcehxgSj\nlGW8XMwux2nG+z/p/MC9wVLAnOEW7GbXBIhxj1HLiezGf/2v4librtzVi5kCpfFYAdhH81\nTZ7u9uUV7xGkCHajKb9BQP6ceSP7MjAVmyV8gXb2LQLwZkLBk0vXawJqNuPHpj0nYZK9eR\nzBW4FJKi2a6K3Cusq1fuvrCUOPctvzBguPVSVzGSVAmDQL78AhZOa7ErKHzgjCWTQYif8A\n79e66m2tV4LRIIFtbFPQxf2rOEl2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gsi1KINifEmJgTC2/dvbGOOgtSUetzz6nDrp/YgdZuaVK6dRx\nbjwluRvNtyVP8AAAEBAM6uW9MLpYR6wTxa12BgQWDAd7+p0NUsWJI9iWkHCWZbKANqtVnl\ncR/0KJUw4eQonBfQ9QgoYhj+inJoP0bud3X+s6kzL1fjy5Cyy5iA1uwpL7917r3oECI+NV\n0nlc/z1ZBSI1k44h1PODd4/nLB+iNSn8bn2n5tnbcQg5Q5V556VVuVTKHM8LeMK9/sG2UD\nCCFIV4BZGAw9O6LPrebz+KYdb5CNNOYHd/SrRKqWc8P1r2VMi9EHtWVIdmaVdVc/akfmku\n2uAx3jXKIjaDfCqGbAkYUsq3+WisOw6x9xeERITParkyzm14SlVjMvSlB2g1Srr16JlPYn\nxMZGLxYXKLsAAAAIdGVzdCBrZXkBAgM=\n-----END\ OPENSSH\ PRIVATE\ KEY-----

(Note - This was a temp key, created just for testing)

It looks like the slashes are treated as line continuations for the export command, so by the time we come to use it while the spaces can be recovered, the newlines have become justn.

Instead, seems must escape spaces as\ and new lines as\\n when entering them into TravisCI.

@asmeurer
Copy link
Member

I tried finishing this over at#350. When I try to encrypt the private key, I get

Traceback (most recent call last):  File"/Users/aaronmeurer/anaconda3/lib/python3.6/runpy.py", line193, in_run_module_as_main"__main__", mod_spec)  File"/Users/aaronmeurer/anaconda3/lib/python3.6/runpy.py", line85, in_run_codeexec(code, run_globals)  File"/Users/aaronmeurer/Documents/doctr/doctr/__main__.py", line616, in<module>    sys.exit(main())  File"/Users/aaronmeurer/Documents/doctr/doctr/__main__.py", line613, inmainreturn process_args(get_parser(config=config))  File"/Users/aaronmeurer/Documents/doctr/doctr/__main__.py", line270, inprocess_argsreturn args.func(args, parser)  File"/Users/aaronmeurer/Documents/doctr/doctr/__main__.py", line512, inconfigure    travis_token=travis_token,**login_kwargs)  File"/Users/aaronmeurer/Documents/doctr/doctr/local.py", line84, inencrypt_variablereturn base64.b64encode(key.encrypt(variable, pad))  File"/Users/aaronmeurer/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line448, inencryptreturn _enc_dec_rsa(self._backend,self, plaintext, padding)  File"/Users/aaronmeurer/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line68, in_enc_dec_rsareturn _enc_dec_rsa_pkey_ctx(backend, key, data, padding_enum, padding)  File"/Users/aaronmeurer/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line122, in_enc_dec_rsa_pkey_ctx    _handle_rsa_enc_dec_error(backend, key)  File"/Users/aaronmeurer/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line136, in_handle_rsa_enc_dec_error"Data too long for key size. Encrypt less data or use a"ValueError:Data too long for key size. Encrypt less data or use a larger key size.

This is probably the original reason why I didn't include the private key directly in the environment variable.

@asmeurer
Copy link
Member

Seehttps://stackoverflow.com/questions/55155642/python-cryptography-data-too-long-for-key-size andhttps://stackoverflow.com/a/7146463/161801. I did some testing and you can only encrypt 501 bytes with the Travis public key. Any more than that and you get the error.

I think if we want to do this, we need to do the double encryption like we currently do, and put the contents of what would be github_deploy_key.enc in an environment variable. This doesn't really save the user much. Instead of doing a checkout of a file in the repo they would add the contents of said file to their .travis.yml.

asmeurer added a commit that referenced this pull requestJul 14, 2019
This is to demonstrate that this doesn't actually work. See#349 (comment). The privatekey is too large to be encrypted with the Travis public key.Instead we have to do what we are currently doing. Create a symmetricencryption key to encrypt the actual SSH key, and then encrypt that symmetrickey into the secure environment variable (and save the encrypted SSH privatekey to a file).
@peterjc
Copy link
Author

@asmeurer I'm not sure why you are trying to encrypt anything - the goal of what I'm doing is to put the (slash escaped) private keydirectly into the continuous integration system's moderately secure environment variables settings (something TravisCI offers, and hopefully others too).

This is working for me now using a proof of principle bash script for deployment, seebiopython/biopython#2172

@asmeurer
Copy link
Member

I didn't try to use the Travis UI. I can't imagine it would work there when it doesn't work in the API, but maybe they do something different there.

The encryption is what makes the key secret. It is encrypted with the public key for the repo. It's the same thing as thetravis encrypt command.

@asmeurer
Copy link
Member

It does let me paste it in the UI. I haven't tested yet if it actually works.travis encrypt gives an error

data too large - consider using travis encrypt-file or travis env set

@peterjc
Copy link
Author

Re:https://docs.travis-ci.com/user/environment-variables/

A common way to customize the build process is to define environment variables, which can be accessed from any stage in your build process.

The best way to define an environment variable depends on what type of information it will contain, and when you need to change it:

  • if it does not contain sensitive information, might be different for different branches and should be available to forks – add it to your .travis.yml
  • if it does contain sensitive information, and might be different for different branches – encrypt it and add it to your .travis.yml
  • if it does contain sensitive information, but is the same for all branches – add it to your Repository Settings

For my use case I don't want special values in.travis.yml as that would block live testing on forked repositories (without a code change in the contents tracked by git, which complicates pull requests etc). Repository Settings is perfect.

If you are willing to trust TravisCI, then you don't need to do anything extra to secure the private key. I'm OK with that, but maybe you're not?

@asmeurer
Copy link
Member

I guess we can usehttps://docs.travis-ci.com/api/#settings-environment-variables. I think this API didn't exist before. I still need to test that it actually works.

@peterjc
Copy link
Author

Nice - if the script can set the secret TravisCI variable via the API, that's one less manual step.

Note in the UI, you can't update an existing secret variable - you have to delete and re-add it with the new value.

@peterjc
Copy link
Author

FYI, my standalone script version of this has been live and working for over a year now:

biopython/biopython@0bc732c

Apologies that I have not got back to finishing this pull request for doctr.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@asmeurerasmeurerasmeurer left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@peterjc@asmeurer

[8]ページ先頭

©2009-2025 Movatter.jp