Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Git Backend #43

Merged
merged 1 commit into from
Jul 3, 2020
Merged

Add Git Backend #43

merged 1 commit into from
Jul 3, 2020

Conversation

robert-cronin
Copy link
Contributor

@robert-cronin robert-cronin commented Jun 5, 2020

This PR will add a way to serve the vaults over http as git repos by exposing them via a git upload pack (stitched together from isomorphic-git/http-receiver). All it needs is an address (ip and port) to listen on (which is auto-generated). The other side is pulling vaults, this also needs an address (ip and port) which is provided by the peer discovery mechanism being implemented concurrently as a part of PR #40

Vault store is also implemented to keep track of which pubKeys have access to which vaults. This is also a convenience to pass into GitServer to retrieve the specific vault that git needs in order to use it's EFS instance to serve the vault from it's upperDir.

Fixes #31
This also in part solves #16, in terms of automatic commits. However, there is still the issue of sensible commit messages when committing more than 1 file (i.e. changing more than one secret at a time).

Fixes #22
Fixes #16
Fixes #32

@robert-cronin robert-cronin added the development Standard development label Jun 5, 2020
@robert-cronin robert-cronin self-assigned this Jun 5, 2020
@robert-cronin robert-cronin force-pushed the add-git-backend branch 2 times, most recently from 1b0525e to 3b00b13 Compare June 9, 2020 02:08
@CMCDragonkai
Copy link
Member

To be precise this enables "pull" behaviour. But not "push" behaviour. Eventually we need to apply capability theory to the connections between different Polykeys and vaults. That is what PK agents are allowed to pull from my vault, and what PK agents are allowed to push to my vault.

However in doing so, we then have to deal with merge conflicts. There are ways to resolve this automatically however.

@CMCDragonkai
Copy link
Member

Vault store is also implemented to keep track of which pubKeys have access to which vaults. This is also a convenience to pass into GitServer to retrieve the specific vault that git needs in order to use it's EFS instance to serve the vault from it's upperDir.

I originally thought that the above could be implemented through hardlinks or something else. A pub key may relate to multiple vaults and indicate some sort of relationship. These relationships are conceptualized as "capabilities".

@CMCDragonkai
Copy link
Member

Automatic commit messages are for convenience, we don't expect users of Polykey to understand Git. So we have to "specialize" the behaviour of git for secrets management. I'm sure they will appreciate it.

@CMCDragonkai
Copy link
Member

I'm thinking everything under GitServer/ should just be under git/. I suspect there's a lot more to managing the git stuff than just the serving of git. I suppose if we maintain directory names to be capitalized, then Git/ is fine too. But I've actually stopped doing that for my other projects. I know I did that for js-virtualfs, but we can leave that as so. So lower case directory names is fine. Upper case file names for actual class files. Lower case file names for non-classes. Also this depends on what the default export is. For some files, the default export is a class, but it has ancillary exports, and upper case name is fine here. In other cases, a file exports lots of little things, or the default export is a function or an object/dictionary/array. Then lowercase name.

Copy link
Member

@CMCDragonkai CMCDragonkai left a comment

Choose a reason for hiding this comment

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

A quick review of this PR. I have a feeling that the git portion of it has a lot of complexity, and it would be better to have that in a separate library, or at least extensively tested. It also has a bunch of code smells. And I'm not sure if alot of that code was just derived from some upstream library.

src/GitServer/GitServer.ts Outdated Show resolved Hide resolved
src/GitServer/GitServer.ts Outdated Show resolved Hide resolved
src/GitServer/GitServer.ts Outdated Show resolved Hide resolved
src/GitServer/GitServer.ts Outdated Show resolved Hide resolved
src/GitServer/GitServer.ts Outdated Show resolved Hide resolved
src/GitServer/pack-objects/GitCommit.ts Outdated Show resolved Hide resolved
src/GitServer/pack-objects/GitObjectManager.ts Outdated Show resolved Hide resolved
src/Polykey.ts Outdated Show resolved Hide resolved
src/Polykey.ts Outdated Show resolved Hide resolved
src/VaultStore/VaultStore.ts Outdated Show resolved Hide resolved
@CMCDragonkai
Copy link
Member

Needs rebase on top of master.

And most importantly lots more tests for this git stuff.

@CMCDragonkai
Copy link
Member

CMCDragonkai commented Jun 16, 2020 via email

@robert-cronin
Copy link
Contributor Author

robert-cronin commented Jun 16, 2020

Surely we don't have roll our own tls. This us very common.

