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

Feature/grpc api #27

Merged
merged 58 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
921cc2c
modify api and cmd folder structure enabling gRPC APIs to be implemented
MGTheTrain Dec 22, 2024
f6a2cf5
create proto file and generate client/server/request/response code fr…
MGTheTrain Dec 22, 2024
22f9d9b
modify generate swagger docs script
MGTheTrain Dec 23, 2024
98ef887
remove swagger generated docs
MGTheTrain Dec 23, 2024
ec95c8d
modify go version and remove Go module replace directives
MGTheTrain Dec 23, 2024
2089323
adjust docs package import
MGTheTrain Dec 23, 2024
43dd220
check in missing generated docs.go file
MGTheTrain Dec 23, 2024
0f26c64
install protobuf-compiler apt package
MGTheTrain Dec 23, 2024
f01a2b8
add script for generating go grpc files from proto file
MGTheTrain Dec 23, 2024
591452a
add install script and utilize it in postCreateCommand
MGTheTrain Dec 23, 2024
094982c
add make target for generating go grpc files
MGTheTrain Dec 23, 2024
a5adac1
modify proto file and generate go grpc code
MGTheTrain Dec 23, 2024
6d4e935
implement gRPC server methods
MGTheTrain Dec 23, 2024
f639120
rename services in RPC file; generate gRPC code and modify server imp…
MGTheTrain Dec 23, 2024
270e7a3
modify description
MGTheTrain Dec 23, 2024
b1bd3f1
pin go version 1.23 in devcontainer
MGTheTrain Dec 23, 2024
7a123b3
update the Go version in the go.mod files and revert changes related …
MGTheTrain Dec 23, 2024
47eac28
add Register...(...) functions; fix signatures and import proto package
MGTheTrain Dec 23, 2024
ad8a306
provide separate configurations for rest and grpc app
MGTheTrain Dec 23, 2024
53df72f
pin go version 1.23 and copy once
MGTheTrain Dec 23, 2024
57d00ef
utilize config port attribute
MGTheTrain Dec 23, 2024
e6f4672
add reference
MGTheTrain Dec 23, 2024
4953462
add external proto files; separate proto files from generated gRPC Go…
MGTheTrain Dec 23, 2024
a2ca6f2
modify protoc command in script, run script to generate gateway Go file
MGTheTrain Dec 23, 2024
da7d0e1
replace config struct with structs for grpc and rest config
MGTheTrain Dec 23, 2024
15599c6
add gateway_port key in yml file
MGTheTrain Dec 23, 2024
2bd1144
add GATEWAY_PORT env var
MGTheTrain Dec 23, 2024
38919d6
rename structs
MGTheTrain Dec 23, 2024
814ff0a
call proper Initialize...(...) functions; setup gRPC server and gatew…
MGTheTrain Dec 23, 2024
02a9e4a
modify console log
MGTheTrain Dec 23, 2024
2d87e13
use log.Printf(...)
MGTheTrain Dec 23, 2024
f2e8aa8
modify routes in annotations and generate Go grpc code
MGTheTrain Dec 23, 2024
2b0faf9
remove env vars on local development
MGTheTrain Dec 23, 2024
c036c60
remove obsolete argument
MGTheTrain Dec 23, 2024
98eb919
modify checks for potential inputs in List...(...) methods
MGTheTrain Dec 23, 2024
b32e51c
add reference
MGTheTrain Dec 23, 2024
c45a8ab
modify routes in annotations and generate Go grpc code
MGTheTrain Dec 23, 2024
e9dc629
add version.go file
MGTheTrain Dec 23, 2024
76c4cf1
modify files affected by missing multipart file uploads support with …
MGTheTrain Dec 23, 2024
4a7e9cc
generate Go gRPC files
MGTheTrain Dec 23, 2024
5337903
add reference
MGTheTrain Dec 23, 2024
7aecdbc
install grpcurl in devcontainer
MGTheTrain Dec 23, 2024
1f32fee
enable reflection
MGTheTrain Dec 23, 2024
965c9df
generate user id temporary internally
MGTheTrain Dec 23, 2024
8b041bd
add check
MGTheTrain Dec 23, 2024
e2f1623
access input attributes directly
MGTheTrain Dec 23, 2024
1b10772
expose ports in Dockerfile and setup gRPC service in docker-compose
MGTheTrain Dec 23, 2024
a4c876d
adjust method name
MGTheTrain Dec 23, 2024
aba6c67
modify README
MGTheTrain Dec 23, 2024
2ce9bea
modify and check bullet point
MGTheTrain Dec 23, 2024
1510c94
document changes
MGTheTrain Dec 23, 2024
abb8a54
adjust commands
MGTheTrain Dec 23, 2024
873cdc2
rename section
MGTheTrain Dec 23, 2024
4dd8c80
modify note in Upload blob section
MGTheTrain Dec 23, 2024
b812be6
replace verb
MGTheTrain Dec 23, 2024
5e67897
rephrase
MGTheTrain Dec 23, 2024
c48bbd7
fix linter findings on deprecated methods
MGTheTrain Dec 23, 2024
795d9ea
pin Go version 1.23.x in CI
MGTheTrain Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Docker images officially provided by Microsoft that can be utilized as base images
// https://hub.docker.com/_/microsoft-vscode-devcontainers
"name": "Tools for building and running Go projects",
"image": "mcr.microsoft.com/vscode/devcontainers/go:1.21",
"image": "mcr.microsoft.com/vscode/devcontainers/go:1.23",
// Features to add to the dev container. More info: https://containers.dev/features
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
},
"postCreateCommand": "apt-get update && apt-get install -y openssl opensc softhsm libssl-dev libengine-pkcs11-openssl",
"postCreateCommand": "./install.sh",
"remoteUser": "root"
}
7 changes: 7 additions & 0 deletions .devcontainer/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

