GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Crash when private key is formatted incorrectly · Issue #272 · googleapis/google-cloud-node

Crash when private key is formatted incorrectly #272

New issue
Copy link
New issue
Copy link
Closed
Closed
Crash when private key is formatted incorrectly#272
Copy link
Assignees
ryanseys
Labels
🚨This issue needs some love.library: cloud-profilerIssues transferred from another repositorytriage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
Milestone
Core Stable

Description

@leonardpunt
leonardpunt
opened on Oct 31, 2014
Issue body actions

Hi,

The library (v0.9.0) crashes when a private key is formatted incorrectly. Examples are if the private key is a literal with \n characters, or if the newlines are replaced with spaces.

The following error is thrown:

140014095067008:error:0906D06C:PEM routines:PEM_read_bio:no start line:../deps/openssl/openssl/crypto/pem/pem_lib.c
:703:Expecting: ANY PRIVATE KEY
crypto.js:429
  var ret = this._binding.sign(toBuf(key));
                          ^
Error: SignFinal error
    at Sign.sign (crypto.js:429:27)
    at createRS256Signature (/app/node_modules/gcloud/node_modules/gapitoken/node_modules/jws/index.js:75:58)
    at jwsRS256Sign (/app/node_modules/gcloud/node_modules/gapitoken/node_modules/jws/index.js:68:21)
    at Object.jwsSign [as sign] (/app/node_modules/gcloud/node_modules/gapitoken/node_modules/jws/index.js:32:12)
    at GAPI.getAccessToken (/app/node_modules/gcloud/node_modules/gapitoken/gapitoken.js:56:25)
    at GAPI.getToken (/app/node_modules/gcloud/node_modules/gapitoken/gapitoken.js:35:14)
    at /app/node_modules/gcloud/lib/common/connection.js:207:10
    at process._tickCallback (node.js:419:13)

Also, it would be nice if the library could handle some alternative formats of a private key, like spaces instead of newlines. We're retrieving our private key from a environment variable and environment variables can't be multiline. So right now we have to denote newlines with some character and replace them with newlines in our code.

Kind regards,
Leonard

Activity