Not sure what you mean by rolling our own TLS, we can use whatever HTTPS library is provided by the environment polykey is deployed in and the server certificate.pem and key.pem we generate.

I've also found PKI.js is very complicated but I've found something much easier in node-forge it comes with the ability to use just pure JavaScript or node if we're in that environment. Perhaps we can use this instead? PKIjs examples can extend to 900 lines of code to generate a certificate.

If you're talking about the self-signing part, this isn't intended on being a long term solution, I was planning on looking into the Web of trust concepts for peers acting as CAs.

Another thing is, I'm not entirely sure yet how to incorporate keybase keys into this whole thing. They are PGP blocks so technically we can extract the RSA keys out of them to use in the X.509 certificates but I don't see any way to do this in JavaScript as yet. Currently I am generating a new RSA keypair for the X.509 certificates.

@CMCDragonkai
Copy link
Member

PKI is an additional feature that is rather complicated, I want to have a discussion about this before going ahead. Any web of trust should right now be focusing on PGP only.

Copy link
Member

@CMCDragonkai CMCDragonkai left a comment

Choose a reason for hiding this comment

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

Some preliminary review, mostly focusing on the overabundance of dependencies that shouldn't really be there. For a strong crypto app, the less dependencies the better. It becomes easier to audit, and make sure we are not bringing any unknown vulnerabilities.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/lib/KeyManager.ts Outdated Show resolved Hide resolved
src/lib/Polykey.ts Outdated Show resolved Hide resolved
src/lib/Vault.ts Outdated Show resolved Hide resolved
src/lib/git/upload-pack/GitPktLine.ts Outdated Show resolved Hide resolved
src/lib/pki/PublicKeyInfrastructure.ts Outdated Show resolved Hide resolved
@robert-cronin
Copy link
Contributor Author

robert-cronin commented Jun 23, 2020

This PR is ready for review. Among the changes are a reduction of external dependencies, creating local methods for any minimally used packages and even removing some that weren't even used. Additionally, the domain modelling of the whole lib has been strengthened with the creation of a manager for each domain that polykey oversees. The polykey class now is much more like a convenience class that sets everything up for you than anything that manages Vaults/Keys/Peers. The latter have been delegated to their respective Manager classes.

Copy link
Member

@CMCDragonkai CMCDragonkai left a comment

Choose a reason for hiding this comment

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

I want to merge this so I can review the code in its entirety (including nix-shell and execution) and then meetup later to discuss some finer details. But I reckon, you need to add more comments and function documentation (mainly on the the algorithmic details and data flow logic). Anything that is more likely to change and not stabalise you can leave it not commented, but must be documented in the MR or issue, or new issues should be created to address TODO elements.

I haven't got through all of it yet. But this is review number 2!

But it's looking alot more cleaner and structured! :D

metadata Outdated Show resolved Hide resolved
src/cli/initPolykey.ts Show resolved Hide resolved
src/lib/Polykey.ts Show resolved Hide resolved
src/lib/git/GitServer.ts Outdated Show resolved Hide resolved
src/lib/git/GitServer.ts Show resolved Hide resolved
src/lib/keys/KeyManager.ts Outdated Show resolved Hide resolved
src/lib/keys/KeyManager.ts Show resolved Hide resolved
src/lib/keys/KeyManagerWorker.ts Outdated Show resolved Hide resolved
src/lib/peers/PeerManager.ts Outdated Show resolved Hide resolved
src/lib/utils.ts Outdated Show resolved Hide resolved
@CMCDragonkai
Copy link
Member

CMCDragonkai commented Jun 29, 2020 via email

@robert-cronin
Copy link
Contributor Author

robert-cronin commented Jun 30, 2020

Captains log, star-date 73962.7.
I have also added a fix for #22 to the PR. This is explained at the bottom of the linked issue.

@CMCDragonkai
Copy link
Member

Time to merge this!

We'll move on from the git problem. And now start on the IPC architecture and start to draft out how Electron, CLI, Agent, OS platforms and nativescript will all work together.

New issues for IPC required, @robert-cronin please link them at the end of this PR. And just squash/clean the commits.

@robert-cronin
Copy link
Contributor Author

Yes time to merge indeed!

I've added two issues (#51 and #50) from our discussion yesterday that I will also create a new branch and PR for.

@robert-cronin robert-cronin merged commit c5e87c0 into master Jul 3, 2020
@robert-cronin robert-cronin deleted the add-git-backend branch July 3, 2020 02:17
@robert-cronin robert-cronin linked an issue Jul 7, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development
2 participants