Search code examples
node.jsherokugoogle-cloud-platform

error:0909006C:PEM routines:get_name:no start line - for google cloud platform in heroku


When I try to use @google-cloud/storage it returns this error

Error: error:0909006C:PEM routines:get_name:no start line 
2021-12-13T10:36:19.800822+00:00 app[web.1]: at Sign.sign (internal/crypto/sig.js:110:29)
2021-12-13T10:36:19.800823+00:00 app[web.1]: at Object.sign (/app/node_modules/gtoken/node_modules/jwa/index.js:152:45) 
2021-12-13T10:36:19.800823+00:00 app[web.1]: at Object.jwsSign [as sign] (/app/node_modules/gtoken/node_modules/jws/lib/sign-stream.js:32:24) 
2021-12-13T10:36:19.800824+00:00 app[web.1]: at GoogleToken.requestToken (/app/node_modules/gtoken/build/src/index.js:225:31) 
2021-12-13T10:36:19.800824+00:00 app[web.1]: at GoogleToken.getTokenAsyncInner (/app/node_modules/gtoken/build/src/index.js:163:21) 
2021-12-13T10:36:19.800824+00:00 app[web.1]: at GoogleToken.getTokenAsync (/app/node_modules/gtoken/build/src/index.js:142:55) 
2021-12-13T10:36:19.800825+00:00 app[web.1]: at GoogleToken.getToken (/app/node_modules/gtoken/build/src/index.js:94:21) 
2021-12-13T10:36:19.800825+00:00 app[web.1]: at JWT.refreshTokenNoCache (/app/node_modules/google-auth-library/build/src/auth/jwtclient.js:171:36) 
2021-12-13T10:36:19.800826+00:00 app[web.1]: at JWT.refreshToken (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:152:24) 
2021-12-13T10:36:19.800826+00:00 app[web.1]: at JWT.getRequestMetadataAsync (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:284:28) 
2021-12-13T10:36:19.800827+00:00 app[web.1]: at JWT.getRequestMetadataAsync (/app/node_modules/google-auth-library/build/src/auth/jwtclient.js:94:26) 
2021-12-13T10:36:19.800827+00:00 app[web.1]: at JWT.getRequestHeaders (/app/node_modules/google-auth-library/build/src/auth/oauth2client.js:247:37) 
2021-12-13T10:36:19.800827+00:00 app[web.1]: at GoogleAuth.authorizeRequest (/app/node_modules/google-auth-library/build/src/auth/googleauth.js:600:38) 
2021-12-13T10:36:19.800828+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:95:5) 
2021-12-13T10:36:19.800828+00:00 app[web.1]: at async Promise.all (index 1) 
{ 2021-12-13T10:36:19.800829+00:00 app[web.1]: library: 'PEM routines', 
2021-12-13T10:36:19.800829+00:00 app[web.1]: function: 'get_name', 
2021-12-13T10:36:19.800829+00:00 app[web.1]: reason: 'no start line', 
2021-12-13T10:36:19.800829+00:00 app[web.1]: code: 'ERR_OSSL_PEM_NO_START_LINE' 
2021-12-13T10:36:19.800830+00:00 app[web.1]: } 
2021-12-13T10:36:19.800879+00:00 app[web.1]: Error error:0909006C:PEM routines:get_name:no start line 

It appears the error is based on the private key from google cloud service account

-----BEGIN PRIVATE KEY-----
ENTIREKEY
-----END PRIVATE KEY----- 

Solution

  • I solved this by removing the \n line in the keys and manually adding a new line eg:

    Private key: \n---BEGIN PRIVATE KEY----\nShfkkJHNJK\nJeidj\n---END PRIVATE KEY----\n

    To:

    
    ---BEGIN PRIVATE KEY----
    ShfkkJHNJK
    Jeidj
    ---END PRIVATE KEY----
    
    

    NB: Don't forget the last \n.