apt-get update
apt-get install -y openssl opensc softhsm libssl-dev libengine-pkcs11-openssl protobuf-compiler
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
4 changes: 2 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Go 1.21.x 🐹
- name: Setup Go 1.23.x 🐹
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
go-version: '1.23.x'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Go 1.21.x 🐹
- name: Setup Go 1.23.x 🐹
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
go-version: '1.23.x'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Go 1.21.x 🐹
- name: Setup Go 1.23.x 🐹
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
go-version: '1.23.x'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Go 1.21.x 🐹
- name: Setup Go 1.23.x 🐹
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
go-version: '1.23.x'

- name: Install golangci-lint package 📦
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Expand Down
21 changes: 1 addition & 20 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {
"PORT": "8080",
"DATABASE_TYPE": "postgres",
"DATABASE_DSN": "user=postgres password=postgres host=localhost port=5432 sslmode=disable",
"DATABASE_NAME": "meta",
"BLOB_CONNECTOR_CLOUD_PROVIDER": "azure",
"BLOB_CONNECTOR_CONNECTION_STRING": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
"BLOB_CONNECTOR_CONTAINER_NAME": "blobs",
"KEY_CONNECTOR_CLOUD_PROVIDER": "azure",
"KEY_CONNECTOR_CONNECTION_STRING": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
"KEY_CONNECTOR_CONTAINER_NAME": "keys",
"LOGGER_LOG_LEVEL": "info",
"LOGGER_LOG_TYPE": "console",
"LOGGER_FILE_PATH": "",
"PKCS11_MODULE_PATH": "/usr/lib/softhsm/libsofthsm2.so",
"PKCS11_SO_PIN": "123456",
"PKCS11_USER_PIN": "234567",
"PKCS11_SLOT_ID": "0x0"
}
"program": "${fileDirname}"
}
]
}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Logging**: Integrated console and file logging (e.g. using structured logging with `logrus`)
- **Manage cryptographic material**: Enabled management of private/public key pairs and symmetric keys and implemented key lifecycle management including primarily key generation and key export
- **Secure file storage integration**: Provided mechanisms to securely store encrypted files in Azure Blob Storage
- **RESTful API**: Provided HTTP endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- **RESTful API**: Provided HTTP endpoints to manage cryptographic material and secure data at rest.
- **Documentation**: Provided clear API documentation (e.g. Swagger/OpenAPI) for ease of integration by other developers.
- **Versioning**: Implemented proper API versioning to maintain backward compatibility as the API evolves.
- **gRPC API**: Provided gRPC endpoints to manage cryptographic material and secure data at rest

## [0.1.0] - TBD-TBD-TBD

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ shut-down-docker-containers:

generate-swagger-docs:
@cd $(SCRIPT_DIR) && ./generate-docs.sh

