AWS SSO, Codecommit (GRC git clone link) and npm install

Viewed 50

Single Sign On (SSO) is implemented on AWS account. After running aws sso login, cloning a node a repo using (GRC link) works. However, running npm install in repo results in different errors.

ex. package.json

...
"dependencies": {
    ...
    "common-resource-1": "git+https://git-codecommit.us-east-1.amazonaws.com/v1/repos/common-resource-1#develop",
   ...
}
...

The errors

npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://git-codecommit.us-east-1.amazonaws.com/v1/repos/common-resource-1
npm ERR!
npm ERR! some-user@git-codecommit.us-east-1.amazonaws.com : Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

That makes sense because there are no ssh or https creds. git-remote-codecommit python package is installed as recommended buy AWS https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-git-remote-codecommit.html

However, the following returns repo information: /usr/local/bin/git ls-remote -h -t codecommit://common-resource-1

also tried with putting the following in package.json "common-resource-2": "codecommit::east-1://common-resource-2#develop", The error I get is

npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "codecommit:": codecommit::east-1://common-resource-2#develop

This is an issue for many repos, since other repos use common-resource-1 and common-resource-2 repos.

Any help with this would be greatly appreciated.

1 Answers

NPM CLI custom protocol

I am posting this answer here, but there should be a better one that is more robust.

For npm-cli (which is the same as what is run when using npm on commandline) in file node_modules/npm-package-arg/npa.js around line 232, add another case statement like:

case 'git+codecommit:':

And that is it.

There is an issue here though. The GRC links also user codecommit::us-east-1: protocol, where after the :: is the region where codecommit and the repo reside.

The current use of the case statements will not work for something like codecommit::us-east-1:. So to make it more robust, there will need to be better parsing of the "urls" in dependencies.

Related