Next
  1. stephenplusplus commented on Oct 31, 2014

    @stephenplusplus
    stephenplusplus
    on Oct 31, 2014
    Contributor
    More actions

    Hi Leonard - it seems like a better solution might be storing the path to a private key as an environment variable, rather than the key itself. You can pass that path to gcloud as keyFilename, and it will read and parse the file.

  2. leonardpunt commented on Oct 31, 2014

    @leonardpunt
    leonardpunt
    on Oct 31, 2014
    Author
    More actions

    Hi Stephen,

    The reason we're storing the private key as an environment variable is that we're using Managed VMs. This means the key should be retrieved somehow when booting a new VM. Since adding the key file to our repository is not on option (security wise), we choose to add the private key to Compute Engine's MetaData. On startup we request the private key from the MetaData and store it as an environment variable.
    We were thinking to store the key in Cloud Storage. This would enable us to download the key on startup, however adding the key to the MetaData felt like a better/easier option, at that time. What is your opinion on this? And do you think there is a better alternative?

  3. stephenplusplus commented on Oct 31, 2014

    @stephenplusplus
    stephenplusplus
    on Oct 31, 2014
    Contributor
    More actions

    Just speaking generally, it's best to keep private data out of public access and global context. But in this case, I'm not very familiar with Managed VMs. Talking with @silvolu, I think he has an idea -- expect to hear from him soon :)

  4. silvolu commented on Oct 31, 2014

    @silvolu
    silvolu
    on Oct 31, 2014
    Contributor
    More actions

    @leonardpunt The service account associated with a Managed VM is pre-authorized to provide access to your project’s default storage bucket and default datastore dataset.
    If that suits your need, you don't need to pass in any key, and we'll handle the token request to the GCE metadata server for you.

  5. silvolu commented on Oct 31, 2014

    @silvolu
    silvolu
    on Oct 31, 2014
    Contributor
    More actions

    @leonardpunt as an example, gcloud-node-todos "should just work"™ on Managed VMs with no need for keys.

  6. leonardpunt commented on Oct 31, 2014

    @leonardpunt
    leonardpunt
    on Oct 31, 2014
    Author
    More actions

    @silvolu I need to connect to the datastore of a different project. But I could store the key file in the project's default storage bucket and download it from there on startup. Would that be a better solution?

  7. silvolu commented on Oct 31, 2014

    @silvolu
    silvolu
    on Oct 31, 2014
    Contributor
    More actions

    @leonardpunt You could also give the Managed VM's service account access to the other project: go to the Developer's Console, choose the other project, and under Permission add the Managed VM's service account email as a member. That should work.

  8. leonardpunt commented on Oct 31, 2014

    @leonardpunt
    leonardpunt
    on Oct 31, 2014
    Author
    More actions

    @silvolu I gave the MVM's service account access to the other project and removed the credentials information from the configuration details. I'm only passing the project id along. However I get this error:

    Unauthorized.
    Error: Unauthorized.
        at Object.handleResp (/app/node_modules/gcloud/lib/common/util.js:168:14)
        at IncomingMessage.<anonymous> (/app/node_modules/gcloud/lib/datastore/request.js:461:14)
        at IncomingMessage.emit (events.js:117:20)
        at _stream_readable.js:943:16
        at process._tickCallback (node.js:419:13)
    
  9. silvolu commented on Oct 31, 2014

    @silvolu
    silvolu
    on Oct 31, 2014
    Contributor
    More actions

    @leonardpunt please use the storage based workaround for the moment. I'll investigate as soon as I can and update this bug.

  10. Guuz commented on Nov 3, 2014

    @Guuz
    Guuz
    on Nov 3, 2014
    More actions

    @silvolu In theory the pre-authorization should work. However there is an open issue that this does not. See https://code.google.com/p/googleappengine/issues/detail?id=11380
    I hope it is only broken for the datastore and works for cloud storage. That should solve our problem :)

    Thanks for the help!

  11. ryanseys commented on Dec 23, 2014

    @ryanseys
    ryanseys
    on Dec 23, 2014
    Contributor
    More actions

    I realise this is rather untimely but if you would rather use an environment variable to store your key, you can download the key in JSON form, then store it in an environment variable, it will work.

    .bashrc or .zshrc file:

    export GCLOUD_KEY='{"private_key_id":"XXX", "private_key":"YYY", "client_email":"[email protected]", "client_id":"ABC123", "type":"service_account"}'

    yourcode.js file:

    var projectId = process.env.GAE_LONG_APP_ID || process.env.DATASET_ID;
    var keyContents = process.env.GCLOUD_KEY;
    
    var gcloud = require('gcloud')({
      projectId: projectId,
      credentials: JSON.parse(keyContents) // parse the environment variable as JSON
    });
  12. ryanseys commented on Dec 23, 2014

    @ryanseys
    ryanseys
    on Dec 23, 2014
    Contributor
    More actions

    Additionally, the private key is stored in this json blob with newlines just written as \n and = encoded as \u003d so the correct format in this json blob is something like:

    "private_key": "-----BEGIN PRIVATE KEY-----\nXXX\nYYY\nZZZ\u003d\n-----END PRIVATE KEY-----\n"

    Perhaps the = was encoded improperly when you stored it in the environment variable?

  13. Guuz commented on Dec 24, 2014

    @Guuz
    Guuz
    on Dec 24, 2014
    More actions

    Thanks @ryanseys , that does sound a bit simpler than what we are doing now. I'll have a look after the holidays ;-)
    Have a nice one!

  14. ryanseys commented on Dec 24, 2014

    @ryanseys
    ryanseys
    on Dec 24, 2014
    Contributor
    More actions

    Great @Guuz! Have a great holiday! :)

  15. stephenplusplus commented on Jan 20, 2015

    @stephenplusplus
    stephenplusplus
    on Jan 20, 2015
    Contributor
    More actions

    @silvolu was there anything left to check on for this issue?

  16. 52 remaining items

  17. sofisl
    added a commit that references this issue on Feb 26, 2026

    chore: move mocha options to mocha.opts (#272)

    419f298
  18. codyoss
    added a commit that references this issue on Mar 5, 2026

    build(node): run linkinator against index.html (#1227) (#272)

    e397c85
  19. sofisl
    added 3 commits that reference this issue on Mar 5, 2026

    chore: migrate code from googleapis/gcp-metadata (#53)

    fa9a454

    feat!: require node 10 in engines field (#272)

    c3b6865

    feat: Add support for `NO_PROXY` (#272)

    a216ee1
  20. codyoss
    added 2 commits that reference this issue on Mar 9, 2026

    chore: Report warning on `.github/workflows/ci.yaml` (#272)

    935d653

    chore: Report warning on `.github/workflows/ci.yaml` (#272)

    2ce5c06
  21. GautamSharda
    added 2 commits that reference this issue on Mar 12, 2026

    build: enable release-trigger bot (#1212) (#272)

    80d7d77

    build: enable release-trigger bot (#1212) (#272)

    d6f765e
  22. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    refactor(ts): merge initial TypeScript conversion (googleapis#334)

    03e06b0
  23. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    chore: do not use npm ci (#272)

    ac5fd4f

    chore: do not use npm ci (#272)

    0781070
  24. feywind
    added a commit that references this issue on Mar 27, 2026

    (New) Synchronous Pull with Lease Management (#272)

    84c9b90
  25. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    chore: do not use npm ci (#272)

    900a498
  26. thiyaguk09
    added a commit that references this issue on May 5, 2026

    chore: do not use npm ci (googleapis#272)

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

Metadata

Metadata

Assignees

  • @ryanseys
    ryanseys

Labels

🚨This issue needs some love.library: cloud-profilerIssues transferred from another repositorytriage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    • Core Stable

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.