generate-grpc-files:
@cd $(SCRIPT_DIR) && ./generate-grpc-files.sh
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ Interfaces (CLIs, gRPC APIs, RESTful Web APIs) for managing cryptographic keys a
- [OpenSSL with libp11 for Signing, Verifying and Encrypting, Decrypting](https://docs.yubico.com/hardware/yubihsm-2/hsm-2-user-guide/hsm2-openssl-libp11.html#rsa-pkcs)
- [pkcs11-tool usage](https://docs.nitrokey.com/nethsm/pkcs11-tool#id1)
- [OpenFGA online editor](https://play.fga.dev/sandbox/?store=github)
- [Adding gRPC-Gateway annotations to an existing proto file](https://grpc-ecosystem.github.io/grpc-gateway/docs/tutorials/adding_annotations/)
- [grpc-gateway Github repository](https://github.com/grpc-ecosystem/grpc-gateway)
- [grpcurl Github repository](https://github.com/fullstorydev/grpcurl)

## Features

### Functional

- [x] **RESTful API**: Provide HTTP endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- [ ] **gRPC API**: Provide gRPC endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- [x] **RESTful API**: Provide HTTP endpoints to manage cryptographic material and secure data at rest.
- [x] **gRPC API**: Provide gRPC endpoints to manage cryptographic material and secure data at rest.
- [x] **Asymmetric encryption and decryption**: Support RSA encryption algorithm for data protection.
- [x] **Symmetric encryption**: Support for symmetric key encryption (e.g. AES) for data protection.
- [x] **Signature creation and verification:** Support for hashing algorithms (e.g. SHA-256, SHA-512) to create digital signatures and the ability to verify these signatures using asymmetric keys (RSA, ECDSA).
Expand Down
22 changes: 22 additions & 0 deletions cmd/crypto-vault-grpc-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build stage
FROM golang:1.23-alpine AS build

WORKDIR /app

RUN apk update
COPY . .
RUN go mod tidy
RUN go build -o crypto_vault_service ./cmd/crypto-vault-grpc-service/crypto_vault_service.go

# Serve stage
FROM alpine:latest

WORKDIR /root/

RUN apk update && apk add --no-cache libc6-compat
COPY --from=build /app/crypto_vault_service .

EXPOSE 8090
EXPOSE 50051

ENTRYPOINT ["./crypto_vault_service"]
151 changes: 151 additions & 0 deletions cmd/crypto-vault-grpc-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# crypto-vault-grpc-service

## Table of Contents

+ [Summary](#summary)
+ [Getting started](#getting-started)

## Summary

gRPC service capable of managing cryptographic keys and securing data at rest (metadata, BLOB)

## Getting Started

Set up your IDE with the necessary Go tooling (such as the `delve` debugger or `grpcurl`) or use the provided [devcontainer.json file](../../.devcontainer/devcontainer.json). You can start the service by either running `go run crypto_vault_service.go` from this directory or by using the `spin-up-docker-containers Make target` from the [Makefile](../../Makefile).

### List available services

Run `grpcurl -plaintext localhost:50051 list`

The output should resemble:

```sh
grpc.reflection.v1.ServerReflection
grpc.reflection.v1alpha.ServerReflection
internal.BlobDownload
internal.BlobMetadata
internal.BlobUpload
internal.CryptoKeyDownload
internal.CryptoKeyMetadata
internal.CryptoKeyUpload
```

### Upload blob

**NOTE:** Multipart file uploads are not supported with grpc-gateway and `curl`. For more details checkout: `https://grpc-ecosystem.github.io/grpc-gateway/docs/mapping/binary_file_uploads/`.

Run:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"file_name": "task.tmp",
"file_content": "'$(base64 -w 0 task.tmp)'"
}' -plaintext localhost:50051 internal.BlobUpload/Upload
```

### List blob metadata

Run `curl -X 'GET' 'http://localhost:8090/api/v1/cvs/blobs' -H 'accept: application/json'`

Optionally:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"name": null,
"size": null,
"type": null,
"date_time_created": null,
"limit": null,
"offset": null,
"sort_by": null,
"sort_order": null
}' -plaintext localhost:50051 internal.BlobMetadata/ListMetadata
```

#### Get blob metadata

Run `curl -X 'GET' 'http://localhost:8090/api/v1/cvs/blobs/<blob_id>' -H 'accept: application/json'`

Optionally:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"id": "<blob_id>"
}' -plaintext localhost:50051 internal.BlobMetadata/GetMetadataById
```

### Download blob

Run `curl -X 'GET' 'http://localhost:8090/api/v1/cvs/blobs/<blob_id>/file' -H 'accept: application/json'`

Optionally:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"id": "<blob_id>",
"decryption_key_id": ""
}' -plaintext localhost:50051 internal.BlobDownload/DownloadById
```

### Delete blob

Run `curl -X 'DELETE' 'http://localhost:8090/api/v1/cvs/blobs/<blob_id>' -H 'accept: application/json'`

Optionally:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"id": "<blob_id>"
}' -plaintext localhost:50051 internal.BlobMetadata/DeleteById
```

### Generate and upload keys

Run:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"algorithm": "RSA",
"key_size": "2048"
}' -plaintext localhost:50051 internal.CryptoKeyUpload/Upload
```

### List key metadata

Run:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"algorithm": null,
"type": null,
"date_time_created": null,
"limit": null,
"offset": null,
"sort_by": null,
"sort_order": null
}' -plaintext localhost:50051 internal.CryptoKeyMetadata/ListMetadata
```

### Get key metadata

Run:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"id": "<key_id>"
}' -plaintext localhost:50051 internal.CryptoKeyMetadata/GetMetadataById
```

### Download key

Run:

```sh
grpcurl -import-path ./internal/api/grpc/v1/proto -proto internal/api/grpc/v1/proto/internal/service.proto -d '{
"id": "<key_id>"
}' -plaintext localhost:50051 internal.CryptoKeyDownload/DownloadById
```

### Delete key

Run `curl -X 'DELETE' 'http://localhost:8090/api/v1/cvs/keys/<key_id>' -H 'accept: application/json'`
Loading
Loading